Planning Public Transportation with Raku

Commands

by Arne Sommer

Commands

[159.1.3] Published 15. December 2021. (Updated 31. December 2021)

[ Introduction | Oslo Metro | Oslo Tram | Bergen | Misc. ]
[ About | Terms | Files | Commands | FAQ | Changelog | Roadmap | 60 Minutes NEW ]

Waterloo & City Line

I am using the Waterloo & City Line (in London) as example in this and the «Commands» article. It has two stops only, and looks like this:

See the Oslo Metro articles for a more comprehensive example.

Commands

Actions that the «networkplanner» program will react to, either in a network setup file, or interactively.

help

Use this command to get help. It will point to this article, and give the location of the sample networks that are described here (which come in a zip file):

$ networkplanner
networkplanner: Enter «exit» to exit
> help
See https://raku-musings.com/transit-network for a description of this program.
Sample networks are bundled with this program. Unpack the following zip file in a
 suitable location: /home/foo-bar/.raku/resources/1C04xE74A46753197D9D2554D8891.zip

You can also use the «--help» command line option.

batch <network-setup-file>

Use this command to load and execute the commands in a network setup file. It is recommended to use this command in interactive mode only, and not in a network setup file.

Note that the program will look for the files in the same directory as the network setup file. So do't specify the path inside the network setup file.

The above is done by setting the path (see lower down). And this will be left as it is after the batch command has finished. (So the current directory is not the current directory any more..)

$ networkplanner
networkplanner: Enter «exit» to exit
> batch london/wc.setup

Use the «-silent» flag to suppress (most) output:

> batch -silent london/wc.setup

This can be used to set up a network in interactive mode by loading a network setup file, allowing the user to run additional commands afterwards. Including additional «batch» commands.

route set <route-id> file:<route definition file>

Use this command to set up a new route, or redefine (overwrite) an existing one.

The route definition file must have the «.def» extension.

Let us start «networkplanner» in interactive mode, and set up the route manually:

$ networkplanner
networkplanner: Enter «exit» to exit
> route set W&C file:london/wc.def
> 

Not very verbose at all. You have to wait a couple of paragraphs before we come to commands that cause output.

I have chosen to rebrand the route as «W&C» as «WC» does not sound especially serious.

The «route set» command supports the following optional arguments:

down:<number>
The offset from 00 for the first departure in the Down direction. Whole and half minutes are supported. Do not use negative values (but they are supported; see the Railway article for why).

The offset can also be specified in days, as described for the route definition file. [Added in v0.0.2]

The default value is 0.

Values higher than 60 minutes is supported, and should be specified with the <hour>h<minutes> syntax to make them readable. 12 hours is the same as 720 minutes, but «12h00» is preferable. [0.0.2]: It is also possible to specify days, with «d». E.g. «2d12h15» for «2 days, 12 hours amd 15 minutes».

down:<number>[<stop-id>]
The offset can be applied from any stop enroute, by specifying the stop ID in brackets. The offset from the start of the route is calculated so that the departure passes the specified stop with the given offset value.

If the route visits the stop more than once, the first one is used. Specifying a stop ID not on the route will cause program termination.

down:off
Disable departures in the Down direction.

up:<number>
The offset from 00 for the first departure in the Up direction. Whole and half minutes are supported. Do not use negative values.

The default value is 0.

Values higher than 60 minutes are supported. See «down», above.

up:<number>[<stop-id>]
As for «down»; see above.

up:off
Disable departures in the Up direction.

interval:<number>
The number of minutes between the departures; e.g. 1, 2, 3 and so on. Half minutes are also supported; e.g. 0.5, 1.5 and so on.

The number should add up to 60, so that the program can use the same minutes past the hour for the second hour and so on. If not, the program will go on until has reached a multiple of 60 minutes. Note that the timingpoints will be off in this case.

Eight departures per hour can either be specified as «7.5», if you allow half minutes, or as «7;8» if you want the intervals to be 8 and 7 minutes respectively (or as «8;7» if that order is better). Any number of values are supported; e.g. «3;3.5;3.5», but they should add up to 60.

The default value is 10.

It is possible to use 60 and higher values. The timingpoints will be off, and the summary is disabled.

Values higher than 60 minutes should be specified with the <hour>h<minutes> syntax, to make them readable. 12 hous is the same as 720 minutes, but «12h00» is preferable.

interval-down:<number>
Use this command if you want to set an interval for the Down direction only. The value set with «interval» will be used if this is not specified. [Added in v0.0.3]

interval-up:<number>
Use this command if you want to set an interval for the Up direction only. The value set with «interval» will be used if this is not specified. [Added in v0.0.3]

start-at:<stop-id>
The route will start at the first stop, unless an intermediary stop is specified here. Use the stop-id, and not the stop name.

The platforms can also be overridden, but you have to specify both if you do.

start-at:OS104[C;D]

The travel time can also be overridden:

start-at:OS104[C;D:10]

end-at:<top-id>
The route will end at the last stop, unless an intermediary stop is specified here. Use the stop-id, and not the stop name.

The platforms (and travel time) can be overridden here as well.

reverse:1
Reverse the route definition as it is read from the file. The value after the colon is not important, but it has to be there.

route append <route-id> file:<route definition file>

Use this command to append (add) more stops to an existing route.

This is the minimum command, with a route id and a file to read the route from. The file must have a «.def» extension.

The route must exist (set up with «route set»).

The optional fields «start-at», «end-at» and «reverse» are supported. See «route set» (above) for details. «reverse» applies to the selected section only. [v.0.0.3: Removed support for the other optional fields supported by «route set».]

route source <route-id>

Use this command to show the route definition, nicely tabulated.

This will basically print the route definition file. Any changes applied with «end-at», «start-at», and «route append» will be included.

This is useful for debugging, when the result does not match the expectation.

route source :reverse <route-id>

Use this command to show the route definition, reversed.

route list

This command will list the (defined) routes. This is useful in interactive mode only.

route delete <route-id>

This command will delete the specified route. This is useful in interactive mode only.

summary

This will print the summary. The command does not work if the interval is 60 minutes or more. (Use the «:raw» option in that case.) [v.0.0.3: The «summary» command will automatically use the «:raw» option if the interval is 60 minutes or more.]

Enter the «summary» command in interactive mode, after setting up the route W&C:

> summary
Route W&C: Waterloo - Bank
----------------------------------------------------------------
00  | 00  10  20  30  40  50  Waterloo [25]
04  | 04  14  24  34  44  54  Bank [7|8]

Route W&C: Bank - Waterloo
----------------------------------------------------------------
00  | 00  10  20  30  40  50  Bank [7|8]
03  | 03  13  23  33  43  53  Waterloo [26]

summary :raw

This will print a raw version of the summary. This will be used automatically (as of v0.0.3) when the interval is 60 minutes or more. See the railway article for a useful example.

> summary :raw
Route W&C: Waterloo - Bank
----------------------------------------------------------------
02  | Waterloo [25]
06  | Bank [7|8]

Route W&C: Bank - Waterloo
----------------------------------------------------------------
09  | Bank [7|8]
12  | Waterloo [26]

timingpoints <timingpoints definition file>

Use this command to print the departure times at the specified stops.

Routes with an interval of 60 or more are skipped.

Why Timingpoints?

Timinpoints are useful when you have a network with several routes with one or more shared sections, where you want to time the departures. An example:

We'll not discuss this here, but will look into it when we come to the Oslo metro and Bergen light rail networks.

It is easy to set up the departures from A (route 1 and 3), and M (route 2 and 3), but this does not help with the situation at e.g. Q (in the middle).

> timingpoints london/wc-timingpoints.def
Bank [7|8]
 06  16  26  36  46  56  | W&C Bank
 09  19  29  39  49  59  | W&C Waterloo

Waterloo [25]
 02  12  22  32  42  52  | W&C Bank

Waterloo [26]
 02  12  22  32  42  52  | W&C Waterloo

If you have several routes, with different intervals, use the «:tabulated» option:

> route set W&C file:london/wc.def
> route set W&C2 file:london/wc.def interval:30 down:5 up:5
> timingpoints london/wc-timingpoints.def
Bank [7|8]
 00  10  20  30  40  50  | W&C Waterloo
 04  14  24  34  44  54  | W&C Bank
 05  35  | W&C2 Waterloo
 09  39  | W&C2 Bank

Waterloo [25]
 00  10  20  30  40  50  | W&C Bank
 05  35  | W&C2 Bank

Waterloo [26]
 03  13  23  33  43  53  | W&C Waterloo
 08  38  | W&C2 Waterloo

> timingpoints :tabulated london/wc-timingpoints.def
Bank [7|8]
-- 04 -- -- -- 14 -- 24 -- 34 -- -- -- 44 -- 54 | W&C Bank
00 -- -- -- 10 -- 20 -- 30 -- -- -- 40 -- 50 -- | W&C Waterloo
-- -- -- 09 -- -- -- -- -- -- -- 39 -- -- -- -- | W&C2 Bank
-- -- 05 -- -- -- -- -- -- -- 35 -- -- -- -- -- | W&C2 Waterloo

Waterloo [25]
00 -- 10 20 30 -- 40 50 | W&C Bank
-- 05 -- -- -- 35 -- -- | W&C2 Bank

Waterloo [26]
03 -- 13 23 33 -- 43 53 | W&C Waterloo
-- 08 -- -- -- 38 -- -- | W&C2 Waterloo

It is possible to merge routes, as long as they have the same destination. Use the «:merge» option, with a semicolon separated list of route IDs in brackets. Like this:

> timingpoints :merge[W&C;W&C2] london/wc-timingpoints.def
Bank [7|8]
-- 04 -- 09 -- 14 -- 24 -- 34 -- 39 -- 44 -- 54 | W&C Bank
00 -- 05 -- 10 -- 20 -- 30 -- 35 -- 40 -- 50 -- | W&C Waterloo

Waterloo [25]
00 05 10 20 30 35 40 50 | W&C Bank

Waterloo [26]
03 08 13 23 33 38 43 53 | W&C Waterloo

The first route ID in the list will be used, in this case W&C.

Note that «:merge» will enable «:tabulated» as well. This can not be disabled.

You can have multiple :merge arguments as of v.0.0.3. In earlier version they replaced each other, and the last one was used.

Alternate Platforms

This example is not very useful, but we can use it to alternate between the stub platforms at Bank (as «7|8» is't very precise):

We have rto set up two separate routes, each one using one platform at Bank. We can do this in the network setup file:

File: london/wcII.setup
## Networkplanner ##

route set W&Ca file:wc.def down:2  up:19 interval:20 end-at:LO002[7:4;7]
route set W&Cb file:wc.def down:12 up:9  interval:20 end-at:LO002[8:4;8]

summary

timingpoints :merge[W&C;W&Ca;W&Cb] wc-timingpoints.def

vehicles wc-vehiclesII.def

The vehicle definition file:

File: wc-vehiclesII.def
=WC00
W&Ca D Wloo/25;Wloo/26  8
W&Ca U Bank/7           8
W&Cb D Wloo/25;Wloo/26  8
W&Cb U Bank/8           8

The result:

              WC01  WC02  WC03
------------------------------
Wloo/25 dep   0002  0022  0042 
Bank/7  arr   0006  0026  0046 
Bank/7  dep   0019  0039  0059 
Wloo/26 arr   0022  0042  0102 
Wloo/25 dep   0032  0052  0112 
Bank/8  arr   0036  0056  0116 
Bank/8  dep   0049  0109  0129 
Wloo/26 arr   0052  0112  0132 
Wloo/25 dep   0102  0122  0142 

WC00: Number of vehicles: 3
---------------------------------------
Total number of vehicles: 3

tp <stop name|stop ID>

Use this command to get the timingpoint data for the specified stop or stops (space separated). tp <stop-name> tp <stop-name> <stop-name> …

> tp Bank Farringdon
Bank [W1]
 00  10  20  30  40  50   W&C Waterloo

Bank [W2]
 04  14  24  34  44  54   W&C Bank

Non-existing stop names are silently ignored, as illustrated with «Farringdon».

The «:tabulated» and «:merge» options (see «timingpoints» above) are also supported. Routes with an interval of 60 or more are skipped.

Note that this command accept stop names that contain one or more spaces, if you quote the name. Single (') and double (") quotes are supported. E.g.:

> tp "Kings Cross" "Liverpool Street" Bank

vehicles <vehicle definition file>

Use this command to get a summary of the departures and the required number of vehicles.

> vehicles london/wc-vehicles.def

	      WC01  WC02  WC03  WC04
-------------------------------------
Wloo	dep   0000  0010  0020  0030 
Bank	arr   0004  0014  0024  0034 
Bank	dep   0020  0030  0040  0050 
Wloo	arr   0023  0033  0043  0053 
Wloo	dep   0040  0050  0100  0110 

WC00: Number of vehicles: 4
---------------------------------------
Total number of vehicles: 4

The departure times, and the required number of vehicles, change if we change the «down» and/or «up» values:

> route set W&C file:london/wc.def down:2 up:9
> vehicles london/wc-vehicles.def

	      WC01  WC02  WC03
-------------------------------
Wloo	dep   0002  0012  0022 
Bank	arr   0006  0016  0026 
Bank	dep   0019  0029  0039 
Wloo	arr   0022  0032  0042 
Wloo	dep   0032  0042  0052 

WC00: Number of vehicles: 3
---------------------------------------
Total number of vehicles: 3
> route set W&C file:london/wc.def down:2 up:9 interval:7.5
> vehicles london/wc-vehicles.def

	      WC01  WC02  WC03  WC04
-------------------------------------
Wloo	dep   0002  0009' 0017  0024'
Bank	arr   0006  0013' 0021  0028'
Bank	dep   0016' 0024  0031' 0039 
Wloo	arr   0019' 0027  0034' 0042 
Wloo	dep   0032  0039' 0047  0054'

WC00: Number of vehicles: 4
---------------------------------------
Total number of vehicles: 4

The Waterloo & City line has 5 trains, so we can safely use 3 of them. 4 will probably be ok, most of the time.

The same interval will be used on all the rows. It is taken from the first route, in the Down direction (the «interval-down» argument), with fallback to «interval». This is a bug; #001. See the Roadmap for details.

stops

This command will list all the stops, with IDs and names. The list is sorted by IDs.

> stops
LO001 Waterloo
LO002 Bank

Note that deleting or redefining routes will not remove unused stops from this list.

path <directory>

Use this command to specify a directory to look in for the files. The following are equivalent:

> route set W&C file:london/wc.def down:2 up:9 interval:7.5
> vehicles london/wc-vehicles.def
> path london
> route set W&C file:wc.def down:2 up:9 interval:7.5
> vehicles wc-vehicles.def

This mimics what is done when loading a network setup file.

lang

Use this command to see the language used for output.

Supported languages:

  • EN (English) - the default
  • NO (Norwegian)

lang <language code>

Use this command to change the language used for output.

You can also use the «--lang» command line option. E.g. «--lang=NO».

Output to a file

The «summary», «timingpoints» and «vehicles» commands support an extra argument. Specify a file name (ending with «.txt») at the end, and the output will be saved to that file instead of beeing printed to the screen.

Leave the filename blank (as shown above), or use «-», to get the output to the screen.

[ Introduction | Oslo Metro | Oslo Tram | Bergen | Misc. ]
[ About | Terms | Files | Commands | FAQ | Changelog | Roadmap | 60 Minutes NEW ]