Static Traffic Assignment

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

Matrix#

We get the demand matrices for the AM peak for one iteration

project_dir = TempModel("Grid")

sta_param = STAInputs()
sta_param.max_iterations = 5
sta_param.rgap = 0.1

static_run(project_dir, sta_param=sta_param, save_assignment_results=True)
                                                  :   0%|          | 0/15 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [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
/home/gitlab-runner/builds/polaris/code/polarislib/polaris/runs/calibrate/mode_choice.py:154: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  return df.groupby("person").apply(set_home_based).reset_index(drop=True)
/home/gitlab-runner/builds/polaris/code/polarislib/polaris/runs/calibrate/mode_choice.py:169: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  return df.groupby("mode").apply(f).reset_index()
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
/home/gitlab-runner/builds/polaris/code/polarislib/polaris/runs/calibrate/mode_choice.py:154: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  return df.groupby("person").apply(set_home_based).reset_index(drop=True)
/home/gitlab-runner/builds/polaris/code/polarislib/polaris/runs/calibrate/mode_choice.py:169: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  return df.groupby("mode").apply(f).reset_index()
Exception in thread Thread-3113 (static_async_fn):
Traceback (most recent call last):
  File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.12/threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "/home/gitlab-runner/builds/polaris/code/polarislib/polaris/utils/logging_utils.py", line 38, in wrapper
    rv = function(*args, **kwargs)
         ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gitlab-runner/builds/polaris/code/polarislib/polaris/runs/static_assignment/static_run.py", line 113, in static_async_fn
    kpi.cache_all_available_metrics(metrics_to_cache=planning_kpis)
  File "/home/gitlab-runner/builds/polaris/code/polarislib/polaris/analyze/result_kpis.py", line 165, in cache_all_available_metrics
    for m in metrics_to_cache:
  File "/home/gitlab-runner/builds/polaris/code/polarislib/polaris/analyze/result_kpis.py", line 160, in <genexpr>
    metrics_to_cache = (m for m in metrics_to_cache if self.kpi_filter.allows(m))
                                                       ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gitlab-runner/builds/polaris/code/polarislib/polaris/analyze/kpi_utils.py", line 49, in allows
    return any(t in self.include for t in tags) and not any(t in self.exclude for t in tags)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'KPITag' object is not iterable
                                                  :   0%|          | 0/15 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [00:00<?, ?it/s]
combined                                          :   0%|          | 0/15 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/5 [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
/home/gitlab-runner/builds/polaris/code/polarislib/polaris/runs/calibrate/mode_choice.py:154: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  return df.groupby("person").apply(set_home_based).reset_index(drop=True)
/home/gitlab-runner/builds/polaris/code/polarislib/polaris/runs/calibrate/mode_choice.py:169: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  return df.groupby("mode").apply(f).reset_index()
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
/home/gitlab-runner/builds/polaris/code/polarislib/polaris/runs/calibrate/mode_choice.py:154: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  return df.groupby("person").apply(set_home_based).reset_index(drop=True)
/home/gitlab-runner/builds/polaris/code/polarislib/polaris/runs/calibrate/mode_choice.py:169: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  return df.groupby("mode").apply(f).reset_index()
Exception in thread Thread-6429 (static_async_fn):
Traceback (most recent call last):
  File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.12/threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "/home/gitlab-runner/builds/polaris/code/polarislib/polaris/utils/logging_utils.py", line 38, in wrapper
    rv = function(*args, **kwargs)
         ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gitlab-runner/builds/polaris/code/polarislib/polaris/runs/static_assignment/static_run.py", line 113, in static_async_fn
    kpi.cache_all_available_metrics(metrics_to_cache=planning_kpis)
  File "/home/gitlab-runner/builds/polaris/code/polarislib/polaris/analyze/result_kpis.py", line 165, in cache_all_available_metrics
    for m in metrics_to_cache:
  File "/home/gitlab-runner/builds/polaris/code/polarislib/polaris/analyze/result_kpis.py", line 160, in <genexpr>
    metrics_to_cache = (m for m in metrics_to_cache if self.kpi_filter.allows(m))
                                                       ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gitlab-runner/builds/polaris/code/polarislib/polaris/analyze/kpi_utils.py", line 49, in allows
    return any(t in self.include for t in tags) and not any(t in self.exclude for t in tags)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'KPITag' object is not iterable

Total running time of the script: (2 minutes 46.258 seconds)

Gallery generated by Sphinx-Gallery