Static Traffic Assignment

Static Traffic Assignment#

We can also perform static traffic assignment using Open-Source libraries for back-of-the-envelop analysis during debugging efforts

Exporting matrices#

sphinx_gallery_thumbnail_path = ‘../../examples/modelling_like_the_old_days/sta_results.png’

from pathlib import Path

from polaris.analyze.trip_metrics import TripMetrics
from polaris.runs.convergence.convergence_iteration import ConvergenceIteration
from polaris.runs.static_skimmer.static_assign import static_assignment
from polaris.runs.static_skimmer.static_graph import build_graph

Matrix#

We get the demand matrices for the AM peak for one iteration

project_dir = Path("/tmp/Bloomington")
supply_pth = project_dir / "Bloomington-Supply.sqlite"

iteration_3 = ConvergenceIteration.from_dir(project_dir / "Bloomington_iteration_3")
tm3 = TripMetrics(supply_pth, iteration_3.files.demand_db)

# Let's say that one afternoon peak hour is from 16:45AM to 17:45AM, so we egt trips starting during that time
matrix = tm3.vehicle_trip_matrix(from_start_time=16.75 * 3600, to_start_time=17.75 * 3600)

# This matrix has multiple vehicle types, and we could separate them to make sure we observe
# link type constraints, but that shouldn't be needed in a back-of-the-envelope exercise
# Instead, we will just multiply the PCEs for each matrix to the matrices themselves

pces = {"SOV_0": 1.0, "TAXI_9": 1.0, "MD_TRUCK_17": 2.5, "HD_TRUCK_18": 4.0, "BPLATE_19": 2.0, "LD_TRUCK_20": 1.8}
for i, mat in enumerate(matrix.names):
    matrix.matrices[:, :, i] *= pces[mat]
Traceback (most recent call last):
  File "/home/jamie/git/anl/polarislib/docs/examples/modelling_like_the_old_days/plot_sta.py", line 31, in <module>
    iteration_3 = ConvergenceIteration.from_dir(project_dir / "Bloomington_iteration_3")
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jamie/git/anl/polarislib/polaris/runs/convergence/convergence_iteration.py", line 57, in from_dir
    iteration.files = PolarisInputs.from_dir(Path(dir), db_name)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jamie/git/anl/polarislib/polaris/runs/polaris_inputs.py", line 24, in from_dir
    raise FileNotFoundError(f"No such directory {dir}")
FileNotFoundError: No such directory /tmp/Bloomington/Bloomington_iteration_3

Graph#

We build an AequilibraE graph using the underlying Polaris supply model

This procedure asserts some things about the links so we can get everything we need for a static traffic assignment Assumptions are made about (HOURLY) capacities and centroid connector placements

graph = build_graph(supply_pth)

One can see the results of these assumptions in the graph object

graph.network.head()

Assignment#

We perform traffic assignment and skimming using the AequilibraE library

We can load the assignment parameters from the default values and change them

from polaris.runs.static_skimmer.static_skimmer_inputs import STAInputs

sta_pars = STAInputs()

# Not sure why somewhat would want msa over bi-conjugate Frank-Wolfe, but...
sta_pars.assignment_algorithm = "msa"
sta_pars.max_iterations = 10
sta_pars.rgap = 0.01

# By default assignment uses BPR, but we can change the parameters
sta_pars.bpr_alpha = 0.14
sta_pars.bpr_beta = 3.9

No turning constraints are observed in this assignment

assig = static_assignment(graph, matrix, sta_pars)

Then we can see the results

link_loads = assig.results()
link_loads.head()

And get the skims

assig_class = assig.classes[0]
skim = assig_class.results.skims
# And show some elements
skim.time[:10, :10]

Total running time of the script: (0 minutes 0.022 seconds)

Gallery generated by Sphinx-Gallery