15 #include "../core/pool_type.hpp" 16 #include "../core/smallmap_type.hpp" 17 #include "../core/smallmatrix_type.hpp" 18 #include "../station_base.h" 19 #include "../cargotype.h" 20 #include "../date_func.h" 76 template<
typename Tedge>
93 uint
Capacity()
const {
return this->edge.capacity; }
99 uint
Usage()
const {
return this->edge.usage; }
117 Date LastUpdate()
const {
return max(this->edge.last_unrestricted_update, this->edge.last_restricted_update); }
125 template<
typename Tnode,
typename Tedge>
140 NodeWrapper(Tnode &node, Tedge *edges, NodeID index) : node(node),
141 edges(edges), index(index) {}
147 uint
Supply()
const {
return this->node.supply; }
153 uint
Demand()
const {
return this->node.demand; }
159 StationID
Station()
const {
return this->node.station; }
181 template <
class Tedge,
class Tedge_wrapper,
class Titer>
217 current(current == INVALID_NODE ? current : base[current].next_edge)
226 this->current = this->base[this->current].next_edge;
227 return static_cast<Titer &
>(*this);
236 Titer ret(static_cast<Titer &>(*
this));
237 this->current = this->base[this->current].next_edge;
248 template<
class Tother>
251 return this->base == other.base && this->current == other.current;
261 template<
class Tother>
264 return this->base != other.base || this->current != other.current;
281 return FakePointer(this->
operator*());
301 void Restrict() { this->edge.last_unrestricted_update =
INVALID_DATE; }
302 void Release() { this->edge.last_restricted_update =
INVALID_DATE; }
411 this->node.supply +=
supply;
412 this->node.last_update =
_date;
430 this->node.demand =
demand;
433 void AddEdge(NodeID to, uint capacity, uint usage,
EdgeUpdateMode mode);
434 void UpdateEdge(NodeID to, uint capacity, uint usage,
EdgeUpdateMode mode);
435 void RemoveEdge(NodeID to);
455 inline static uint
Scale(uint val, uint target_age, uint orig_age)
457 return val > 0 ?
max(1U, val * target_age / orig_age) : 0;
468 void Init(uint size);
539 #define FOR_ALL_LINK_GRAPHS(var) FOR_ALL_ITEMS_FROM(LinkGraph, link_graph_index, var, 0)
ConstNode operator[](NodeID num) const
Get a const reference to a node with the specified id.
uint Demand() const
Get demand of wrapped node.
TileIndex xy
Location of the station referred to by the node.
void Init(TileIndex xy=INVALID_TILE, StationID st=INVALID_STATION, uint demand=0)
Create a node or clear it.
EdgeIterator Begin()
Get an iterator pointing to the start of the edges array.
SmallPair< NodeID, Tedge_wrapper > operator*() const
Dereference with operator*.
NodeID AddNode(const Station *st)
Add a node to the component and create empty edges associated with it.
static const uint COMPRESSION_INTERVAL
Minimum number of days between subsequent compressions of a LG.
NodeID index
ID of wrapped node.
Pool< LinkGraph, LinkGraphID, 32, 0xFFFF > LinkGraphPool
Type of the pool for link graph components.
An edge in the link graph.
Date LastUnrestrictedUpdate() const
Get the date of the last update to the edge's unrestricted capacity.
BaseEdgeIterator(Tedge *base, NodeID current)
Constructor.
Titer & operator++()
Prefix-increment.
Edge operator[](NodeID to)
Get an Edge.
Date LastUpdate() const
Get node's last update.
uint Supply() const
Get supply of wrapped node.
CargoID Cargo() const
Get the cargo ID this component's link graph refers to.
Tnode & node
Node being wrapped.
uint demand
Acceptance at the station.
uint Usage() const
Get edge's usage.
uint supply
Supply at the station.
friend const SaveLoad * GetLinkGraphJobDesc()
Get a SaveLoad array for a link graph job.
ConstEdgeIterator(const BaseEdge *edges, NodeID current)
Constructor.
ConstNode(const LinkGraph *lg, NodeID node)
Constructor.
Tindex index
Index of this pool item.
void ShiftDates(int interval)
Shift all dates by given interval.
LinkGraphPool _link_graph_pool
The actual pool with link graphs.
CargoID cargo
Cargo of this component's link graph.
A "fake" pointer to enable operator-> on temporaries.
uint usage
Usage of the link.
static T max(const T a, const T b)
Returns the maximum of two values.
StationID Station() const
Get ID of station belonging to wrapped node.
EdgeWrapper(Tedge &edge)
Wrap a an edge.
Edge(BaseEdge &edge)
Constructor.
A connected component of a link graph.
NodeID next_edge
Destination of next valid edge starting at the same source node.
Date last_update
When the supply was last updated.
static uint Scale(uint val, uint target_age, uint orig_age)
Scale a value from a link graph of age orig_age for usage in one of age target_age.
SmallPair< NodeID, Tedge_wrapper > * operator->()
Retrieve the pair by operator->.
uint Size() const
Get the current size of the component.
EdgeIterator End()
Get an iterator pointing beyond the end of the edges array.
uint Length() const
Get the number of items in the list.
void UpdateSupply(uint supply)
Update the node's supply and set last_update to the current date.
LinkGraph()
Bare constructor, only for save/load.
EdgeWrapper< const BaseEdge > ConstEdge
A constant edge class.
void SetDemand(uint demand)
Set the node's demand.
static const Date INVALID_DATE
Representation of an invalid date.
uint Monthly(uint base) const
Scale a value to its monthly equivalent, based on last compression.
static const uint MIN_TIMEOUT_DISTANCE
Minimum effective distance for timeout calculation.
Tedge & edge
Actual edge to be used.
ConstEdge operator[](NodeID to) const
Get a ConstEdge.
friend const SaveLoad * GetLinkGraphDesc()
Get a SaveLoad array for a link graph.
EdgeMatrix edges
Edges in the component.
Date last_restricted_update
When the restricted part of the link was last updated.
Date LastRestrictedUpdate() const
Get the date of the last update to the edge's restricted capacity.
An iterator for const edges.
Declaration of link graph types used for cargo distribution.
Wrapper for an edge (const or not) allowing retrieval, but no modification.
Date LastCompression() const
Get date of last compression.
Base class for all PoolItems.
EdgeIterator(BaseEdge *edges, NodeID current)
Constructor.
Base class for iterating across outgoing edges of a node.
Date LastUpdate() const
Get the date of the last update to any part of the edge's capacity.
void RemoveNode(NodeID id)
Remove a node from the link graph by overwriting it with the last node.
TileIndex XY() const
Get the location of the station associated with the node.
Base class for all pools.
void UpdateLocation(TileIndex xy)
Update the node's location on the map.
EdgeUpdateMode
Special modes for updating links.
uint capacity
Capacity of the link.
FakePointer(const SmallPair< NodeID, Tedge_wrapper > &pair)
Construct a fake pointer from a pair of NodeID and edge.
friend void SaveLoad_LinkGraph(LinkGraph &lg)
Save/load a link graph.
Titer operator++(int)
Postfix-increment.
uint32 TileIndex
The index/ID of a Tile.
bool operator==(const Tother &other)
Compare with some other edge iterator.
LinkGraph(CargoID cargo)
Real constructor.
static const byte INVALID_CARGO
Constant representing invalid cargo.
ConstEdgeIterator End() const
Get an iterator pointing beyond the end of the edges array.
Date last_compression
Last time the capacities and supplies were compressed.
bool operator!=(const Tother &other)
Compare for inequality with some other edge iterator.
int32 Date
The type to store our dates in.
Tedge * edges
Outgoing edges for wrapped node.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
StationID station
Station ID.
byte CargoID
Cargo slots to indicate a cargo type within a game.
An iterator for non-const edges.
NodeID current
Current offset in edges array.
Node operator[](NodeID num)
Get a node with the specified id.
ConstEdgeIterator Begin() const
Get an iterator pointing to the start of the edges array.
FakePointer operator->() const
Dereference with operator->.
NodeVector nodes
Nodes in the component.
uint Capacity() const
Get edge's capacity.
NodeWrapper(Tnode &node, Tedge *edges, NodeID index)
Wrap a node.
Date _date
Current date in days (day counter)
void Merge(LinkGraph *other)
Merge a link graph with another one.
Wrapper for a node (const or not) allowing retrieval, but no modification.
Node(LinkGraph *lg, NodeID node)
Constructor.
Date last_unrestricted_update
When the unrestricted part of the link was last updated.
Tedge * base
Array of edges being iterated.