A simple computer model for simulating traffic congestion.
- Install dependencies:
npm install
- Generate configuration files:
npm run configure
- Run simulation:
npm run simulate
For an overview of the computer model and how it can be used, please see this article investigating whether lane changing in traffic is a zero-sum game.
npm run configure
generates two configuration files:
Copied from the sample file: config/common.sample.json
. Contains the following fields:
arrivalProbability
: Likelihood a car arrives on the next tickdurationInTicks
: How long each simulation runs fornumberOfIterations
: The number of times (iterations) each configured simulation is run. The result takes an average of all iterationssimulationDefaults
: The values of the Independent Variables used in all simulations, unless they are overridden in the simulation configurationlaneChangeDelayTicks
: The time added to the Total Time in Lane upon a lane changelanePlacement
: How each Car is assigned to a Lane (levelled
orrandom
)minTicksInLane
: The minimum time in Lane until Car considers switching LanesminTickSpeedupPercent
: The minimum time saved by switching Lanes for Car to consider switching LanesnumberOfLanes
: The number of lanes (minimum 2)timeOnRoadFunction
: The functiont = f(n)
used to calculate total time on roadt
. Based onn
, the number of Cars in lane.
output
: Configuration for how simulation output is writtenformat
: File format (markdown
orcsv
).path
: File path (filename will beresults
).columns
: Columns to include in results. Array of tuples. First entry is the variable name, the second is the column header used. Examples:[ "minTicksInLane", "Min Time in Lane" ]
[ "overallThroughput", "Aggregate Throughput (cars / 100 ticks)" ]
Contains configurations for every simulation, where one or more Independent Variables can be overridden.
This file is auto-generated by prompting the user, varying one Independent Variable at a time.
Additional simulations can be added by editing this file directly (prior to running npm run simulate
).
npm run simulate
runs the simulation and outputs debug data to the console.
It also generates the results and writes them to the path and format as specified in the common configuration.
The following can be included in the results file by adding them to the common configuration (under output.columns
):
simulationTime
: Elapsed time of simulationcarsEntered
: Total number of cars entered over the course of the simulationcarsRemaining
: Cars remaining on the road at the end of the simulationaverageTimeOnRoad
: Average time spent on the road by all carscarsOnRoadAggregateTime
: Total of all times spent by all cars on the roadtotalLaneChanges
: Total number of lane changes that occurredoverallThroughput
: Measures traffic performance.Aggregate Throughput (cars / 100 ticks) = Total Cars Exited / Aggregate Time * 100
averageThroughput
: Same as above, except that it is calculated per tick, then averaged
- Run tests while you code:
npm run specs -- --watch
- Run ESLint and all tests:
npm test
- NOTE: also runs in Travis CI
- Run ESLint on its own:
npm run lint
- NOTE: not recommended, instead configure your IDE to use the project's ESLint configuration