Update: Translations from eints
[openttd-github.git] / src / linkgraph / flowmapper.cpp
blob2fdd0a61f980527cd9fc8ff429412855f62f2201
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
8 /** @file flowmapper.cpp Definition of flowmapper. */
10 #include "../stdafx.h"
11 #include "flowmapper.h"
13 #include "../safeguards.h"
15 /**
16 * Map the paths generated by the MCF solver into flows associated with nodes.
17 * @param job the link graph component to be used.
19 void FlowMapper::Run(LinkGraphJob &job) const
21 for (NodeID node_id = 0; node_id < job.Size(); ++node_id) {
22 Node &prev_node = job[node_id];
23 StationID prev = prev_node.base.station;
24 for (const Path *path : prev_node.paths) {
25 uint flow = path->GetFlow();
26 if (flow == 0) break;
27 Node &node = job[path->GetNode()];
28 StationID via = node.base.station;
29 StationID origin = job[path->GetOrigin()].base.station;
30 assert(prev != via && via != origin);
31 /* Mark all of the flow for local consumption at "first". */
32 node.flows.AddFlow(origin, via, flow);
33 if (prev != origin) {
34 /* Pass some of the flow marked for local consumption at "prev" on
35 * to this node. */
36 prev_node.flows.PassOnFlow(origin, via, flow);
37 } else {
38 /* Prev node is origin. Simply add flow. */
39 prev_node.flows.AddFlow(origin, via, flow);
44 for (NodeID node_id = 0; node_id < job.Size(); ++node_id) {
45 /* Remove local consumption shares marked as invalid. */
46 Node &node = job[node_id];
47 FlowStatMap &flows = node.flows;
48 flows.FinalizeLocalConsumption(node.base.station);
49 if (this->scale) {
50 /* Scale by time the graph has been running without being compressed. Add 1 to avoid
51 * division by 0 if spawn date == last compression date. This matches
52 * LinkGraph::Monthly(). */
53 auto runtime = job.JoinDate() - job.Settings().recalc_time / CalendarTime::SECONDS_PER_DAY - job.LastCompression() + 1;
54 for (auto &it : flows) {
55 it.second.ScaleToMonthly(runtime.base());
58 /* Clear paths. */
59 for (Path *i : node.paths) delete i;
60 node.paths.clear();