.. 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_turn_penalties.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_turn_penalties.py: .. _example_usage_route_choice_turn_penalties: Route Choice with Turn Penalties ================================ In this example, we show how route choice accounts for turn penalties during choice set generation and path-size logit calculations. .. GENERATED FROM PYTHON SOURCE LINES 11-15 .. admonition:: References * :doc:`../../route_choice` * :ref:`turn_restrictions` .. GENERATED FROM PYTHON SOURCE LINES 17-22 .. seealso:: Several functions, methods, classes and modules are used in this example: * :class:`aequilibrae.routing.Network` * :func:`aequilibrae.route_choice.RouteChoice` .. GENERATED FROM PYTHON SOURCE LINES 24-25 Imports .. GENERATED FROM PYTHON SOURCE LINES 25-31 .. code-block:: Python import numpy as np import pandas as pd from aequilibrae.routing import Network from aequilibrae.route_choice import RouteChoice .. GENERATED FROM PYTHON SOURCE LINES 32-33 Create a small network with two routes from node 10 to node 40. .. GENERATED FROM PYTHON SOURCE LINES 33-43 .. code-block:: Python links = pd.DataFrame( { "link_id": [71, 12, 55, 24], "a_node": [10, 20, 10, 30], "b_node": [20, 40, 30, 40], "direction": [1, 1, 1, 1], "time": [1.0, 1.0, 2.0, 2.0], } ) .. GENERATED FROM PYTHON SOURCE LINES 44-45 Add a five-unit turn penalty to the direct route before building the graph. .. GENERATED FROM PYTHON SOURCE LINES 45-56 .. code-block:: Python turns = pd.DataFrame( { "from_node": [10], "via_node": [20], "to_node": [40], "penalty": [5.0], } ) network = Network(links, centroids=np.array([10, 20, 30, 40]), turn_restrictions=turns) graph = network.build_graph("c", cost="time", compact=True, block_centroid_flows=False) .. GENERATED FROM PYTHON SOURCE LINES 57-59 Generate the route choice set. The direct route has a cost of 2 plus the turn penalty, so the alternative route with a cost of 4 is more likely. .. GENERATED FROM PYTHON SOURCE LINES 59-66 .. code-block:: Python rc = RouteChoice(graph) rc.set_choice_set_generation("bfsle", max_routes=2, max_depth=5) rc.execute_single(10, 40, demand=1.0) route_choice_results = rc.get_results() print(route_choice_results) .. rst-class:: sphx-glr-script-out .. code-block:: none 0/1 ODs processed : 0%| | 0/1 [00:00` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_route_choice_turn_penalties.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_route_choice_turn_penalties.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_