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)
/tmp/polaris_studio_testing/2025-11-19_23-19-46--282c46ed1b22/scenario_abm.json
: 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 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 50.821 seconds)