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]

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()
link_id distance a_node b_node capacity_ab capacity_ba time_ab time_ba direction connector_penalty source id
0 4 118.540138 304 305 300 300 0.147315 0.147315 0 0.0 NaN NaN
1 6 102.954767 305 307 300 300 0.127946 0.127946 0 0.0 NaN NaN
2 10 76.423068 310 311 300 300 0.094974 0.094974 0 0.0 NaN NaN
3 11 295.416116 312 310 300 300 0.367126 0.367126 0 0.0 NaN NaN
4 12 187.871361 311 313 300 300 0.233476 0.233476 0 0.0 NaN NaN


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()
SOV_0_ab SOV_0_ba SOV_0_tot TAXI_9_ab TAXI_9_ba TAXI_9_tot Congested_Time_AB Congested_Time_BA Congested_Time_Max Delay_factor_AB Delay_factor_BA Delay_factor_Max VOC_AB VOC_BA VOC_max PCE_AB PCE_BA PCE_tot
link_id
4 81.0 63.0 144.0 0.0 0.0 0.0 0.147440 0.147362 0.147440 1.000848 1.000318 1.000848 0.27 0.21 0.27 81.0 63.0 144.0
6 81.0 63.0 144.0 0.0 0.0 0.0 0.128055 0.127987 0.128055 1.000848 1.000318 1.000848 0.27 0.21 0.27 81.0 63.0 144.0
10 0.0 0.0 0.0 0.0 0.0 0.0 0.094974 0.094974 0.094974 1.000000 1.000000 1.000000 0.00 0.00 0.00 0.0 0.0 0.0
11 0.0 0.0 0.0 0.0 0.0 0.0 0.367126 0.367126 0.367126 1.000000 1.000000 1.000000 0.00 0.00 0.00 0.0 0.0 0.0
12 0.0 0.0 0.0 0.0 0.0 0.0 0.233476 0.233476 0.233476 1.000000 1.000000 1.000000 0.00 0.00 0.00 0.0 0.0 0.0


And get the skims

assig_class = assig.classes[0]
skim = assig_class.results.skims
# And show some elements
skim.time[:10, :10]
array([[ 0.        , 10.72525311, 11.09792241,  3.05528289,  9.59183309,
        12.05935857,  7.449427  ,  8.53424246, 18.95207301, 17.17192461],
       [ 9.91433502,  0.        ,  6.82115976,  7.99497836,  9.56899909,
         4.3716828 ,  3.9530001 ,  2.60127583, 10.99201782,  8.77701631],
       [ 6.13958631,  5.90069039,  0.        ,  4.22022966,  5.3956873 ,
         8.01126605,  5.2005823 ,  6.24085908, 12.61857909, 10.40357758],
       [ 3.0933902 ,  8.84400376,  9.2442819 ,  0.        ,  7.73819258,
        10.17810923,  5.56817766,  6.65299312, 17.07082367, 15.29067526],
       [14.97472757, 13.62285481, 15.73691789, 13.05537091,  0.        ,
        15.73343047, 14.03572356, 13.9630235 , 20.34074351, 18.125742  ],
       [ 9.01695494,  6.63138036,  3.45268894,  7.09759828,  8.27305592,
         0.        ,  8.07795092,  6.97154905, 13.34926906, 11.13426755],
       [ 7.48775638,  4.80194239,  8.39508237,  5.56839972,  7.19658839,
         6.13604785,  0.        ,  2.47360663, 13.46361539, 11.24861388],
       [ 8.5637817 ,  3.44932876,  7.23291118,  6.64442504,  8.27261371,
         4.78343422,  2.47271727,  0.        , 12.11100176,  9.89600025],
       [12.67958458,  6.00653394,  8.48053116, 10.76022792, 12.33424865,
         6.0310542 ,  6.71824966,  5.36652539,  0.        ,  7.86602815],
       [18.75297181, 12.59764007, 15.07163729, 16.83361515, 15.02076644,
        12.62216032, 13.30935579, 11.95763152, 10.08535766,  0.        ]])

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

Gallery generated by Sphinx-Gallery