OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
10 #include "../stdafx.h"
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 uint size = this->
Size();
105 for (NodeID node_id = 0; node_id < size; ++node_id) {
106 Node from = (*this)[node_id];
118 if (ge.
link_graph != this->link_graph.index || ge.
node != node_id) {
127 if (from[it->first].Flow() == 0)
continue;
128 StationID to = (*this)[it->first].Station();
130 if (st2 ==
nullptr || st2->
goods[this->Cargo()].
link_graph != this->link_graph.index ||
131 st2->
goods[this->Cargo()].
node != it->first ||
132 (*lg)[node_id][it->first].LastUpdate() ==
INVALID_DATE) {
139 }
else if ((*lg)[node_id][it->first].LastUnrestrictedUpdate() ==
INVALID_DATE) {
149 for (FlowStatMap::iterator it(ge.
flows.begin()); it != ge.
flows.end();) {
150 FlowStatMap::iterator new_it = flows.find(it->first);
151 if (new_it == flows.end()) {
153 it->second.Invalidate();
156 FlowStat shares(INVALID_STATION, 1);
157 it->second.SwapShares(shares);
158 ge.
flows.erase(it++);
159 for (FlowStat::SharesMap::const_iterator shares_it(shares.
GetShares()->begin());
160 shares_it != shares.
GetShares()->end(); ++shares_it) {
165 it->second.SwapShares(new_it->second);
170 ge.
flows.insert(flows.begin(), flows.end());
182 uint size = this->
Size();
183 this->
nodes.resize(size);
185 for (uint i = 0; i < size; ++i) {
188 for (uint j = 0; j < size; ++j) {
189 node_edges[j].
Init();
211 this->undelivered_supply = supply;
213 new (&this->paths) PathList;
226 this->capacity = std::min(base->
capacity, cap);
227 this->free_capacity = std::min(base->
free_capacity, free_cap);
228 this->distance = base->
distance + dist;
229 assert(this->distance > 0);
230 if (this->parent != base) {
235 this->origin = base->
origin;
248 if (this->parent !=
nullptr) {
250 if (max_saturation != UINT_MAX) {
251 uint usable_cap = edge.
Capacity() * max_saturation / 100;
252 if (usable_cap > edge.
Flow()) {
253 new_flow = std::min(new_flow, usable_cap - edge.
Flow());
258 new_flow = this->parent->AddFlow(new_flow, job, max_saturation);
259 if (this->flow == 0 && new_flow > 0) {
260 job[this->parent->node].Paths().push_front(
this);
264 this->flow += new_flow;
274 distance(source ? 0 : UINT_MAX),
275 capacity(source ? UINT_MAX : 0),
276 free_capacity(source ? INT_MAX : INT_MIN),
277 flow(0), node(n), origin(source ? n : INVALID_NODE),
278 num_children(0), parent(nullptr)
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-...
Minimal stack that uses a pool to avoid pointers.
uint capacity
This capacity is min(capacity) fom all edges.
GoodsEntry goods[NUM_CARGO]
Goods at this station.
Titem Pop()
Pop an item from the stack.
uint demand
Transport demand between the nodes.
A leg of a path in the link graph.
static Titem * Get(size_t index)
Returns Titem with given index.
A connected component of a link graph.
void RerouteCargo(Station *st, CargoID c, StationID avoid, StationID avoid2)
Reroute cargo of type c at station st or in any vehicles unloading there.
NodeAnnotationVector nodes
Extra node data necessary for link graph calculation.
static Path * invalid_path
Static instance of an invalid path.
uint Flow() const
Get the total flow on the edge.
Class for calculation jobs to be run on link graphs.
Tindex index
Index of this pool item.
~LinkGraphJob()
Join the link graph job and destroy it.
@ DT_MANUAL
Manual distribution. No link graph calculations are run.
void Init()
Initialize a linkgraph job edge.
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.
void JoinThread()
Join the calling thread with this job's thread if threading is enabled.
uint flow
Planned flow over this edge.
NodeID origin
Link graph node this path originates from.
@ WC_STATION_VIEW
Station view; Window numbers:
EdgeAnnotationMatrix edges
Extra edge data necessary for link graph calculation.
void RestrictFlows(StationID via)
Restrict all flows at a station for specific cargo and destination.
LinkGraphJobPool _link_graph_job_pool("LinkGraphJob")
The actual pool with link graph jobs.
Flow statistics telling how much flow should be sent along a link.
StationIDStack DeleteFlows(StationID via)
Delete all flows at a station for specific cargo and destination.
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)
void SpawnThread()
Spawn a thread if possible and run the link graph job in the thread.
uint unsatisfied_demand
Demand over this edge that hasn't been satisfied yet.
const SharesMap * GetShares() const
Get the actual shares as a const pointer so that they can be iterated over.
Annotation for a link graph edge.
NodeID node
ID of node in link graph referring to this goods entry.
const LinkGraph link_graph
Link graph to by analyzed. Is copied when job is started and mustn't be modified later.
bool StartNewThread(std::thread *thr, const char *name, TFn &&_Fx, TArgs &&... _Ax)
Start a new thread.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
std::thread thread
Thread the job is running in or a default-constructed thread if it's running in the main thread.
uint Capacity() const
Get edge's capacity.
fluid_settings_t * settings
FluidSynth settings handle.
LinkGraphSettings linkgraph
settings for link graph calculations
LinkGraphID link_graph
Link graph this station belongs to.
StationID Station() const
Get ID of station belonging to wrapped node.
uint distance
Sum(distance of all legs up to this one).
uint Size() const
Get the size of the underlying link graph.
Stores station stats for a single cargo.
Base class for all pools.
FlowStatMap & Flows()
Get the flows running through this node.
static const Date INVALID_DATE
Representation of an invalid date.
EdgeIterator End() const
Iterator for the "end" of the edge array.
bool IsJobAborted() const
Check if job has been aborted.
FlowStatMap flows
Planned flows through this station.
void AddFlow(uint f)
Increase the flow on this leg only by the specified amount.
Flow descriptions by origin stations.
static bool CleaningPool()
Returns current state of pool cleaning - yes or no.
Path(NodeID n, bool source=false)
Create a leg of a path in the link graph.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
int free_capacity
This capacity is min(edge.capacity - edge.flow) for the current run of Dijkstra.
bool IsEmpty() const
Check if the stack is empty.
static Station * GetIfValid(size_t index)
Returns station if the index is a valid index for this station type.
static void Run(LinkGraphJob *job)
Run all handlers for the given Job.
CargoID Cargo() const
Get the cargo of the underlying link graph.
void EraseFlows(NodeID from)
Erase all flows originating at a specific node.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
EdgeIterator Begin() const
Iterator for the "begin" of the edge array.
uint num_children
Number of child legs that have been forked from this path.
void Init()
Initialize the link graph job: Resize nodes and edges and populate them.
LinkGraphJob()
Bare constructor, only for save/load.
void Init(uint supply)
Initialize a Linkgraph job node.
void AddFlow(uint flow)
Add some flow.