Note
Go to the end to download the full example code.
Static Traffic Assignment#
We can also run the Polaris Activity-Based model with static assignment, including for model calibration exercises.
Even when the intention is to use Polaris powerful dynamic traffic assignment, this mode may be useful in speeding up the calibration process or obtaining a more realistic starting for the equilibration of skim matrices.
For this integration we have used [AequilibraE](https://www.aequilibrae.com/), which is an open source modelling package with incredibly fast static assignment capabilities, but similar integrations are possible with other packages.
Exporting matrices#
sphinx_gallery_thumbnail_path = ‘../../examples/modelling_like_the_old_days/pol_aeq.png’
from pathlib import Path
from polaris import Polaris
from polaris.runs.scenario_file import load_yaml, save_yaml
from polaris.runs.static_assignment.static_assignment_inputs import STAInputs
from polaris.runs.static_assignment.static_run import static_run
from polaris.utils.testing.temp_model import TempModel
We create a new model directory with a grid network that has already been run
project_dir = TempModel("Grid")
Before anything else, we mark it for a single iteration
config = load_yaml(Path(project_dir) / "convergence_control.yaml")
config["do_skim"] = False
config["do_abm_init"] = False
config["num_abm_runs"] = 1
save_yaml(Path(project_dir) / "convergence_control.yaml", config)
Now we run a single iteration of Polaris with static assignment
sta_param = STAInputs()
sta_param.max_iterations = 1 # You obviously want a MUCH higher number of iterations
sta_param.rgap = 0.1 # And a much tighter rgap
sta_param.num_cores = 5 # Delete this line to use all of your cores
# We would normally compute the KPIs, but let's leave it out to make the example faster
static_run(project_dir, sta_param=sta_param, save_assignment_results=True, run_kpis=False)
: 0%| | 0/15 [00:00<?, ?it/s]
combined : 0%| | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment : 0%| | 0/1 [00:00<?, ?it/s]
combined : 0%| | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment : 0%| | 0/1 [00:00<?, ?it/s]
combined : 0%| | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment : 0%| | 0/1 [00:00<?, ?it/s]
combined : 0%| | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment : 0%| | 0/1 [00:00<?, ?it/s]
combined : 0%| | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment : 0%| | 0/1 [00:00<?, ?it/s]
combined : 0%| | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment : 0%| | 0/1 [00:00<?, ?it/s]
combined : 0%| | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment : 0%| | 0/1 [00:00<?, ?it/s]
combined : 0%| | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment : 0%| | 0/1 [00:00<?, ?it/s]
combined : 0%| | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment : 0%| | 0/1 [00:00<?, ?it/s]
combined : 0%| | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment : 0%| | 0/1 [00:00<?, ?it/s]
combined : 0%| | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment : 0%| | 0/1 [00:00<?, ?it/s]
combined : 0%| | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment : 0%| | 0/1 [00:00<?, ?it/s]
combined : 0%| | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment : 0%| | 0/1 [00:00<?, ?it/s]
combined : 0%| | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment : 0%| | 0/1 [00:00<?, ?it/s]
combined : 0%| | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment : 0%| | 0/1 [00:00<?, ?it/s]
combined : 0%| | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment : 0%| | 0/1 [00:00<?, ?it/s]
Failed running sql: CREATE TABLE IF NOT EXISTS work_straight_line_dist_Average As
SELECT avg(sqrt(pow(work_loc.x - home_loc.x, 2.0) + pow(work_loc.y - home_loc.y, 2.0))) / 1000 as dist_avg,
1.0*count(*) as count
FROM person, household, a.location as home_loc, a.location as work_loc
WHERE person.household = household.household
and household.location = home_loc.location
and person.work_location_id = work_loc.location
and home_loc.location <> work_loc.location
Failed running sql: CREATE TABLE boardings_by_agency_mode as
SELECT
ta.agency as agency,
CASE WHEN tr."type" = 0 THEN 'TRAM'
WHEN tr."type" = 1 THEN 'METRO'
WHEN tr."type" = 2 THEN 'COMM'
WHEN tr."type" = 3 THEN 'BUS'
WHEN tr."type" = 4 THEN 'FERRY'
WHEN tr."type" = 5 THEN 'CABLE'
WHEN tr."type" = 6 THEN 'LIFT'
WHEN tr."type" = 7 THEN 'FUNICULAR'
WHEN tr."type" = 11 THEN 'TROLLEY'
WHEN tr."type" = 12 THEN 'MONO'
END as "mode",
4.0*sum(tvl.value_boardings) as boardings,
4.0*sum(tvl.value_alightings) as alightings
FROM
"Transit_Vehicle_links" tvl,
transit_vehicle tv,
a.transit_trips tt,
a.transit_patterns tp,
a.transit_routes tr,
a.transit_agencies ta
where
tvl.value_transit_vehicle_trip = tv.transit_vehicle_trip and
tvl.value_transit_vehicle_trip = tt.trip_id and
tp.pattern_id = tt.pattern_id and
tr.route_id = tp.route_id AND
tr.agency_id = ta.agency_id
group by 1,2
order by 1,2
Failed running sql: CREATE TABLE IF NOT EXISTS work_straight_line_dist_Average As
SELECT avg(sqrt(pow(work_loc.x - home_loc.x, 2.0) + pow(work_loc.y - home_loc.y, 2.0))) / 1000 as dist_avg,
1.0*count(*) as count
FROM person, household, a.location as home_loc, a.location as work_loc
WHERE person.household = household.household
and household.location = home_loc.location
and person.work_location_id = work_loc.location
and home_loc.location <> work_loc.location
Total running time of the script: (0 minutes 55.725 seconds)