next up previous contents
Next: Input file: Trips Up: Route planner Previous: Library support for graph   Contents

General structure

The general structure of the router is as follows (not assuming the use of templates as discussed in Chap. 10):


{}
class Link ; 
class Node {
    ...
};
class Link {
    ...
};
class Plan {
    ...
} ;
class RouteWorld {
private:
    typedef map<Id,Node*> Nodes ;
    Nodes nodes ;
    typedef map<Id,Link*> Links ;
    Links links ;
public:
    void findPath( Plan& ) ;
} ;
...
int main() {
    // instantiate routeWorld:
    RouteWorld routeWorld ;

    // read the network:
    routeWorld.readNodes() ;
    routeWorld.readLinks() ;

    // main loop:
    Plan plan ;
    while ( plan.readNextTrip()==0 ) {
        routeWorld.findPath( plan ) ;
        plan.writePlan() ;
    }
}
As discussed in Chap. 10, the node, link, and plan classes and methods can be taken from previous chapters. Depending on the intention, one can just copy them into the route code and comment out unneeded portions. Alternatively, one can put them into a separate file and include them both into the simulation and into the router code. As discussed in Chap. 10, the best solution would be to use inheritance, which however implies the use of templates.



2004-02-02