* Map the paths generated by the MCF solver into flows associated with nodes. * @param job the link graph component to be used. */
| 17 | * @param job the link graph component to be used. |
| 18 | */ |
| 19 | void FlowMapper::Run(LinkGraphJob &job) const |
| 20 | { |
| 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); |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 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()); |
| 56 | } |
| 57 | } |
| 58 | /* Clear paths. */ |
| 59 | for (Path *i : node.paths) delete i; |
| 60 | node.paths.clear(); |
| 61 | } |
| 62 | } |
nothing calls this directly
no test coverage detected