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.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)