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 110.4 75.2 185.6 0.0 4.0 4.0 0.147733 0.147429 0.147733 1.002837 1.000777 1.002837 0.368 0.264 0.368 110.4 79.2 189.6
6 110.4 75.2 185.6 0.0 4.0 4.0 0.128309 0.128046 0.128309 1.002837 1.000777 1.002837 0.368 0.264 0.368 110.4 79.2 189.6
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.000 0.000 0.000 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.000 0.000 0.000 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.000 0.000 0.000 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.72378925, 11.03299467,  3.05384258,  9.495832  ,
        12.057879  ,  7.44790965,  8.53131648, 18.95511791, 17.17043974],
       [ 9.90164306,  0.        ,  6.85224504,  7.9951628 ,  9.46052064,
         4.37169384,  3.95284109,  2.60159987, 10.99210724,  8.77702144],
       [ 6.12626902,  5.90071157,  0.        ,  4.21978876,  5.33740108,
         8.01127333,  5.20013819,  6.24117936, 12.61866506, 10.40357926],
       [ 3.08051381,  8.84398022,  9.17381706,  0.        ,  7.63665439,
        10.17806997,  5.56810062,  6.65150744, 17.07530887, 15.2906307 ],
       [14.96177325, 13.62287573, 15.71006799, 13.05529298,  0.        ,
        15.7334375 , 14.03564241, 13.96334352, 20.34082922, 18.12574342],
       [ 9.03471188,  6.6315039 ,  3.48376318,  7.12823162,  8.24584395,
         0.        ,  8.10858105,  6.97197169, 13.34945739, 11.13437159],
       [ 7.47475277,  4.80188422,  8.42461526,  5.5682725 ,  7.09502663,
         6.13597397,  0.        ,  2.47376734, 13.4636205 , 11.24853471],
       [ 8.55146828,  3.44934104,  7.26398199,  6.64498802,  8.17174215,
         4.78343079,  2.47246537,  0.        , 12.11107732,  9.89599152],
       [12.66718291,  6.0066198 ,  8.51167188, 10.76070264, 12.22606049,
         6.03112067,  6.71838093,  5.36713971,  0.        ,  7.86607547],
       [18.74057001, 12.5975991 , 15.10265118, 16.83408974, 15.04009126,
        12.62209997, 13.30936023, 11.95811901, 10.08526073,  0.        ]])

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

Gallery generated by Sphinx-Gallery