57 for (NodeID node1 = 0; node1 < this->
Size(); ++node1) {
67void LinkGraph::Compress()
70 for (NodeID node1 = 0; node1 < this->
Size(); ++node1) {
71 this->
nodes[node1].supply /= 2;
73 if (edge.capacity > 0) {
74 uint new_capacity = std::max(1U, edge.capacity / 2);
75 if (edge.capacity < (1 << 16)) {
76 edge.travel_time_sum = edge.travel_time_sum * new_capacity / edge.capacity;
77 }
else if (edge.travel_time_sum != 0) {
78 edge.travel_time_sum = std::max<uint64_t>(1, edge.travel_time_sum / 2);
80 edge.capacity = new_capacity;
95 NodeID first = this->
Size();
96 for (NodeID node1 = 0; node1 < other->
Size(); ++node1) {
98 NodeID new_node = this->
AddNode(st);
104 BaseEdge &new_edge = this->
nodes[new_node].edges.emplace_back(first + e.dest_node);
119 assert(id < this->
Size());
121 NodeID last_node = this->
Size() - 1;
126 this->
nodes.pop_back();
127 for (
auto &n : this->
nodes) {
129 auto [first, last] = std::equal_range(n.edges.begin(), n.edges.end(),
id);
131 auto insert = n.edges.erase(first, last);
133 if (!n.edges.empty() && n.edges.back().dest_node == last_node) {
135 n.edges.back().dest_node = id;
136 n.edges.insert(insert, n.edges.back());
154 NodeID new_node = this->
Size();
173 BaseEdge &edge = *this->edges.emplace(std::upper_bound(this->edges.begin(), this->edges.end(), to), to);
191 assert(capacity > 0);
192 assert(usage <= capacity);
194 this->
AddEdge(to, capacity, usage, travel_time, modes);
196 this->GetEdge(to)->Update(capacity, usage, travel_time, modes);
206 auto [first, last] = std::equal_range(this->edges.begin(), this->edges.end(), to);
207 this->edges.erase(first, last);
222 assert(this->capacity > 0);
228 }
else if (travel_time == 0) {
234 this->usage +=
usage;
237 this->capacity = std::max(this->capacity,
capacity);
238 this->
travel_time_sum =
static_cast<uint64_t
>(travel_time) * this->capacity;
239 }
else if (
capacity > this->capacity) {
243 this->usage = std::max(this->usage,
usage);
256 assert(this->
Size() == 0);
257 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.