File diff r21528:9a05538a9ffc → r21529:6bf3ee37953c
src/linkgraph/linkgraph.cpp
Show inline comments
 
@@ -18,30 +18,30 @@
 
/* Initialize the link-graph-pool */
 
LinkGraphPool _link_graph_pool("LinkGraph");
 
INSTANTIATE_POOL_METHODS(LinkGraph)
 

	
 
/**
 
 * Create a node or clear it.
 
 * @param xy Location of the associated station.
 
 * @param st ID of the associated station.
 
 * @param demand Demand for cargo at the station.
 
 */
 
inline void LinkGraph::BaseNode::Init(StationID st, uint demand)
 
inline void LinkGraph::BaseNode::Init(TileIndex xy, StationID st, uint demand)
 
{
 
	this->xy = xy;
 
	this->supply = 0;
 
	this->demand = demand;
 
	this->station = st;
 
	this->last_update = INVALID_DATE;
 
}
 

	
 
/**
 
 * Create an edge.
 
 * @param distance Length of the link as manhattan distance.
 
 */
 
inline void LinkGraph::BaseEdge::Init(uint distance)
 
inline void LinkGraph::BaseEdge::Init()
 
{
 
	this->distance = distance;
 
	this->capacity = 0;
 
	this->usage = 0;
 
	this->last_unrestricted_update = INVALID_DATE;
 
	this->last_restricted_update = INVALID_DATE;
 
	this->next_edge = INVALID_NODE;
 
}
 
@@ -144,27 +144,12 @@ void LinkGraph::RemoveNode(NodeID id)
 
	/* Not doing EraseRow here, as having the extra invalid row doesn't hurt
 
	 * and removing it would trigger a lot of memmove. The data has already
 
	 * been copied around in the loop above. */
 
}
 

	
 
/**
 
 * Update distances between the given node and all others.
 
 * @param id Node that changed position.
 
 * @param xy New position of the node.
 
 */
 
void LinkGraph::UpdateDistances(NodeID id, TileIndex xy)
 
{
 
	assert(id < this->Size());
 
	for (NodeID other = 0; other < this->Size(); ++other) {
 
		if (other == id) continue;
 
		this->edges[id][other].distance = this->edges[other][id].distance =
 
				DistanceMaxPlusManhattan(xy, Station::Get(this->nodes[other].station)->xy);
 
	}
 
}
 

	
 
/**
 
 * Add a node to the component and create empty edges associated with it. Set
 
 * the station's last_component to this component. Calculate the distances to all
 
 * other nodes. The distances to _all_ nodes are important as the demand
 
 * calculator relies on their availability.
 
 * @param st New node's station.
 
 * @return New node's ID.
 
@@ -177,24 +162,23 @@ NodeID LinkGraph::AddNode(const Station 
 
	this->nodes.Append();
 
	/* Avoid reducing the height of the matrix as that is expensive and we
 
	 * most likely will increase it again later which is again expensive. */
 
	this->edges.Resize(new_node + 1U,
 
			max(new_node + 1U, this->edges.Height()));
 

	
 
	this->nodes[new_node].Init(st->index,
 
	this->nodes[new_node].Init(st->xy, st->index,
 
			HasBit(good.status, GoodsEntry::GES_ACCEPTANCE));
 

	
 
	BaseEdge *new_edges = this->edges[new_node];
 

	
 
	/* Reset the first edge starting at the new node */
 
	new_edges[new_node].next_edge = INVALID_NODE;
 

	
 
	for (NodeID i = 0; i <= new_node; ++i) {
 
		uint distance = DistanceMaxPlusManhattan(st->xy, Station::Get(this->nodes[i].station)->xy);
 
		new_edges[i].Init(distance);
 
		this->edges[i][new_node].Init(distance);
 
		new_edges[i].Init();
 
		this->edges[i][new_node].Init();
 
	}
 
	return new_node;
 
}
 

	
 
/**
 
 * Fill an edge with values from a link. Set the restricted or unrestricted