You want the router to compute new routes only for 10% of the travelers. For this, you need to generate a random sample of the trips file. Do the following:
Write the trips file header.
For each traveler in the trips file, decide if that traveler should be re-planned. If yes, write the trip line into the new file.
Awk is a good language for parsing line-oriented files, which is why we introduce it here.
{}
BEGIN {
# print header line of trips file
print "ID" , "DEPTLINK" , "ARRLINK" , "TIME", "NOTES" ;
}
{
# Skip header line and comments:
if ( $1 == "#" || $1 == "ID" ) { next; }
# w/ proba 10%, write out the line again:
if ( rand() < 0.1 ) {
print $0 ;
}
}
If the above is called SelectTrips.awk, then is is called via
{}
gawk -f SelectTrips.awk < 0.trips > 1.trips
The code consists of three parts:
An optional ``BEGIN'' block. This is executed before anything is read.
A block without special identifier. For every line out of test.events, this block is executed.
An optional ``END'' block. This is executed just before the program is exited.
See ``man awk'' for more information.
IMPORTANT: Make sure you use different random seeds every time you call this module, otherwise the same 10% travelers get replanned over and over again.
In awk, ``rand()'' returns a random number. See ``man awk''.