# flowmapper.cpp

Go to the documentation of this file.

    00001 /* $Id$ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00012 #include "../stdafx.h"
    00013 #include "flowmapper.h"
    00014
    00019 void FlowMapper::Run(LinkGraphComponent *component)
    00020 {
    00021   for (NodeID node_id = 0; node_id < component->GetSize(); ++node_id) {
    00022     Node &prev_node = component->GetNode(node_id);
    00023     StationID prev = prev_node.station;
    00024     PathSet &paths = prev_node.paths;
    00025     for (PathSet::iterator i = paths.begin(); i != paths.end(); ++i) {
    00026       Path *path = *i;
    00027       uint flow = path->GetFlow();
    00028       if (flow == 0) continue;
    00029       Node &node = component->GetNode(path->GetNode());
    00030       StationID via = node.station;
    00031       assert(prev != via);
    00032       StationID origin = component->GetNode(path->GetOrigin()).station;
    00033       assert(via != origin);
    00034       /* mark all of the flow for local consumption at "first" */
    00035       node.flows[origin][via] += flow;
    00036       /* pass some of the flow marked for local consumption at "prev" on
    00037        * to this node
    00038        */
    00039       prev_node.flows[origin][via] += flow;
    00040       /* find simple circular flows ... */
    00041       assert(node.flows[origin][prev] == 0);
    00042       if (prev != origin) {
    00043         prev_node.flows[origin][prev] -= flow;
    00044       }
    00045     }
    00046   }
    00047   for (NodeID node_id = 0; node_id < component->GetSize(); ++node_id) {
    00048     PathSet &paths = component->GetNode(node_id).paths;
    00049     for (PathSet::iterator i = paths.begin(); i != paths.end(); ++i) {
    00050       delete *i;
    00051     }
    00052     paths.clear();
    00053   }
    00054 }