Note
Go to the end to download the full example code.
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()
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]
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)