.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_test_otr.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_test_otr.py: Example showing OTR anomalie ============================ Here we investigate the routing specification for a train with interesting OTRs. .. GENERATED FROM PYTHON SOURCE LINES 8-12 .. code-block:: default from tom.plot import plot_train, plot_graph from tom.tom import make_train_from_yml, TrainRun, RouteSection, Route from tom.util import example, dump_routing_info_as_xml .. GENERATED FROM PYTHON SOURCE LINES 13-14 Load example from yaml specification .. GENERATED FROM PYTHON SOURCE LINES 14-17 .. code-block:: default _, t_spec_file = example('../tests/data', 'otr-test') print(t_spec_file.read_text()) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none --- coreID: 30AB version: 1 sections: - departure_station: A arrival_station: B travel_time: '01:00:00' calendar: begin: '2020-12-01' end: '2020-12-02' id: 10 color: salmon succ: - 20 - 40 - departure_station: B arrival_station: C departure_time: '00:30:00' travel_time: '12:00:00' calendar: begin: '2020-12-02' end: '2020-12-02' id: 20 color: red succ: - 30 - departure_station: B arrival_station: C departure_time: '00:30:00' travel_time: '12:00:00' stop_time: '24:00:00' calendar: begin: '2020-12-04' end: '2020-12-04' id: 40 color: green succ: - 30 - departure_station: C arrival_station: D travel_time: '12:00:00' calendar: begin: '2020-12-02' end: '2020-12-04' # Exclude Thu 3.12. No section run on this day! mask: 'Wed Fri' id: 30 color: blue .. GENERATED FROM PYTHON SOURCE LINES 18-19 Create train object and show its train id. .. GENERATED FROM PYTHON SOURCE LINES 19-22 .. 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/30AB/00/2020' .. GENERATED FROM PYTHON SOURCE LINES 23-26 Timetable ^^^^^^^^^ Show timetable as dataframe .. GENERATED FROM PYTHON SOURCE LINES 26-29 .. code-block:: default df = t.to_dataframe() df .. raw:: html
Departure A Arrival B Departure B Arrival C Departure C Arrival D
Daily Train ID
TR/8350/30AB/10/2020/2020-12-01 Di 01.12.20 23:30 Mi 02.12.20 00:30 Mi 02.12.20 00:30 Mi 02.12.20 12:30 Mi 02.12.20 12:30 Do 03.12.20 00:30
TR/8350/30AB/10/2020/2020-12-02 Mi 02.12.20 23:30 Do 03.12.20 00:30 Fr 04.12.20 00:30 Fr 04.12.20 12:30 Fr 04.12.20 12:30 Sa 05.12.20 00:30


.. GENERATED FROM PYTHON SOURCE LINES 30-33 Bildfahrplan ^^^^^^^^^^^^ Show timetable as plot .. GENERATED FROM PYTHON SOURCE LINES 33-35 .. code-block:: default plot_train(t) .. image:: /auto_examples/images/sphx_glr_plot_test_otr_001.png :alt: Timetable TR/8350/30AB/00/2020 v1 :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 36-39 Route Sections ^^^^^^^^^^^^^^ From which sections the train is composed? .. GENERATED FROM PYTHON SOURCE LINES 39-43 .. 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/12 to 02/12 11 Start at: 23:30 in A Arrival at: 00:30 in B Successors: [20, 40] ID : 20.v1 Calender : 02/12 to 02/12 1 Start at: 00:30 in B Arrival at: 12:30 in C Successors: [30] ID : 40.v1 Calender : 04/12 to 04/12 1 Start at: 00:30 in B Arrival at: 12:30 in C Successors: [30] ID : 30.v1 Calender : 02/12 to 04/12 101 Start at: 12:30 in C Arrival at: 00:30 in D Successors: [] .. GENERATED FROM PYTHON SOURCE LINES 44-47 Section graph ^^^^^^^^^^^^^ The section graph is computed using the successor relation: .. GENERATED FROM PYTHON SOURCE LINES 47-51 .. code-block:: default sg = t.section_graph() plot_graph(sg) .. image:: /auto_examples/images/sphx_glr_plot_test_otr_002.png :alt: plot test otr :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 52-56 Routes ^^^^^^ Print all possible routes. Routes are calculated from all possible paths in the section graph. .. GENERATED FROM PYTHON SOURCE LINES 56-60 .. 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 : A-B-C-D Key : 10-20-30 Calendar : 01/12 to 01/12 1 Start at: 23:30 in A Arrival at: 00:30 in B Arrival at: 12:30 in C Arrival at: 00:30 in D Route : A-B-C-D Key : 10-40-30 Calendar : 02/12 to 02/12 1 Start at: 23:30 in A Arrival at: 00:30 in B Arrival at: 12:30 in C Arrival at: 00:30 in D .. GENERATED FROM PYTHON SOURCE LINES 61-65 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 65-69 .. 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: A-B ID A B 2020-12-01 10 2020-12-01 23:30:00 2020-12-02 00:30:00 2020-12-02 10 2020-12-02 23:30:00 2020-12-03 00:30:00 20: B-C ID B C 2020-12-02 20 2020-12-02 00:30:00 2020-12-02 12:30:00 40: B-C ID B C 2020-12-04 40 2020-12-04 00:30:00 2020-12-04 12:30:00 30: C-D ID C D 2020-12-02 30 2020-12-02 12:30:00 2020-12-03 00:30:00 2020-12-04 30 2020-12-04 12:30:00 2020-12-05 00:30:00 .. GENERATED FROM PYTHON SOURCE LINES 70-73 TrainRuns ^^^^^^^^^ Each `TrainRun` defines a row in the timetable of the train above .. GENERATED FROM PYTHON SOURCE LINES 73-80 .. 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/30AB/10/2020/2020-12-01 10.v1:2020-12-01 23:30 OTR=-1 A-B 2020-12-02 00:30 OTR=0 20.v1:2020-12-02 00:30 OTR=0 B-C 2020-12-02 12:30 OTR=0 30.v1:2020-12-02 12:30 OTR=0 C-D 2020-12-03 00:30 OTR=1 TR/8350/30AB/10/2020/2020-12-02 10.v1:2020-12-02 23:30 OTR=-2 A-B 2020-12-03 00:30 OTR=-1 40.v1:2020-12-04 00:30 OTR=0 B-C 2020-12-04 12:30 OTR=0 30.v1:2020-12-04 12:30 OTR=0 C-D 2020-12-05 00:30 OTR=1 .. GENERATED FROM PYTHON SOURCE LINES 81-84 RoutingInformation as TrainInformation ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ An XML Dump of the routing information of version 1 .. GENERATED FROM PYTHON SOURCE LINES 84-86 .. code-block:: default print(dump_routing_info_as_xml(t)) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none RS 8350 --------30AB 10 2020 DE 10000 A 0 DE 10001 B 1 11 2020-12-01T00:00:00 2020-12-02T00:00:00 RS 8350 --------30AB 20 2020 RS 8350 --------30AB 40 2020 RS 8350 --------30AB 20 2020 DE 10001 B 0 DE 10002 C 0 1 2020-12-02T00:00:00 2020-12-02T00:00:00 RS 8350 --------30AB 30 2020 RS 8350 --------30AB 40 2020 DE 10001 B 0 DE 10002 C 0 1 2020-12-04T00:00:00 2020-12-04T00:00:00 RS 8350 --------30AB 30 2020 RS 8350 --------30AB 30 2020 DE 10002 C 0 DE 10003 D 1 101 2020-12-02T00:00:00 2020-12-04T00:00:00 1 2020-12-01T00:00:00 2020-12-01T00:00:00 DE 10000 A 0 DE 10001 B 1 DE 10002 C 0 DE 10003 D 1 1 2020-12-02T00:00:00 2020-12-02T00:00:00 DE 10000 A 0 DE 10001 B 1 DE 10002 C 0 DE 10003 D 1 .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 2.684 seconds) .. _sphx_glr_download_auto_examples_plot_test_otr.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_test_otr.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_test_otr.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_