12 #include "../stdafx.h" 13 #include "../core/pool_func.hpp" 16 #include "../safeguards.h" 32 this->demand = demand;
57 for (NodeID node1 = 0; node1 < this->
Size(); ++node1) {
60 for (NodeID node2 = 0; node2 < this->
Size(); ++node2) {
68 void LinkGraph::Compress()
71 for (NodeID node1 = 0; node1 < this->
Size(); ++node1) {
72 this->
nodes[node1].supply /= 2;
73 for (NodeID node2 = 0; node2 < this->
Size(); ++node2) {
91 NodeID first = this->
Size();
92 for (NodeID node1 = 0; node1 < other->
Size(); ++node1) {
94 NodeID new_node = this->
AddNode(st);
98 for (NodeID node2 = 0; node2 < node1; ++node2) {
101 forward = other->
edges[node1][node2];
102 backward = other->
edges[node2][node1];
111 new_start = other->
edges[node1][node1];
123 assert(id < this->
Size());
125 NodeID last_node = this->
Size() - 1;
126 for (NodeID i = 0; i <= last_node; ++i) {
127 (*this)[i].RemoveEdge(
id);
131 while (next != INVALID_NODE) {
132 if (next == last_node) {
139 node_edges[id] = node_edges[last_node];
161 NodeID new_node = this->
Size();
166 max(new_node + 1U, this->
edges.Height()));
174 new_edges[new_node].
next_edge = INVALID_NODE;
176 for (NodeID i = 0; i <= new_node; ++i) {
178 this->
edges[i][new_node].Init();
193 assert(this->
index != to);
213 assert(capacity > 0);
214 assert(usage <= capacity);
215 if (this->
edges[to].capacity == 0) {
216 this->AddEdge(to, capacity, usage, mode);
218 (*this)[to].Update(capacity, usage, mode);
228 if (this->
index == to)
return;
235 NodeID prev = this->
index;
236 NodeID next = this->
edges[this->
index].next_edge;
237 while (next != INVALID_NODE) {
245 next = this->
edges[next].next_edge;
263 assert(this->edge.capacity > 0);
264 assert(capacity >= usage);
268 this->edge.usage +=
usage;
270 this->edge.capacity =
max(this->edge.capacity, capacity);
271 this->edge.usage =
max(this->edge.usage, usage);
284 assert(this->
Size() == 0);
288 for (uint i = 0; i < size; ++i) {
289 this->
nodes[i].Init();
291 for (uint j = 0; j < size; ++j) column[j].
Init();
NodeID AddNode(const Station *st)
Add a node to the component and create empty edges associated with it.
An edge in the link graph.
LinkGraphPool _link_graph_pool("LinkGraph")
The actual pool with link graphs.
Stores station stats for a single cargo.
Tindex index
Index of this pool item.
void AddEdge(NodeID to, uint capacity, uint usage, EdgeUpdateMode mode)
Fill an edge with values from a link.
void ShiftDates(int interval)
Shift all dates by given interval.
CargoID cargo
Cargo of this component's link graph.
uint usage
Usage of the link.
static T max(const T a, const T b)
Returns the maximum of two values.
GoodsEntry goods[NUM_CARGO]
Goods at this station.
T * Append(uint to_add=1)
Append an item and return it.
A connected component of a link graph.
void Resize(uint num_items)
Set the size of the vector, effectively truncating items from the end or appending uninitialised ones...
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.
uint Size() const
Get the current size of the component.
void Resize(uint new_width, uint new_height)
Set the size to a specific width and height, preserving item positions as far as possible in the proc...
LinkGraphID link_graph
Link graph this station belongs to.
byte status
Status of this cargo, see GoodsEntryStatus.
static const Date INVALID_DATE
Representation of an invalid date.
NodeID node
ID of node in link graph referring to this goods entry.
EdgeMatrix edges
Edges in the component.
Date last_restricted_update
When the restricted part of the link was last updated.
void Init()
Create an edge.
void RemoveNode(NodeID id)
Remove a node from the link graph by overwriting it with the last node.
Base class for all pools.
EdgeUpdateMode
Special modes for updating links.
uint capacity
Capacity of the link.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
void EraseColumn(uint x)
Erase a column, replacing it with the last one.
void Init(uint size)
Resize the component and fill it with empty nodes and edges.
uint32 TileIndex
The index/ID of a Tile.
TileIndex xy
Base tile of the station.
void Erase(T *item)
Removes given item from this vector.
Date last_compression
Last time the capacities and supplies were compressed.
Declaration of link graph classes used for cargo distribution.
int32 Date
The type to store our dates in.
void Update(uint capacity, uint usage, EdgeUpdateMode mode)
Update an edge.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
const T * Get(uint index) const
Get the pointer to item "number" (const)
NodeVector nodes
Nodes in the component.
void RemoveEdge(NodeID to)
Remove an outgoing edge from this node.
void UpdateEdge(NodeID to, uint capacity, uint usage, EdgeUpdateMode mode)
Creates an edge if none exists yet or updates an existing edge.
static Station * Get(size_t index)
Gets station with given index.
Date _date
Current date in days (day counter)
void Merge(LinkGraph *other)
Merge a link graph with another one.
Set when the station accepts the cargo currently for final deliveries.
Date last_unrestricted_update
When the unrestricted part of the link was last updated.