sourcelibs/Graphs/demos/subway.xtl
1⍝!/usr/bin/env xetal
2⍝# A small subway map: eight stations on a red line, a blue line and a
3⍝# branch, with the minutes between stations. How long from the
4⍝# Airport to everywhere, how many stops from the Center, and what a
5⍝# closure cuts off. Run with "just demo Graphs subway".
6
7ᵍ⁼u̲se< "Graphs"
8ᵗ⁼u̲se< "Strings"
9names ← "Airport" "Bridge" "Center" "Docks" "Exchange" "Fair" "Garden" "Harbor"
10⍝ The red line 1-2-3-4-5, the blue line 6-3-7, the branch 4-8: from, to, minutes.
11lines ← 3 7 r̲eshape 1 2 3 4 6 3 4 2 3 4 5 3 7 8 7 4 3 5 6 4 9
12w ← (8 ᵍw̲eighted lines) + o̲\ 8 ᵍw̲eighted lines
13
14⍝ Minutes from the Airport to every station.
15"\n" ᵗj̲oin '{ i → (10 ᵗp̲adRight d̲isclose i s̲elect names) c̲at f̲ormat f̲irst i s̲elect f̲irst ᵍs̲hortest w } m̲ap r̲ange 8
16
17⍝ Stops from the Center.
18(0 < w) ᵍl̲evels 3
19
20⍝ Close the Center: drop its edges, and see the network fall apart.
21open ← (0 < w) ∧ n̲ot ((r̲ange 8) = 3) '∨ t̲able (r̲ange 8) = 3
22ᵍc̲omponents open