12 #ifndef LINKGRAPHJOB_H 13 #define LINKGRAPHJOB_H 15 #include "../thread/thread.h" 21 typedef std::list<Path *> PathList;
50 void Init(uint supply);
119 assert(flow <= this->anno.
flow);
158 base_anno(base_anno) {}
176 return FakePointer(this->
operator*());
197 node_anno(lgj->nodes[node]), edge_annos(lgj->edges[node])
251 const PathList &
Paths()
const {
return this->node_anno.
paths; }
261 (*this)[to].AddDemand(amount);
312 inline uint
Size()
const {
return this->link_graph.
Size(); }
339 #define FOR_ALL_LINK_GRAPH_JOBS(var) FOR_ALL_ITEMS_FROM(LinkGraphJob, link_graph_job_index, var, 0) 348 Path(NodeID n,
bool source =
false);
351 inline NodeID
GetNode()
const {
return this->node; }
354 inline NodeID
GetOrigin()
const {
return this->origin; }
374 return Clamp(free, PATH_CAP_MIN_FREE, PATH_CAP_MAX_FREE) * PATH_CAP_MULTIPLIER /
max(total, 1U);
406 if (this->parent != NULL) {
407 this->parent->num_children--;
412 uint AddFlow(uint f,
LinkGraphJob &job, uint max_saturation);
413 void Fork(
Path *base, uint cap,
int free_cap, uint dist);
421 PATH_CAP_MULTIPLIER = 16,
422 PATH_CAP_MIN_FREE = (INT_MIN + 1) / PATH_CAP_MULTIPLIER,
423 PATH_CAP_MAX_FREE = (INT_MAX - 1) / PATH_CAP_MULTIPLIER
GameSettings _settings_game
Game settings of a running game or the scenario editor.
void Init()
Initialize a linkgraph job edge.
LinkGraphJobPool _link_graph_job_pool
The actual pool with link graph jobs.
int free_capacity
This capacity is min(edge.capacity - edge.flow) for the current run of Dijkstra.
An edge in the link graph.
Annotation for a link graph edge.
FakePointer operator->() const
Dereference.
uint undelivered_supply
Amount of supply that hasn't been distributed yet.
uint Flow() const
Get the total flow on the edge.
CargoID Cargo() const
Get the cargo ID this component's link graph refers to.
Node operator[](NodeID num)
Get a node abstraction with the specified id.
Pool< LinkGraphJob, LinkGraphJobID, 32, 0xFFFF > LinkGraphJobPool
Type of the pool for link graph jobs.
EdgeAnnotation * edge_annos
Edge annotations belonging to this node.
uint GetCapacity() const
Get the overall capacity of the path.
uint demand
Transport demand between the nodes.
FlowStatMap flows
Planned flows to other nodes.
uint flow
Planned flow over this edge.
Tindex index
Index of this pool item.
const PathList & Paths() const
Get a constant version of the paths this node is part of.
void AddFlow(uint f)
Increase the flow on this leg only by the specified amount.
void ShiftJoinDate(int interval)
Change the join date on date cheating.
Date LastCompression() const
Get the date when the underlying link graph was last compressed.
static T max(const T a, const T b)
Returns the maximum of two values.
NodeID GetOrigin() const
Get the overall origin of the path.
A connected component of a link graph.
Edge(const LinkGraph::BaseEdge &edge, EdgeAnnotation &anno)
Constructor.
const LinkGraphSettings & Settings() const
Get the link graph settings for this component.
uint GetNumChildren() const
Get the number of "forked off" child legs of this one.
uint Size() const
Get the current size of the component.
uint unsatisfied_demand
Demand over this edge that hasn't been satisfied yet.
uint GetFlow() const
Get the flow on this leg.
const LinkGraphSettings settings
Copy of _settings_game.linkgraph at spawn time.
uint distance
Sum(distance of all legs up to this one).
NodeID GetNode() const
Get the node this leg passes.
static const Date INVALID_DATE
Representation of an invalid date.
A leg of a path in the link graph.
uint num_children
Number of child legs that have been forked from this path.
void SatisfyDemand(uint demand)
Satisfy some demand.
int GetCapacityRatio() const
Get capacity ratio of this path.
ThreadObject * thread
Thread the job is running in or NULL if it's running in the main thread.
PathList & Paths()
Get the paths this node is part of.
Node(LinkGraphJob *lgj, NodeID node)
Constructor.
static Path * invalid_path
Static instance of an invalid path.
void DeliverSupply(NodeID to, uint amount)
Deliver some supply, adding demand to the respective edge.
void ReduceFlow(uint f)
Reduce the flow on this leg only by the specified amount.
uint capacity
This capacity is min(capacity) fom all edges.
Date JoinDate() const
Get the date when the job should be finished.
void SpawnThread()
Spawn a thread if possible and run the link graph job in the thread.
Wrapper for an edge (const or not) allowing retrieval, but no modification.
Date LastCompression() const
Get date of last compression.
NodeID origin
Link graph node this path originates from.
Edge operator[](NodeID to) const
Retrieve an edge starting at this node.
static int GetCapacityRatio(int free, uint total)
Get ratio of free * 16 (so that we get fewer 0) / max(total capacity, 1) (so that we don't divide by ...
void AddFlow(uint flow)
Add some flow.
Base class for all PoolItems.
uint UnsatisfiedDemand() const
Get the transport demand that hasn't been satisfied by flows, yet.
Base class for iterating across outgoing edges of a node.
int GetFreeCapacity() const
Get the free capacity of the path.
Base class for all pools.
CargoID Cargo() const
Get the cargo of the underlying link graph.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
void RemoveFlow(uint flow)
Remove some flow.
NodeID node
Link graph node this leg passes.
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.
uint GetDistance() const
Get the overall distance of the path.
bool IsFinished() const
Check if job is supposed to be finished.
EdgeIterator(const LinkGraph::BaseEdge *base, EdgeAnnotation *base_anno, NodeID current)
Constructor.
PathList paths
Paths through this node, sorted so that those with flow == 0 are in the back.
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.
NodeAnnotation & node_anno
Annotation being wrapped.
void Detach()
Detach this path from its parent.
uint flow
Flow the current run of the mcf solver assigns.
PathCapacityBoundaries
Some boundaries to clamp agains in order to avoid integer overflows.
EdgeIterator End() const
Iterator for the "end" of the edge array.
Date join_date
Date when the job is to be joined.
const FlowStatMap & Flows() const
Get a constant version of the flows running through this node.
uint Size() const
Get the size of the underlying link graph.
const LinkGraph & Graph() const
Get a reference to the underlying link graph.
LinkGraphJob()
Bare constructor, only for save/load.
friend const SaveLoad * GetLinkGraphJobDesc()
Get a SaveLoad array for a link graph job.
LinkGraphID LinkGraphIndex() const
Get the ID of the underlying link graph.
Flow descriptions by origin stations.
Declaration of link graph classes used for cargo distribution.
int32 Date
The type to store our dates in.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
EdgeAnnotationMatrix edges
Extra edge data necessary for link graph calculation.
EdgeAnnotation & anno
Annotation being wrapped.
uint UndeliveredSupply() const
Get amount of supply that hasn't been delivered, yet.
byte CargoID
Cargo slots to indicate a cargo type within a game.
Path * GetParent()
Get the parent leg of this one.
SmallPair< NodeID, Edge > operator*() const
Dereference.
Date _date
Current date in days (day counter)
EdgeAnnotation * base_anno
Array of annotations to be (indirectly) iterated.
void AddDemand(uint demand)
Add some (not yet satisfied) demand.
Path * parent
Parent leg of this one.
NodeAnnotationVector nodes
Extra node data necessary for link graph calculation.
A Thread Object which works on all our supported OSes.
EdgeIterator Begin() const
Iterator for the "begin" of the edge array.
~LinkGraphJob()
Join the link graph job and destroy it.
uint Demand() const
Get the transport demand between end the points of the edge.
Class for calculation jobs to be run on link graphs.
Annotation for a link graph node.