Planning Public Transportation with Raku

Metro Route 1

by Arne Sommer

Metro Route 1

[159.2.1] Published 15. December 2021.

[ Introduction | Oslo Metro | Oslo Tram | Bergen | Misc. ]
[ Metro Introduction | Metro 1 | Metro 4 | Metro 5 | Metro 2/3 | Metro All | My Metro ]

Route 1: Frognerseteren - Helsfyr (- Bergkrystallen)

This route has a part time extension from Helsfyr to Bergkrystallen, and it has a stop that is only used in one direction (Gulleråsen, towards Frognerseteren only).

We start with a text file defining the route, with stops and travel time between them. Note that the comments (in red, and explained below) are not part of the file. The filename extension «.def» is mandatory:

File: oslo-metro/01.def
#                                         # [1]
# 1 Bergkrystallen - Frognerseteren       # [1] [2]
# --------------------------------------  # [1]
OS415 A   A:3 Bergkrystallen              # [3]
OS414 A   B   Munkelia
OS413 A   B:2 Lambertseter
OS412 A:2 B   Karlsrud                    # [4]
OS411 A   B:2 Brattlikollen
OS410 A:2 B   Ryen
OS409 A   B:2 Manglerud
OS408 A:2 B   Høyenhall
OS407 A   B:2 Brynseng
OS406 A:2 B:2 Helsfyr
OS405 A:2 B   Ensjø
OS404 A:2 B:3 Tøyen
OS403 A:2 B   Grønland
OS402 A   B   Jernbanetorget
OS401 A   B:2 Stortinget
OS421 B:2 A:2 Nationaltheatret
OS422 B:3 A:2 Majorstuen
OS423 B   A:2 Frøen
OS424 B:2 A:2 Steinerud
OS425 B   A:2 Vinderen
OS426 B   A   Gaustad
OS427 B   A:2 Ris
OS428 B:3 A:2 Slemdal
OS429 B:2 A:2 Gråkammen
OS430 B   -   Gulleråsen                 # [5]
OS431 B   A:2 Vettakollen
OS432 B   A   Skådalen
OS433 B:2 A   Midtstuen
OS434 B:2 A:2 Besserud
OS435 B:2 A:3 Holmenkollen
OS436 B:3 A:2 Voksenlia
OS437 B:2 A:2 Skogen
OS438 B:2 A:2 Lillevann
OS439 B:2 A   Voksenkollen
OS440 B:3 A   Frognerseteren

[1] Lines starting with # are ignored by the program. Use them to add comments to help a person reading the file.

[2] The route number on this line is just a comment. The number in the file name is also just a comment (so to speak). We'll get back to the route number later on.

[3] This is the first stop on the route, in the first direction (which is Down). The next row is the next stop, and so on. The second direction (Up), starts at the bottom. The columns, which are separated by one or more spaces, are:

Stop ID
OS415 A   A:3 Bergkrystallen

A unique identifier for each stop, consisting of two uppercase letters and three digits.

The letters used here is «OS» which is short for «Oslo». I have numbered the stops sequentially from the city centre (Stortinget) outwards.

Platform in the Down direction
OS491 A   A:3 Bergkrystallen

Platforms are indicated by a single uppercase letter. I have chosen «A» for the direction to the city centre, and «B» outwards from it.

[4] The travel time in minutes to the current stop (from the previous one) is 1, unless given explicitly after a colon:

OS412 A:2 B   Karlsrud

Legal values are «0», «0.5», «1», «1.5» and so on. Do not use values larger than «59» (as the program does not handle such values very well).

Platform in the Up direction
OS412 A:2 B   Karlsrud

As above. Start reading from the bottom of the list.

[5] Stops in only one direction are supported; specify - (a minus sign) instead of the platform identifier:

OS430 B   -   Gulleråsen

Stop name
OS412 A   A:3 Bergkrystallen

The first character in the name must be a letter. The name may contain spaces, as shown for this fictitious stop:

LN123 A:2 B   Oxford Circus

Then we need a setup file. I have given it the «.setup» filename extension, but this is just a suggestion.

File: oslo-metro/metro-1.setup
## Networkplanner ##                              # [1]
                                                  # [2]
route set 1 file:01.def down:2 up:13 interval:15  # [3]

summary                                           # [4]

[1] The first row must contain the following string:

## Networkplanner ##

[2] Empty rows are ignored.

[3] Use the «route» command to set up a new route. This command can be used several times, thus setting up a network of routes.

The first part tells the program to set up a route:

 route 1 file:01.def down:2 up:13 interval:15

The next part is the route number. Note that any route value in the file itself (on a comment row), and part of the filename, are not used.

route set 1 file:01.def down:2 up:13 interval:15

The rest of the row is a list of colon separated values, in any order. The first one here is the filename for the route specification file (as shown above):

route set 1 file:01.def down:2 up:13 interval:15

Then we have the offset value in minutes for the departures in the Down direction. Legal values are «0», «0.5», »1» and so on. The first departure will start at 0 minutes past the hour if this is not set.

route set 1 file:01.def down:2 up:13 interval:15

As above, for the Up direction:

route set 1 file:01.def down:2 up:13 interval:15

And finally the interval between departures, again in minutes. Legal values are «0.5», »1» and so on. The default value is 10 minutes.

route set 1 file:01.def down:2 up:13 interval:15

[4] Save the summary (as shown below) with the «summary» command. The summary will be printed to the screen:

summary

Specify a file, if you want the output to be saved instead of printed to the screen. The filename must have the «.txt» extension. This command will overwrite an existing file, if any

summary summary.txt

The special filename «-» (a minus sign) can also be used to print the summary to the screen. Note that the file is written to the current directory, which may be different from where the files were read from.

summary -

Run the comamnd from the directory you unapcked the zip file in, e.g. «/home/arne/public-transportation«:

$ networkplanner oslo-metro/metro-1.setup

The first half of the result, the Down direction, looks like this:

Route 1: Bergkrystallen - Frognerseteren
----------------------------------------------------------------
00  | 02  17  32  47  Bergkrystallen [B]
01  | 03  18  33  48  Munkelia [A]
02  | 04  19  34  49  Lambertseter [A]
04  | 06  21  36  51  Karlsrud [A]
05  | 07  22  37  52  Brattlikollen [A]
07  | 09  24  39  54  Ryen [A]
08  | 10  25  40  55  Manglerud [A]
10  | 12  27  42  57  Høyenhall [A]
11  | 13  28  43  58  Brynseng [A]
13  | 15  30  45  00  Helsfyr [A]
15  | 17  32  47  02  Ensjø [A]
17  | 19  34  49  04  Tøyen [A]
19  | 21  36  51  06  Grønland [A]
20  | 22  37  52  07  Jernbanetorget [A]
21  | 23  38  53  08  Stortinget [A]
23  | 25  40  55  10  Nationaltheatret [B]
26  | 28  43  58  13  Majorstuen [B]
27  | 29  44  59  14  Frøen [B]
29  | 31  46  01  16  Steinerud [B]
30  | 32  47  02  17  Vinderen [B]
31  | 33  48  03  18  Gaustad [B]
32  | 34  49  04  19  Ris [B]
35  | 37  52  07  22  Slemdal [B]
37  | 39  54  09  24  Gråkammen [B]
38  | 40  55  10  25  Gulleråsen [B]
39  | 41  56  11  26  Vettakollen [B]
40  | 42  57  12  27  Skådalen [B]
42  | 44  59  14  29  Midtstuen [B]
44  | 46  01  16  31  Besserud [B]
46  | 48  03  18  33  Holmenkollen [B]
49  | 51  06  21  36  Voksenlia [B]
51  | 53  08  23  38  Skogen [B]
53  | 55  10  25  40  Lillevann [B]
55  | 57  12  27  42  Voksenkollen [B]
58  | 00  15  30  45  Frognerseteren [B]

It compares favourably with the official timetable (albeit with selected stops only), the first gray area:

The second half of the result, the Up direction, looks like this:

Route 1: Frognerseteren - Bergkrystallen
----------------------------------------------------------------
00  | 13  28  43  58  Frognerseteren [A]
01  | 14  29  44  59  Voksenkollen [A]
03  | 16  31  46  01  Lillevann [A]
05  | 18  33  48  03  Skogen [A]
07  | 20  35  50  05  Voksenlia [A]
10  | 23  38  53  08  Holmenkollen [A]
12  | 25  40  55  10  Besserud [A]
13  | 26  41  56  11  Midtstuen [A]
14  | 27  42  57  12  Skådalen [A]
16  | 29  44  59  14  Vettakollen [A]
18  | 31  46  01  16  Gråkammen [A]
20  | 33  48  03  18  Slemdal [A]
22  | 35  50  05  20  Ris [A]
23  | 36  51  06  21  Gaustad [A]
25  | 38  53  08  23  Vinderen [A]
27  | 40  55  10  25  Steinerud [A]
29  | 42  57  12  27  Frøen [A]
31  | 44  59  14  29  Majorstuen [A]
33  | 46  01  16  31  Nationaltheatret [A]
35  | 48  03  18  33  Stortinget [B]
36  | 49  04  19  34  Jernbanetorget [B]
37  | 50  05  20  35  Grønland [B]
40  | 53  08  23  38  Tøyen [B]
41  | 54  09  24  39  Ensjø [B]
43  | 56  11  26  41  Helsfyr [B]
45  | 58  13  28  43  Brynseng [B]
46  | 59  14  29  44  Høyenhall [B]
48  | 01  16  31  46  Manglerud [B]
49  | 02  17  32  47  Ryen [B]
51  | 04  19  34  49  Brattlikollen [B]
52  | 05  20  35  50  Karlsrud [B]
54  | 07  22  37  52  Lambertseter [B]
55  | 08  23  38  53  Munkelia [B]
58  | 11  26  41  56  Bergkrystallen [B]

This part also compares favourably with the official timetable:

Let us see how many vehicles we need to run the route every fifteen minues.

First we have to tell the program how to combine the routes. This is easy, as we have hust one. But the program supports multiple routes, and differentiates between the directions as well:

File: oslo-metro/vehicles-1a.def
=0100             # [1]
1 D Bk/1;Bk    6  # [2]
1 U Frs/1;Frs 10  # [3]

[1] The series to place the vehicles in. Use four digits, with zeroes as the last two. The vehicles are numbered from «01» and upwards in the series.

[2] Start with route 1 in the Down direction. The third column is the text to show on the departure and arival rows. Specify a second text after a semicolon if you want a different text on the arrival rows.

[3] The next departure, this time on the same route and in the Up direction.

We have to change the setup file. Here is the modified version:

File: oslo-metro/metro-1a.setup
## Networkplanner ##

route set 1 file:01.def down:2 up:13 interval:15

summary

vehicles vehicles-1a.def  # [1]

[1] A new vehicle definition file.

Then we can run the program with the new setup file:

$ networkplanner oslo-metro/metro-1a.setup

The number of vehicles is shown after the summary. Here it is:

	      0101  0102  0103  0104  0105  0106  0107  0108  0109
-------------------------------------------------------------------
Bk/1	dep   0002  0017  0032  0047  0102  0117  0132  0147  0202 
Frs	arr   0100  0115  0130  0145  0200  0215  0230  0245  0300 
Frs/1	dep   0113  0128  0143  0158  0213  0228  0243  0258  0313 
Bk	arr   0211  0226  0241  0256  0311  0326  0341  0356  0411 
Bk/1	dep   0217  0232  0247  0302  0317  0332  0347  0402  0417 

0100: Number of vehicles: 9
---------------------------------------
Total number of vehicles: 9

The separate arrival and departure rows make it easy to see how much time is available at the route ends for turning the vehicle and so on.

Short Runnings to Helsfyr

Route 1 ends at Helsfyr, which has a two directional siding just east of the station, in the evenings:

We can reuse the existing route definition file for short runnings. Specify the first and/or last stop in the setup file:

File: oslo-metro/metro-1b.setup
## Networkplanner ##

route set 1 file:01.def down:0 up:13 interval:15 start-at:OS406

summary

vehicles vehicles-1b.def

The new vehicle definition file:

File: oslo-metro/vehicles-1b.def
=0100
1 D Hfy/1;Hfy  8
1 U Frs/1;Frs 10

Running it:

$ networkplanner oslo-metro/metro-1b.setup

The number of vehicles is shown after the summary. Here it is:

	      0101  0102  0103  0104  0105  0106  0107  0108
-------------------------------------------------------------
Hfy/1	dep   0000  0015  0030  0045  0100  0115  0130  0145 
Frs	arr   0045  0100  0115  0130  0145  0200  0215  0230 
Frs/1	dep   0058  0113  0128  0143  0158  0213  0228  0243 
Hfy	arr   0141  0156  0211  0226  0241  0256  0311  0326 
Hfy/1	dep   0200  0215  0230  0245  0300  0315  0330  0345 

0100: Number of vehicles: 8
---------------------------------------
Total number of vehicles: 8

Just one vehicle saved compared with running all the way to Bergkrystallen. That is caused by the layover time at Helsfyr (which someone may say is excessive at 19 minutes). The alternative is 4 minutes, which really is too little to check that the metro set is empty, then drive to the siding, change direction, and drive to the other platform. But here we go:

File: oslo-metro/metro-1c.setup
## Networkplanner ##

route set 1 file:01.def down:0 up:13 interval:15 start-at:OS406

summary

vehicles oslo-metro/vehicles-1c.def
File: oslo-metro/vehicles-1c.def
=0100
1 D Hfy/1;Hfy  4
1 U Frs/1;Frs 10

Running it:

$ networkplanner oslo-metro/metro-1b.setup

We have saved one additional vehicle:

	      0101  0102  0103  0104  0105  0106  0107
-------------------------------------------------------
Hfy/1	dep   0000  0015  0030  0045  0100  0115  0130 
Frs	arr   0045  0100  0115  0130  0145  0200  0215 
Frs/1	dep   0058  0113  0128  0143  0158  0213  0228 
Hfy	arr   0141  0156  0211  0226  0241  0256  0311 
Hfy/1	dep   0145  0200  0215  0230  0245  0300  0315 

0100: Number of vehicles: 7
---------------------------------------
Total number of vehicles: 7

[ Introduction | Oslo Metro | Oslo Tram | Bergen | Misc. ]
[ Metro Introduction | Metro 1 | Metro 4 | Metro 5 | Metro 2/3 | Metro All | My Metro ]