We need to get the congestion information into the router. More specifically, we need that the correct link travel time information is returned by link->tTime(now) in Sec. 11.7.
As said above, the way we do this is by reading the events file, calculating each vehicle's link travel times, and then aggregating those times into the desired time bins. Here is a suggestion of a method to do this; comments are added below.
/home/nagel/src/book/router/book/EnterEvent
/home/nagel/src/book/router/book/RouteWorld::readEvents
Comments:
/home/nagel/src/book/router/book/Link::tTimeIni
sum_ and cnt_ are vectors (e.g. vector<int> sum etc.). The assign(N,X) command sets elements 0 to N-1 of the vector to value X.
After that, the file is opened and the header line is read.
/home/nagel/src/book/router/book/Link::addToSum
This uses
/home/nagel/src/book/router/book/timeToBin
/home/nagel/src/book/router/book/Link::tTime
Note that this uses the free speed travel time if no events information is available. Here, we use the global variable GBL_FREE_SPEED; this could be replaced by link-dependent free speeds in more sophisticated implementations. However, when doing this, one needs to make sure that also the traffic simulation generates link-dependent free speeds. Our simulation of Chap. 7 does not do this; improving this will be discussed in Chap. 17.
It is useful to note that all conversions from time-of-day to time-bins is done via the function timeToBin. The inverse conversion (from time bins to time-of-day) is never needed. This makes sure that if the router requests information for a certain time-of-day, it will always receive the same time bin that a link entry event at the same time would have obtained.12.1
Clearly, the overall integration into the router has to look as follows:
{} int main() { // instantiate routeWorld: RouteWorld routeWorld ; // read the network: routeWorld.readNodes() ; routeWorld.readLinks() ; // read the events: routeWorld.readEvents() ; // main loop: ... }