
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "_auto_examples/assignment_workflows/plot_public_transit_assignment.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download__auto_examples_assignment_workflows_plot_public_transit_assignment.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr__auto_examples_assignment_workflows_plot_public_transit_assignment.py:


.. _example_gtfs_import_and_asssignment:

Public transport assignment with Optimal Strategies
===================================================

In this example, we import a GTFS feed to our model, create a public transport network, create project match connectors, and perform a Spiess & Florian assignment. `Click here <https://doi.org/10.1016/0191-2615(89)90034-9>`_ 
to check out the article.

We use data from Coquimbo, a city in La Serena Metropolitan Area in Chile.

.. GENERATED FROM PYTHON SOURCE LINES 13-16

.. admonition:: References

  * :ref:`transit_assignment`

.. GENERATED FROM PYTHON SOURCE LINES 18-26

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

    * :func:`aequilibrae.transit.Transit`
    * :func:`aequilibrae.transit.TransitGraphBuilder`
    * :func:`aequilibrae.paths.TransitClass`
    * :func:`aequilibrae.paths.TransitAssignment`
    * :func:`aequilibrae.matrix.AequilibraeMatrix`

.. GENERATED FROM PYTHON SOURCE LINES 28-37

.. code-block:: Python


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

    from aequilibrae.transit import Transit
    from aequilibrae.utils.create_example import create_example








.. GENERATED FROM PYTHON SOURCE LINES 39-45

.. code-block:: Python


    # Let's create an empty project on an arbitrary folder.
    fldr = join(gettempdir(), uuid4().hex)

    project = create_example(fldr, "coquimbo")








.. GENERATED FROM PYTHON SOURCE LINES 46-47

Let's create our ``Transit`` object.

.. GENERATED FROM PYTHON SOURCE LINES 47-49

.. code-block:: Python

    data = Transit(project)








.. GENERATED FROM PYTHON SOURCE LINES 50-58

Graph building
--------------
Let's build the transit network. We'll disable ``outer_stop_transfers`` and ``walking_edges`` 
because Coquimbo doesn't have any parent stations.

For the OD connections we'll use the ``overlapping_regions`` method and create some accurate line geometry later.
Creating the graph should only take a moment. By default zoning information is pulled from the project network. 
If you have your own zoning information add it using ``graph.add_zones(zones)`` then ``graph.create_graph()``. 

.. GENERATED FROM PYTHON SOURCE LINES 60-65

.. code-block:: Python

    graph = data.create_graph(with_outer_stop_transfers=False, with_walking_edges=False, blocking_centroid_flows=False, connector_method="overlapping_regions")

    # We drop geometry here for the sake of display.
    graph.vertices.drop(columns="geometry")






.. raw:: html

    <div class="output_subarea output_html rendered_html output_result">
    <div>
    <style scoped>
        .dataframe tbody tr th:only-of-type {
            vertical-align: middle;
        }

        .dataframe tbody tr th {
            vertical-align: top;
        }

        .dataframe thead th {
            text-align: right;
        }
    </style>
    <table border="1" class="dataframe">
      <thead>
        <tr style="text-align: right;">
          <th></th>
          <th>node_id</th>
          <th>node_type</th>
          <th>stop_id</th>
          <th>line_id</th>
          <th>line_seg_idx</th>
          <th>taz_id</th>
        </tr>
        <tr>
          <th>index</th>
          <th></th>
          <th></th>
          <th></th>
          <th></th>
          <th></th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th>0</th>
          <td>1</td>
          <td>od</td>
          <td></td>
          <td></td>
          <td>-1</td>
          <td>1</td>
        </tr>
        <tr>
          <th>1</th>
          <td>2</td>
          <td>od</td>
          <td></td>
          <td></td>
          <td>-1</td>
          <td>2</td>
        </tr>
        <tr>
          <th>2</th>
          <td>3</td>
          <td>od</td>
          <td></td>
          <td></td>
          <td>-1</td>
          <td>3</td>
        </tr>
        <tr>
          <th>3</th>
          <td>4</td>
          <td>od</td>
          <td></td>
          <td></td>
          <td>-1</td>
          <td>4</td>
        </tr>
        <tr>
          <th>4</th>
          <td>5</td>
          <td>od</td>
          <td></td>
          <td></td>
          <td>-1</td>
          <td>5</td>
        </tr>
        <tr>
          <th>...</th>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
        </tr>
        <tr>
          <th>362</th>
          <td>363</td>
          <td>alighting</td>
          <td>10000000075</td>
          <td>1_10001003000</td>
          <td>31</td>
          <td></td>
        </tr>
        <tr>
          <th>363</th>
          <td>364</td>
          <td>alighting</td>
          <td>10000000076</td>
          <td>1_10001003000</td>
          <td>32</td>
          <td></td>
        </tr>
        <tr>
          <th>364</th>
          <td>365</td>
          <td>alighting</td>
          <td>10000000077</td>
          <td>1_10001003000</td>
          <td>33</td>
          <td></td>
        </tr>
        <tr>
          <th>365</th>
          <td>366</td>
          <td>alighting</td>
          <td>10000000078</td>
          <td>1_10001003000</td>
          <td>34</td>
          <td></td>
        </tr>
        <tr>
          <th>366</th>
          <td>367</td>
          <td>alighting</td>
          <td>10000000053</td>
          <td>1_10001003000</td>
          <td>35</td>
          <td></td>
        </tr>
      </tbody>
    </table>
    <p>367 rows × 6 columns</p>
    </div>
    </div>
    <br />
    <br />

.. GENERATED FROM PYTHON SOURCE LINES 66-68

.. code-block:: Python

    graph.edges






.. raw:: html

    <div class="output_subarea output_html rendered_html output_result">
    <div>
    <style scoped>
        .dataframe tbody tr th:only-of-type {
            vertical-align: middle;
        }

        .dataframe tbody tr th {
            vertical-align: top;
        }

        .dataframe thead th {
            text-align: right;
        }
    </style>
    <table border="1" class="dataframe">
      <thead>
        <tr style="text-align: right;">
          <th></th>
          <th>link_id</th>
          <th>link_type</th>
          <th>line_id</th>
          <th>stop_id</th>
          <th>line_seg_idx</th>
          <th>b_node</th>
          <th>a_node</th>
          <th>trav_time</th>
          <th>freq</th>
          <th>o_line_id</th>
          <th>d_line_id</th>
          <th>direction</th>
        </tr>
        <tr>
          <th>index</th>
          <th></th>
          <th></th>
          <th></th>
          <th></th>
          <th></th>
          <th></th>
          <th></th>
          <th></th>
          <th></th>
          <th></th>
          <th></th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th>0</th>
          <td>1</td>
          <td>on-board</td>
          <td>1_10001001000</td>
          <td></td>
          <td>0</td>
          <td>212</td>
          <td>290</td>
          <td>90.000000</td>
          <td>inf</td>
          <td></td>
          <td></td>
          <td>1</td>
        </tr>
        <tr>
          <th>1</th>
          <td>2</td>
          <td>on-board</td>
          <td>1_10001001000</td>
          <td></td>
          <td>1</td>
          <td>213</td>
          <td>291</td>
          <td>90.000000</td>
          <td>inf</td>
          <td></td>
          <td></td>
          <td>1</td>
        </tr>
        <tr>
          <th>2</th>
          <td>3</td>
          <td>on-board</td>
          <td>1_10001001000</td>
          <td></td>
          <td>2</td>
          <td>214</td>
          <td>292</td>
          <td>120.000000</td>
          <td>inf</td>
          <td></td>
          <td></td>
          <td>1</td>
        </tr>
        <tr>
          <th>3</th>
          <td>4</td>
          <td>on-board</td>
          <td>1_10001001000</td>
          <td></td>
          <td>3</td>
          <td>215</td>
          <td>293</td>
          <td>120.000000</td>
          <td>inf</td>
          <td></td>
          <td></td>
          <td>1</td>
        </tr>
        <tr>
          <th>4</th>
          <td>5</td>
          <td>on-board</td>
          <td>1_10001001000</td>
          <td></td>
          <td>4</td>
          <td>216</td>
          <td>294</td>
          <td>120.000000</td>
          <td>inf</td>
          <td></td>
          <td></td>
          <td>1</td>
        </tr>
        <tr>
          <th>...</th>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
        </tr>
        <tr>
          <th>641</th>
          <td>642</td>
          <td>egress_connector</td>
          <td></td>
          <td></td>
          <td>-1</td>
          <td>166</td>
          <td>112</td>
          <td>630.543431</td>
          <td>inf</td>
          <td></td>
          <td></td>
          <td>1</td>
        </tr>
        <tr>
          <th>642</th>
          <td>643</td>
          <td>egress_connector</td>
          <td></td>
          <td></td>
          <td>-1</td>
          <td>177</td>
          <td>112</td>
          <td>754.081137</td>
          <td>inf</td>
          <td></td>
          <td></td>
          <td>1</td>
        </tr>
        <tr>
          <th>643</th>
          <td>644</td>
          <td>egress_connector</td>
          <td></td>
          <td></td>
          <td>-1</td>
          <td>178</td>
          <td>112</td>
          <td>386.262027</td>
          <td>inf</td>
          <td></td>
          <td></td>
          <td>1</td>
        </tr>
        <tr>
          <th>644</th>
          <td>645</td>
          <td>egress_connector</td>
          <td></td>
          <td></td>
          <td>-1</td>
          <td>179</td>
          <td>112</td>
          <td>558.108038</td>
          <td>inf</td>
          <td></td>
          <td></td>
          <td>1</td>
        </tr>
        <tr>
          <th>645</th>
          <td>646</td>
          <td>egress_connector</td>
          <td></td>
          <td></td>
          <td>-1</td>
          <td>166</td>
          <td>113</td>
          <td>604.831967</td>
          <td>inf</td>
          <td></td>
          <td></td>
          <td>1</td>
        </tr>
      </tbody>
    </table>
    <p>646 rows × 12 columns</p>
    </div>
    </div>
    <br />
    <br />

.. GENERATED FROM PYTHON SOURCE LINES 69-72

The graphs also also stored in the ``Transit.graphs`` dictionary. They are keyed by the 'period_id' they 
were created for. A graph for a different 'period_id' can be created by providing ``period_id=`` in the 
``Transit.create_graph`` call. You can view previously created periods with the ``Periods`` object.

.. GENERATED FROM PYTHON SOURCE LINES 72-75

.. code-block:: Python

    periods = project.network.periods
    periods.data






.. raw:: html

    <div class="output_subarea output_html rendered_html output_result">
    <div>
    <style scoped>
        .dataframe tbody tr th:only-of-type {
            vertical-align: middle;
        }

        .dataframe tbody tr th {
            vertical-align: top;
        }

        .dataframe thead th {
            text-align: right;
        }
    </style>
    <table border="1" class="dataframe">
      <thead>
        <tr style="text-align: right;">
          <th></th>
          <th>period_id</th>
          <th>period_start</th>
          <th>period_end</th>
          <th>period_description</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th>0</th>
          <td>1</td>
          <td>0</td>
          <td>86400</td>
          <td>Default time period, whole day</td>
        </tr>
      </tbody>
    </table>
    </div>
    </div>
    <br />
    <br />

.. GENERATED FROM PYTHON SOURCE LINES 76-78

Connector project matching
--------------------------

.. GENERATED FROM PYTHON SOURCE LINES 78-80

.. code-block:: Python

    project.network.build_graphs()








.. GENERATED FROM PYTHON SOURCE LINES 81-85

Now we'll create the line strings for the access connectors, this step is optinal but provides more accurate distance 
estimations and better looking geometry.

Because Coquimbo doesn't have many walking edges we'll match onto the ``"c"`` graph.

.. GENERATED FROM PYTHON SOURCE LINES 85-87

.. code-block:: Python

    graph.create_line_geometry(method="connector project match", graph="c")





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    /opt/hostedtoolcache/Python/3.10.15/x64/lib/python3.10/site-packages/aequilibrae/transit/transit_graph_builder.py:1215: UserWarning: In its current implementation, the "connector project match" method may take a while for large networks.
      warnings.warn(




.. GENERATED FROM PYTHON SOURCE LINES 88-91

Saving and reloading
--------------------
Lets save all graphs to the 'public_transport.sqlite' database.

.. GENERATED FROM PYTHON SOURCE LINES 91-93

.. code-block:: Python

    data.save_graphs()





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    /opt/hostedtoolcache/Python/3.10.15/x64/lib/python3.10/site-packages/aequilibrae/transit/transit.py:99: UserWarning: Currently only a single transit graph can be saved and reloaded. Multiple graph support is plan for a future release.
      warnings.warn(




.. GENERATED FROM PYTHON SOURCE LINES 94-98

We can reload the saved graphs with ``data.load``. 
This will create new ``TransitGraphBuilder``\'s based on the 'period_id' of the saved graphs.
The graph configuration is stored in the 'transit_graph_config' table in 'project_database.sqlite' 
as serialised JSON.

.. GENERATED FROM PYTHON SOURCE LINES 98-100

.. code-block:: Python

    data.load()





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    /opt/hostedtoolcache/Python/3.10.15/x64/lib/python3.10/site-packages/aequilibrae/transit/transit.py:113: UserWarning: Currently only a single transit graph can be saved and reloaded. Multiple graph support is plan for a future release. `period_ids` argument is currently ignored.
      warnings.warn(




.. GENERATED FROM PYTHON SOURCE LINES 101-106

Links and nodes are stored in a similar manner to the 'project_database.sqlite' database.

Reading back into AequilibraE
-----------------------------
You can create back in a particular graph via it's 'period_id'.

.. GENERATED FROM PYTHON SOURCE LINES 106-109

.. code-block:: Python

    from aequilibrae.project.database_connection import database_connection
    from aequilibrae.transit.transit_graph_builder import TransitGraphBuilder








.. GENERATED FROM PYTHON SOURCE LINES 110-115

.. code-block:: Python

    pt_con = database_connection("transit")

    graph_db = TransitGraphBuilder.from_db(pt_con, periods.default_period.period_id)
    graph_db.vertices.drop(columns="geometry")






.. raw:: html

    <div class="output_subarea output_html rendered_html output_result">
    <div>
    <style scoped>
        .dataframe tbody tr th:only-of-type {
            vertical-align: middle;
        }

        .dataframe tbody tr th {
            vertical-align: top;
        }

        .dataframe thead th {
            text-align: right;
        }
    </style>
    <table border="1" class="dataframe">
      <thead>
        <tr style="text-align: right;">
          <th></th>
          <th>node_id</th>
          <th>node_type</th>
          <th>stop_id</th>
          <th>line_id</th>
          <th>line_seg_idx</th>
          <th>taz_id</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th>0</th>
          <td>1</td>
          <td>od</td>
          <td></td>
          <td></td>
          <td>-1</td>
          <td>1</td>
        </tr>
        <tr>
          <th>1</th>
          <td>2</td>
          <td>od</td>
          <td></td>
          <td></td>
          <td>-1</td>
          <td>2</td>
        </tr>
        <tr>
          <th>2</th>
          <td>3</td>
          <td>od</td>
          <td></td>
          <td></td>
          <td>-1</td>
          <td>3</td>
        </tr>
        <tr>
          <th>3</th>
          <td>4</td>
          <td>od</td>
          <td></td>
          <td></td>
          <td>-1</td>
          <td>4</td>
        </tr>
        <tr>
          <th>4</th>
          <td>5</td>
          <td>od</td>
          <td></td>
          <td></td>
          <td>-1</td>
          <td>5</td>
        </tr>
        <tr>
          <th>...</th>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
        </tr>
        <tr>
          <th>362</th>
          <td>363</td>
          <td>alighting</td>
          <td>10000000075</td>
          <td>1_10001003000</td>
          <td>31</td>
          <td></td>
        </tr>
        <tr>
          <th>363</th>
          <td>364</td>
          <td>alighting</td>
          <td>10000000076</td>
          <td>1_10001003000</td>
          <td>32</td>
          <td></td>
        </tr>
        <tr>
          <th>364</th>
          <td>365</td>
          <td>alighting</td>
          <td>10000000077</td>
          <td>1_10001003000</td>
          <td>33</td>
          <td></td>
        </tr>
        <tr>
          <th>365</th>
          <td>366</td>
          <td>alighting</td>
          <td>10000000078</td>
          <td>1_10001003000</td>
          <td>34</td>
          <td></td>
        </tr>
        <tr>
          <th>366</th>
          <td>367</td>
          <td>alighting</td>
          <td>10000000053</td>
          <td>1_10001003000</td>
          <td>35</td>
          <td></td>
        </tr>
      </tbody>
    </table>
    <p>367 rows × 6 columns</p>
    </div>
    </div>
    <br />
    <br />

.. GENERATED FROM PYTHON SOURCE LINES 116-118

.. code-block:: Python

    graph_db.edges






.. raw:: html

    <div class="output_subarea output_html rendered_html output_result">
    <div>
    <style scoped>
        .dataframe tbody tr th:only-of-type {
            vertical-align: middle;
        }

        .dataframe tbody tr th {
            vertical-align: top;
        }

        .dataframe thead th {
            text-align: right;
        }
    </style>
    <table border="1" class="dataframe">
      <thead>
        <tr style="text-align: right;">
          <th></th>
          <th>link_id</th>
          <th>link_type</th>
          <th>line_id</th>
          <th>stop_id</th>
          <th>line_seg_idx</th>
          <th>b_node</th>
          <th>a_node</th>
          <th>trav_time</th>
          <th>freq</th>
          <th>o_line_id</th>
          <th>d_line_id</th>
          <th>direction</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th>0</th>
          <td>1</td>
          <td>on-board</td>
          <td>1_10001001000</td>
          <td></td>
          <td>0</td>
          <td>212</td>
          <td>290</td>
          <td>90.000000</td>
          <td>inf</td>
          <td></td>
          <td></td>
          <td>1</td>
        </tr>
        <tr>
          <th>1</th>
          <td>2</td>
          <td>on-board</td>
          <td>1_10001001000</td>
          <td></td>
          <td>1</td>
          <td>213</td>
          <td>291</td>
          <td>90.000000</td>
          <td>inf</td>
          <td></td>
          <td></td>
          <td>1</td>
        </tr>
        <tr>
          <th>2</th>
          <td>3</td>
          <td>on-board</td>
          <td>1_10001001000</td>
          <td></td>
          <td>2</td>
          <td>214</td>
          <td>292</td>
          <td>120.000000</td>
          <td>inf</td>
          <td></td>
          <td></td>
          <td>1</td>
        </tr>
        <tr>
          <th>3</th>
          <td>4</td>
          <td>on-board</td>
          <td>1_10001001000</td>
          <td></td>
          <td>3</td>
          <td>215</td>
          <td>293</td>
          <td>120.000000</td>
          <td>inf</td>
          <td></td>
          <td></td>
          <td>1</td>
        </tr>
        <tr>
          <th>4</th>
          <td>5</td>
          <td>on-board</td>
          <td>1_10001001000</td>
          <td></td>
          <td>4</td>
          <td>216</td>
          <td>294</td>
          <td>120.000000</td>
          <td>inf</td>
          <td></td>
          <td></td>
          <td>1</td>
        </tr>
        <tr>
          <th>...</th>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
        </tr>
        <tr>
          <th>641</th>
          <td>642</td>
          <td>egress_connector</td>
          <td></td>
          <td></td>
          <td>-1</td>
          <td>166</td>
          <td>112</td>
          <td>1039.945114</td>
          <td>inf</td>
          <td></td>
          <td></td>
          <td>1</td>
        </tr>
        <tr>
          <th>642</th>
          <td>643</td>
          <td>egress_connector</td>
          <td></td>
          <td></td>
          <td>-1</td>
          <td>177</td>
          <td>112</td>
          <td>1149.832226</td>
          <td>inf</td>
          <td></td>
          <td></td>
          <td>1</td>
        </tr>
        <tr>
          <th>643</th>
          <td>644</td>
          <td>egress_connector</td>
          <td></td>
          <td></td>
          <td>-1</td>
          <td>178</td>
          <td>112</td>
          <td>508.359402</td>
          <td>inf</td>
          <td></td>
          <td></td>
          <td>1</td>
        </tr>
        <tr>
          <th>644</th>
          <td>645</td>
          <td>egress_connector</td>
          <td></td>
          <td></td>
          <td>-1</td>
          <td>179</td>
          <td>112</td>
          <td>968.705083</td>
          <td>inf</td>
          <td></td>
          <td></td>
          <td>1</td>
        </tr>
        <tr>
          <th>645</th>
          <td>646</td>
          <td>egress_connector</td>
          <td></td>
          <td></td>
          <td>-1</td>
          <td>166</td>
          <td>113</td>
          <td>1831.651685</td>
          <td>inf</td>
          <td></td>
          <td></td>
          <td>1</td>
        </tr>
      </tbody>
    </table>
    <p>646 rows × 12 columns</p>
    </div>
    </div>
    <br />
    <br />

.. GENERATED FROM PYTHON SOURCE LINES 119-122

Converting to a AequilibraE graph object
----------------------------------------
To perform an assignment we need to convert the graph builder into a graph.

.. GENERATED FROM PYTHON SOURCE LINES 122-124

.. code-block:: Python

    transit_graph = graph.to_transit_graph()








.. GENERATED FROM PYTHON SOURCE LINES 125-129

Mock demand matrix
------------------
We'll create a mock demand matrix with demand 1 for every zone.
We'll also need to convert from ``zone_id``\'s to ``node_id``\'s.

.. GENERATED FROM PYTHON SOURCE LINES 129-132

.. code-block:: Python

    import numpy as np
    from aequilibrae.matrix import AequilibraeMatrix








.. GENERATED FROM PYTHON SOURCE LINES 133-145

.. code-block:: Python

    zones_in_the_model = len(transit_graph.centroids)

    names_list = ['pt']

    mat = AequilibraeMatrix()
    mat.create_empty(zones=zones_in_the_model,
                     matrix_names=names_list,
                     memory_only=True)
    mat.index = transit_graph.centroids[:]
    mat.matrices[:, :, 0] = np.full((zones_in_the_model, zones_in_the_model), 1.0)
    mat.computational_view()








.. GENERATED FROM PYTHON SOURCE LINES 146-149

Hyperpath generation/assignment
-------------------------------
We'll create a ``TransitAssignment`` object as well as a ``TransitClass``

.. GENERATED FROM PYTHON SOURCE LINES 149-151

.. code-block:: Python

    from aequilibrae.paths import TransitAssignment, TransitClass








.. GENERATED FROM PYTHON SOURCE LINES 152-173

.. code-block:: Python


    # Create the assignment class
    assigclass = TransitClass(name="pt", graph=transit_graph, matrix=mat)

    assig = TransitAssignment()

    assig.add_class(assigclass)

    # We need to tell AequilbraE where to find the appropriate fields we want to use,  
    # as well as the assignment algorithm to use.
    assig.set_time_field("trav_time")
    assig.set_frequency_field("freq")

    assig.set_algorithm("os")

    # When there's multiple matrix cores we'll also need to set the core to use for the demand.
    assigclass.set_demand_matrix_core("pt")

    # Let's perform the assignment for the transit classes added
    assig.execute()








.. GENERATED FROM PYTHON SOURCE LINES 174-175

View the results

.. GENERATED FROM PYTHON SOURCE LINES 175-177

.. code-block:: Python

    assig.results()






.. raw:: html

    <div class="output_subarea output_html rendered_html output_result">
    <div>
    <style scoped>
        .dataframe tbody tr th:only-of-type {
            vertical-align: middle;
        }

        .dataframe tbody tr th {
            vertical-align: top;
        }

        .dataframe thead th {
            text-align: right;
        }
    </style>
    <table border="1" class="dataframe">
      <thead>
        <tr style="text-align: right;">
          <th></th>
          <th>pt_volume</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th>479</th>
          <td>0.0</td>
        </tr>
        <tr>
          <th>480</th>
          <td>35.0</td>
        </tr>
        <tr>
          <th>481</th>
          <td>24.0</td>
        </tr>
        <tr>
          <th>482</th>
          <td>18.0</td>
        </tr>
        <tr>
          <th>483</th>
          <td>12.0</td>
        </tr>
        <tr>
          <th>...</th>
          <td>...</td>
        </tr>
        <tr>
          <th>74</th>
          <td>71.0</td>
        </tr>
        <tr>
          <th>75</th>
          <td>48.0</td>
        </tr>
        <tr>
          <th>76</th>
          <td>48.0</td>
        </tr>
        <tr>
          <th>77</th>
          <td>54.0</td>
        </tr>
        <tr>
          <th>78</th>
          <td>27.0</td>
        </tr>
      </tbody>
    </table>
    <p>646 rows × 1 columns</p>
    </div>
    </div>
    <br />
    <br />

.. GENERATED FROM PYTHON SOURCE LINES 178-183

Saving results
--------------
We'll be saving the results to another sqlite db called 'results_database.sqlite'. 
The 'results' table with 'project_database.sqlite' contains some metadata about each table in 
'results_database.sqlite'.

.. GENERATED FROM PYTHON SOURCE LINES 183-185

.. code-block:: Python

    assig.save_results(table_name='hyperpath example')








.. GENERATED FROM PYTHON SOURCE LINES 186-187

Wrapping up

.. GENERATED FROM PYTHON SOURCE LINES 187-188

.. code-block:: Python

    project.close()








.. rst-class:: sphx-glr-timing

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


.. _sphx_glr_download__auto_examples_assignment_workflows_plot_public_transit_assignment.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: plot_public_transit_assignment.ipynb <plot_public_transit_assignment.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: plot_public_transit_assignment.py <plot_public_transit_assignment.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: plot_public_transit_assignment.zip <plot_public_transit_assignment.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
