56 for (NodeID node1 = 0; node1 < this->
Size(); ++node1) {
66void LinkGraph::Compress()
69 for (NodeID node1 = 0; node1 < this->
Size(); ++node1) {
70 this->
nodes[node1].supply /= 2;
72 if (edge.capacity > 0) {
73 uint new_capacity = std::max(1U, edge.capacity / 2);
74 if (edge.capacity < (1 << 16)) {
75 edge.travel_time_sum = edge.travel_time_sum * new_capacity / edge.capacity;
76 }
else if (edge.travel_time_sum != 0) {
77 edge.travel_time_sum = std::max<uint64_t>(1, edge.travel_time_sum / 2);
79 edge.capacity = new_capacity;
94 NodeID first = this->
Size();
95 for (NodeID node1 = 0; node1 < other->
Size(); ++node1) {
97 NodeID new_node = this->
AddNode(st);
103 BaseEdge &new_edge = this->
nodes[new_node].edges.emplace_back(first + e.dest_node);
118 assert(id < this->
Size());
120 NodeID last_node = this->
Size() - 1;
125 this->
nodes.pop_back();
126 for (
auto &n : this->
nodes) {
128 auto [first, last] = std::equal_range(n.edges.begin(), n.edges.end(),
id);
130 auto insert = n.edges.erase(first, last);
132 if (!n.edges.empty() && n.edges.back().dest_node == last_node) {
134 n.edges.back().dest_node = id;
135 n.edges.insert(insert, n.edges.back());
153 NodeID new_node = this->
Size();
172 BaseEdge &edge = *this->edges.emplace(std::upper_bound(this->edges.begin(), this->edges.end(), to), to);
190 assert(capacity > 0);
191 assert(usage <= capacity);
193 this->
AddEdge(to, capacity, usage, travel_time, modes);
195 this->GetEdge(to)->Update(capacity, usage, travel_time, modes);
205 auto [first, last] = std::equal_range(this->edges.begin(), this->edges.end(), to);
206 this->edges.erase(first, last);
221 assert(this->capacity > 0);
227 }
else if (travel_time == 0) {
233 this->usage +=
usage;
236 this->capacity = std::max(this->capacity,
capacity);
237 this->
travel_time_sum =
static_cast<uint64_t
>(travel_time) * this->capacity;
238 }
else if (
capacity > this->capacity) {
242 this->usage = std::max(this->usage,
usage);
255 assert(this->
Size() == 0);
256 this->
nodes.resize(size);
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
A connected component of a link graph.
void Merge(LinkGraph *other)
Merge a link graph with another one.
void Init(uint size)
Resize the component and fill it with empty nodes and edges.
CargoType cargo
Cargo of this component's link graph.
NodeVector nodes
Nodes in the component.
void ShiftDates(TimerGameEconomy::Date interval)
Shift all dates by given interval.
NodeID AddNode(const Station *st)
Add a node to the component and create empty edges associated with it.
NodeID Size() const
Get the current size of the component.
void RemoveNode(NodeID id)
Remove a node from the link graph by overwriting it with the last node.
static uint Scale(uint val, TimerGameEconomy::Date target_age, TimerGameEconomy::Date orig_age)
Scale a value from a link graph of age orig_age for usage in one of age target_age.
LinkGraph(LinkGraphID index, CargoType cargo=INVALID_CARGO)
Real constructor.
TimerGameEconomy::Date last_compression
Last time the capacities and supplies were compressed.
static constexpr TimerGame< struct Economy >::Date INVALID_DATE
static Date date
Current date in days (day counter).
Declaration of link graph classes used for cargo distribution.
LinkGraphPool _link_graph_pool
The actual pool with link graphs.
Pool< LinkGraph, LinkGraphID, 32 > LinkGraphPool
Type of the pool for link graph components.
@ Refresh
Refresh capacity.
@ Unrestricted
Use unrestricted link.
@ Increase
Increase capacity.
@ Restricted
Use restricted link.
Some methods of Pool are placed here in order to reduce compilation time and binary size.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
A number of safeguards to prevent using unsafe methods.
Definition of base types and functions in a cross-platform compatible way.
TileIndex xy
Base tile of the station.
Stores station stats for a single cargo.
States status
Status of this cargo, see State.
@ Acceptance
Set when the station accepts the cargo currently for final deliveries.
An edge in the link graph.
TimerGameEconomy::Date last_restricted_update
When the restricted part of the link was last updated.
uint64_t travel_time_sum
Sum of the travel times of the link, in ticks.
NodeID dest_node
Destination of the edge.
uint usage
Usage of the link.
void Update(uint capacity, uint usage, uint32_t time, EdgeUpdateModes modes)
Update an edge.
BaseEdge(NodeID dest_node=INVALID_NODE)
Create an edge.
TimerGameEconomy::Date last_unrestricted_update
When the unrestricted part of the link was last updated.
uint capacity
Capacity of the link.
StationID station
Station ID.
TimerGameEconomy::Date last_update
When the supply was last updated.
BaseNode(TileIndex xy=INVALID_TILE, StationID st=StationID::Invalid(), uint demand=0)
Create a node or clear it.
uint supply
Supply at the station.
void RemoveEdge(NodeID to)
Remove an outgoing edge from this node.
void AddEdge(NodeID to, uint capacity, uint usage, uint32_t time, EdgeUpdateModes modes)
Fill an edge with values from a link.
TileIndex xy
Location of the station referred to by the node.
uint demand
Acceptance at the station.
void UpdateEdge(NodeID to, uint capacity, uint usage, uint32_t time, EdgeUpdateModes modes)
Creates an edge if none exists yet or updates an existing edge.
bool HasEdgeTo(NodeID dest) const
Check if an edge to a destination is present.
static Station * Get(auto index)
std::array< GoodsEntry, NUM_CARGO > goods
Goods at this station.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.