A Finer Model: Documentation

I don't normally publish code, so this page is likely done differently than a typical documentation page. If you would like to try the code yourself, you can find it here. Ensure you can run C++ code before downloading! If you want to suggest improvements to the code, please contact me.

This code is essentially a modified Dijkstra's implementation. This documentation is written assuming the reader does not know Dijkstra's (I didn't either). It will run a sample of \(N\) pseudorandomly-chosen individuals who choose their route based on how quickly they can get between Point 0 and their origin point, using perceived values which multiply the time spent walking or waiting for transit. These multipliers are taken from the TTC's service standards .

Assumptions

-All building area is weighted the same (multipliers may apply for taller buildings).
-Demand for transit from employees is equally likely to come from any employment space ("weighting") in the study area.
-Users can only choose between taking a single transit route and walking.
-No one will choose driving over transit if it is more convenient.

Inputs

The first line of input contains integers \(R\), \(P\), and \(N\): \(R\) is the number of routes in the study area. I have capped the number of routes at 5, you may increase it by downloading and editing the code but I can not be certain the code will run fast enough if you do.
\(P\) is the number of points the model considers. Each route will go between these points and all points will be assigned a weighting based on the nearby floor area devoted to employment (roughly). The number of points is capped at 299 in this code. You may download and edit the code to add more, but I do not know if it will run fast enough for it.
\(N\) is the sample size, the number of passengers this program will simulate. There is no limit to this number though my preferred \(N\) of 20,000 is already a very large sample size.

The next line of input contains the \(proportion\) array, the weightings of each of the \(P\) points. For the purpose of this project, these come from the total area of nearby buildings. 3+ storey buildings have been given a multiplier equal to less than the number of floors, as offices tend to be more affluent and more likely to drive.

Next, the information for each route is inputted. The first line for each route contains three variables:

-\(freq[i]\), the frequency of route \(i\). The randomly generated workers will have their wait time for route \(i\) randomly generated to be a number between \(0\) and \(freq[i]\).
-\(routeP\), the number of points besides the first point which the route serves.
-The initial \(lastPoint\) value, which is the first point on the route (this should be set to \(0\)).

The next \(routeP\) lines contain four variables about each segment of the route:

-\(speed1\) and \(speed2\), the speed in the forward and reverse directions. This program presently only analyzes the forwards direction so I normally set \(speed1\) and \(speed2\) to be the same.
-\(D\), the distance, in metres, between the last point and the new point. -\(thisPoint\), the new point on the route.

After all route information is inputted, the next line you input will have one variable: \(links\), the total number of walking links. The next \(links\) lines have three inputs: \(D\) (distance), \(lastPoint\), and \(thisPoint\) (the last two are self-explanatory).

The model used for this project has around 150 points and 180 links. You do not really need to get every building in detail, that would require nearly 500 points and will not run as fast.

Outputs

The program will output the following to the console:

"WALKED: \(a\)", where \(a\) is the number of people who walked.

The \(i\)th of the next \(n\) lines will have "Route \(i\): \(b\)", where \(b\) is the number of people riding route \(i\) solely within the study area. This program does not simulate the continuation of routes beyond the study area.

The final line will output "TOTAL TRAVEL TIME: \(c\)", where \(c\) is the total percieved travel time, measured in person-minutes with the aforementioned multipliers applied.

I have included a sample case with a very simple scenario intended to help you understand the code: Sample input, Sample output.

How it runs

Upon getting all of its walking points, the code runs a Dijkstra's algorithm only on the walking routes, originating from Point \(0\). This determines the maximum times you would need to get to each point. After, it repeats this but with one of the transit routes operating. All travel time values are stored.

When each random traveller is generated, the code picks a number between 1 and the sum of the weightings, and uses that number to determine where the traveller is. It additionally randomizes how long the traveller will have to wait for each bus route and adds it to the total travel time for each route. The traveller picks the route (including route \(0\) - Walking) with the lowest value. This repeats for each traveller until all \(N\) travellers have been simulated.

The code counts how many travellers take each route and the total length of time they take, which is used for the outputs once the program is finished running.




Last updated: 06/11/2026