Go to the documentation of this file.
10 #include "../stdafx.h"
11 #include "../core/pool_func.hpp"
14 #include "../safeguards.h"
30 this->demand = demand;
55 for (NodeID node1 = 0; node1 < this->
Size(); ++node1) {
58 for (NodeID node2 = 0; node2 < this->
Size(); ++node2) {
66 void LinkGraph::Compress()
69 for (NodeID node1 = 0; node1 < this->
Size(); ++node1) {
70 this->
nodes[node1].supply /= 2;
71 for (NodeID node2 = 0; node2 < this->
Size(); ++node2) {
72 BaseEdge &edge = this->
edges[node1][node2];
73 if (edge.capacity > 0) {
74 edge.
capacity = std::max(1U, edge.capacity / 2);
89 NodeID first = this->
Size();
90 for (NodeID node1 = 0; node1 < other->
Size(); ++node1) {
92 NodeID new_node = this->
AddNode(st);
96 for (NodeID node2 = 0; node2 < node1; ++node2) {
99 forward = other->
edges[node1][node2];
100 backward = other->
edges[node2][node1];
109 new_start = other->
edges[node1][node1];
121 assert(id < this->
Size());
123 NodeID last_node = this->
Size() - 1;
124 for (NodeID i = 0; i <= last_node; ++i) {
125 (*this)[i].RemoveEdge(
id);
129 while (next != INVALID_NODE) {
130 if (next == last_node) {
137 node_edges[id] = node_edges[last_node];
143 this->
nodes.pop_back();
162 NodeID new_node = this->
Size();
163 this->
nodes.emplace_back();
166 this->
edges.
Resize(new_node + 1U, std::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;
261 assert(this->edge.capacity > 0);
262 assert(capacity >= usage);
265 this->edge.capacity += capacity;
266 this->edge.usage += usage;
268 this->edge.capacity = std::max(this->edge.capacity, capacity);
269 this->edge.usage = std::max(this->edge.usage, usage);
282 assert(this->
Size() == 0);
284 this->
nodes.resize(size);
286 for (uint i = 0; i < size; ++i) {
287 this->
nodes[i].Init();
289 for (uint j = 0; j < size; ++j) column[j].
Init();
uint32 TileIndex
The index/ID of a Tile.
GoodsEntry goods[NUM_CARGO]
Goods at this station.
EdgeMatrix edges
Edges in the component.
void AddEdge(NodeID to, uint capacity, uint usage, EdgeUpdateMode mode)
Fill an edge with values from a link.
A connected component of a link graph.
void UpdateEdge(NodeID to, uint capacity, uint usage, EdgeUpdateMode mode)
Creates an edge if none exists yet or updates an existing edge.
uint usage
Usage of the link.
NodeVector nodes
Nodes in the component.
@ EUM_UNRESTRICTED
Use unrestricted link.
Tindex index
Index of this pool item.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
void Init()
Create an edge.
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.
@ EUM_INCREASE
Increase capacity.
static Station * Get(size_t index)
Gets station with given index.
void RemoveNode(NodeID id)
Remove a node from the link graph by overwriting it with the last node.
void Init(uint size)
Resize the component and fill it with empty nodes and edges.
byte status
Status of this cargo, see GoodsEntryStatus.
EdgeUpdateMode
Special modes for updating links.
Date last_update
When the supply was last updated.
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...
Date _date
Current date in days (day counter)
uint capacity
Capacity of the link.
NodeID node
ID of node in link graph referring to this goods entry.
int32 Date
The type to store our dates in.
An edge in the link graph.
uint Size() const
Get the current size of the component.
void EraseColumn(uint x)
Erase a column, replacing it with the last one.
LinkGraphID link_graph
Link graph this station belongs to.
@ EUM_REFRESH
Refresh capacity.
LinkGraphPool _link_graph_pool("LinkGraph")
The actual pool with link graphs.
void ShiftDates(int interval)
Shift all dates by given interval.
Date last_unrestricted_update
When the unrestricted part of the link was last updated.
Stores station stats for a single cargo.
Base class for all pools.
NodeID AddNode(const Station *st)
Add a node to the component and create empty edges associated with it.
void RemoveEdge(NodeID to)
Remove an outgoing edge from this node.
static const Date INVALID_DATE
Representation of an invalid date.
CargoID cargo
Cargo of this component's link graph.
void Update(uint capacity, uint usage, EdgeUpdateMode mode)
Update an edge.
Date last_compression
Last time the capacities and supplies were compressed.
@ GES_ACCEPTANCE
Set when the station accepts the cargo currently for final deliveries.
void Merge(LinkGraph *other)
Merge a link graph with another one.
TileIndex xy
Base tile of the station.
@ EUM_RESTRICTED
Use restricted link.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
Date last_restricted_update
When the restricted part of the link was last updated.
uint capacity
The available space for storing items.
NodeID next_edge
Destination of next valid edge starting at the same source node.