11#include "../core/pool_func.hpp"
12#include "../window_func.h"
16#include "../safeguards.h"
52 for (NodeID node_id = 0; node_id < this->
Size(); ++node_id) {
53 (*this)[node_id].flows.erase(from);
80 if (this->
thread.joinable()) {
104 uint16_t size = this->
Size();
105 for (NodeID node_id = 0; node_id < size; ++node_id) {
118 if (ge.
link_graph != this->link_graph.index || ge.
node != node_id) {
126 for (
const auto &edge : from.
edges) {
127 if (edge.Flow() == 0)
continue;
128 NodeID dest_id = edge.base.dest_node;
129 StationID to = this->
nodes[dest_id].base.station;
131 if (st2 ==
nullptr || st2->
goods[this->Cargo()].
link_graph != this->link_graph.index ||
132 st2->
goods[this->Cargo()].
node != dest_id ||
133 !(*lg)[node_id].HasEdgeTo(dest_id) ||
151 for (FlowStatMap::iterator it(ge.
flows.begin()); it != ge.
flows.end();) {
152 FlowStatMap::iterator new_it = flows.find(it->first);
153 if (new_it == flows.end()) {
155 it->second.Invalidate();
158 FlowStat shares(INVALID_STATION, 1);
159 it->second.SwapShares(shares);
160 ge.
flows.erase(it++);
161 for (FlowStat::SharesMap::const_iterator shares_it(shares.
GetShares()->begin());
162 shares_it != shares.
GetShares()->end(); ++shares_it) {
167 it->second.SwapShares(new_it->second);
172 ge.
flows.insert(flows.begin(), flows.end());
184 uint size = this->
Size();
185 this->
nodes.reserve(size);
186 for (uint i = 0; i < size; ++i) {
205 if (this->
parent != base) {
223 if (this->
parent !=
nullptr) {
225 if (max_saturation != UINT_MAX) {
226 uint usable_cap = edge.
base.
capacity * max_saturation / 100;
227 if (usable_cap > edge.
Flow()) {
228 new_flow = std::min(new_flow, usable_cap - edge.
Flow());
233 new_flow = this->
parent->
AddFlow(new_flow, job, max_saturation);
234 if (this->
flow == 0 && new_flow > 0) {
235 job[this->
parent->
node].paths.push_front(
this);
239 this->
flow += new_flow;
249 distance(source ? 0 : UINT_MAX),
250 capacity(source ? UINT_MAX : 0),
251 free_capacity(source ? INT_MAX : INT_MIN),
252 flow(0), node(n), origin(source ? n : INVALID_NODE),
253 num_children(0), parent(nullptr)
Storage class for Economy time constants.
Flow descriptions by origin stations.
StationIDStack DeleteFlows(StationID via)
Delete all flows at a station for specific cargo and destination.
void RestrictFlows(StationID via)
Restrict all flows at a station for specific cargo and destination.
Flow statistics telling how much flow should be sent along a link.
const SharesMap * GetShares() const
Get the actual shares as a const pointer so that they can be iterated over.
Class for calculation jobs to be run on link graphs.
NodeAnnotationVector nodes
Extra node data necessary for link graph calculation.
~LinkGraphJob()
Join the link graph job and destroy it.
LinkGraphJob()
Bare constructor, only for save/load.
bool IsJobAborted() const
Check if job has been aborted.
void Init()
Initialize the link graph job: Resize nodes and edges and populate them.
void SpawnThread()
Spawn a thread if possible and run the link graph job in the thread.
void EraseFlows(NodeID from)
Erase all flows originating at a specific node.
NodeID Size() const
Get the size of the underlying link graph.
const LinkGraph link_graph
Link graph to by analyzed. Is copied when job is started and mustn't be modified later.
CargoID Cargo() const
Get the cargo of the underlying link graph.
void JoinThread()
Join the calling thread with this job's thread if threading is enabled.
std::thread thread
Thread the job is running in or a default-constructed thread if it's running in the main thread.
static void Run(LinkGraphJob *job)
Run all handlers for the given Job.
A connected component of a link graph.
NodeVector nodes
Nodes in the component.
A leg of a path in the link graph.
Path(NodeID n, bool source=false)
Create a leg of a path in the link graph.
void AddFlow(uint f)
Increase the flow on this leg only by the specified amount.
static Path * invalid_path
Static instance of an invalid path.
NodeID origin
Link graph node this path originates from.
uint num_children
Number of child legs that have been forked from this path.
void Detach()
Detach this path from its parent.
uint flow
Flow the current run of the mcf solver assigns.
uint distance
Sum(distance of all legs up to this one).
void Fork(Path *base, uint cap, int free_cap, uint dist)
Add this path as a new child to the given base path, thus making this path a "fork" of the base path.
NodeID node
Link graph node this leg passes.
uint capacity
This capacity is min(capacity) fom all edges.
Path * parent
Parent leg of this one.
int free_capacity
This capacity is min(edge.capacity - edge.flow) for the current run of Dijkstra.
Minimal stack that uses a pool to avoid pointers.
Titem Pop()
Pop an item from the stack.
bool IsEmpty() const
Check if the stack is empty.
static constexpr TimerGame< struct Economy >::Date INVALID_DATE
Representation of an invalid date.
Timer that is increased every 27ms, and counts towards economy time units, expressed in days / months...
fluid_settings_t * settings
FluidSynth settings handle.
@ DT_MANUAL
Manual distribution. No link graph calculations are run.
Declaration of link graph job classes used for cargo distribution.
Declaration of link graph schedule used for cargo distribution.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
void RerouteCargo(Station *st, CargoID c, StationID avoid, StationID avoid2)
Reroute cargo of type c at station st or in any vehicles unloading there.
LinkGraphSettings linkgraph
settings for link graph calculations
Stores station stats for a single cargo.
FlowStatMap flows
Planned flows through this station.
NodeID node
ID of node in link graph referring to this goods entry.
LinkGraphID link_graph
Link graph this station belongs to.
Annotation for a link graph edge.
const LinkGraph::BaseEdge & base
Reference to the edge that is annotated.
uint Flow() const
Get the total flow on the edge.
void AddFlow(uint flow)
Add some flow.
Annotation for a link graph node.
const LinkGraph::BaseNode & base
Reference to the node that is annotated.
std::vector< EdgeAnnotation > edges
Annotations for all edges originating at this node.
FlowStatMap flows
Planned flows to other nodes.
uint capacity
Capacity of the link.
StationID station
Station ID.
Tindex index
Index of this pool item.
static bool CleaningPool()
Returns current state of pool cleaning - yes or no.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static Titem * Get(size_t index)
Returns Titem with given index.
Base class for all pools.
static Station * GetIfValid(size_t index)
Returns station if the index is a valid index for this station type.
GoodsEntry goods[NUM_CARGO]
Goods at this station.
bool StartNewThread(std::thread *thr, const char *name, TFn &&_Fx, TArgs &&... _Ax)
Start a new thread.
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
@ WC_STATION_VIEW
Station view; Window numbers: