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)
combined : 0%| | 0/185 [00:00<?, ?it/s]
Equilibrium Assignment : 0%| | 0/10 [00:00<?, ?it/s]
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.72950249, 11.07650937, 3.05909778, 9.57554742,
12.06349172, 7.45321222, 8.54191182, 19.00137716, 17.17614961],
[ 9.97593559, 0. , 6.81602216, 7.99665223, 9.55058381,
4.37169649, 3.95329687, 2.60309435, 10.99233268, 8.77710246],
[ 6.2015449 , 5.90085046, 0. , 4.22226153, 5.40048564,
8.0113307 , 5.20197456, 6.24272855, 12.61893152, 10.40370131],
[ 3.1533169 , 8.84443826, 9.19144513, 0. , 7.69048318,
10.17842749, 5.56814799, 6.65684759, 17.11631293, 15.29108538],
[15.03529763, 13.62302879, 15.73520033, 13.05601427, 0. ,
15.73350903, 14.0357273 , 13.96490689, 20.34110986, 18.12587964],
[ 9.07376223, 6.63178138, 3.44753765, 7.09447887, 8.27270297,
0. , 8.07419189, 6.97365948, 13.34986245, 11.13463223],
[ 7.54855131, 4.80202182, 8.42934015, 5.56926795, 7.14880055,
6.13601105, 0. , 2.4750703 , 13.46389915, 11.24866894],
[ 8.62781675, 3.44962088, 7.22793578, 6.64853339, 8.22806599,
4.78361011, 2.47287189, 0. , 12.11149821, 9.896268 ],
[12.74129896, 6.00670621, 8.47543579, 10.76201559, 12.31594718,
6.03111012, 6.71866024, 5.36845771, 0. , 7.86615438],
[18.87815539, 12.59831288, 15.06704246, 16.89887203, 15.19508285,
12.62271679, 13.31026691, 11.96006438, 10.08607497, 0. ]])
Total running time of the script: (0 minutes 1.407 seconds)