Forecasting#

In this example, we present a full forecasting workflow for the Sioux Falls example model.

We start creating the skim matrices, running the assignment for the base-year, and then distributing these trips into the network. Later, we estimate a set of future demand vectors which are going to be the input of a future year assignment with select link analysis.

See also

Several functions, methods, classes and modules are used in this example:

# Imports
from uuid import uuid4
from os.path import join
from tempfile import gettempdir

import pandas as pd

from aequilibrae.examples import create_example
from aequilibrae.utils import basic_config
from aequilibrae.traffic.vdf import bpr
# We create the example project inside our temp folder
fldr = join(gettempdir(), uuid4().hex)

project = create_example(fldr)
# We'll also apply a basic logging configuration.

basic_config()
<AequilibraETQDMStreamHandler (NOTSET)>

Traffic assignment with skimming#

In this step, we’ll set the skims for the variable free_flow_time, and execute the traffic assignment for the base-year.

from dataclasses import replace

from aequilibrae.traffic import TrafficAssignment, TrafficClass

Let’s get the demand matrix directly from its file, and inspect what matrices we have in the project.

proj_matrices = project.matrices
proj_matrices.get_available_matrices_and_metadata()
{'skims.omx': {'procedure': None, 'procedure_id': None, 'timestamp': None, 'description': 'Example skim'}, 'demand.omx': {'procedure': None, 'procedure_id': None, 'timestamp': '2020-11-24 08:47:18', 'description': 'Original data imported to OMX format'}, 'demand_mc.omx': {'procedure': None, 'procedure_id': None, 'timestamp': '2021-02-24 00:51:35', 'description': None}}

Load the demand matrix core for computation.

demand = proj_matrices.get_matrix("demand.omx", subset=["matrix"])

Let’s perform the traffic assignment

# Create the assignment class
assigclass = TrafficClass(
    name="car",
    mode="c",
    cost="free_flow_time",
    demand=demand,
    skimming=["free_flow_time", "distance"],
    # Every node in Sioux Falls is a centroid, so paths must pass through centroids.
    graph_options={"block_centroid_flows": False},
)

# Configure the VDF, network fields, and assignment algorithm.
assig = TrafficAssignment(
    network=network,
    project=project,
    classes=[assigclass],
    vdf=bpr,
    name_mapping={"alpha": "b", "beta": "power"},
    capacity_field="capacity",
    time_field="free_flow_time",
    algorithm="bfw",
)
assig.execute(max_iterations=1000, rgap=0.001)
2026-11-23 06:36:15,186;INFO ; Traffic Class specification
2026-11-23 06:36:15,186;INFO ; {'network mode': 'c', 'cost': 'free_flow_time', 'PCE': 1.0, 'Value-of-time': 1.0, 'Fixed cost field': None, 'Fixed cost multiplier': 1.0, 'matrix_totals': {'matrix': 360600.0}}
2026-11-23 06:36:15,186;INFO ; Traffic Assignment specification
2026-11-23 06:36:15,186;INFO ; {'Algorithm': 'bfw', 'Time field': 'free_flow_time', 'Capacity field': 'capacity', 'VDF function': 'bpr', 'VDF parameters': {'alpha': 'b', 'beta': 'power'}, 'Maximum iterations': 1000, 'Target RGAP': 0.001, 'BFW conjugacy': 'approximate', 'Number of cores': 1}
2026-11-23 06:36:15,187;INFO ; bfw Assignment stats
2026-11-23 06:36:15,187;INFO ; Iteration, RelativeGap (AoN), stepsize

Equilibrium Assignment                            :   0%|          | 0/1000 [00:00<?, ?it/s]
All-or-Nothing - Traffic Class: car               :   0%|          | 1/1000 [00:00<00:00, 64527.75it/s]

2026-11-23 06:36:15,188;INFO ; 1,inf,1.0

All-or-Nothing - Traffic Class: car               :   0%|          | 1/1000 [00:00<00:00, 2464.34it/s]
Equilibrium Assignment - Iteration: 1/1000 - RGap: inf:   0%|          | 1/1000 [00:00<00:00, 2158.67it/s]
Equilibrium Assignment                            :   0%|          | 2/1000 [00:00<00:00, 3955.02it/s]
All-or-Nothing - Traffic Class: car               :   0%|          | 2/1000 [00:00<00:00, 3679.21it/s]

2026-11-23 06:36:15,188;INFO ; 2,0.89780457879145,0.32839952448634563

All-or-Nothing - Traffic Class: car               :   0%|          | 2/1000 [00:00<00:00, 1898.73it/s]
Equilibrium Assignment - Iteration: 2/1000 - RGap: 0.897805:   0%|          | 2/1000 [00:00<00:00, 1780.26it/s]
Equilibrium Assignment                            :   0%|          | 3/1000 [00:00<00:00, 2530.25it/s]
All-or-Nothing - Traffic Class: car               :   0%|          | 3/1000 [00:00<00:00, 2448.51it/s]

2026-11-23 06:36:15,189;WARNING ; zero weight blend: infinite skim values may produce NaN

All-or-Nothing - Traffic Class: car               :   0%|          | 3/1000 [00:00<00:00, 1981.87it/s]

2026-11-23 06:36:15,189;INFO ; 3,0.5279325275367827,0.18660240547488702

All-or-Nothing - Traffic Class: car               :   0%|          | 3/1000 [00:00<00:00, 1641.82it/s]
Equilibrium Assignment - Iteration: 3/1000 - RGap: 0.527933:   0%|          | 3/1000 [00:00<00:00, 1601.90it/s]
Equilibrium Assignment                            :   0%|          | 4/1000 [00:00<00:00, 2095.06it/s]
All-or-Nothing - Traffic Class: car               :   0%|          | 4/1000 [00:00<00:00, 2062.35it/s]

2026-11-23 06:36:15,190;WARNING ; zero weight blend: infinite skim values may produce NaN

All-or-Nothing - Traffic Class: car               :   0%|          | 4/1000 [00:00<00:00, 1693.98it/s]

2026-11-23 06:36:15,190;INFO ; 4,0.28874383368012313,0.24114774402917927

All-or-Nothing - Traffic Class: car               :   0%|          | 4/1000 [00:00<00:00, 1486.95it/s]
Equilibrium Assignment - Iteration: 4/1000 - RGap: 0.288744:   0%|          | 4/1000 [00:00<00:00, 1460.16it/s]
Equilibrium Assignment                            :   0%|          | 5/1000 [00:00<00:00, 1800.29it/s]
All-or-Nothing - Traffic Class: car               :   0%|          | 5/1000 [00:00<00:00, 1776.95it/s]

2026-11-23 06:36:15,190;WARNING ; zero weight blend: infinite skim values may produce NaN

All-or-Nothing - Traffic Class: car               :   0%|          | 5/1000 [00:00<00:00, 1553.33it/s]

2026-11-23 06:36:15,191;INFO ; 5,0.19607377855371996,0.8185470737942451

All-or-Nothing - Traffic Class: car               :   0%|          | 5/1000 [00:00<00:00, 1426.25it/s]
Equilibrium Assignment - Iteration: 5/1000 - RGap: 0.196074:   0%|          | 5/1000 [00:00<00:00, 1408.90it/s]
Equilibrium Assignment                            :   1%|          | 6/1000 [00:00<00:00, 1674.15it/s]
All-or-Nothing - Traffic Class: car               :   1%|          | 6/1000 [00:00<00:00, 1659.91it/s]

2026-11-23 06:36:15,191;INFO ; Line-search optimum at the boundary (alpha = 1.0); descent throughout [0, 1]

All-or-Nothing - Traffic Class: car               :   1%|          | 6/1000 [00:00<00:00, 1463.64it/s]

2026-11-23 06:36:15,191;WARNING ; zero weight blend: infinite skim values may produce NaN

All-or-Nothing - Traffic Class: car               :   1%|          | 6/1000 [00:00<00:00, 1427.12it/s]

2026-11-23 06:36:15,192;INFO ; 6,0.22325602275663892,1.0

All-or-Nothing - Traffic Class: car               :   1%|          | 6/1000 [00:00<00:00, 1386.39it/s]
Equilibrium Assignment - Iteration: 6/1000 - RGap: 0.223256:   1%|          | 6/1000 [00:00<00:00, 1373.31it/s]
Equilibrium Assignment                            :   1%|          | 7/1000 [00:00<00:00, 1588.41it/s]
All-or-Nothing - Traffic Class: car               :   1%|          | 7/1000 [00:00<00:00, 1577.57it/s]

2026-11-23 06:36:15,192;INFO ; 7,0.17157154728042692,0.16910548905080566

All-or-Nothing - Traffic Class: car               :   1%|          | 7/1000 [00:00<00:00, 1432.83it/s]
Equilibrium Assignment - Iteration: 7/1000 - RGap: 0.171572:   1%|          | 7/1000 [00:00<00:00, 1419.39it/s]
Equilibrium Assignment                            :   1%|          | 8/1000 [00:00<00:00, 1609.02it/s]
All-or-Nothing - Traffic Class: car               :   1%|          | 8/1000 [00:00<00:00, 1597.83it/s]

2026-11-23 06:36:15,193;INFO ; 8,0.08442324131581802,0.2373694741062248

All-or-Nothing - Traffic Class: car               :   1%|          | 8/1000 [00:00<00:00, 1470.46it/s]
Equilibrium Assignment - Iteration: 8/1000 - RGap: 0.0844232:   1%|          | 8/1000 [00:00<00:00, 1458.06it/s]
Equilibrium Assignment                            :   1%|          | 9/1000 [00:00<00:00, 1629.28it/s]
All-or-Nothing - Traffic Class: car               :   1%|          | 9/1000 [00:00<00:00, 1620.05it/s]

2026-11-23 06:36:15,193;WARNING ; zero weight blend: infinite skim values may produce NaN

All-or-Nothing - Traffic Class: car               :   1%|          | 9/1000 [00:00<00:00, 1507.72it/s]

2026-11-23 06:36:15,193;INFO ; 9,0.07826339212239238,0.5860366441988628

All-or-Nothing - Traffic Class: car               :   1%|          | 9/1000 [00:00<00:00, 1437.06it/s]
Equilibrium Assignment - Iteration: 9/1000 - RGap: 0.0782634:   1%|          | 9/1000 [00:00<00:00, 1427.34it/s]
Equilibrium Assignment                            :   1%|          | 10/1000 [00:00<00:00, 1576.87it/s]
All-or-Nothing - Traffic Class: car               :   1%|          | 10/1000 [00:00<00:00, 1568.96it/s]

2026-11-23 06:36:15,194;INFO ; Line-search optimum at the boundary (alpha = 1.0); descent throughout [0, 1]

All-or-Nothing - Traffic Class: car               :   1%|          | 10/1000 [00:00<00:00, 1466.80it/s]

2026-11-23 06:36:15,194;WARNING ; zero weight blend: infinite skim values may produce NaN

All-or-Nothing - Traffic Class: car               :   1%|          | 10/1000 [00:00<00:00, 1447.51it/s]

2026-11-23 06:36:15,194;INFO ; 10,0.09301015583411931,1.0

All-or-Nothing - Traffic Class: car               :   1%|          | 10/1000 [00:00<00:00, 1425.42it/s]
Equilibrium Assignment - Iteration: 10/1000 - RGap: 0.0930102:   1%|          | 10/1000 [00:00<00:00, 1418.29it/s]
Equilibrium Assignment                            :   1%|          | 11/1000 [00:00<00:00, 1552.87it/s]
All-or-Nothing - Traffic Class: car               :   1%|          | 11/1000 [00:00<00:00, 1546.31it/s]

2026-11-23 06:36:15,195;INFO ; 11,0.06921891008667841,0.11507399176716364

All-or-Nothing - Traffic Class: car               :   1%|          | 11/1000 [00:00<00:00, 1462.40it/s]
Equilibrium Assignment - Iteration: 11/1000 - RGap: 0.0692189:   1%|          | 11/1000 [00:00<00:00, 1453.10it/s]
Equilibrium Assignment                            :   1%|          | 12/1000 [00:00<00:00, 1577.84it/s]
All-or-Nothing - Traffic Class: car               :   1%|          | 12/1000 [00:00<00:00, 1571.78it/s]

2026-11-23 06:36:15,195;INFO ; 12,0.040234500847269324,0.15591705624574248

All-or-Nothing - Traffic Class: car               :   1%|          | 12/1000 [00:00<00:00, 1493.74it/s]
Equilibrium Assignment - Iteration: 12/1000 - RGap: 0.0402345:   1%|          | 12/1000 [00:00<00:00, 1485.76it/s]
Equilibrium Assignment                            :   1%|▏         | 13/1000 [00:00<00:00, 1602.86it/s]
All-or-Nothing - Traffic Class: car               :   1%|▏         | 13/1000 [00:00<00:00, 1595.82it/s]

2026-11-23 06:36:15,196;WARNING ; zero weight blend: infinite skim values may produce NaN

All-or-Nothing - Traffic Class: car               :   1%|▏         | 13/1000 [00:00<00:00, 1530.77it/s]

2026-11-23 06:36:15,196;INFO ; 13,0.03296645686481366,0.2778261672706741

All-or-Nothing - Traffic Class: car               :   1%|▏         | 13/1000 [00:00<00:00, 1482.05it/s]
Equilibrium Assignment - Iteration: 13/1000 - RGap: 0.0329665:   1%|▏         | 13/1000 [00:00<00:00, 1474.75it/s]
Equilibrium Assignment                            :   1%|▏         | 14/1000 [00:00<00:00, 1582.20it/s]
All-or-Nothing - Traffic Class: car               :   1%|▏         | 14/1000 [00:00<00:00, 1576.81it/s]

2026-11-23 06:36:15,197;INFO ; 14,0.035081093446416724,0.6208345025526621

All-or-Nothing - Traffic Class: car               :   1%|▏         | 14/1000 [00:00<00:00, 1490.21it/s]
Equilibrium Assignment - Iteration: 14/1000 - RGap: 0.0350811:   1%|▏         | 14/1000 [00:00<00:00, 1483.32it/s]
Equilibrium Assignment                            :   2%|▏         | 15/1000 [00:00<00:00, 1583.07it/s]
All-or-Nothing - Traffic Class: car               :   2%|▏         | 15/1000 [00:00<00:00, 1577.79it/s]

2026-11-23 06:36:15,197;INFO ; Line-search optimum at the boundary (alpha = 1.0); descent throughout [0, 1]

All-or-Nothing - Traffic Class: car               :   2%|▏         | 15/1000 [00:00<00:00, 1511.64it/s]

2026-11-23 06:36:15,197;WARNING ; zero weight blend: infinite skim values may produce NaN

All-or-Nothing - Traffic Class: car               :   2%|▏         | 15/1000 [00:00<00:00, 1497.61it/s]

2026-11-23 06:36:15,197;INFO ; 15,0.03200399984459911,1.0

All-or-Nothing - Traffic Class: car               :   2%|▏         | 15/1000 [00:00<00:00, 1481.49it/s]
Equilibrium Assignment - Iteration: 15/1000 - RGap: 0.032004:   2%|▏         | 15/1000 [00:00<00:00, 1475.90it/s]
Equilibrium Assignment                            :   2%|▏         | 16/1000 [00:00<00:00, 1568.95it/s]
All-or-Nothing - Traffic Class: car               :   2%|▏         | 16/1000 [00:00<00:00, 1564.13it/s]

2026-11-23 06:36:15,198;INFO ; 16,0.021040384142766117,0.11598592580715987

All-or-Nothing - Traffic Class: car               :   2%|▏         | 16/1000 [00:00<00:00, 1507.45it/s]
Equilibrium Assignment - Iteration: 16/1000 - RGap: 0.0210404:   2%|▏         | 16/1000 [00:00<00:00, 1498.53it/s]
Equilibrium Assignment                            :   2%|▏         | 17/1000 [00:00<00:00, 1586.63it/s]
All-or-Nothing - Traffic Class: car               :   2%|▏         | 17/1000 [00:00<00:00, 1581.84it/s]

2026-11-23 06:36:15,198;INFO ; 17,0.012925420204469549,0.1073638625831236

All-or-Nothing - Traffic Class: car               :   2%|▏         | 17/1000 [00:00<00:00, 1525.56it/s]
Equilibrium Assignment - Iteration: 17/1000 - RGap: 0.0129254:   2%|▏         | 17/1000 [00:00<00:00, 1519.68it/s]
Equilibrium Assignment                            :   2%|▏         | 18/1000 [00:00<00:00, 1604.25it/s]
All-or-Nothing - Traffic Class: car               :   2%|▏         | 18/1000 [00:00<00:00, 1600.13it/s]

2026-11-23 06:36:15,199;INFO ; 18,0.012294041013807001,0.1558846600948632

All-or-Nothing - Traffic Class: car               :   2%|▏         | 18/1000 [00:00<00:00, 1528.47it/s]
Equilibrium Assignment - Iteration: 18/1000 - RGap: 0.012294:   2%|▏         | 18/1000 [00:00<00:00, 1523.02it/s]
Equilibrium Assignment                            :   2%|▏         | 19/1000 [00:00<00:00, 1603.10it/s]
All-or-Nothing - Traffic Class: car               :   2%|▏         | 19/1000 [00:00<00:00, 1599.24it/s]

2026-11-23 06:36:15,200;INFO ; 19,0.012316538874428259,0.33733828320278225

All-or-Nothing - Traffic Class: car               :   2%|▏         | 19/1000 [00:00<00:00, 1537.44it/s]
Equilibrium Assignment - Iteration: 19/1000 - RGap: 0.0123165:   2%|▏         | 19/1000 [00:00<00:00, 1531.47it/s]
Equilibrium Assignment                            :   2%|▏         | 20/1000 [00:00<00:00, 1607.47it/s]
All-or-Nothing - Traffic Class: car               :   2%|▏         | 20/1000 [00:00<00:00, 1603.66it/s]

2026-11-23 06:36:15,200;INFO ; 20,0.011735043381187355,0.5959894379150801

All-or-Nothing - Traffic Class: car               :   2%|▏         | 20/1000 [00:00<00:00, 1542.31it/s]
Equilibrium Assignment - Iteration: 20/1000 - RGap: 0.011735:   2%|▏         | 20/1000 [00:00<00:00, 1537.14it/s]
Equilibrium Assignment                            :   2%|▏         | 21/1000 [00:00<00:00, 1609.95it/s]
All-or-Nothing - Traffic Class: car               :   2%|▏         | 21/1000 [00:00<00:00, 1606.31it/s]

2026-11-23 06:36:15,201;INFO ; Line-search optimum at the boundary (alpha = 1.0); descent throughout [0, 1]

All-or-Nothing - Traffic Class: car               :   2%|▏         | 21/1000 [00:00<00:00, 1562.43it/s]

2026-11-23 06:36:15,201;WARNING ; zero weight blend: infinite skim values may produce NaN

All-or-Nothing - Traffic Class: car               :   2%|▏         | 21/1000 [00:00<00:00, 1552.71it/s]

2026-11-23 06:36:15,201;INFO ; 21,0.013592539642584927,1.0

All-or-Nothing - Traffic Class: car               :   2%|▏         | 21/1000 [00:00<00:00, 1540.92it/s]
Equilibrium Assignment - Iteration: 21/1000 - RGap: 0.0135925:   2%|▏         | 21/1000 [00:00<00:00, 1535.04it/s]
Equilibrium Assignment                            :   2%|▏         | 22/1000 [00:00<00:00, 1604.19it/s]
All-or-Nothing - Traffic Class: car               :   2%|▏         | 22/1000 [00:00<00:00, 1600.60it/s]

2026-11-23 06:36:15,201;INFO ; 22,0.00994976386388666,0.07079581621265686

All-or-Nothing - Traffic Class: car               :   2%|▏         | 22/1000 [00:00<00:00, 1557.64it/s]
Equilibrium Assignment - Iteration: 22/1000 - RGap: 0.00994976:   2%|▏         | 22/1000 [00:00<00:00, 1552.74it/s]
Equilibrium Assignment                            :   2%|▏         | 23/1000 [00:00<00:00, 1619.67it/s]
All-or-Nothing - Traffic Class: car               :   2%|▏         | 23/1000 [00:00<00:00, 1616.36it/s]

2026-11-23 06:36:15,202;INFO ; 23,0.007300114596153,0.07166629092302472

All-or-Nothing - Traffic Class: car               :   2%|▏         | 23/1000 [00:00<00:00, 1576.50it/s]
Equilibrium Assignment - Iteration: 23/1000 - RGap: 0.00730011:   2%|▏         | 23/1000 [00:00<00:00, 1572.26it/s]
Equilibrium Assignment                            :   2%|▏         | 24/1000 [00:00<00:00, 1635.45it/s]
All-or-Nothing - Traffic Class: car               :   2%|▏         | 24/1000 [00:00<00:00, 1632.05it/s]

2026-11-23 06:36:15,202;INFO ; 24,0.006804251749703222,0.16836899188970833

All-or-Nothing - Traffic Class: car               :   2%|▏         | 24/1000 [00:00<00:00, 1579.38it/s]
Equilibrium Assignment - Iteration: 24/1000 - RGap: 0.00680425:   2%|▏         | 24/1000 [00:00<00:00, 1574.73it/s]
Equilibrium Assignment                            :   2%|▎         | 25/1000 [00:00<00:00, 1636.66it/s]
All-or-Nothing - Traffic Class: car               :   2%|▎         | 25/1000 [00:00<00:00, 1633.50it/s]

2026-11-23 06:36:15,203;WARNING ; zero weight blend: infinite skim values may produce NaN

All-or-Nothing - Traffic Class: car               :   2%|▎         | 25/1000 [00:00<00:00, 1596.95it/s]

2026-11-23 06:36:15,203;INFO ; 25,0.005393460474102812,0.17808313987176075

All-or-Nothing - Traffic Class: car               :   2%|▎         | 25/1000 [00:00<00:00, 1571.65it/s]
Equilibrium Assignment - Iteration: 25/1000 - RGap: 0.00539346:   2%|▎         | 25/1000 [00:00<00:00, 1567.82it/s]
Equilibrium Assignment                            :   3%|▎         | 26/1000 [00:00<00:00, 1627.25it/s]
All-or-Nothing - Traffic Class: car               :   3%|▎         | 26/1000 [00:00<00:00, 1624.25it/s]

2026-11-23 06:36:15,204;INFO ; 26,0.005851357665095232,0.3501427558560422

All-or-Nothing - Traffic Class: car               :   3%|▎         | 26/1000 [00:00<00:00, 1578.34it/s]
Equilibrium Assignment - Iteration: 26/1000 - RGap: 0.00585136:   3%|▎         | 26/1000 [00:00<00:00, 1574.53it/s]
Equilibrium Assignment                            :   3%|▎         | 27/1000 [00:00<00:00, 1631.91it/s]
All-or-Nothing - Traffic Class: car               :   3%|▎         | 27/1000 [00:00<00:00, 1629.09it/s]

2026-11-23 06:36:15,204;INFO ; 27,0.007713407379077174,0.7043109868542726

All-or-Nothing - Traffic Class: car               :   3%|▎         | 27/1000 [00:00<00:00, 1582.07it/s]
Equilibrium Assignment - Iteration: 27/1000 - RGap: 0.00771341:   3%|▎         | 27/1000 [00:00<00:00, 1577.71it/s]
Equilibrium Assignment                            :   3%|▎         | 28/1000 [00:00<00:00, 1632.82it/s]
All-or-Nothing - Traffic Class: car               :   3%|▎         | 28/1000 [00:00<00:00, 1629.96it/s]

2026-11-23 06:36:15,205;INFO ; Line-search optimum at the boundary (alpha = 1.0); descent throughout [0, 1]

All-or-Nothing - Traffic Class: car               :   3%|▎         | 28/1000 [00:00<00:00, 1593.47it/s]

2026-11-23 06:36:15,205;WARNING ; zero weight blend: infinite skim values may produce NaN

All-or-Nothing - Traffic Class: car               :   3%|▎         | 28/1000 [00:00<00:00, 1584.23it/s]

2026-11-23 06:36:15,205;INFO ; 28,0.006665546808826156,1.0

All-or-Nothing - Traffic Class: car               :   3%|▎         | 28/1000 [00:00<00:00, 1573.95it/s]
Equilibrium Assignment - Iteration: 28/1000 - RGap: 0.00666555:   3%|▎         | 28/1000 [00:00<00:00, 1570.77it/s]
Equilibrium Assignment                            :   3%|▎         | 29/1000 [00:00<00:00, 1623.59it/s]
All-or-Nothing - Traffic Class: car               :   3%|▎         | 29/1000 [00:00<00:00, 1620.89it/s]

2026-11-23 06:36:15,205;INFO ; 29,0.004781690445278009,0.04490489890507015

All-or-Nothing - Traffic Class: car               :   3%|▎         | 29/1000 [00:00<00:00, 1589.62it/s]
Equilibrium Assignment - Iteration: 29/1000 - RGap: 0.00478169:   3%|▎         | 29/1000 [00:00<00:00, 1585.69it/s]
Equilibrium Assignment                            :   3%|▎         | 30/1000 [00:00<00:00, 1637.33it/s]
All-or-Nothing - Traffic Class: car               :   3%|▎         | 30/1000 [00:00<00:00, 1634.70it/s]

2026-11-23 06:36:15,206;INFO ; 30,0.004261520961977526,0.07014221441138183

All-or-Nothing - Traffic Class: car               :   3%|▎         | 30/1000 [00:00<00:00, 1602.88it/s]
Equilibrium Assignment - Iteration: 30/1000 - RGap: 0.00426152:   3%|▎         | 30/1000 [00:00<00:00, 1599.25it/s]
Equilibrium Assignment                            :   3%|▎         | 31/1000 [00:00<00:00, 1649.67it/s]
All-or-Nothing - Traffic Class: car               :   3%|▎         | 31/1000 [00:00<00:00, 1647.08it/s]

2026-11-23 06:36:15,207;INFO ; 31,0.0038126726071258076,0.09742344627690626

All-or-Nothing - Traffic Class: car               :   3%|▎         | 31/1000 [00:00<00:00, 1606.02it/s]
Equilibrium Assignment - Iteration: 31/1000 - RGap: 0.00381267:   3%|▎         | 31/1000 [00:00<00:00, 1602.68it/s]
Equilibrium Assignment                            :   3%|▎         | 32/1000 [00:00<00:00, 1651.65it/s]
All-or-Nothing - Traffic Class: car               :   3%|▎         | 32/1000 [00:00<00:00, 1649.13it/s]

2026-11-23 06:36:15,207;INFO ; 32,0.0039018385989099892,0.06258400921325322

All-or-Nothing - Traffic Class: car               :   3%|▎         | 32/1000 [00:00<00:00, 1607.76it/s]
Equilibrium Assignment - Iteration: 32/1000 - RGap: 0.00390184:   3%|▎         | 32/1000 [00:00<00:00, 1603.94it/s]
Equilibrium Assignment                            :   3%|▎         | 33/1000 [00:00<00:00, 1651.24it/s]
All-or-Nothing - Traffic Class: car               :   3%|▎         | 33/1000 [00:00<00:00, 1648.76it/s]

2026-11-23 06:36:15,208;INFO ; 33,0.0027691782467265474,0.06719595392325393

All-or-Nothing - Traffic Class: car               :   3%|▎         | 33/1000 [00:00<00:00, 1606.38it/s]
Equilibrium Assignment - Iteration: 33/1000 - RGap: 0.00276918:   3%|▎         | 33/1000 [00:00<00:00, 1602.66it/s]
Equilibrium Assignment                            :   3%|▎         | 34/1000 [00:00<00:00, 1648.13it/s]
All-or-Nothing - Traffic Class: car               :   3%|▎         | 34/1000 [00:00<00:00, 1644.03it/s]

2026-11-23 06:36:15,208;INFO ; 34,0.002922596383931646,0.12319408791407051

All-or-Nothing - Traffic Class: car               :   3%|▎         | 34/1000 [00:00<00:00, 1604.57it/s]
Equilibrium Assignment - Iteration: 34/1000 - RGap: 0.0029226:   3%|▎         | 34/1000 [00:00<00:00, 1601.26it/s]
Equilibrium Assignment                            :   4%|▎         | 35/1000 [00:00<00:00, 1645.64it/s]
All-or-Nothing - Traffic Class: car               :   4%|▎         | 35/1000 [00:00<00:00, 1643.15it/s]

2026-11-23 06:36:15,209;INFO ; 35,0.0025376020166008187,0.12906133722764354

All-or-Nothing - Traffic Class: car               :   4%|▎         | 35/1000 [00:00<00:00, 1600.76it/s]
Equilibrium Assignment - Iteration: 35/1000 - RGap: 0.0025376:   4%|▎         | 35/1000 [00:00<00:00, 1597.40it/s]
Equilibrium Assignment                            :   4%|▎         | 36/1000 [00:00<00:00, 1640.48it/s]
All-or-Nothing - Traffic Class: car               :   4%|▎         | 36/1000 [00:00<00:00, 1638.35it/s]

2026-11-23 06:36:15,210;INFO ; 36,0.0025870156274787927,0.08532578952857073

All-or-Nothing - Traffic Class: car               :   4%|▎         | 36/1000 [00:00<00:00, 1603.89it/s]
Equilibrium Assignment - Iteration: 36/1000 - RGap: 0.00258702:   4%|▎         | 36/1000 [00:00<00:00, 1601.07it/s]
Equilibrium Assignment                            :   4%|▎         | 37/1000 [00:00<00:00, 1643.12it/s]
All-or-Nothing - Traffic Class: car               :   4%|▎         | 37/1000 [00:00<00:00, 1640.93it/s]

2026-11-23 06:36:15,210;INFO ; 37,0.002256256926787925,0.1731558811922753

All-or-Nothing - Traffic Class: car               :   4%|▎         | 37/1000 [00:00<00:00, 1604.84it/s]
Equilibrium Assignment - Iteration: 37/1000 - RGap: 0.00225626:   4%|▎         | 37/1000 [00:00<00:00, 1601.62it/s]
Equilibrium Assignment                            :   4%|▍         | 38/1000 [00:00<00:00, 1642.05it/s]
All-or-Nothing - Traffic Class: car               :   4%|▍         | 38/1000 [00:00<00:00, 1639.73it/s]

2026-11-23 06:36:15,211;INFO ; 38,0.0019712280906955966,0.15293940408908577

All-or-Nothing - Traffic Class: car               :   4%|▍         | 38/1000 [00:00<00:00, 1602.51it/s]
Equilibrium Assignment - Iteration: 38/1000 - RGap: 0.00197123:   4%|▍         | 38/1000 [00:00<00:00, 1599.21it/s]
Equilibrium Assignment                            :   4%|▍         | 39/1000 [00:00<00:00, 1638.79it/s]
All-or-Nothing - Traffic Class: car               :   4%|▍         | 39/1000 [00:00<00:00, 1636.65it/s]

2026-11-23 06:36:15,211;WARNING ; zero weight blend: infinite skim values may produce NaN

All-or-Nothing - Traffic Class: car               :   4%|▍         | 39/1000 [00:00<00:00, 1613.18it/s]

2026-11-23 06:36:15,212;INFO ; 39,0.0016944864716724052,0.12413536741025445

All-or-Nothing - Traffic Class: car               :   4%|▍         | 39/1000 [00:00<00:00, 1597.35it/s]
Equilibrium Assignment - Iteration: 39/1000 - RGap: 0.00169449:   4%|▍         | 39/1000 [00:00<00:00, 1594.78it/s]
Equilibrium Assignment                            :   4%|▍         | 40/1000 [00:00<00:00, 1633.42it/s]
All-or-Nothing - Traffic Class: car               :   4%|▍         | 40/1000 [00:00<00:00, 1631.41it/s]

2026-11-23 06:36:15,212;INFO ; 40,0.001855434633644199,0.21741995994704033

All-or-Nothing - Traffic Class: car               :   4%|▍         | 40/1000 [00:00<00:00, 1598.70it/s]
Equilibrium Assignment - Iteration: 40/1000 - RGap: 0.00185543:   4%|▍         | 40/1000 [00:00<00:00, 1595.73it/s]
Equilibrium Assignment                            :   4%|▍         | 41/1000 [00:00<00:00, 1633.48it/s]
All-or-Nothing - Traffic Class: car               :   4%|▍         | 41/1000 [00:00<00:00, 1631.54it/s]

2026-11-23 06:36:15,213;WARNING ; zero weight blend: infinite skim values may produce NaN

All-or-Nothing - Traffic Class: car               :   4%|▍         | 41/1000 [00:00<00:00, 1610.37it/s]

2026-11-23 06:36:15,213;INFO ; 41,0.002068813194238471,0.1935494212591544

All-or-Nothing - Traffic Class: car               :   4%|▍         | 41/1000 [00:00<00:00, 1593.42it/s]
Equilibrium Assignment - Iteration: 41/1000 - RGap: 0.00206881:   4%|▍         | 41/1000 [00:00<00:00, 1590.85it/s]
Equilibrium Assignment                            :   4%|▍         | 42/1000 [00:00<00:00, 1627.55it/s]
All-or-Nothing - Traffic Class: car               :   4%|▍         | 42/1000 [00:00<00:00, 1625.64it/s]

2026-11-23 06:36:15,214;INFO ; 42,0.0019774079905162064,0.44975105825027883

All-or-Nothing - Traffic Class: car               :   4%|▍         | 42/1000 [00:00<00:00, 1594.73it/s]
Equilibrium Assignment - Iteration: 42/1000 - RGap: 0.00197741:   4%|▍         | 42/1000 [00:00<00:00, 1592.21it/s]
Equilibrium Assignment                            :   4%|▍         | 43/1000 [00:00<00:00, 1628.09it/s]
All-or-Nothing - Traffic Class: car               :   4%|▍         | 43/1000 [00:00<00:00, 1626.21it/s]

2026-11-23 06:36:15,214;INFO ; 43,0.0015921406213157043,0.17421327791691452

All-or-Nothing - Traffic Class: car               :   4%|▍         | 43/1000 [00:00<00:00, 1594.76it/s]
Equilibrium Assignment - Iteration: 43/1000 - RGap: 0.00159214:   4%|▍         | 43/1000 [00:00<00:00, 1591.68it/s]
Equilibrium Assignment                            :   4%|▍         | 44/1000 [00:00<00:00, 1626.13it/s]
All-or-Nothing - Traffic Class: car               :   4%|▍         | 44/1000 [00:00<00:00, 1624.30it/s]

2026-11-23 06:36:15,215;INFO ; 44,0.0012555453136291039,0.13748393745882995

All-or-Nothing - Traffic Class: car               :   4%|▍         | 44/1000 [00:00<00:00, 1595.62it/s]
Equilibrium Assignment - Iteration: 44/1000 - RGap: 0.00125555:   4%|▍         | 44/1000 [00:00<00:00, 1593.22it/s]
Equilibrium Assignment                            :   4%|▍         | 45/1000 [00:00<00:00, 1626.58it/s]
All-or-Nothing - Traffic Class: car               :   4%|▍         | 45/1000 [00:00<00:00, 1624.68it/s]

2026-11-23 06:36:15,215;INFO ; 45,0.0011701957344778826,0.10615777662183085

All-or-Nothing - Traffic Class: car               :   4%|▍         | 45/1000 [00:00<00:00, 1597.02it/s]
Equilibrium Assignment - Iteration: 45/1000 - RGap: 0.0011702:   4%|▍         | 45/1000 [00:00<00:00, 1594.67it/s]
Equilibrium Assignment                            :   5%|▍         | 46/1000 [00:00<00:00, 1628.20it/s]
All-or-Nothing - Traffic Class: car               :   5%|▍         | 46/1000 [00:00<00:00, 1626.54it/s]

2026-11-23 06:36:15,216;INFO ; 46,0.0012990275462257785,0.2592836388961607

All-or-Nothing - Traffic Class: car               :   5%|▍         | 46/1000 [00:00<00:00, 1597.79it/s]
Equilibrium Assignment - Iteration: 46/1000 - RGap: 0.00129903:   5%|▍         | 46/1000 [00:00<00:00, 1594.86it/s]
Equilibrium Assignment                            :   5%|▍         | 47/1000 [00:00<00:00, 1627.46it/s]
All-or-Nothing - Traffic Class: car               :   5%|▍         | 47/1000 [00:00<00:00, 1625.82it/s]

2026-11-23 06:36:15,217;INFO ; 47,0.0016251801857951145,0.22776458945281172

All-or-Nothing - Traffic Class: car               :   5%|▍         | 47/1000 [00:00<00:00, 1599.46it/s]
Equilibrium Assignment - Iteration: 47/1000 - RGap: 0.00162518:   5%|▍         | 47/1000 [00:00<00:00, 1597.17it/s]
Equilibrium Assignment                            :   5%|▍         | 48/1000 [00:00<00:00, 1629.33it/s]
All-or-Nothing - Traffic Class: car               :   5%|▍         | 48/1000 [00:00<00:00, 1627.71it/s]

2026-11-23 06:36:15,217;INFO ; 48,0.0012404030429357153,0.22479302809702625

All-or-Nothing - Traffic Class: car               :   5%|▍         | 48/1000 [00:00<00:00, 1601.10it/s]
Equilibrium Assignment - Iteration: 48/1000 - RGap: 0.0012404:   5%|▍         | 48/1000 [00:00<00:00, 1598.78it/s]
Equilibrium Assignment                            :   5%|▍         | 49/1000 [00:00<00:00, 1630.33it/s]
All-or-Nothing - Traffic Class: car               :   5%|▍         | 49/1000 [00:00<00:00, 1628.77it/s]

2026-11-23 06:36:15,218;INFO ; 49,0.0011197535305810323,0.16572384651685768

All-or-Nothing - Traffic Class: car               :   5%|▍         | 49/1000 [00:00<00:00, 1597.41it/s]
Equilibrium Assignment - Iteration: 49/1000 - RGap: 0.00111975:   5%|▍         | 49/1000 [00:00<00:00, 1594.54it/s]
Equilibrium Assignment                            :   5%|▌         | 50/1000 [00:00<00:00, 1624.99it/s]
All-or-Nothing - Traffic Class: car               :   5%|▌         | 50/1000 [00:00<00:00, 1623.35it/s]

2026-11-23 06:36:15,219;INFO ; 50,0.001084921254077063,0.20326482699172146

All-or-Nothing - Traffic Class: car               :   5%|▌         | 50/1000 [00:00<00:00, 1595.31it/s]
Equilibrium Assignment - Iteration: 50/1000 - RGap: 0.00108492:   5%|▌         | 50/1000 [00:00<00:00, 1592.71it/s]
Equilibrium Assignment                            :   5%|▌         | 51/1000 [00:00<00:00, 1622.59it/s]
All-or-Nothing - Traffic Class: car               :   5%|▌         | 51/1000 [00:00<00:00, 1620.81it/s]

2026-11-23 06:36:15,219;INFO ; 51,0.0008283431216585221,nan

All-or-Nothing - Traffic Class: car               :   5%|▌         | 51/1000 [00:00<00:00, 1610.19it/s]

2026-11-23 06:36:15,219;INFO ; bfw Assignment finished. 51 iterations, final AoN rgap = 0.0008283431216585221

All-or-Nothing - Traffic Class: car               :   5%|▌         | 51/1000 [00:00<00:00, 1605.14it/s]
matrix_ab matrix_ba matrix_tot Preload_AB Preload_BA Preload_tot Congested_Time_AB Congested_Time_BA Congested_Time_Max Delay_factor_AB Delay_factor_BA Delay_factor_Max VOC_AB VOC_BA VOC_max PCE_AB PCE_BA PCE_tot
link_id
1 4532.259225 0.0 4532.259225 0.0 0.0 0.0 6.000844 0.0 6.000844 1.000141 0.0 1.000141 0.174989 0.0 0.174989 4532.259225 0.0 4532.259225
2 8124.401779 0.0 8124.401779 0.0 0.0 0.0 4.008714 0.0 4.008714 1.002178 0.0 1.002178 0.347145 0.0 0.347145 8124.401779 0.0 8124.401779
3 4524.401779 0.0 4524.401779 0.0 0.0 0.0 6.000838 0.0 6.000838 1.000140 0.0 1.000140 0.174686 0.0 0.174686 4524.401779 0.0 4524.401779
4 5913.685237 0.0 5913.685237 0.0 0.0 0.0 6.517765 0.0 6.517765 1.303553 0.0 1.303553 1.192713 0.0 1.192713 5913.685237 0.0 5913.685237
5 8132.259225 0.0 8132.259225 0.0 0.0 0.0 4.008747 0.0 4.008747 1.002187 0.0 1.002187 0.347481 0.0 0.347481 8132.259225 0.0 8132.259225
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
72 9645.734151 0.0 9645.734151 0.0 0.0 0.0 12.310217 0.0 12.310217 3.077554 0.0 3.077554 1.929147 0.0 1.929147 9645.734151 0.0 9645.734151
73 7848.474395 0.0 7848.474395 0.0 0.0 0.0 3.711266 0.0 3.711266 1.855633 0.0 1.855633 1.545429 0.0 1.545429 7848.474395 0.0 7848.474395
74 11066.019693 0.0 11066.019693 0.0 0.0 0.0 17.391130 0.0 17.391130 4.347782 0.0 4.347782 2.173534 0.0 2.173534 11066.019693 0.0 11066.019693
75 10214.009370 0.0 10214.009370 0.0 0.0 0.0 11.598290 0.0 11.598290 3.866097 0.0 3.866097 2.090739 0.0 2.090739 10214.009370 0.0 10214.009370
76 7833.540663 0.0 7833.540663 0.0 0.0 0.0 3.698279 0.0 3.698279 1.849139 0.0 1.849139 1.542488 0.0 1.542488 7833.540663 0.0 7833.540663

76 rows × 18 columns



After finishing the assignment, we can easily see the convergence report.

convergence_report = assig.report()
convergence_report.head()
iteration time rgap alpha warnings beta0 beta1 beta2 conjugacy_prev conjugacy_prev2 hessian_drift bfw_clamped
0 1 0.001184 inf 1.000000 1.000000 0.000000 0.0 NaN NaN NaN NaN
1 2 0.001860 0.897805 0.328400 1.000000 0.000000 0.0 NaN NaN NaN NaN
2 3 0.002666 0.527933 0.186602 1.000000 0.000000 0.0 NaN NaN NaN NaN
3 4 0.003513 0.288744 0.241148 1.000000 0.000000 0.0 9.131125e-03 0.150500 0.076780 True
4 5 0.004350 0.196074 0.818547 0.607382 0.392618 0.0 -2.891974e-18 0.021602 -0.069162 True


And we can also see the results of the assignment

results = assig.results()
results.head()
matrix_ab matrix_ba matrix_tot Preload_AB Preload_BA Preload_tot Congested_Time_AB Congested_Time_BA Congested_Time_Max Delay_factor_AB Delay_factor_BA Delay_factor_Max VOC_AB VOC_BA VOC_max PCE_AB PCE_BA PCE_tot
link_id
1 4532.259225 0.0 4532.259225 0.0 0.0 0.0 6.000844 0.0 6.000844 1.000141 0.0 1.000141 0.174989 0.0 0.174989 4532.259225 0.0 4532.259225
2 8124.401779 0.0 8124.401779 0.0 0.0 0.0 4.008714 0.0 4.008714 1.002178 0.0 1.002178 0.347145 0.0 0.347145 8124.401779 0.0 8124.401779
3 4524.401779 0.0 4524.401779 0.0 0.0 0.0 6.000838 0.0 6.000838 1.000140 0.0 1.000140 0.174686 0.0 0.174686 4524.401779 0.0 4524.401779
4 5913.685237 0.0 5913.685237 0.0 0.0 0.0 6.517765 0.0 6.517765 1.303553 0.0 1.303553 1.192713 0.0 1.192713 5913.685237 0.0 5913.685237
5 8132.259225 0.0 8132.259225 0.0 0.0 0.0 4.008747 0.0 4.008747 1.002187 0.0 1.002187 0.347481 0.0 0.347481 8132.259225 0.0 8132.259225


We can export our results to CSV or get a Pandas DataFrame, but let’s put it directly into the results database

assig.save_results("base_year_assignment")
ResultRecord(scenario=None, year=None, table_name='base_year_assignment', reference_table='links', procedure='traffic assignment', procedure_id='baeb1defa1814b39a835a2c5fd1c9f18', procedure_report='{"convergence": {"iteration": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51], "time": [0.0011842320000141626, 0.0018602000000100816, 0.002666407999981857, 0.003513069000064206, 0.0043502370000396695, 0.005178334999982326, 0.00572390800004996, 0.0062822370000503724, 0.007106844000077217, 0.007872394000060012, 0.008364372000073672, 0.008876917000065987, 0.009618541000008918, 0.010238601000082781, 0.0109816020000153, 0.011458411000035085, 0.011985008999999991, 0.012618177000035757, 0.013202547999981107, 0.0138096719999794, 0.014488104000065505, 0.014966630999992958, 0.015436105000048883, 0.0160378819999778, 0.01675567500001307, 0.017324281000014707, 0.017908413999975892, 0.018646128000000317, 0.0190935210000589, 0.019560607000016716, 0.02015273500001058, 0.020741937000025246, 0.021383365000019694, 0.022031648000051973, 0.022696484999983113, 0.023291774000085752, 0.023893172000043705, 0.02453001900005347, 0.025268446000040967, 0.02586226699997951, 0.02657071300006919, 0.02718701499998133, 0.02779724599997735, 0.028422443000067688, 0.029020669000033195, 0.02962214900003346, 0.030229006000013214, 0.030820616000028167, 0.031406458999981623, 0.03217059000007794, 0.032503682000083245], "rgap": [null, 0.89780457879145, 0.5279325275367827, 0.28874383368012313, 0.19607377855371996, 0.22325602275663892, 0.17157154728042692, 0.08442324131581802, 0.07826339212239238, 0.09301015583411931, 0.06921891008667841, 0.040234500847269324, 0.03296645686481366, 0.035081093446416724, 0.03200399984459911, 0.021040384142766117, 0.012925420204469549, 0.012294041013807001, 0.012316538874428259, 0.011735043381187355, 0.013592539642584927, 0.00994976386388666, 0.007300114596153, 0.006804251749703222, 0.005393460474102812, 0.005851357665095232, 0.007713407379077174, 0.006665546808826156, 0.004781690445278009, 0.004261520961977526, 0.0038126726071258076, 0.0039018385989099892, 0.0027691782467265474, 0.002922596383931646, 0.0025376020166008187, 0.0025870156274787927, 0.002256256926787925, 0.0019712280906955966, 0.0016944864716724052, 0.001855434633644199, 0.002068813194238471, 0.0019774079905162064, 0.0015921406213157043, 0.0012555453136291039, 0.0011701957344778826, 0.0012990275462257785, 0.0016251801857951145, 0.0012404030429357153, 0.0011197535305810323, 0.001084921254077063, 0.0008283431216585221], "alpha": [1.0, 0.32839952448634563, 0.18660240547488702, 0.24114774402917927, 0.8185470737942451, 1.0, 0.16910548905080566, 0.2373694741062248, 0.5860366441988628, 1.0, 0.11507399176716364, 0.15591705624574248, 0.2778261672706741, 0.6208345025526621, 1.0, 0.11598592580715987, 0.1073638625831236, 0.1558846600948632, 0.33733828320278225, 0.5959894379150801, 1.0, 0.07079581621265686, 0.07166629092302472, 0.16836899188970833, 0.17808313987176075, 0.3501427558560422, 0.7043109868542726, 1.0, 0.04490489890507015, 0.07014221441138183, 0.09742344627690626, 0.06258400921325322, 0.06719595392325393, 0.12319408791407051, 0.12906133722764354, 0.08532578952857073, 0.1731558811922753, 0.15293940408908577, 0.12413536741025445, 0.21741995994704033, 0.1935494212591544, 0.44975105825027883, 0.17421327791691452, 0.13748393745882995, 0.10615777662183085, 0.2592836388961607, 0.22776458945281172, 0.22479302809702625, 0.16572384651685768, 0.20326482699172146, null], "warnings": ["", "", "", "", "", "", "Invalid BFW mu coefficient; using the Frank-Wolfe direction.", "", "", "", "Invalid BFW mu coefficient; using the Frank-Wolfe direction.", "", "", "", "", "Invalid BFW mu coefficient; using the Frank-Wolfe direction.", "", "", "", "", "", "Invalid BFW mu coefficient; using the Frank-Wolfe direction.", "", "", "", "", "", "", "Invalid BFW mu coefficient; using the Frank-Wolfe direction.", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""], "beta0": [1.0, 1.0, 1.0, 1.0, 0.6073815058784465, 0.07423949064975859, 1.0, 0.8978530762747693, 0.5210859419543844, 0.1310033991660148, 1.0, 0.9742007731752091, 0.6352581871354512, 0.2722926744813646, 0.09981147064012809, 1.0, 0.6455493939118717, 0.5446197221699854, 0.37684414353412243, 0.16621614561922343, 0.04991453282323065, 1.0, 0.7074847674334792, 0.4072593278628423, 0.40744644365281185, 0.20433348406491295, 0.06663070239531205, 0.029625006738385674, 1.0, 0.5852667007449526, 0.4424370061333522, 0.3708511650436959, 0.4551343032566526, 0.2748343405904143, 0.22452183524522543, 0.20186352946257047, 0.16232137716499528, 0.1259922663383409, 0.1615674198680147, 0.15289844737629416, 0.12132552966917991, 0.06015011468395385, 0.06792101594525256, 0.10930383488126696, 0.10902569537616233, 0.07965537234423714, 0.06287953215867469, 0.07618194736558329, 0.04815025482449651, 0.048560120740651316, null], "beta1": [0.0, 0.0, 0.0, 0.0, 0.3926184941215534, 0.9219957845105672, 0.0, 0.10214692372523075, 0.4789140580456156, 0.8197346588839601, 0.0, 0.025799226824790834, 0.3647418128645487, 0.5721070219950798, 0.8181558381669438, 0.0, 0.35445060608812834, 0.4000965092918508, 0.4927909805267271, 0.6548989237156498, 0.7769507091170393, 0.0, 0.29251523256652084, 0.28549566818797606, 0.592553556347188, 0.5576934139435734, 0.6817201921586137, 0.8163820339273872, 0.0, 0.4147332992550475, 0.460177344064391, 0.5738578607038743, 0.37492390353725413, 0.4607323288241859, 0.509807610503288, 0.6619456170545638, 0.34772563023431324, 0.7353255450795453, 0.8384325801319853, 0.7604848469753155, 0.8786744703308201, 0.5133108057202137, 0.6564197384787078, 0.4267799495993852, 0.6184552488281203, 0.5705998302076256, 0.8286395700832462, 0.49426833985049434, 0.6279091242565378, 0.6527313799882105, null], "beta2": [0.0, 0.0, 0.0, 0.0, 0.0, 0.003764724839674331, 0.0, 0.0, 0.0, 0.04926194195002498, 0.0, 0.0, 0.0, 0.15560030352355556, 0.08203269119292825, 0.0, 0.0, 0.05528376853816371, 0.1303648759391504, 0.1788849306651267, 0.1731347580597302, 0.0, 0.0, 0.30724500394918164, 0.0, 0.23797310199151364, 0.2516491054460742, 0.15399295933422713, 0.0, 0.0, 0.09738564980225695, 0.055290974252429695, 0.16994179320609326, 0.2644333305853997, 0.26567055425148656, 0.13619085348286575, 0.48995299260069153, 0.13868218858211373, 0.0, 0.08661670564839039, 0.0, 0.42653907959583237, 0.27565924557603955, 0.46391621551934775, 0.27251905579571745, 0.34974479744813725, 0.10848089775807905, 0.42954971278392234, 0.3239406209189658, 0.2987084992711381, null], "conjugacy_prev": [null, null, null, 0.009131125464184143, -2.8919736861073706e-18, -0.012511873440793726, null, null, 9.752112149740471e-17, -0.01421060232796462, null, null, -5.180557641603795e-17, -0.03721667928957669, -0.04232333304460143, null, null, -9.054458857724459e-05, -0.00599182744972153, 0.006162339055411461, -0.007986557804704938, null, null, 0.004880909102529844, 1.5231514511258254e-16, 0.00467255658374935, -0.007193655299715711, -0.004901760723609507, null, null, 0.0007232929946526874, 7.544979653403968e-05, -6.704952251526902e-05, -0.0013564303708551416, -0.00012783640107913652, 0.0007741767294959595, 0.001178485086821133, 0.0003441741181014419, -4.5556893021176925e-17, -0.00010649996786908598, -1.816473036328716e-16, -0.0020837002783275784, -0.0002144675944955004, -0.0004330480114696872, -8.092878046182701e-05, -0.00020829470406362387, -0.00046207405415329126, -0.0014479060710527714, -9.254720616895141e-05, -0.00035889450234194545, null], "conjugacy_prev2": [null, null, null, 0.15050043269340133, 0.021601664936027155, -0.2642675529346801, null, null, 0.28017408784291503, -0.05927016099392479, null, null, 0.2803824954703134, -0.08575523367277281, -0.1096874048538775, null, null, -0.0005017604791585371, -0.020422748016858314, 0.012649178133339902, -0.013055424727827317, null, null, 0.006768499271202243, 0.12252034341003173, 0.013370079227946679, -0.011095890630428802, -0.006554309703401488, null, null, 0.002301386623972259, 0.0005818622776930699, -0.0002586772162807555, -0.0033470987061794614, -0.00020690333696106846, 0.003715793060792712, 0.0025013983969461003, 0.0011484359452320892, 0.04631206018352924, -0.001260021423547524, 0.03392168236437078, -0.004718828010445438, -0.0002238746805746971, -0.0019105744808382787, -0.0003513939430952122, -0.0006232238578322755, -0.001906964014079279, -0.003441148244840033, -0.0002631320716060108, -0.0010830181436810766, null], "hessian_drift": [null, null, null, 0.07677956339453926, -0.06916185755930719, -0.289376248048675, null, null, -0.02816755779577692, -0.03801781620375066, null, null, -0.09102804077988096, -0.07210923042491592, -0.0804766525163474, null, null, -0.0009016798345824896, -0.021791667020364055, 0.011136820823544244, -0.010569437978811937, null, null, 0.005878800227037329, 0.007459167322626112, 0.010803265852573003, -0.008479651188456349, -0.008888264229722404, null, null, 0.0031040050432984195, 0.001185455735074406, -0.00045607283930179676, -0.0029182540810906614, -0.0002497897074662279, 0.006245668916215601, 0.0019077997364233428, 0.0013943363656468942, 0.004679392374055461, -0.0013019729187760843, 0.003151011683804278, -0.00281699871434828, -0.0006718164508872158, -0.003303396410221019, -0.0005017025925719387, -0.0004350362038069228, -0.0028935715748487773, -0.0046576551129433865, -0.00031388510170638476, -0.0012176889884835357, null], "bfw_clamped": [null, null, null, true, true, false, null, null, true, false, null, null, true, false, false, null, null, false, false, false, false, null, null, false, true, false, false, false, null, null, false, false, false, false, false, false, false, false, true, false, true, false, false, false, false, false, false, false, false, false, null]}, "setup": {"Algorithm": "bfw", "Classes": {"car": {"network mode": "c", "cost": "free_flow_time", "PCE": 1.0, "Value-of-time": 1.0, "Fixed cost field": null, "Fixed cost multiplier": 1.0, "matrix_totals": {"matrix": 360600.0}}}, "Computer name": "runnervm0hi8g", "Maximum iterations": 1000, "Procedure ID": "baeb1defa1814b39a835a2c5fd1c9f18", "Target RGap": 0.001}}', timestamp='2026-11-23 06:36:15.163306', description='')

And save the skims

assig.save_skims("base_year_assignment_skims", which_ones="all", format="omx")
['base_year_assignment_skims_car.omx']

Trip distribution#

First, let’s have a function to plot the Trip Length Frequency Distribution.

from math import log10, floor
import matplotlib.pyplot as plt
def plot_tlfd(demand, skim, name):
    plt.clf()
    b = floor(log10(skim.shape[0]) * 10)
    n, bins, patches = plt.hist(
        np.nan_to_num(skim.flatten(), 0),
        bins=b,
        weights=np.nan_to_num(demand.flatten()),
        density=False,
        facecolor="g",
        alpha=0.75,
    )

    plt.xlabel("Trip length")
    plt.ylabel("Probability")
    plt.title(f"Trip-length frequency distribution for {name}")
    return plt

Calibration#

We will calibrate synthetic gravity models using the skims for free_flow_time that we just generated

import numpy as np
from aequilibrae.distribution import GravityCalibration

Load the demand matrix core for computation.

demand = proj_matrices.get_matrix("demand.omx", subset=["matrix"])

We also need the skims we just saved into our project. We select the congested-time core.

imped_core = "free_flow_time_final"
imped = proj_matrices.get_matrix("base_year_assignment_skims_car.omx", subset=[imped_core])

# Where ``free_flow_time_final`` is the congested time for the last iteration.
# Use 75% of the closest zone for intrazonal impedance.
impedance_values = imped[imped_core].copy()
np.fill_diagonal(impedance_values, 0)
intrazonals = np.amin(
    impedance_values, where=impedance_values > 0, initial=impedance_values.max(), axis=1
)
intrazonals *= 0.75
np.fill_diagonal(impedance_values, intrazonals)

# Store the prepared core as a separate project matrix.
del imped[imped_core]
imped["final_time_with_intrazonals"] = impedance_values
proj_matrices.save_matrix(
    "base_year_assignment_skims_car_intrazonals.omx",
    matrix=imped,
)

Let’s calibrate our Gravity Model

for function in ["power", "expo"]:
    gc = GravityCalibration(matrix=demand, impedance=imped, function=function, nan_as_zero=True)
    gc.calibrate()
    model = gc.model
    # We save the model
    model.save(join(fldr, f"{function}_model.mod"))

    result_core = next(iter(gc.result_matrix))
    _ = plot_tlfd(
        gc.result_matrix[result_core], imped["final_time_with_intrazonals"], f"{function} model"
    )

    # We can save the result of applying the model as well
    # We can also save the calibration report
    with open(join(fldr, f"{function}_convergence.log"), "w") as otp:
        for r in gc.report:
            otp.write(r + "\n")
Trip-length frequency distribution for expo model

And let’s plot a trip length frequency distribution for the demand itself

plt = plot_tlfd(demand["matrix"], imped["final_time_with_intrazonals"], "demand")
plt.show()
Trip-length frequency distribution for demand

Forecast#

We create a set of ‘future’ vectors using some random growth factors. We apply the model for inverse power, as the trip frequency length distribution (TFLD) seems to be a better fit for the actual one.

from aequilibrae.distribution import Ipf, GravityApplication, SyntheticGravityModel

Compute future vectors#

First thing to do is to compute the future vectors from our matrix.

origins = np.sum(demand["matrix"], axis=1)
destinations = np.sum(demand["matrix"], axis=0)

# Then grow them with some random growth between 0 and 10%, and balance them
orig = origins * (1 + np.random.rand(origins.shape[0]) / 10)
dest = destinations * (1 + np.random.rand(origins.shape[0]) / 10)
dest *= orig.sum() / dest.sum()

vectors = pd.DataFrame({"origins":orig, "destinations":dest}, index=demand.index[:])

IPF for the future vectors#

Let’s balance the future vectors. The output of this step is going to be used later in the traffic assignment for future year.

args = {
    "matrix": demand,
    "vectors": vectors,
    "column_field": "destinations",
    "row_field": "origins",
    "nan_as_zero": True,
}

ipf = Ipf(project=project, **args)
ipf.fit()

Save the balanced matrix into the project’s matrix folder

ipf.save_to_project(file_name="demand_ipfd.omx")

Impedance#

Let’s get the base-year assignment skim for car we created before and prepare it for computation

imped = proj_matrices.get_matrix(
    "base_year_assignment_skims_car_intrazonals.omx", subset=["final_time_with_intrazonals"]
)

If we wanted the main diagonal to not be considered…

# np.fill_diagonal(imped["final_time_with_intrazonals"], np.nan)

Now we apply the Synthetic Gravity model

for function in ["power", "expo"]:
    model = SyntheticGravityModel()
    model.load(join(fldr, f"{function}_model.mod"))

    args = {
        "impedance": imped,
        "vectors": vectors,
        "row_field": "origins",
        "model": model,
        "column_field": "destinations",
        "nan_as_zero": True,
    }

    gravity = GravityApplication(project=project, **args)
    gravity.apply()

    # We get the output matrix and save it to OMX too,
    gravity.save_to_project(file_name=f"demand_{function}_modeled.omx")

We inspect the matrix files and verify that the new matrices are indeed there

proj_matrices.get_available_matrices_and_metadata()
{'demand_ipfd.omx': {'procedure': 'Iterative Proportional fitting', 'procedure_id': '7fbefdc3055b4c518c0dce4585cd89b2', 'timestamp': '2026-11-23 06:36:15.406065', 'description': 'Original data imported to OMX format'}, 'base_year_assignment_skims_car.omx': {'procedure': 'Traffic Assignment', 'procedure_id': 'baeb1defa1814b39a835a2c5fd1c9f18', 'timestamp': '2026-11-23 06:36:15.163306', 'description': 'Skimming for assignment procedure. Class car'}, 'demand_expo_modeled.omx': {'procedure': 'Synthetic gravity trip distribution', 'procedure_id': 'cd332bd635ce47cf98a7273c2341a553', 'timestamp': '2026-11-23 06:36:15.417100', 'description': 'Synthetic gravity trip distribution. EXPO'}, 'base_year_assignment_skims_car_intrazonals.omx': {'procedure': 'Traffic Assignment', 'procedure_id': 'baeb1defa1814b39a835a2c5fd1c9f18', 'timestamp': '2026-11-23 06:36:15.163306', 'description': 'Skimming for assignment procedure. Class car'}, 'demand_power_modeled.omx': {'procedure': 'Synthetic gravity trip distribution', 'procedure_id': '0d3c15445c794298b0ee4bb77930cb15', 'timestamp': '2026-11-23 06:36:15.412062', 'description': 'Synthetic gravity trip distribution. POWER'}, 'skims.omx': {'procedure': None, 'procedure_id': None, 'timestamp': None, 'description': 'Example skim'}, 'demand.omx': {'procedure': None, 'procedure_id': None, 'timestamp': '2020-11-24 08:47:18', 'description': 'Original data imported to OMX format'}, 'demand_mc.omx': {'procedure': None, 'procedure_id': None, 'timestamp': '2021-02-24 00:51:35', 'description': None}}