next up previous contents
Next: Visualizer Up: Cellular automata micro-simulation Previous: Initializing vehicles for testing   Contents


Main program

Finally all the above functionality needs to be put together. This can be done as follows:


{}
typedef double Time ;
...
Time globalTime = -1 ; // global definition of a time; see text
...
class Link ; // forward declaration
class Node {
    ...
};
class Link {
    ...
} ;
class Veh {
    ...
} ;
class SimWorld {
    ...
    void simulate() { // see later
        ...
    }
} ;
...
int main () {
    // network construction as discussed earlier
    ...

    // build the links:
    for ( SimWorld::Links::iterator ll =simWorld.links.begin(); 
                                    ll!=simWorld.links.end(); 
                                  ++ll ) {
        Link* link = ll->second ;
        link->build() ;
    }

    // insert some vehicles as explained above
    ...

    // time iteration:
    for ( globalTime=simStartTime; globalTime<99999; globalTime++ ) {
        bool done = false ;
        simWorld.simulate( done ) ;
        if ( done ) break ;
    }
    return 0;
}
and finally


/home/nagel/src/book/sim/book/SimWorld::simulate

The above code fragment also contains a provision for visualizer output, to be used in the next chapter.

Note the time is defined globally as globalTime. There are better ways to do this; this is, as always in this text, left to the experts.



2004-02-02