.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_annex_4.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_annex_4.py: Example Train Annex 4 v1 ======================== A train with three routes each composed of two sections. Given this infrastructure: .. uml:: ../uml/tom-06-example-annex-4-infrastructure.puml The following routing specification describes the initial planned routes for the rain with `ID1`. As you can see, there is no route section needed which mentions Station `M`. This station does not play a role in the routing planning process because it is no origin, destination or handover. .. GENERATED FROM PYTHON SOURCE LINES 17-23 .. code-block:: default from networkx import DiGraph from tom.plot import * from tom.tom import make_train_from_yml, RouteSection, Route from tom.util import example, dump_routing_info_as_xml .. GENERATED FROM PYTHON SOURCE LINES 24-26 Load example annex 4 from yaml specification .. GENERATED FROM PYTHON SOURCE LINES 26-29 .. code-block:: default _, t_spec_file = example('../tests/data', 'annex-4.yml') print(t_spec_file.read_text()) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none --- coreID: ID1 lead_ru: RU1 version: 1 # RoutingInfo version sections: - id: 10 version: 1 # RouteSection version departure_station: S departure_time: '00:10:00' # => Route Construction Start arrival_station: H1 travel_time: &s1-tt '24:20:00' calendar: begin: '2021-02-01' end: '2021-02-07' color: green succ: - 11 - id: 11 version: 1 departure_station: H1 arrival_station: T travel_time: &s2-tt '07:30:00' - id: 20 version: 1 departure_station: S departure_time: '23:50:00' # => Route Construction Start arrival_station: H1 travel_time: *s1-tt color: blue calendar: begin: '2021-02-07' end: '2021-02-13' succ: - 21 - id: 21 version: 1 departure_station: H1 arrival_station: T travel_time: *s2-tt # Shorten calender of D-T - id: 30 version: 1 departure_station: D departure_time: '02:00:00' # => Route Construction Start arrival_station: H1 travel_time: '22:30:00' color: salmon calendar: begin: '2021-02-15' end: '2021-02-20' succ: - 31 - id: 31 version: 1 departure_station: H1 arrival_station: T travel_time: *s2-tt .. GENERATED FROM PYTHON SOURCE LINES 30-35 Notice the route sections which have a departure time. These are considered as *route construction starts*. Only one section in a route may be a construction start. Now create train object and show its train id. .. GENERATED FROM PYTHON SOURCE LINES 35-38 .. code-block:: default t = make_train_from_yml(t_spec_file) t.train_id() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 'TR/8350/ID1/00/2021' .. GENERATED FROM PYTHON SOURCE LINES 39-48 Timetable ^^^^^^^^^ This is the timetable of version 1 of TR-ID1. Notice the two train runs with ID `TR/8350/ID1/10/2021/2021-02-07` and `TR/8350/ID1/20/2021/2021-02-07`. They both start on `07/02`. To make the daily train ID unique on this operating day, we propose to add the `section_id` to be part of `TrainRun.train_id()`. Here `10` for the train starting at `00:10` and `20` for the train departing at `23:50` at station `S`. .. GENERATED FROM PYTHON SOURCE LINES 48-51 .. code-block:: default df = t.to_dataframe() df .. raw:: html
Departure D Departure S Arrival H1 Departure H1 Arrival T
Daily Train ID
TR/8350/ID1/10/2021/2021-02-01 Mo 01.02.21 00:10 Di 02.02.21 00:30 Di 02.02.21 00:30 Di 02.02.21 08:00
TR/8350/ID1/10/2021/2021-02-02 Di 02.02.21 00:10 Mi 03.02.21 00:30 Mi 03.02.21 00:30 Mi 03.02.21 08:00
TR/8350/ID1/10/2021/2021-02-03 Mi 03.02.21 00:10 Do 04.02.21 00:30 Do 04.02.21 00:30 Do 04.02.21 08:00
TR/8350/ID1/10/2021/2021-02-04 Do 04.02.21 00:10 Fr 05.02.21 00:30 Fr 05.02.21 00:30 Fr 05.02.21 08:00
TR/8350/ID1/10/2021/2021-02-05 Fr 05.02.21 00:10 Sa 06.02.21 00:30 Sa 06.02.21 00:30 Sa 06.02.21 08:00
TR/8350/ID1/10/2021/2021-02-06 Sa 06.02.21 00:10 So 07.02.21 00:30 So 07.02.21 00:30 So 07.02.21 08:00
TR/8350/ID1/10/2021/2021-02-07 So 07.02.21 00:10 Mo 08.02.21 00:30 Mo 08.02.21 00:30 Mo 08.02.21 08:00
TR/8350/ID1/20/2021/2021-02-07 So 07.02.21 23:50 Di 09.02.21 00:10 Di 09.02.21 00:10 Di 09.02.21 07:40
TR/8350/ID1/20/2021/2021-02-08 Mo 08.02.21 23:50 Mi 10.02.21 00:10 Mi 10.02.21 00:10 Mi 10.02.21 07:40
TR/8350/ID1/20/2021/2021-02-09 Di 09.02.21 23:50 Do 11.02.21 00:10 Do 11.02.21 00:10 Do 11.02.21 07:40
TR/8350/ID1/20/2021/2021-02-10 Mi 10.02.21 23:50 Fr 12.02.21 00:10 Fr 12.02.21 00:10 Fr 12.02.21 07:40
TR/8350/ID1/20/2021/2021-02-11 Do 11.02.21 23:50 Sa 13.02.21 00:10 Sa 13.02.21 00:10 Sa 13.02.21 07:40
TR/8350/ID1/20/2021/2021-02-12 Fr 12.02.21 23:50 So 14.02.21 00:10 So 14.02.21 00:10 So 14.02.21 07:40
TR/8350/ID1/20/2021/2021-02-13 Sa 13.02.21 23:50 Mo 15.02.21 00:10 Mo 15.02.21 00:10 Mo 15.02.21 07:40
TR/8350/ID1/30/2021/2021-02-15 Mo 15.02.21 02:00 Di 16.02.21 00:30 Di 16.02.21 00:30 Di 16.02.21 08:00
TR/8350/ID1/30/2021/2021-02-16 Di 16.02.21 02:00 Mi 17.02.21 00:30 Mi 17.02.21 00:30 Mi 17.02.21 08:00
TR/8350/ID1/30/2021/2021-02-17 Mi 17.02.21 02:00 Do 18.02.21 00:30 Do 18.02.21 00:30 Do 18.02.21 08:00
TR/8350/ID1/30/2021/2021-02-18 Do 18.02.21 02:00 Fr 19.02.21 00:30 Fr 19.02.21 00:30 Fr 19.02.21 08:00
TR/8350/ID1/30/2021/2021-02-19 Fr 19.02.21 02:00 Sa 20.02.21 00:30 Sa 20.02.21 00:30 Sa 20.02.21 08:00
TR/8350/ID1/30/2021/2021-02-20 Sa 20.02.21 02:00 So 21.02.21 00:30 So 21.02.21 00:30 So 21.02.21 08:00


.. GENERATED FROM PYTHON SOURCE LINES 52-55 Bildfahrplan ^^^^^^^^^^^^ Show timetable as `Bildfahrplan `_. .. GENERATED FROM PYTHON SOURCE LINES 55-57 .. code-block:: default plot_train(t) .. image:: /auto_examples/images/sphx_glr_plot_annex_4_001.png :alt: Timetable TR/8350/ID1/00/2021 v1 :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 58-61 Route Sections ^^^^^^^^^^^^^^ From which sections the train is composed? .. GENERATED FROM PYTHON SOURCE LINES 61-65 .. code-block:: default section: RouteSection for section in t.sections: print(section.description(), "\n") .. rst-class:: sphx-glr-script-out Out: .. code-block:: none ID : 10.v1 Calender : 01/02 to 07/02 1111111 Start at: 00:10 in S Arrival at: 00:30 in H1 Successors: [11] ID : 11.v1 Calender : 02/02 to 08/02 1111111 Start at: 00:30 in H1 Arrival at: 08:00 in T Successors: [] ID : 20.v1 Calender : 07/02 to 13/02 1111111 Start at: 23:50 in S Arrival at: 00:10 in H1 Successors: [21] ID : 21.v1 Calender : 09/02 to 15/02 1111111 Start at: 00:10 in H1 Arrival at: 07:40 in T Successors: [] ID : 30.v1 Calender : 15/02 to 20/02 111111 Start at: 02:00 in D Arrival at: 00:30 in H1 Successors: [31] ID : 31.v1 Calender : 16/02 to 21/02 111111 Start at: 00:30 in H1 Arrival at: 08:00 in T Successors: [] .. GENERATED FROM PYTHON SOURCE LINES 66-69 Section graph ^^^^^^^^^^^^^ The section graph is computed using the successor relation. .. GENERATED FROM PYTHON SOURCE LINES 69-72 .. code-block:: default sg: DiGraph = t.section_graph() plot_graph(sg) .. image:: /auto_examples/images/sphx_glr_plot_annex_4_002.png :alt: plot annex 4 :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 73-77 Routes ^^^^^^ Print all possible routes. Routes are calculated from all possible paths in the section graph. .. GENERATED FROM PYTHON SOURCE LINES 77-81 .. code-block:: default route: Route for route in t.routes(): print(route.description(), "\n") .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Route : S-H1-T Key : 10-11 Calendar : 01/02 to 07/02 1111111 Start at: 00:10 in S Arrival at: 00:30 in H1 Arrival at: 08:00 in T Route : S-H1-T Key : 20-21 Calendar : 07/02 to 13/02 1111111 Start at: 23:50 in S Arrival at: 00:10 in H1 Arrival at: 07:40 in T Route : D-H1-T Key : 30-31 Calendar : 15/02 to 20/02 111111 Start at: 02:00 in D Arrival at: 00:30 in H1 Arrival at: 08:00 in T .. GENERATED FROM PYTHON SOURCE LINES 82-86 Section runs ^^^^^^^^^^^^ For each day of the calendar of a section a `SectionRun` is created. The section runs are the rows of RouteSection.to_dataframe: .. GENERATED FROM PYTHON SOURCE LINES 86-90 .. code-block:: default for section in t.sections: print(f"{section.section_id}: {section}") print(section.to_dataframe(), "\n") .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 10: S-H1 ID S H1 2021-02-01 10 2021-02-01 00:10:00 2021-02-02 00:30:00 2021-02-02 10 2021-02-02 00:10:00 2021-02-03 00:30:00 2021-02-03 10 2021-02-03 00:10:00 2021-02-04 00:30:00 2021-02-04 10 2021-02-04 00:10:00 2021-02-05 00:30:00 2021-02-05 10 2021-02-05 00:10:00 2021-02-06 00:30:00 2021-02-06 10 2021-02-06 00:10:00 2021-02-07 00:30:00 2021-02-07 10 2021-02-07 00:10:00 2021-02-08 00:30:00 11: H1-T ID H1 T 2021-02-02 11 2021-02-02 00:30:00 2021-02-02 08:00:00 2021-02-03 11 2021-02-03 00:30:00 2021-02-03 08:00:00 2021-02-04 11 2021-02-04 00:30:00 2021-02-04 08:00:00 2021-02-05 11 2021-02-05 00:30:00 2021-02-05 08:00:00 2021-02-06 11 2021-02-06 00:30:00 2021-02-06 08:00:00 2021-02-07 11 2021-02-07 00:30:00 2021-02-07 08:00:00 2021-02-08 11 2021-02-08 00:30:00 2021-02-08 08:00:00 20: S-H1 ID S H1 2021-02-07 20 2021-02-07 23:50:00 2021-02-09 00:10:00 2021-02-08 20 2021-02-08 23:50:00 2021-02-10 00:10:00 2021-02-09 20 2021-02-09 23:50:00 2021-02-11 00:10:00 2021-02-10 20 2021-02-10 23:50:00 2021-02-12 00:10:00 2021-02-11 20 2021-02-11 23:50:00 2021-02-13 00:10:00 2021-02-12 20 2021-02-12 23:50:00 2021-02-14 00:10:00 2021-02-13 20 2021-02-13 23:50:00 2021-02-15 00:10:00 21: H1-T ID H1 T 2021-02-09 21 2021-02-09 00:10:00 2021-02-09 07:40:00 2021-02-10 21 2021-02-10 00:10:00 2021-02-10 07:40:00 2021-02-11 21 2021-02-11 00:10:00 2021-02-11 07:40:00 2021-02-12 21 2021-02-12 00:10:00 2021-02-12 07:40:00 2021-02-13 21 2021-02-13 00:10:00 2021-02-13 07:40:00 2021-02-14 21 2021-02-14 00:10:00 2021-02-14 07:40:00 2021-02-15 21 2021-02-15 00:10:00 2021-02-15 07:40:00 30: D-H1 ID D H1 2021-02-15 30 2021-02-15 02:00:00 2021-02-16 00:30:00 2021-02-16 30 2021-02-16 02:00:00 2021-02-17 00:30:00 2021-02-17 30 2021-02-17 02:00:00 2021-02-18 00:30:00 2021-02-18 30 2021-02-18 02:00:00 2021-02-19 00:30:00 2021-02-19 30 2021-02-19 02:00:00 2021-02-20 00:30:00 2021-02-20 30 2021-02-20 02:00:00 2021-02-21 00:30:00 31: H1-T ID H1 T 2021-02-16 31 2021-02-16 00:30:00 2021-02-16 08:00:00 2021-02-17 31 2021-02-17 00:30:00 2021-02-17 08:00:00 2021-02-18 31 2021-02-18 00:30:00 2021-02-18 08:00:00 2021-02-19 31 2021-02-19 00:30:00 2021-02-19 08:00:00 2021-02-20 31 2021-02-20 00:30:00 2021-02-20 08:00:00 2021-02-21 31 2021-02-21 00:30:00 2021-02-21 08:00:00 .. GENERATED FROM PYTHON SOURCE LINES 91-94 TrainRuns ^^^^^^^^^ Each `TrainRun` defines a row in the timetable of the train above .. GENERATED FROM PYTHON SOURCE LINES 94-101 .. code-block:: default tr: TrainRun for tr in t.train_run_iterator(): print(tr) for sr in tr.sections_runs: print(sr) print("\n") .. rst-class:: sphx-glr-script-out Out: .. code-block:: none TR/8350/ID1/10/2021/2021-02-01 10.v1:2021-02-01 00:10 OTR=0 S-H1 2021-02-02 00:30 OTR=1 11.v1:2021-02-02 00:30 OTR=1 H1-T 2021-02-02 08:00 OTR=1 TR/8350/ID1/10/2021/2021-02-02 10.v1:2021-02-02 00:10 OTR=0 S-H1 2021-02-03 00:30 OTR=1 11.v1:2021-02-03 00:30 OTR=1 H1-T 2021-02-03 08:00 OTR=1 TR/8350/ID1/10/2021/2021-02-03 10.v1:2021-02-03 00:10 OTR=0 S-H1 2021-02-04 00:30 OTR=1 11.v1:2021-02-04 00:30 OTR=1 H1-T 2021-02-04 08:00 OTR=1 TR/8350/ID1/10/2021/2021-02-04 10.v1:2021-02-04 00:10 OTR=0 S-H1 2021-02-05 00:30 OTR=1 11.v1:2021-02-05 00:30 OTR=1 H1-T 2021-02-05 08:00 OTR=1 TR/8350/ID1/10/2021/2021-02-05 10.v1:2021-02-05 00:10 OTR=0 S-H1 2021-02-06 00:30 OTR=1 11.v1:2021-02-06 00:30 OTR=1 H1-T 2021-02-06 08:00 OTR=1 TR/8350/ID1/10/2021/2021-02-06 10.v1:2021-02-06 00:10 OTR=0 S-H1 2021-02-07 00:30 OTR=1 11.v1:2021-02-07 00:30 OTR=1 H1-T 2021-02-07 08:00 OTR=1 TR/8350/ID1/10/2021/2021-02-07 10.v1:2021-02-07 00:10 OTR=0 S-H1 2021-02-08 00:30 OTR=1 11.v1:2021-02-08 00:30 OTR=1 H1-T 2021-02-08 08:00 OTR=1 TR/8350/ID1/20/2021/2021-02-07 20.v1:2021-02-07 23:50 OTR=0 S-H1 2021-02-09 00:10 OTR=2 21.v1:2021-02-09 00:10 OTR=2 H1-T 2021-02-09 07:40 OTR=2 TR/8350/ID1/20/2021/2021-02-08 20.v1:2021-02-08 23:50 OTR=0 S-H1 2021-02-10 00:10 OTR=2 21.v1:2021-02-10 00:10 OTR=2 H1-T 2021-02-10 07:40 OTR=2 TR/8350/ID1/20/2021/2021-02-09 20.v1:2021-02-09 23:50 OTR=0 S-H1 2021-02-11 00:10 OTR=2 21.v1:2021-02-11 00:10 OTR=2 H1-T 2021-02-11 07:40 OTR=2 TR/8350/ID1/20/2021/2021-02-10 20.v1:2021-02-10 23:50 OTR=0 S-H1 2021-02-12 00:10 OTR=2 21.v1:2021-02-12 00:10 OTR=2 H1-T 2021-02-12 07:40 OTR=2 TR/8350/ID1/20/2021/2021-02-11 20.v1:2021-02-11 23:50 OTR=0 S-H1 2021-02-13 00:10 OTR=2 21.v1:2021-02-13 00:10 OTR=2 H1-T 2021-02-13 07:40 OTR=2 TR/8350/ID1/20/2021/2021-02-12 20.v1:2021-02-12 23:50 OTR=0 S-H1 2021-02-14 00:10 OTR=2 21.v1:2021-02-14 00:10 OTR=2 H1-T 2021-02-14 07:40 OTR=2 TR/8350/ID1/20/2021/2021-02-13 20.v1:2021-02-13 23:50 OTR=0 S-H1 2021-02-15 00:10 OTR=2 21.v1:2021-02-15 00:10 OTR=2 H1-T 2021-02-15 07:40 OTR=2 TR/8350/ID1/30/2021/2021-02-15 30.v1:2021-02-15 02:00 OTR=0 D-H1 2021-02-16 00:30 OTR=1 31.v1:2021-02-16 00:30 OTR=1 H1-T 2021-02-16 08:00 OTR=1 TR/8350/ID1/30/2021/2021-02-16 30.v1:2021-02-16 02:00 OTR=0 D-H1 2021-02-17 00:30 OTR=1 31.v1:2021-02-17 00:30 OTR=1 H1-T 2021-02-17 08:00 OTR=1 TR/8350/ID1/30/2021/2021-02-17 30.v1:2021-02-17 02:00 OTR=0 D-H1 2021-02-18 00:30 OTR=1 31.v1:2021-02-18 00:30 OTR=1 H1-T 2021-02-18 08:00 OTR=1 TR/8350/ID1/30/2021/2021-02-18 30.v1:2021-02-18 02:00 OTR=0 D-H1 2021-02-19 00:30 OTR=1 31.v1:2021-02-19 00:30 OTR=1 H1-T 2021-02-19 08:00 OTR=1 TR/8350/ID1/30/2021/2021-02-19 30.v1:2021-02-19 02:00 OTR=0 D-H1 2021-02-20 00:30 OTR=1 31.v1:2021-02-20 00:30 OTR=1 H1-T 2021-02-20 08:00 OTR=1 TR/8350/ID1/30/2021/2021-02-20 30.v1:2021-02-20 02:00 OTR=0 D-H1 2021-02-21 00:30 OTR=1 31.v1:2021-02-21 00:30 OTR=1 H1-T 2021-02-21 08:00 OTR=1 .. GENERATED FROM PYTHON SOURCE LINES 102-108 RoutingInformation as TrainInformation ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ An XML Dump of the routing information of this example according a new version of the TSI XSD. See `Routing planning <../routing-planning-process.html#routininformation-as-traininformation>`_ for more details. .. GENERATED FROM PYTHON SOURCE LINES 108-109 .. code-block:: default print(dump_routing_info_as_xml(t)) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none RS 8350 ---------ID1 10 2021 DE 10004 S 0 DE 10005 H1 1 1111111 2021-02-01T00:00:00 2021-02-07T00:00:00 RS 8350 ---------ID1 11 2021 RS 8350 ---------ID1 11 2021 DE 10005 H1 0 DE 10006 T 0 1111111 2021-02-02T00:00:00 2021-02-08T00:00:00 RS 8350 ---------ID1 20 2021 DE 10004 S 0 DE 10005 H1 2 1111111 2021-02-07T00:00:00 2021-02-13T00:00:00 RS 8350 ---------ID1 21 2021 RS 8350 ---------ID1 21 2021 DE 10005 H1 0 DE 10006 T 0 1111111 2021-02-09T00:00:00 2021-02-15T00:00:00 RS 8350 ---------ID1 30 2021 DE 10003 D 0 DE 10005 H1 1 111111 2021-02-15T00:00:00 2021-02-20T00:00:00 RS 8350 ---------ID1 31 2021 RS 8350 ---------ID1 31 2021 DE 10005 H1 0 DE 10006 T 0 111111 2021-02-16T00:00:00 2021-02-21T00:00:00 1111111 2021-02-01T00:00:00 2021-02-07T00:00:00 DE 10004 S 0 DE 10005 H1 1 DE 10006 T 0 1111111 2021-02-07T00:00:00 2021-02-13T00:00:00 DE 10004 S 0 DE 10005 H1 2 DE 10006 T 0 111111 2021-02-15T00:00:00 2021-02-20T00:00:00 DE 10003 D 0 DE 10005 H1 1 DE 10006 T 0 .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.986 seconds) .. _sphx_glr_download_auto_examples_plot_annex_4.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_annex_4.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_annex_4.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_