12 #include "../stdafx.h" 13 #include "../core/pool_func.hpp" 14 #include "../window_func.h" 18 #include "../safeguards.h" 53 for (NodeID node_id = 0; node_id < this->
Size(); ++node_id) {
54 (*this)[node_id].Flows().erase(from);
82 if (this->
thread != NULL) {
103 uint size = this->
Size();
104 for (NodeID node_id = 0; node_id < size; ++node_id) {
105 Node from = (*this)[node_id];
117 if (ge.
link_graph != this->link_graph.index || ge.
node != node_id) {
126 if (from[it->first].Flow() == 0)
continue;
127 StationID to = (*this)[it->first].Station();
131 (*lg)[node_id][it->first].LastUpdate() ==
INVALID_DATE) {
138 }
else if ((*lg)[node_id][it->first].LastUnrestrictedUpdate() ==
INVALID_DATE) {
148 for (FlowStatMap::iterator it(ge.
flows.begin()); it != ge.
flows.end();) {
149 FlowStatMap::iterator new_it = flows.find(it->first);
150 if (new_it == flows.end()) {
152 it->second.Invalidate();
155 FlowStat shares(INVALID_STATION, 1);
156 it->second.SwapShares(shares);
157 ge.
flows.erase(it++);
158 for (FlowStat::SharesMap::const_iterator shares_it(shares.
GetShares()->begin());
159 shares_it != shares.
GetShares()->end(); ++shares_it) {
164 it->second.SwapShares(new_it->second);
169 ge.
flows.insert(flows.begin(), flows.end());
181 uint size = this->
Size();
184 for (uint i = 0; i < size; ++i) {
187 for (uint j = 0; j < size; ++j) {
188 node_edges[j].
Init();
200 this->unsatisfied_demand = 0;
210 this->undelivered_supply = supply;
212 new (&this->paths) PathList;
227 this->distance = base->
distance + dist;
228 assert(this->distance > 0);
229 if (this->parent != base) {
234 this->origin = base->
origin;
247 if (this->parent != NULL) {
249 if (max_saturation != UINT_MAX) {
250 uint usable_cap = edge.
Capacity() * max_saturation / 100;
251 if (usable_cap > edge.
Flow()) {
252 new_flow =
min(new_flow, usable_cap - edge.
Flow());
257 new_flow = this->parent->AddFlow(new_flow, job, max_saturation);
258 if (this->flow == 0 && new_flow > 0) {
259 job[this->parent->node].Paths().push_front(
this);
263 this->flow += new_flow;
273 distance(source ? 0 : UINT_MAX),
274 capacity(source ? UINT_MAX : 0),
275 free_capacity(source ? INT_MAX : INT_MIN),
276 flow(0), node(n), origin(source ? n : INVALID_NODE),
277 num_children(0), parent(NULL)
GameSettings _settings_game
Game settings of a running game or the scenario editor.
void Init()
Initialize a linkgraph job edge.
Minimal stack that uses a pool to avoid pointers.
int free_capacity
This capacity is min(edge.capacity - edge.flow) for the current run of Dijkstra.
Annotation for a link graph edge.
static Titem * Get(size_t index)
Returns Titem with given index.
LinkGraphJobPool _link_graph_job_pool("LinkGraphJob")
The actual pool with link graph jobs.
uint Flow() const
Get the total flow on the edge.
Manual distribution. No link graph calculations are run.
StationIDStack DeleteFlows(StationID via)
Delete all flows at a station for specific cargo and destination.
Stores station stats for a single cargo.
Tindex index
Index of this pool item.
void AddFlow(uint f)
Increase the flow on this leg only by the specified amount.
StationID Station() const
Get ID of station belonging to wrapped node.
GoodsEntry goods[NUM_CARGO]
Goods at this station.
A connected component of a link graph.
void Resize(uint num_items)
Set the size of the vector, effectively truncating items from the end or appending uninitialised ones...
void Init(uint supply)
Initialize a Linkgraph job node.
void RestrictFlows(StationID via)
Restrict all flows at a station for specific cargo and destination.
bool IsEmpty() const
Check if the stack is empty.
void Init()
Initialize the link graph job: Resize nodes and edges and populate them.
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 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...
LinkGraphID link_graph
Link graph this station belongs to.
Path(NodeID n, bool source=false)
Create a leg of a path in the link graph.
uint distance
Sum(distance of all legs up to this one).
static const Date INVALID_DATE
Representation of an invalid date.
A leg of a path in the link graph.
Declaration of link graph schedule used for cargo distribution.
uint num_children
Number of child legs that have been forked from this path.
Titem Pop()
Pop an item from the stack.
NodeID node
ID of node in link graph referring to this goods entry.
ThreadObject * thread
Thread the job is running in or NULL if it's running in the main thread.
static void Run(void *j)
Run all handlers for the given Job.
Station view; Window numbers:
static Path * invalid_path
Static instance of an invalid path.
Declaration of link graph job classes used for cargo distribution.
static T min(const T a, const T b)
Returns the minimum of two values.
uint capacity
This capacity is min(capacity) fom all edges.
void SpawnThread()
Spawn a thread if possible and run the link graph job in the thread.
NodeID origin
Link graph node this path originates from.
void AddFlow(uint flow)
Add some flow.
Base class for all pools.
CargoID Cargo() const
Get the cargo of the underlying link graph.
FlowStatMap flows
Planned flows through this station.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
static bool CleaningPool()
Returns current state of pool cleaning - yes or no.
virtual void Join()=0
Join this thread.
const LinkGraph link_graph
Link graph to by analyzed. Is copied when job is started and mustn't be modified later.
FlowStatMap & Flows()
Get the flows running through this node.
void EraseFlows(NodeID from)
Erase all flows originating at a specific node.
void JoinThread()
Join the calling thread with this job's thread if threading is enabled.
void RerouteCargo(Station *st, CargoID c, StationID avoid, StationID avoid2)
Reroute cargo of type c at station st or in any vehicles unloading there.
const SharesMap * GetShares() const
Get the actual shares as a const pointer so that they can be iterated over.
EdgeIterator End() const
Iterator for the "end" of the edge array.
uint Size() const
Get the size of the underlying link graph.
Flow statistics telling how much flow should be sent along a link.
LinkGraphJob()
Bare constructor, only for save/load.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-NULL) Titem.
Flow descriptions by origin stations.
EdgeAnnotationMatrix edges
Extra edge data necessary for link graph calculation.
uint Capacity() const
Get edge's capacity.
Date _date
Current date in days (day counter)
NodeAnnotationVector nodes
Extra node data necessary for link graph calculation.
static bool New(OTTDThreadFunc proc, void *param, ThreadObject **thread=NULL, const char *name=NULL)
Create a thread; proc will be called as first function inside the thread, with optional params...
EdgeIterator Begin() const
Iterator for the "begin" of the edge array.
~LinkGraphJob()
Join the link graph job and destroy it.
LinkGraphSettings linkgraph
settings for link graph calculations
Class for calculation jobs to be run on link graphs.
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-...
static Station * GetIfValid(size_t index)
Returns station if the index is a valid index for this station type.