Forecasting#

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

Imports

from uuid import uuid4
from tempfile import gettempdir
from os.path import join
from aequilibrae.utils.create_example import create_example
import logging
import sys

We create the example project inside our temp folder

fldr = join(gettempdir(), uuid4().hex)

project = create_example(fldr)
logger = project.logger

# We get the project open, and we can tell the logger to direct all messages to the terminal as well
stdout_handler = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter("%(asctime)s;%(levelname)s ; %(message)s")
stdout_handler.setFormatter(formatter)
logger.addHandler(stdout_handler)

Traffic assignment with skimming#

from aequilibrae.paths import TrafficAssignment, TrafficClass

We build all graphs

project.network.build_graphs()
# We get warnings that several fields in the project are filled with NaNs.
# This is true, but we won't use those fields
2023-07-10 09:02:47,983;WARNING ; Field(s) name, lanes has(ve) at least one NaN value. Check your computations
2023-07-10 09:02:48,028;WARNING ; Field(s) name, lanes has(ve) at least one NaN value. Check your computations
2023-07-10 09:02:48,073;WARNING ; Field(s) name, lanes has(ve) at least one NaN value. Check your computations
2023-07-10 09:02:48,116;WARNING ; Field(s) name, lanes has(ve) at least one NaN value. Check your computations
2023-07-10 09:02:48,160;WARNING ; Field(s) name, lanes has(ve) at least one NaN value. Check your computations
2023-07-10 09:02:48,204;WARNING ; Field(s) name, lanes has(ve) at least one NaN value. Check your computations

We grab the graph for cars

graph = project.network.graphs["c"]

# Let's say we want to minimize the free_flow_time
graph.set_graph("free_flow_time")

# And will skim time and distance while we are at it
graph.set_skimming(["free_flow_time", "distance"])

# And we will allow paths to be computed going through other centroids/centroid connectors
# required for the Sioux Falls network, as all nodes are centroids
graph.set_blocked_centroid_flows(False)
2023-07-10 09:02:48,234;WARNING ; Cost field with wrong type. Converting to float64

We get the demand matrix directly from the project record So let’s inspect what we have in the project

proj_matrices = project.matrices
print(proj_matrices.list())
         name      file_name  ...                           description status
0  demand_omx     demand.omx  ...  Original data imported to OMX format
1   demand_mc  demand_mc.omx  ...                                  None
2       skims      skims.omx  ...                          Example skim
3  demand_aem     demand.aem  ...  Original data imported to AEM format

[4 rows x 8 columns]

Let’s get it in this better way

demand = proj_matrices.get_matrix("demand_omx")
demand.computational_view(["matrix"])
assig = TrafficAssignment()

# Create the assignment class
assigclass = TrafficClass(name="car", graph=graph, matrix=demand)

# The first thing to do is to add at list of traffic classes to be assigned
assig.add_class(assigclass)

# We set these parameters only after adding one class to the assignment
assig.set_vdf("BPR")  # This is not case-sensitive

# Then we set the volume delay function
assig.set_vdf_parameters({"alpha": "b", "beta": "power"})  # And its parameters

assig.set_capacity_field("capacity")  # The capacity and free flow travel times as they exist in the graph
assig.set_time_field("free_flow_time")

# And the algorithm we want to use to assign
assig.set_algorithm("bfw")

# Since I haven't checked the parameters file, let's make sure convergence criteria is good
assig.max_iter = 1000
assig.rgap_target = 0.001

assig.execute()  # we then execute the assignment
2023-07-10 09:02:48,613;INFO ; Traffic Class specification
2023-07-10 09:02:48,613;INFO ; {'car': {'Graph': "{'Mode': 'c', 'Block through centroids': False, 'Number of centroids': 24, 'Links': 76, 'Nodes': 24}", 'Matrix': "{'Source': '/tmp/605a246ed3434856bcb0123287fe45e2/matrices/demand.omx', 'Number of centroids': 24, 'Matrix cores': ['matrix'], 'Matrix totals': {'matrix': 360600.0}}"}}
2023-07-10 09:02:48,613;INFO ; Traffic Assignment specification
2023-07-10 09:02:48,613;INFO ; {'VDF parameters': {'alpha': 'b', 'beta': 'power'}, 'VDF function': 'bpr', 'Number of cores': 2, 'Capacity field': 'capacity', 'Time field': 'free_flow_time', 'Algorithm': 'bfw', 'Maximum iterations': 250, 'Target RGAP': 0.0001}
2023-07-10 09:02:48,616;WARNING ; Cost field with wrong type. Converting to float64
2023-07-10 09:02:48,616;INFO ; bfw Assignment STATS
2023-07-10 09:02:48,616;INFO ; Iteration, RelativeGap, stepsize
2023-07-10 09:02:48,625;INFO ; 1,inf,1.0
2023-07-10 09:02:48,631;INFO ; 2,0.8550751349428284,0.32839952448634563
2023-07-10 09:02:48,637;INFO ; 3,0.4763455007221067,0.18660240547488702
2023-07-10 09:02:48,646;INFO ; 4,0.2355126365951965,0.2411477440291793
2023-07-10 09:02:48,654;INFO ; 5,0.10924072010481088,0.8185470737942447
2023-07-10 09:02:48,661;INFO ; 6,0.1980945227617506,0.14054330572978305
2023-07-10 09:02:48,669;INFO ; 7,0.0668172221544687,0.36171152718899247
2023-07-10 09:02:48,675;INFO ; 8,0.06792122267870587,0.9634685345644044
2023-07-10 09:02:48,682;INFO ; 9,0.10705582933092855,0.13757153109677187
2023-07-10 09:02:48,687;INFO ; 10,0.04038814432034622,0.1609403425427973
2023-07-10 09:02:48,693;INFO ; 11,0.025801226183773084,0.716435057617116
2023-07-10 09:02:48,700;INFO ; 12,0.042846437173170424,0.08581544277016687
2023-07-10 09:02:48,705;INFO ; 13,0.016971662333407043,0.1660157969033195
2023-07-10 09:02:48,712;INFO ; 14,0.020396548012132195,0.4461322062863191
2023-07-10 09:02:48,718;INFO ; 15,0.025887901335905694,0.08515995223661561
2023-07-10 09:02:48,725;INFO ; 16,0.015188959427663162,0.1988698342670051
2023-07-10 09:02:48,730;INFO ; 17,0.01475141964322897,0.3548856159715819
2023-07-10 09:02:48,737;INFO ; 18,0.015582407302127808,0.06145415154081679
2023-07-10 09:02:48,743;INFO ; 19,0.008935871473338547,0.08603462968532699
2023-07-10 09:02:48,748;INFO ; 20,0.008477045208211683,0.1668913886047936
2023-07-10 09:02:48,754;INFO ; 21,0.009517581409988221,0.4917099156011133
2023-07-10 09:02:48,760;INFO ; 22,0.013060711845093087,0.060284308755231206
2023-07-10 09:02:48,767;INFO ; 23,0.006861821876765184,0.10954009782378307
2023-07-10 09:02:48,772;INFO ; 24,0.006201113315688483,0.12230718464290123
2023-07-10 09:02:48,778;INFO ; 25,0.0074574049738041406,0.3080614235512652
2023-07-10 09:02:48,784;INFO ; 26,0.006900497787039256,0.32835666337221175
2023-07-10 09:02:48,790;INFO ; 27,0.006963554132391016,0.7377893941135681
2023-07-10 09:02:48,796;INFO ; 28,0.006817764279834173,0.0443870768699142
2023-07-10 09:02:48,808;INFO ; 29,0.004277860366532555,0.05431813621783447
2023-07-10 09:02:48,812;INFO ; 30,0.004136181096381436,0.05758294976347482
2023-07-10 09:02:48,816;INFO ; 31,0.0031483923250298237,0.0918038853550363
2023-07-10 09:02:48,822;INFO ; 32,0.0034184967969881734,0.12279944254979965
2023-07-10 09:02:48,828;INFO ; 33,0.002738614050254322,0.08799214942487946
2023-07-10 09:02:48,835;INFO ; 34,0.0023403784016331874,0.1098259985006849
2023-07-10 09:02:48,841;INFO ; 35,0.0023185435502055523,0.18741920884713098
2023-07-10 09:02:48,847;INFO ; 36,0.0023838181828793143,0.1404967362503087
2023-07-10 09:02:48,855;INFO ; 37,0.0017801377860521138,0.25278698153070905
2023-07-10 09:02:48,861;INFO ; 38,0.0019264349761422953,0.30768123024764726
2023-07-10 09:02:48,866;INFO ; 39,0.0018408894375062524,0.3982324050247662
2023-07-10 09:02:48,872;INFO ; 40,0.0018205742523357215,0.5255149131180074
2023-07-10 09:02:48,878;INFO ; 41,0.0020224171108353135,0.012343794696331265
2023-07-10 09:02:48,885;INFO ; 42,0.001423836778473865,0.03045402621736974
2023-07-10 09:02:48,891;INFO ; 43,0.0011877471305860427,0.02283308748607117
2023-07-10 09:02:48,898;INFO ; 44,0.0012106681494599195,0.06969126002892805
2023-07-10 09:02:48,903;INFO ; 45,0.0011336232568064097,0.038970964685986896
2023-07-10 09:02:48,911;INFO ; 46,0.0009780989052684459,0.022071990851560294
2023-07-10 09:02:48,911;INFO ; bfw Assignment finished. 46 iterations and 0.0009780989052684459 final gap

Convergence report is easy to see

import pandas as pd

convergence_report = assig.report()
print(convergence_report.head())
   iteration      rgap     alpha warnings     beta0     beta1  beta2
0          1       inf  1.000000           1.000000  0.000000    0.0
1          2  0.855075  0.328400           1.000000  0.000000    0.0
2          3  0.476346  0.186602           1.000000  0.000000    0.0
3          4  0.235513  0.241148           1.000000  0.000000    0.0
4          5  0.109241  0.818547           0.607382  0.392618    0.0
volumes = assig.results()
print(volumes.head())
           matrix_ab  matrix_ba   matrix_tot  ...       PCE_AB  PCE_BA      PCE_tot
link_id                                       ...
1        4565.043510        NaN  4565.043510  ...  4565.043510     NaN  4565.043510
2        8152.210795        NaN  8152.210795  ...  8152.210795     NaN  8152.210795
3        4552.603997        NaN  4552.603997  ...  4552.603997     NaN  4552.603997
4        5988.789717        NaN  5988.789717  ...  5988.789717     NaN  5988.789717
5        8164.650309        NaN  8164.650309  ...  8164.650309     NaN  8164.650309

[5 rows x 15 columns]

We could export it to CSV or AequilibraE data, but let’s put it directly into the results database

assig.save_results("base_year_assignment")

And save the skims

assig.save_skims("base_year_assignment_skims", which_ones="all", format="omx")
2023-07-10 09:02:48,998;WARNING ; Matrix Record has been saved to the database

Trip distribution#

Calibration#

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

import numpy as np
from aequilibrae.distribution import GravityCalibration

Let’s take another look at what we have in terms of matrices in the model

print(proj_matrices.list())
                             name  ... status
0                      demand_omx  ...
1                       demand_mc  ...
2                           skims  ...
3                      demand_aem  ...
4  base_year_assignment_skims_car  ...

[5 rows x 8 columns]

We need the demand

demand = proj_matrices.get_matrix("demand_aem")

# And the skims
imped = proj_matrices.get_matrix("base_year_assignment_skims_car")

We can check which matrix cores were created for our skims to decide which one to use

imped.names

# Where ``free_flow_time_final`` is actually the congested time for the last iteration
['distance_blended', 'distance_final', 'free_flow_time_blended', 'free_flow_time_final']

But before using the data, let’s get some impedance for the intrazonals Let’s assume it is 75% of the closest zone

imped_core = "free_flow_time_final"
imped.computational_view([imped_core])

# If we run the code below more than once, we will be overwriting the diagonal values with non-sensical data
# so let's zero it first
np.fill_diagonal(imped.matrix_view, 0)

# We compute it with a little bit of NumPy magic
intrazonals = np.amin(imped.matrix_view, where=imped.matrix_view > 0, initial=imped.matrix_view.max(), axis=1)
intrazonals *= 0.75

# Then we fill in the impedance matrix
np.fill_diagonal(imped.matrix_view, intrazonals)

Since we are working with an OMX file, we cannot overwrite a matrix on disk So we give a new name to save it

imped.save(names=["final_time_with_intrazonals"])

This also updates these new matrices as those being used for computation As one can verify below

imped.view_names
['final_time_with_intrazonals']

We set the matrices for being used in computation

demand.computational_view(["matrix"])
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"))

    # 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")

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
from aequilibrae.matrix import AequilibraeData

We compute the vectors from our matrix

origins = np.sum(demand.matrix_view, axis=1)
destinations = np.sum(demand.matrix_view, axis=0)

args = {
    "file_path": join(fldr, "synthetic_future_vector.aed"),
    "entries": demand.zones,
    "field_names": ["origins", "destinations"],
    "data_types": [np.float64, np.float64],
    "memory_mode": False,
}

vectors = AequilibraeData()
vectors.create_empty(**args)

vectors.index[:] = demand.index[:]

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

Impedance#

imped = proj_matrices.get_matrix("base_year_assignment_skims_car")
imped.computational_view(["final_time_with_intrazonals"])

# If we wanted the main diagonal to not be considered...
# ``np.fill_diagonal(imped.matrix_view, np.nan)``
for function in ["power", "expo"]:
    model = SyntheticGravityModel()
    model.load(join(fldr, f"{function}_model.mod"))

    outmatrix = join(proj_matrices.fldr, f"demand_{function}_model.aem")
    args = {
        "impedance": imped,
        "rows": vectors,
        "row_field": "origins",
        "model": model,
        "columns": vectors,
        "column_field": "destinations",
        "nan_as_zero": True,
    }

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

    # We get the output matrix and save it to OMX too,
    gravity.save_to_project(name=f"demand_{function}_modeled", file_name=f"demand_{function}_modeled.omx")
2023-07-10 09:02:49,983;WARNING ; Matrix Record has been saved to the database
2023-07-10 09:02:50,108;WARNING ; Matrix Record has been saved to the database

We update the matrices table/records and verify that the new matrices are indeed there

proj_matrices.update_database()
print(proj_matrices.list())
                             name  ... status
0                      demand_omx  ...
1                       demand_mc  ...
2                           skims  ...
3                      demand_aem  ...
4  base_year_assignment_skims_car  ...
5            demand_power_modeled  ...
6             demand_expo_modeled  ...

[7 rows x 8 columns]

IPF for the future vectors#

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

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

ipf.save_to_project(name="demand_ipfd", file_name="demand_ipfd.aem")
ipf.save_to_project(name="demand_ipfd_omx", file_name="demand_ipfd.omx")
2023-07-10 09:02:50,192;WARNING ; Matrix Record has been saved to the database
2023-07-10 09:02:50,210;WARNING ; Matrix Record has been saved to the database

<aequilibrae.project.data.matrix_record.MatrixRecord object at 0x7f95e4ad2250>
df = proj_matrices.list()

Future traffic assignment#

from aequilibrae.paths import TrafficAssignment, TrafficClass
logger.info("\n\n\n TRAFFIC ASSIGNMENT FOR FUTURE YEAR")
2023-07-10 09:02:50,221;INFO ;


 TRAFFIC ASSIGNMENT FOR FUTURE YEAR
demand = proj_matrices.get_matrix("demand_ipfd")

# Let's see what is the core we ended up getting. It should be 'gravity'
demand.names
['matrix']

Let’s use the IPF matrix

demand.computational_view("matrix")

assig = TrafficAssignment()

# Creates the assignment class
assigclass = TrafficClass(name="car", graph=graph, matrix=demand)

# The first thing to do is to add at a list of traffic classes to be assigned
assig.add_class(assigclass)

assig.set_vdf("BPR")  # This is not case-sensitive

# Then we set the volume delay function
assig.set_vdf_parameters({"alpha": "b", "beta": "power"})  # And its parameters

assig.set_capacity_field("capacity")  # The capacity and free flow travel times as they exist in the graph
assig.set_time_field("free_flow_time")

# And the algorithm we want to use to assign
assig.set_algorithm("bfw")

# Since I haven't checked the parameters file, let's make sure convergence criteria is good
assig.max_iter = 500
assig.rgap_target = 0.00001

OPTIONAL

# If we want to execute select link analysis on a particular TrafficClass, we set the links we are analyzing.
# The format of the input select links is a dictionary (str: list[tuple]).
# Each entry represents a separate set of selected links to compute. The str name will name the set of links.
# The list[tuple] is the list of links being selected, of the form (link_id, direction), as it occurs in the Graph.
# Direction can be 0, 1, -1. 0 denotes bi-directionality
# For example, let's use Select Link on two sets of links:
select_links = {
    "Leaving node 1": [(1, 1), (2, 1)],
    "Random nodes": [(3, 1), (5, 1)],
}
# We call this command on the class we are analyzing with our dictionary of values
assigclass.set_select_links(select_links)

assig.execute()  # we then execute the assignment
/home/runner/work/aequilibrae/aequilibrae/aequilibrae/paths/traffic_class.py:145: UserWarning: Input string name has a space in it. Replacing with _
  warnings.warn("Input string name has a space in it. Replacing with _")
2023-07-10 09:02:50,585;INFO ; Traffic Class specification
2023-07-10 09:02:50,585;INFO ; {'car': {'Graph': "{'Mode': 'c', 'Block through centroids': False, 'Number of centroids': 24, 'Links': 76, 'Nodes': 24}", 'Matrix': "{'Source': '/tmp/605a246ed3434856bcb0123287fe45e2/matrices/demand_ipfd.aem', 'Number of centroids': 24, 'Matrix cores': ['matrix'], 'Matrix totals': {'matrix': 382536.20097205363}}", 'select_links': "{'Leaving node 1': [(1, 1), (2, 1)], 'Random nodes': [(3, 1), (5, 1)]}"}}
2023-07-10 09:02:50,585;INFO ; Traffic Assignment specification
2023-07-10 09:02:50,585;INFO ; {'VDF parameters': {'alpha': 'b', 'beta': 'power'}, 'VDF function': 'bpr', 'Number of cores': 2, 'Capacity field': 'capacity', 'Time field': 'free_flow_time', 'Algorithm': 'bfw', 'Maximum iterations': 250, 'Target RGAP': 0.0001}
2023-07-10 09:02:50,588;WARNING ; Cost field with wrong type. Converting to float64
2023-07-10 09:02:50,588;INFO ; bfw Assignment STATS
2023-07-10 09:02:50,588;INFO ; Iteration, RelativeGap, stepsize
2023-07-10 09:02:50,597;INFO ; 1,inf,1.0
2023-07-10 09:02:50,607;INFO ; 2,0.8795919869953654,0.31331063682955723
2023-07-10 09:02:50,617;INFO ; 3,0.5360129873389503,0.17597819200958426
2023-07-10 09:02:50,626;INFO ; 4,0.2924614505718223,0.16482489782032997
2023-07-10 09:02:50,635;INFO ; 5,0.1052366041857067,0.6349735624197105
2023-07-10 09:02:50,644;INFO ; 6,0.2715136772478963,0.10459945679965084
2023-07-10 09:02:50,656;INFO ; 7,0.11781011966163812,0.21111735540988738
2023-07-10 09:02:50,664;INFO ; 8,0.0850776283739523,0.575286412372591
2023-07-10 09:02:50,673;INFO ; 9,0.12322167565410132,0.12643870939740742
2023-07-10 09:02:50,681;INFO ; 10,0.044833141154050314,0.26088861278030745
2023-07-10 09:02:50,691;INFO ; 11,0.07118456106039972,0.1307238518677271
2023-07-10 09:02:50,699;INFO ; 12,0.039141468289747135,0.3239761053686282
2023-07-10 09:02:50,707;INFO ; 13,0.054521372480731745,0.10992762611035817
2023-07-10 09:02:50,715;INFO ; 14,0.02742691631925726,0.3060594266344289
2023-07-10 09:02:50,724;INFO ; 15,0.037248656511930406,0.11470875303026531
2023-07-10 09:02:50,732;INFO ; 16,0.022168393029814968,0.23127947168080548
2023-07-10 09:02:50,741;INFO ; 17,0.028421536520833044,0.6217799894523263
2023-07-10 09:02:50,750;INFO ; 18,0.03443458476548453,0.10013338528657975
2023-07-10 09:02:50,757;INFO ; 19,0.01792423440110266,0.136382999268021
2023-07-10 09:02:50,764;INFO ; 20,0.01624402913455306,0.1726291635312231
2023-07-10 09:02:50,773;INFO ; 21,0.01730505872104108,0.3414184028839711
2023-07-10 09:02:50,781;INFO ; 22,0.017224025319293332,0.07933633674991811
2023-07-10 09:02:50,789;INFO ; 23,0.008453754315633846,0.09851131023680491
2023-07-10 09:02:50,796;INFO ; 24,0.008959340766600123,0.25121581087844397
2023-07-10 09:02:50,805;INFO ; 25,0.012810859360898343,0.5846345453765212
2023-07-10 09:02:50,813;INFO ; 26,0.012182501418995828,0.06750141787551657
2023-07-10 09:02:50,821;INFO ; 27,0.00805109885593924,0.09448581388184552
2023-07-10 09:02:50,829;INFO ; 28,0.008086985650916074,0.06516453917555576
2023-07-10 09:02:50,837;INFO ; 29,0.004795922659532676,0.11402598084043394
2023-07-10 09:02:50,850;INFO ; 30,0.004581637707119888,0.11922158215850195
2023-07-10 09:02:50,855;INFO ; 31,0.003954985445439641,0.2620558755772106
2023-07-10 09:02:50,863;INFO ; 32,0.006045029505366215,0.6016057534665686
2023-07-10 09:02:50,871;INFO ; 33,0.005348195403870384,0.527951371363937
2023-07-10 09:02:50,878;INFO ; 34,0.005096634103988734,0.0262769807022434
2023-07-10 09:02:50,887;INFO ; 35,0.003949092198394268,0.03651730692390135
2023-07-10 09:02:50,897;INFO ; 36,0.0038003904720482094,0.03990543314685324
2023-07-10 09:02:50,905;INFO ; 37,0.003670045522030177,0.06034230149079298
2023-07-10 09:02:50,913;INFO ; 38,0.002912982227615266,0.07048185073264468
2023-07-10 09:02:50,921;INFO ; 39,0.0030409694940760216,0.16481405892793247
2023-07-10 09:02:50,929;INFO ; 40,0.0027591377277773276,0.1335900860216397
2023-07-10 09:02:50,936;INFO ; 41,0.0025579840597767345,0.23759978828051437
2023-07-10 09:02:50,944;INFO ; 42,0.003260109982034019,0.26609932679328263
2023-07-10 09:02:50,954;INFO ; 43,0.002536731973152834,0.5641305251561892
2023-07-10 09:02:50,963;INFO ; 44,0.002511136360147208,0.39225909127925757
2023-07-10 09:02:50,974;INFO ; 45,0.00274257510563123,0.026080459448644178
2023-07-10 09:02:50,983;INFO ; 46,0.0018856101689677962,0.02348179044707602
2023-07-10 09:02:50,992;INFO ; 47,0.0021861474818193477,0.07512938456181646
2023-07-10 09:02:51,002;INFO ; 48,0.0016739660545813792,0.07927634188015342
2023-07-10 09:02:51,013;INFO ; 49,0.001899529517356197,0.07282131142052241
2023-07-10 09:02:51,021;INFO ; 50,0.0020783792081383585,0.12553692504114122
2023-07-10 09:02:51,029;INFO ; 51,0.0017423887334275907,0.11589261233558219
2023-07-10 09:02:51,038;INFO ; 52,0.0017304608321709642,0.10136553812873626
2023-07-10 09:02:51,045;INFO ; 53,0.0019474635740083237,0.22475752812313018
2023-07-10 09:02:51,053;INFO ; 54,0.0018836364974386297,0.19643040389821675
2023-07-10 09:02:51,061;INFO ; 55,0.001503882686417598,0.1884777650148602
2023-07-10 09:02:51,070;INFO ; 56,0.0018577417713637604,0.21342891290479482
2023-07-10 09:02:51,078;INFO ; 57,0.0014601304904929308,0.15254053652518829
2023-07-10 09:02:51,086;INFO ; 58,0.0014421961739812632,0.16584953611447498
2023-07-10 09:02:51,094;INFO ; 59,0.0011212490879746136,0.22973758620001955
2023-07-10 09:02:51,101;INFO ; 60,0.0010650320010480157,0.13850210016724127
2023-07-10 09:02:51,110;INFO ; 61,0.0008754136100392398,0.1379350062569473
2023-07-10 09:02:51,118;INFO ; 62,0.0010878559507291488,0.1974025177115801
2023-07-10 09:02:51,126;INFO ; 63,0.0006934427021390482,0.1535325920197813
2023-07-10 09:02:51,134;INFO ; 64,0.0007959678979975738,0.23883196287548367
2023-07-10 09:02:51,141;INFO ; 65,0.000854931208144216,0.2270157280140509
2023-07-10 09:02:51,150;INFO ; 66,0.0007775119352846981,0.3243126584281078
2023-07-10 09:02:51,157;INFO ; 67,0.0006408145302825692,0.4727817374676372
2023-07-10 09:02:51,168;INFO ; 68,0.000840271580909131,0.7433611264114656
2023-07-10 09:02:51,175;INFO ; 69,0.00046624247484360775,0.00418198827608828
2023-07-10 09:02:51,182;INFO ; 70,0.00040816272906712986,0.0035063420973530674
2023-07-10 09:02:51,191;INFO ; 71,0.00028632508872209015,0.0033774900548020504
2023-07-10 09:02:51,198;INFO ; 72,0.0003542787192700869,0.006472120824146454
2023-07-10 09:02:51,205;INFO ; 73,0.0003513355162123584,0.007379664566134248
2023-07-10 09:02:51,213;INFO ; 74,0.00040038961472196833,0.008013636698444317
2023-07-10 09:02:51,220;INFO ; 75,0.0003077749781407919,0.008414828014141415
2023-07-10 09:02:51,227;INFO ; 76,0.0002673416693883339,0.010233322394313769
2023-07-10 09:02:51,239;INFO ; 77,0.00022215413010170406,0.007331972336702027
2023-07-10 09:02:51,248;INFO ; 78,0.0002458712785717049,0.02480901150880819
2023-07-10 09:02:51,257;INFO ; 79,0.0003673172311296969,0.03704489470960014
2023-07-10 09:02:51,268;INFO ; 80,0.00039867017623383254,0.037900571943819204
2023-07-10 09:02:51,276;INFO ; 81,0.0004138110075605399,0.06707827631213112
2023-07-10 09:02:51,286;INFO ; 82,0.0005332014347248512,0.06854219444030372
2023-07-10 09:02:51,295;INFO ; 83,0.0005127626871952679,0.08461539703786569
2023-07-10 09:02:51,303;INFO ; 84,0.0006699919051773183,0.06931663840571813
2023-07-10 09:02:51,311;INFO ; 85,0.0005721047196707885,0.1310723931835755
2023-07-10 09:02:51,319;INFO ; 86,0.0006286042095486444,0.16116735454538703
2023-07-10 09:02:51,330;INFO ; 87,0.0005860750831822693,0.16731614933547775
2023-07-10 09:02:51,339;INFO ; 88,0.00046934585867646964,0.19548363843865987
2023-07-10 09:02:51,350;INFO ; 89,0.0005778423144599168,0.5450785850611354
2023-07-10 09:02:51,360;INFO ; 90,0.0008283464182400514,0.005023884893104243
2023-07-10 09:02:51,366;INFO ; 91,0.0005675791128780879,0.004317446792188356
2023-07-10 09:02:51,373;INFO ; 92,0.00041919965734406203,0.006672673147345475
2023-07-10 09:02:51,381;INFO ; 93,0.0003877989837987309,0.0065327817923431465
2023-07-10 09:02:51,390;INFO ; 94,0.0003613486632819095,0.005351047073223328
2023-07-10 09:02:51,397;INFO ; 95,0.0003019232194705184,0.01076324145841966
2023-07-10 09:02:51,405;INFO ; 96,0.00029834345440517306,0.006223398600107243
2023-07-10 09:02:51,415;INFO ; 97,0.0002384488801752135,0.00355521284030283
2023-07-10 09:02:51,424;INFO ; 98,0.0002551530501862887,0.0066473856785785775
2023-07-10 09:02:51,431;INFO ; 99,0.00020598588127097823,0.006843943301575729
2023-07-10 09:02:51,439;INFO ; 100,0.0002253229993610786,0.005538505659202623
2023-07-10 09:02:51,454;INFO ; 101,0.00015440500950257097,0.006699122108697002
2023-07-10 09:02:51,461;INFO ; 102,0.00017944168098162923,0.006324193756796103
2023-07-10 09:02:51,468;INFO ; 103,0.00015620786440705234,0.007454503387794137
2023-07-10 09:02:51,475;INFO ; 104,0.00014658088257625513,0.0062616351498408305
2023-07-10 09:02:51,486;INFO ; 105,0.00014787002461289704,0.009215022567731688
2023-07-10 09:02:51,495;INFO ; 106,0.00015227437798790827,0.015198121666321573
2023-07-10 09:02:51,503;INFO ; 107,0.00016683204893853574,0.019420367915596096
2023-07-10 09:02:51,511;INFO ; 108,0.0001812310635732247,0.025790542997628348
2023-07-10 09:02:51,519;INFO ; 109,0.00025007012042540155,0.0370997037873868
2023-07-10 09:02:51,534;INFO ; 110,0.0001893945698273953,0.012606460192501613
2023-07-10 09:02:51,543;INFO ; 111,0.0001972282888147966,0.03479547382806847
2023-07-10 09:02:51,552;INFO ; 112,0.0002514937097639262,0.03457721607788962
2023-07-10 09:02:51,558;INFO ; 113,0.0002608802321134632,0.04265964090495435
2023-07-10 09:02:51,566;INFO ; 114,0.00019926022110655246,0.01620653415863235
2023-07-10 09:02:51,574;INFO ; 115,0.00015765488732130662,0.011642749448050238
2023-07-10 09:02:51,582;INFO ; 116,0.00018180430216606553,0.009409185569638587
2023-07-10 09:02:51,591;INFO ; 117,0.00021199301165657583,0.013421992113628744
2023-07-10 09:02:51,598;INFO ; 118,0.0002000396681602639,0.034690391709377266
2023-07-10 09:02:51,606;INFO ; 119,0.00027831747989401123,0.019664098446992156
2023-07-10 09:02:51,616;INFO ; 120,0.0002436461273874042,0.026171354942390975
2023-07-10 09:02:51,623;INFO ; 121,0.0001828377258744023,0.011062161448324745
2023-07-10 09:02:51,632;INFO ; 122,0.0001559495858835074,0.007179412501574701
2023-07-10 09:02:51,643;INFO ; 123,0.00013021338190349788,0.005853419585461514
2023-07-10 09:02:51,651;INFO ; 124,0.00015373741132635713,0.0069277568399000854
2023-07-10 09:02:51,663;INFO ; 125,0.00015222166881329036,0.007209284959284299
2023-07-10 09:02:51,673;INFO ; 126,0.00014036251212703232,0.0068863731293087194
2023-07-10 09:02:51,681;INFO ; 127,0.0001418719789923101,0.00560608507288408
2023-07-10 09:02:51,690;INFO ; 128,0.00012189561096489692,0.007247598943499635
2023-07-10 09:02:51,699;INFO ; 129,0.0001026305702456409,0.0034213011348957086
2023-07-10 09:02:51,708;INFO ; 130,7.290402090883709e-05,0.002368971065587894
2023-07-10 09:02:51,714;INFO ; 131,6.95503100478399e-05,0.00244891925991186
2023-07-10 09:02:51,725;INFO ; 132,5.904527158711379e-05,0.0017424229611368261
2023-07-10 09:02:51,732;INFO ; 133,6.046216057069565e-05,0.003141959922600194
2023-07-10 09:02:51,739;INFO ; 134,5.646111814562615e-05,0.004618865002243959
2023-07-10 09:02:51,747;INFO ; 135,6.720097567553978e-05,0.003932788973568239
2023-07-10 09:02:51,755;INFO ; 136,8.254873164805332e-05,0.004284286830092834
2023-07-10 09:02:51,763;INFO ; 137,5.038630753438695e-05,0.0024513618748711868
2023-07-10 09:02:51,770;INFO ; 138,5.946245375707026e-05,0.00604173241837557
2023-07-10 09:02:51,778;INFO ; 139,9.90835749160952e-05,0.01562755133627102
2023-07-10 09:02:51,786;INFO ; 140,9.793717526121199e-05,0.012334752691573324
2023-07-10 09:02:51,794;INFO ; 141,0.0001146645247974342,0.019398243392960073
2023-07-10 09:02:51,802;INFO ; 142,0.00011669964232786223,0.012997523471937132
2023-07-10 09:02:51,810;INFO ; 143,8.794330388500209e-05,0.010192573721376903
2023-07-10 09:02:51,818;INFO ; 144,0.0001134983371483706,0.017126729896665412
2023-07-10 09:02:51,825;INFO ; 145,9.781615506804478e-05,0.010238376477482049
2023-07-10 09:02:51,837;INFO ; 146,8.132048957209661e-05,0.004420867660191597
2023-07-10 09:02:51,845;INFO ; 147,0.00010900647237128249,0.010894874842863963
2023-07-10 09:02:51,853;INFO ; 148,7.853311246295067e-05,0.0059024088376661244
2023-07-10 09:02:51,862;INFO ; 149,7.383085906959559e-05,0.004828935337538302
2023-07-10 09:02:51,870;INFO ; 150,5.818199534836585e-05,0.0036738398493046044
2023-07-10 09:02:51,879;INFO ; 151,6.415125311293194e-05,0.007745626165556865
2023-07-10 09:02:51,886;INFO ; 152,6.958116945661642e-05,0.006324415316318216
2023-07-10 09:02:51,893;INFO ; 153,6.380283197161464e-05,0.008961578329978554
2023-07-10 09:02:51,901;INFO ; 154,8.784586696745541e-05,0.009639946116548474
2023-07-10 09:02:51,910;INFO ; 155,8.911963705275499e-05,0.011790894676758047
2023-07-10 09:02:51,917;INFO ; 156,7.48254125176654e-05,0.016118256226939763
2023-07-10 09:02:51,927;INFO ; 157,8.906854017663402e-05,0.024375516235695668
2023-07-10 09:02:51,934;INFO ; 158,9.219005491375855e-05,0.030682135151100343
2023-07-10 09:02:51,943;INFO ; 159,8.451842010799867e-05,0.012441203037777179
2023-07-10 09:02:51,951;INFO ; 160,7.617404794557955e-05,0.010251487251019362
2023-07-10 09:02:51,960;INFO ; 161,8.126627218304592e-05,0.025096459659599817
2023-07-10 09:02:51,968;INFO ; 162,0.00010867064756797329,0.020969540836683807
2023-07-10 09:02:51,979;INFO ; 163,8.403031591964032e-05,0.014305007119091316
2023-07-10 09:02:51,987;INFO ; 164,5.9373255133219804e-05,0.005139759339130624
2023-07-10 09:02:51,994;INFO ; 165,5.701968257373778e-05,0.002116727695382285
2023-07-10 09:02:52,002;INFO ; 166,5.8512376325083995e-05,0.005653410106120713
2023-07-10 09:02:52,009;INFO ; 167,6.60875449821225e-05,0.004859656041259047
2023-07-10 09:02:52,018;INFO ; 168,4.739749498854435e-05,0.00528946228440911
2023-07-10 09:02:52,025;INFO ; 169,5.8754092699786554e-05,0.004618340064569566
2023-07-10 09:02:52,032;INFO ; 170,5.9079772726143226e-05,0.005357448897534797
2023-07-10 09:02:52,040;INFO ; 171,4.999620098396712e-05,0.0030408702927343114
2023-07-10 09:02:52,047;INFO ; 172,4.053911756453242e-05,0.005431328824731116
2023-07-10 09:02:52,055;INFO ; 173,3.62503870691023e-05,0.0021980586495679586
2023-07-10 09:02:52,065;INFO ; 174,2.7099042977002324e-05,0.001919183729364015
2023-07-10 09:02:52,072;INFO ; 175,2.6963043940850188e-05,0.0018180485734206684
2023-07-10 09:02:52,079;INFO ; 176,2.3301535109231142e-05,0.004121715852541134
2023-07-10 09:02:52,087;INFO ; 177,3.097539206317121e-05,0.0032615360286586087
2023-07-10 09:02:52,094;INFO ; 178,2.299144654718181e-05,0.0028898698548042636
2023-07-10 09:02:52,102;INFO ; 179,2.7918253538242087e-05,0.0033686095877039296
2023-07-10 09:02:52,110;INFO ; 180,2.34434587298162e-05,0.0029673946997295624
2023-07-10 09:02:52,117;INFO ; 181,2.5792760151772297e-05,0.0041566765340753375
2023-07-10 09:02:52,125;INFO ; 182,3.287711440835853e-05,0.007771096735253722
2023-07-10 09:02:52,134;INFO ; 183,3.830956466513236e-05,0.011539343856501367
2023-07-10 09:02:52,143;INFO ; 184,4.1263014170103914e-05,0.005917043591152821
2023-07-10 09:02:52,151;INFO ; 185,4.177327466033177e-05,0.01102749710860528
2023-07-10 09:02:52,158;INFO ; 186,5.102664806630979e-05,0.009631479227425282
2023-07-10 09:02:52,169;INFO ; 187,4.08363019743329e-05,0.008867500029010711
2023-07-10 09:02:52,176;INFO ; 188,4.769547333560501e-05,0.010857839095845182
2023-07-10 09:02:52,186;INFO ; 189,4.753671097890951e-05,0.015212687243440248
2023-07-10 09:02:52,197;INFO ; 190,6.951386095377016e-05,0.015082967146466068
2023-07-10 09:02:52,204;INFO ; 191,7.527590855841855e-05,0.027687044689755205
2023-07-10 09:02:52,213;INFO ; 192,6.103076312828843e-05,0.011681262726835649
2023-07-10 09:02:52,221;INFO ; 193,6.105436133016611e-05,0.03458838870139844
2023-07-10 09:02:52,228;INFO ; 194,7.02459861172076e-05,0.02169459865478047
2023-07-10 09:02:52,235;INFO ; 195,7.41425613234523e-05,0.02091550913776363
2023-07-10 09:02:52,246;INFO ; 196,5.735220934554726e-05,0.0149731087368918
2023-07-10 09:02:52,253;INFO ; 197,6.32120741852196e-05,0.02230564535166377
2023-07-10 09:02:52,261;INFO ; 198,6.0048125548792525e-05,0.02606946657492617
2023-07-10 09:02:52,269;INFO ; 199,8.196630628136298e-05,0.06783437973948782
2023-07-10 09:02:52,276;INFO ; 200,9.899611993322787e-05,0.06422141368588252
2023-07-10 09:02:52,285;INFO ; 201,0.00010083685090375343,0.10645081677876027
2023-07-10 09:02:52,293;INFO ; 202,0.0001261740401742717,0.12016097060292139
2023-07-10 09:02:52,301;INFO ; 203,0.0001402600864845667,0.11894394097294536
2023-07-10 09:02:52,309;INFO ; 204,0.00017006090291694798,0.24178249962116666
2023-07-10 09:02:52,320;INFO ; 205,0.00016896879048240653,0.20689886636160906
2023-07-10 09:02:52,330;INFO ; 206,0.0001318071089814073,0.2776848778168442
2023-07-10 09:02:52,338;INFO ; 207,0.00011214029923758186,0.07427739685863319
2023-07-10 09:02:52,348;INFO ; 208,0.00010533761360680822,0.12060544341319589
2023-07-10 09:02:52,357;INFO ; 209,0.00014073252654511634,0.21748097644643846
2023-07-10 09:02:52,368;INFO ; 210,0.00010592632545831636,0.18454573392273457
2023-07-10 09:02:52,375;INFO ; 211,0.00012080224592274441,0.19468874281570378
2023-07-10 09:02:52,382;INFO ; 212,0.00011377045072390432,0.18342650742600825
2023-07-10 09:02:52,390;INFO ; 213,0.00011389016894533687,0.15872733643838047
2023-07-10 09:02:52,398;INFO ; 214,9.108415385904836e-05,0.15196305027187762
2023-07-10 09:02:52,406;INFO ; 215,7.787623451732004e-05,0.10339329556835128
2023-07-10 09:02:52,414;INFO ; 216,4.90322100299805e-05,0.05148325718987655
2023-07-10 09:02:52,422;INFO ; 217,4.29814880143111e-05,0.18315963040774336
2023-07-10 09:02:52,429;INFO ; 218,5.046060998174961e-05,0.13719015955175598
2023-07-10 09:02:52,437;INFO ; 219,5.843246257909758e-05,0.31044293300695924
2023-07-10 09:02:52,445;INFO ; 220,6.59971428708859e-05,0.26344073684927677
2023-07-10 09:02:52,453;INFO ; 221,5.0993667301121936e-05,0.3732804184832128
2023-07-10 09:02:52,461;INFO ; 222,5.007738435563279e-05,0.3725121534226131
2023-07-10 09:02:52,470;INFO ; 223,5.047169605755835e-05,0.7064771441472657
2023-07-10 09:02:52,478;INFO ; 224,5.3242455954693e-05,0.000253937416198129
2023-07-10 09:02:52,490;INFO ; 225,3.6905335159565344e-05,0.0004894582342616051
2023-07-10 09:02:52,498;INFO ; 226,4.68637496073974e-05,0.0010315125116870647
2023-07-10 09:02:52,506;INFO ; 227,3.5749798584540536e-05,0.0012577591903375576
2023-07-10 09:02:52,513;INFO ; 228,2.479355249857846e-05,0.0007038040202670911
2023-07-10 09:02:52,524;INFO ; 229,2.5450272016297706e-05,0.0007692725859037279
2023-07-10 09:02:52,530;INFO ; 230,2.6535499490467524e-05,0.0008442048177153683
2023-07-10 09:02:52,539;INFO ; 231,1.955968135221743e-05,0.0005280608505818936
2023-07-10 09:02:52,546;INFO ; 232,2.2100410402126703e-05,0.0007711924658222645
2023-07-10 09:02:52,555;INFO ; 233,1.35160729143381e-05,0.0003163164656962088
2023-07-10 09:02:52,566;INFO ; 234,1.4315547162781446e-05,0.0006100744608752764
2023-07-10 09:02:52,574;INFO ; 235,1.096192820554258e-05,0.0006306114672946604
2023-07-10 09:02:52,583;INFO ; 236,1.237550131122646e-05,0.0004098984181829807
2023-07-10 09:02:52,594;INFO ; 237,8.433735211950508e-06,0.0003753927609437029
2023-07-10 09:02:52,594;INFO ; bfw Assignment finished. 237 iterations and 8.433735211950508e-06 final gap

Now let us save our select link results, all we need to do is provide it with a name In addition to exporting the select link flows, it also exports the Select Link matrices in OMX format.

assig.save_select_link_results("select_link_analysis")

Say we just want to save our select link flows, we can call:

assig.save_select_link_flows("just_flows")

# Or if we just want the SL matrices:
assig.save_select_link_matrices("just_matrices")
# Internally, the save_select_link_results calls both of these methods at once.

# We could export it to CSV or AequilibraE data, but let's put it directly into the results database
assig.save_results("future_year_assignment")

# And save the skims
assig.save_skims("future_year_assignment_skims", which_ones="all", format="omx")
2023-07-10 09:02:52,684;WARNING ; Matrix Record has been saved to the database

We can also plot convergence#

import matplotlib.pyplot as plt

df = assig.report()
x = df.iteration.values
y = df.rgap.values

fig = plt.figure()
ax = fig.add_subplot(111)

plt.plot(x, y, "k--")
plt.yscale("log")
plt.grid(True, which="both")
plt.xlabel(r"Iterations")
plt.ylabel(r"Relative Gap")
plt.show()
plot forecasting

Close the project

project.close()

Total running time of the script: ( 0 minutes 5.325 seconds)

Gallery generated by Sphinx-Gallery