.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_auto_examples/route_choice/plot_route_choice_set.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr__auto_examples_route_choice_plot_route_choice_set.py: .. _example_usage_route_choice_generation: Route Choice set generation =========================== In this example, we show how to generate route choice sets for estimation of route choice models, using a a city in La Serena Metropolitan Area in Chile. .. GENERATED FROM PYTHON SOURCE LINES 11-14 .. admonition:: References * :doc:`../../route_choice` .. GENERATED FROM PYTHON SOURCE LINES 16-20 .. seealso:: Several functions, methods, classes and modules are used in this example: * :func:`aequilibrae.route_choice.route_choice` .. GENERATED FROM PYTHON SOURCE LINES 22-33 .. code-block:: Python # Imports from uuid import uuid4 from tempfile import gettempdir from os.path import join import folium import numpy as np from aequilibrae.examples import create_example .. GENERATED FROM PYTHON SOURCE LINES 35-41 .. code-block:: Python # We create the example project inside our temp folder fldr = join(gettempdir(), uuid4().hex) project = create_example(fldr, "coquimbo") .. GENERATED FROM PYTHON SOURCE LINES 42-45 Model parameters ---------------- Let's select a set of nodes of interest .. GENERATED FROM PYTHON SOURCE LINES 45-48 .. code-block:: Python od_pairs_of_interest = [(71645, 79385), (77011, 74089)] nodes_of_interest = (71645, 74089, 77011, 79385) .. GENERATED FROM PYTHON SOURCE LINES 49-50 Load the network snapshot .. GENERATED FROM PYTHON SOURCE LINES 50-54 .. code-block:: Python network = project.road.build_network() # Several fields in the project are filled with NaNs. # This is true, but we won't use those fields. .. GENERATED FROM PYTHON SOURCE LINES 55-56 Build the car graph with distance as the cost field. .. GENERATED FROM PYTHON SOURCE LINES 56-64 .. code-block:: Python graph = network.build_graph(mode="c", cost="distance", centroids=np.array(nodes_of_interest), compact=True) # Available network modes: network.modes # We set the nodes of interest as centroids to make sure they are not simplified away when we create the network graph.centroids .. rst-class:: sphx-glr-script-out .. code-block:: none array([71645, 74089, 77011, 79385], dtype=uint64) .. GENERATED FROM PYTHON SOURCE LINES 65-68 Route Choice class ------------------ Here we'll construct and use the Route Choice class to generate our route sets .. GENERATED FROM PYTHON SOURCE LINES 68-70 .. code-block:: Python from aequilibrae.route_choice import RouteChoice .. GENERATED FROM PYTHON SOURCE LINES 71-73 Graph construction has already prepared the compressed-link to network-link mapping. RouteChoice reuses that mapping and snapshots the routing costs. .. GENERATED FROM PYTHON SOURCE LINES 73-75 .. code-block:: Python rc = RouteChoice(graph) .. GENERATED FROM PYTHON SOURCE LINES 76-80 It is highly recommended to set either ``max_routes`` or ``max_depth`` to prevent runaway results. We'll also set a 5% penalty (``penalty=1.05``), which is likely a little too large, but it creates routes that are distinct enough to make this simple example more interesting. .. GENERATED FROM PYTHON SOURCE LINES 80-86 .. code-block:: Python rc.set_choice_set_generation("bfsle", max_routes=5, penalty=1.05) rc.prepare(od_pairs_of_interest) rc.execute(perform_assignment=True) choice_set = rc.get_results() .. rst-class:: sphx-glr-script-out .. code-block:: none 0/2 ODs processed : 0%| | 0/2 [00:00
Make this Notebook Trusted to load map: File -> Trust Notebook


.. GENERATED FROM PYTHON SOURCE LINES 137-138 .. code-block:: Python project.close() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.385 seconds) .. _sphx_glr_download__auto_examples_route_choice_plot_route_choice_set.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_route_choice_set.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_route_choice_set.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_route_choice_set.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_