├── code ├── ed.dyalog ├── path.dyalog ├── trip.dyalog ├── compile.dyalog └── replaces.dyalog ├── notes ├── ed.txt ├── describe.txt ├── path.txt ├── script.txt ├── source.txt ├── test.dyalog ├── trip.txt ├── zip_cat.txt ├── tube.txt └── compile.txt ├── dyalog-tube-ws.dyalogbuild ├── README.md ├── sources ├── cairo.txt ├── tyne_wear.txt ├── petersburg.txt ├── barcelona.txt ├── milano.txt ├── madrid.txt ├── paris.txt ├── london.txt ├── copenhagen.txt └── new_york.txt └── LICENSE /code/ed.dyalog: -------------------------------------------------------------------------------- 1 | ed←{ ⍝ Edit source for subway ⍵. 2 | _←'→'⍵.⎕ED'source' ⍝ edit source. 3 | _←⍵.⎕EX'graph' ⍝ force recompilation by removing: graph, 4 | _←⍵.⎕EX'labels' ⍝ and vertex labels. 5 | } 6 | -------------------------------------------------------------------------------- /notes/ed.txt: -------------------------------------------------------------------------------- 1 | #.ed subway ⍝ Edit subway coding ⍵.source [ed] places the source array (⍵.source) into an edit window and removes the compiled arrays ⍵.(graph labels) in order to trigger re-compilation. See also: →compile← →path← →trip← 2 | -------------------------------------------------------------------------------- /dyalog-tube-ws.dyalogbuild: -------------------------------------------------------------------------------- 1 | DYALOGBUILD : 1.0 2 | ID : tube, Version=1.0 3 | DESCRIPTION : tube workspace 4 | DEFAULTS : (⎕IO ⎕ML ⎕WX)←1 1 3 5 | TARGET : tube.dws 6 | LX : notes.describe 7 | 8 | DATA : sources/*.txt, Format=charvec, SetEOL=cr 9 | EXEC : {(⍎⍵⎕NS ⍬).source←⍎⍵}¨⎕NL ¯2.1 10 | DATA : notes/*.txt, Target=#.notes, Format=charvec, SetEOL=cr 11 | NS : notes/*.dyalog, Target=#.notes 12 | NS : code/*.dyalog 13 | -------------------------------------------------------------------------------- /notes/describe.txt: -------------------------------------------------------------------------------- 1 | For an overview: )ed notes.tube To examine source: ed∘⍎¨⌽↓⎕nl 9 Some sample trips: barcelona trip 'Besos' 'Congres' copenhagen trip 'Mælkevejen' 'Zoo' london trip 'Hammersmith' 'Mornington' madrid trip 'Aeropuerto' 'Sol' milano trip 'Turro' 'Sondrio' paris trip 'Pigalle' 'Saint-Germain' petersburg trip 'Deviatkino' 'Rybatskoe' tyne_wear trip 'South Shields' 'North Shields' -------------------------------------------------------------------------------- /notes/path.txt: -------------------------------------------------------------------------------- 1 | vvec ← graph #.path (from to) ⍝ Shortest path between ⍵ in graph ⍺. Returns a vector of vertices that represents a shortest path between end-point vertices [from] and [to] of [graph]. There may be many paths of the _same_ length, but none shorter. Notice that the reverse path (to from) may not be the reverse of the original forward path. See notes.Graphs in workspace dfns.dws for a full description of graphs. See also: dfns.dws/notes.Graphs dfns.dws/notes.path See also: →compile← →trip← →ed← 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![roundel](https://user-images.githubusercontent.com/10961427/42541400-15625124-849a-11e8-8576-f8f25235f11b.png) 2 | # Dyalog Tube Workspace 3 | *Source for building the dfns tube planner workspace (tube.dws)* 4 | 5 | ## Building 6 | 7 | `]DBuild path/tube.dyalogbuild` 8 | 9 | ## Contributing 10 | 11 | Feel free to submit pull requests for files in the [`sources`](sources) directory, both with corrections to already included cities, and with entirely new cities. 12 | 13 | The format for simple routes should be fairly self-explanatory. [`notes/tube.txt`](notes/tube.txt) describes the exact format for the more complicated constructs; forks, crosses, and one-way sections, while [`notes/source.txt`](notes/source.txt) demonstrates their use in a minimal route network. 14 | 15 | Contributions will be acknowledged at the bottom of [`notes/tube.txt`](notes/tube.txt). 16 | -------------------------------------------------------------------------------- /sources/cairo.txt: -------------------------------------------------------------------------------- 1 | ///////////////// // Cairo Metro // ///////////////// Line 1 El-Marg Ezbet El-Nakhl Ain Shams El-Matareyya Helmlet El-Zaitoun Hadayeq El-Zaitoun Saray El-Qobba Hammamat El-Qobba Kobri El-Qobba Manshiet El-Sadr El-Demerdash Ghamra Mubarak Orabi Nasser Sadat Saad Zaghloul Sayyeda Zeinab El-Malek El-Saleh Mar Girgis El-Zahraa Dar El-Salam Hadayeq El-Maadi Maadi Sakanat El-Maadi Tora El-Balad Kozzika Tora El-Asmant El-Maasara Hadayeq Helwan Wadi Hof Ain Helwan Helwan Line 2 Shobra Koliet El-Zeraa Mezallat Khalafawy Sainte Teresa Road El-Farag Masarra Mubarak Naguib El-Rihani Ataba Awqaf (Bostan) Sadat Gezira Dokki Bohooth Cairo University Giza Square Giza Railway Giza Suburbs Line 3 Embaba Sudan Zamalek Boulaq Nasser Emad-Eldin Ataba Port-Said Al-Azhar Salah Salem 2 | -------------------------------------------------------------------------------- /code/path.dyalog: -------------------------------------------------------------------------------- 1 | path←{ ⍝ Shortest path from/to ⍵ in graph ⍺. 2 | graph←⍺ ⍝ ⍺ is graph vector. 3 | fm to←⍵ ⍝ starting and target vertex(ices). 4 | tree←¯2+(⍳⍴⍺)∊fm ⍝ initial spanning tree. 5 | free←{(¯2=tree[⍵])/⍵} ⍝ free vertices in ⍵. 6 | ⍬{ ⍝ path accumulator. 7 | ⍵<0:(⍵=¯2)↓⍺ ⍝ root or unvisited vertex: finished. 8 | (⍵,⍺)∇ ⍵⊃tree ⍝ otherwise: prefix previous (parent) vertex. 9 | }{ ⍝ find partial spanning tree: 10 | ⍵≡⍬:¯1 ⍝ no vertices left: stitched. 11 | 1∊to∊⍵:1↑⍵∩to ⍝ found target: finished. 12 | next←free¨graph[⍵] ⍝ next vertices to visit. 13 | back←↑,/⍵+0×next ⍝ back links. 14 | wave←↑,/next ⍝ vertex wave front. 15 | tree[wave]←back ⍝ set back links in tree. 16 | ∇∪wave ⍝ advance wave front. 17 | }fm ⍝ from starting vertex. 18 | } 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Dyalog Ltd. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /sources/tyne_wear.txt: -------------------------------------------------------------------------------- 1 | ///////////////////////// // Tyne and Wear Metro // ///////////////////////// Green Line Airport Callerton Parkway Bank Foot Kingston Park Fawdon Wansbeck Road Regent Centre South Gosforth Green Line South Gosforth Ilford Road West Jesmond Jesmond Haymarket Monument Yellow Line Monument St. James Yellow Line Monument Manors Byker Chillingham Walkergate Wallsend Hadrian Road Howdon Percy Main Meadow Well North Shields Tynemouth Cullercoats Whitley Bay Monkseaton West Monkseaton Shiremoor Palmersville Benton Four Lane Ends Longbenton South Gosforth Yellow Line Monument Central Station Gateshead Gateshead Stadium Felling Weworth Pelaw Yellow Line (Extension) Pelaw Fellgate Brockley Whins East Boldon Seaburn Stadium of Light St. Peter's Sunderland Park Lane University Millfield Pallion South Hylton Green Line Monument Central Station Gateshead Gateshead Stadium Felling Weworth Pelaw Hebburn Jarrow Bede Tyne Dock Chichester South Shields 2 | -------------------------------------------------------------------------------- /notes/script.txt: -------------------------------------------------------------------------------- 1 | ⍝ Test script: (compile notes) trip 'Apple' 'Pear' ⍝ simple trip Apple Apple Fruit Tomato Fruit Pear Fruit Pear notes trip 'Apple' 'Banana' ⍝ via fork Apple Apple Fruit Tomato Fruit Tomato Tomato Fruit Banana Fruit Banana notes trip 'Grape' 'Pear' ⍝ via 1-way Grape Grape Fruit Tomato Fruit Tomato Tomato Fruit Pear Fruit Pear notes trip 'Apple' 'Onion' ⍝ line change Apple Apple Fruit Tomato Fruit Tomato Tomato Veggie Onion Veggie Onion notes trip 'Cabbage' 'Spinach' ⍝ via cross Cabbage Cabbage Veggie Onion Veggie Onion Onion Veggie Spinach Veggie Spinach notes trip 'S' 'C' 'G' 'A' 'B' ⍝ grand tour Spinach Spinach Veggie Onion Veggie Onion Onion Veggie Cabbage Veggie Cabbage Cabbage Veggie Onion Veggie Lettuce Veggie Tomato Veggie Tomato Tomato Fruit Pear Fruit Grape Fruit Grape Grape Fruit Tomato Fruit Apple Fruit Apple Apple Fruit Tomato Fruit Tomato Tomato Fruit Banana Fruit Banana -------------------------------------------------------------------------------- /sources/petersburg.txt: -------------------------------------------------------------------------------- 1 | ////////////////////////// // St. Petersburg Metro // ////////////////////////// Line 1 Deviatkino Grazhdanskiy Prospekt Akademicheskaya Politekhnicheskaya Ploschad Muzhestva Lesnaya Vyborgskaya Ploschad Lenina Chernychevskaya Ploschad Vosstaniya Vladimirskaya Pushkinskaya Tekhnologicheskiy Institut Baltiyskaya Narvskaya Kirovkiy Zavod Avtovo Leninskiy Prospekt Prospekt Veteranov Line 2 Prospekt Prosvescheniya Ozerki Udelnaya Pionerskaya Chernaya Rechka Petrogradskaya Gorkovskaya Nevskiy prospekt Sennaya ploschad Tekhnologicheskiy Institut Frunzenskaya Moskovskiye Vorota Elektrosila Park Pobedy Moskovskaya Zvezdnaya Kupchino Line 3 Primorskaya Vasileostrovskaya Gostiniy Dvor Mayakovskaya Ploschad Aleksandra Nevskogo Elizarovskaya Lomonosovskaya Proletarskaya Obukhovo Rybatskoe Line 4 Chkalovskaya Sportivnaya Sadovaya Dostoevskaya Ligovskiy Prospekt Ploschad Aleksandra Nevskogo Novocherkasskaya Ladozhskaya Prospekt Bolshevikov Ulytsa Dybenko Walk // Lines 1←→3 Ploschad Vosstaniya Mayakovskaya Walk // Lines 2←→3 Nevskiy prospekt Gostiniy Dvor Walk // Lines 1←→4 Vladimirskaya Dostoevskaya Walk // Lines 2←→4 Sadovaya Sennaya ploschad 2 | -------------------------------------------------------------------------------- /code/trip.dyalog: -------------------------------------------------------------------------------- 1 | trip←{⎕IO ⎕ML←1 0 ⍝ Trip from/to ⍵ in network space ⍺. 2 | 3 | 0=⍺.⎕NC'graph':⍺{ ⍝ source not compiled for this space. 4 | ⎕←'compiling graph ...' ⍝ explain slight delay. 5 | (compile ⍺)trip ⍵ ⍝ try again with compiled graph. 6 | }⍵ 7 | 8 | access←⍺.((1=≡¨labels)/labels) ⍝ access via station entrances. 9 | 10 | legs←{ ⍝ start and end station indices. 11 | hits←∨/⍵⍷↑access ⍝ stations containing supplied string. 12 | best←1+⊃⍋↑⍴¨hits/access ⍝ best (tightest) fit. 13 | best⊃0,hits/⍳⍴hits ⍝ index of chosen station. 14 | }¨⍵ ⍝ for each leg of the journey. 15 | 16 | 0∊legs:'Can''t find: ',↑{ ⍝ misspelled station name: 17 | ⍺,' or ',⍵ ⍝ (one or more stations) 18 | }/(0=legs)/⍵ ⍝ give up :-( 19 | 20 | find←⍺.graph{⍺⍺ path ⍺ ⍵} ⍝ find one leg of the route. 21 | route←↑{⍺,1↓⍵}/2 find/legs ⍝ suggested route via all points. 22 | 23 | labels←⍺.labels[route] ⍝ labels for all legs of route. 24 | 25 | masks←1 2=⊂≡¨labels ⍝ masks of stations and stops. 26 | stats stops←masks/¨⊂labels ⍝ station and stop labels. 27 | 28 | zip←{↓⍉↑⍵} ⍝ transpose vector-of-vectors. 29 | cat←{↑,/⍵} ⍝ concatenate .. .. 30 | pad←{↓↑⍵} ⍝ pad vectors with blanks. 31 | 32 | slabs←cat¨zip pad¨zip stops ⍝ aligned stop labels. 33 | ↑(stats,slabs)[⍋⍋2⊃masks] ⍝ merged stations and stops. 34 | } 35 | -------------------------------------------------------------------------------- /notes/source.txt: -------------------------------------------------------------------------------- 1 | /////////////////// Sample Network /////////////////// // // // A B Fruit Line: A, B, T, G, P // // │ │ // // └─┬─┘ one-way: T→P→G→T // // │ // // ┌───T───┐ forks: A B ┌T┐ // // │ │ │ └T┘ G P // // │ ┌─┴─┐ │ // // │ ↑ ↓ │ Veggie Line: T, L, O, C, S // // │ │ │ │ // // │ G─←─P │ cross: O // // │ │ // // L───────O─────C // // │ // // │ // // S // // // /////////////////// Sample Trips ///////////////////// // // // notes trip 'Apple' 'Pear' ⍝ simple trip // // notes trip 'Apple' 'Banana' ⍝ via fork // // notes trip 'Grape' 'Pear' ⍝ via 1-way // // notes trip 'Apple' 'Onion' ⍝ line change // // notes trip 'Cabbage' 'Spinach' ⍝ via cross // // notes trip 'Tomato' 'Cabbage' ⍝ avoid cross // // notes trip 'S' 'C' 'G' 'A' 'B' ⍝ grand tour // // // ////////////////////////////////////////////////////// Fruit Apple ∊ Tomato // fork Banana Fruit ↓ Grape // one-way section ∊↓ Tomato // with fork ↓ Pear Grape Veggie Spinach + Onion // cross Tomato Lettuce + Onion // cross Cabbage 2 | -------------------------------------------------------------------------------- /sources/barcelona.txt: -------------------------------------------------------------------------------- 1 | //////////////////////// // Metro de Barcelona // //////////////////////// L1 Red Feixa Llarga Bellvitge Av Carrilet Rble Just Oliveras Can Serra Florida Torrassa Sant Eulalia Mercat Nou Placa de Sants Hostafrancs Espanya Rocafort Urgell Universitat Catalunya Urquinaona Arc de Triomf Marina Glories Clot Navas Sagrera Fabra i Puig Sant Andreu Torras i Bages Trinitat Vella Baro de Viver Santa Coloma Fondo L2 Purple Paral-lel Sant Antoni Universitat Passeig de Gracia Tetuan Monumental Sagrada Familia Encants Clot Bac de Roda St. Marti La Pau Verneda Artigues Sant Adria Sant Roc Gorg Pep Ventura L3 Green Zona Universitaria Palau Reial Maria Cristina Les Corts Placa del Centre Sants Estacio Tarragona Espanya Poble Sec Paral-lel Drassannes Liceu Catalunya Passeig de Gracia Diagonal Fontana Lesseps Vallcarca Penitents Vall d' Hebron Mondbau Mundet Valldaura Canyelles L4 Yellow Trinitat Nova Via Julia Llucmajor Maragall Guinardo Alfons X Joanic Verdaguer Girona Passeig de Gracia Urquinaona Jaume I Barceloneta Ciutadella Vila Olimpica Bogatell Llacuna Poblenou Selva de Mar Besos Mar Besos La Pau L5 Mid Blue Cornella Gavarra Sant lldefons Can Boixeres Can Vidalet Pubilla Casses Collblanc Badal Placa de Sants Sants Estacio Entenca Hospital Clinic Diagonal Verdaguer Sagrada Familia Hospital de Sant Pau Camp de l' Arpa Sagrera Congres Maragall Virrei Amat Vilapicina Horta L6 Dark Blue Catalunya Provença Gràcia Sant Gervasi Muntaner La Bonanova Les Tres Torres Sarrià Reina Elisenda L7 Brown Catalunya Provença Gràcia Plaça Molina Pàdua El Putxet Avinguda Tibidabo L8 Magenta Espanya Magoria-La Campana Ildefons Cerdà Gornal Sant Josep Av Carrilet Almeda Cornellà-Riera Sant Boi Moli Nou-Ciutat Cooperativa L11 Lime Trinitat Nova Casa de l'Aigua Torre Baró / Vallbona Ciutat Meridiana Can Cuiàs Transfer Gràcia Diagonal 2 | -------------------------------------------------------------------------------- /code/compile.dyalog: -------------------------------------------------------------------------------- 1 | compile←{⎕IO ⎕ML←1 0 ⍝ Compile graph from ⍵.source. 2 | 3 | zip←{↓⍉↑⍵} ⋄ cat←{↑,/⍵} ⍝ transpose/concatenate vec-of-vecs. 4 | 5 | lines stats ctrls←zip zip¨{ ⍝ first pass: source → line sections. 6 | vecs←{↓⎕FMT↑⍵} ⍝ normalise source to vector-of-vectors. 7 | rcom←{(∧\~'//'⍷⍵)/⍵} ⍝ remove comments '// ···' from line. 8 | rbls←{(∨/¨' '≠⍵)/⍵} ⍝ remove blanks lines: '' '' ··· 9 | segt←{(' '≠⊃¨⍵)⊂⍵} ⍝ segment at non-blank first column. 10 | trim←{(∨\⍵≠' ')/⍵}{⌽⍺⍺⌽⍺⍺ ⍵} ⍝ remove blanks, fore and aft. 11 | tupl←'+↓∊'{⍺(trim ⍵~⍺⍺)(⍺⍺∩⍵)} ⍝ tupl: (line stat ctrl). 12 | tups←{(⊂trim⊃⍵)tupl¨1↓⍵} ⍝ tuples: tupl tupl ···. 13 | tups¨segt rbls rcom¨vecs ⍵ ⍝ line segments. 14 | }⍵.source 15 | 16 | seqs←{(⍳¨⍵)+0,+\¯1↓⍵} ⍝ sequence of sequences. 17 | csids←{⍵\¨seqs+/¨⍵}'+'∊¨¨ctrls ⍝ stations marked as cross-tracks. 18 | stops←zip¨zip lines stats csids ⍝ subway stops. 19 | plats←{↓⍵∘.,'^∨'}¨stops ⍝ platform for each direction. 20 | slist←{⍵[⍋↑⍵]}∪cat stats ⍝ sorted station list. 21 | verts←slist,∪cat cat plats ⍝ graph vertices. 22 | platx←{↓verts⍳↑⍵}¨plats ⍝ platform indices within graph. 23 | statx←{2/¨verts⍳⍵}¨stats ⍝ station indices within graph. 24 | linex←{(∪⍵)⍳⍵}⊃¨lines ⍝ line indices per segment. 25 | rests←'↓∊'∘∊¨¨ctrls ⍝ restrictions: 1-way sects and forks. 26 | 27 | plinks←cat¨2{ ⍝ platform-to-platform links / section. 28 | links((ow fk)_)←zip ⍺ ⍵ ⍝ directions and restrictions. 29 | rev←{⌽⍵}\ ⍝ reverse second pair. 30 | oway←{⍺:1↑⍵ ⋄ rev ⍵} ⍝ one-way section. 31 | fork←{⍺:⌽zip rev ⍵ ⋄ zip ⍵} ⍝ fork. 32 | ow oway fk fork links ⍝ ⍺←→⍵ links. 33 | }/¨zip¨zip platx rests ⍝ pairwise for each line section. 34 | 35 | clinks←((∪linex)=⊂linex)/¨⊂plinks ⍝ link sections collected by line. 36 | 37 | llinks←cat↑{ ⍝ connected sections for all lines. 38 | next←⍺~⍵ ⍝ next section, duplicates removed. 39 | clash←↑∪zip∩⌿↑zip¨next ⍵ ⍝ incompatible directions. 40 | diffs←⍉¯1 1∘.×-/clash ⍝ vertex index differences. 41 | avecs←↑+/,diffs×clash=⊂next ⍝ adjustment vectors. 42 | (next+avecs),⍵ ⍝ connected line subsections. 43 | }/¨clinks ⍝ for each section of each line. 44 | 45 | slinks←cat zip¨zip cat¨statx platx ⍝ (stat plat) ··· links. 46 | elinks←0 1∘.⌽slinks ⍝ station-platform each-way links. 47 | nlinks←{⍵[⍋↑⍵]}∪(,elinks),llinks ⍝ combined network-wide links. 48 | ⍵.graph←↑{(⍺≠¯1⌽⍺)⊂⍵}/zip nlinks ⍝ network graph. 49 | 50 | stags←2/⌽¨2↑¨∪cat stops ⍝ (stop line) label pairs. 51 | slabs←cat¨zip¨zip(⊂4 1↑¨⊂'')stags ⍝ indented stop labels. 52 | ⍵.labels←slist,slabs ⍝ station/stop labels. 53 | 54 | 1:shy←⍵ ⍝ shy result: namespace ref. 55 | } 56 | -------------------------------------------------------------------------------- /notes/test.dyalog: -------------------------------------------------------------------------------- 1 | test←{ ⍝ Run test script: no news => good news. 2 | ⍺←0 ⍝ default: don't show progress. 3 | ⍵≡'':⍺ ∇ ⎕NL 2 ⍝ null: test all scripts. 4 | 2=⍴⍴⍵:⍺ ∇↓⍵ ⍝ matrix: each row is a script. 5 | 2=≡⍵:⍺ ∇¨⍵ ⍝ nested: test each script. 6 | 7 | tag scr←{ ⍝ name and content of script. 8 | ⎕PATH←'' ⍝ isolate test. 9 | 6::{'' ''}⎕←'No test.',⍵ ⍝ value error:: display message. 10 | ⍵(⍎⍵) ⍝ name and content. 11 | }⍵ 12 | 13 | exec←{⎕ML←0 ⍝ execute script lines in tmp space. 14 | 0=⍴⍵:⍺ ⍝ no more, finished. 15 | ⎕←show⊃⍵ ⍝ show expression. 16 | exp←unc⊃⍵ ⍝ uncommented first line. 17 | ''≡exp~' ':⍺ ∇ 1↓⍵ ⍝ ignore blank line. 18 | 1∊'←{'⍷unq exp:⍺ ∇ dfn ⍵ ⍝ make local dfn. 19 | '←'∊unq exp:⍺ ∇ asgn ⍵ ⍝ make local var. 20 | act←tmp{6::0 0⍴'' ⋄ ⍺⍎⍵}exp ⍝ actual result. 21 | ⎕←show act ⍝ show result. 22 | ok rem←act check 1↓⍵ ⍝ check against expected result. 23 | (⍺∧ok)∇ rem ⍝ check remaining script. 24 | } 25 | 26 | check←{⎕ML←0 27 | act←↓tmp.⎕FMT ⍺ ⍝ actual result, 28 | exp←(⍴act)↑⍵ ⍝ expected result, 29 | act≡exp:1,⊂(⍴act)↓⍵ ⍝ match: continue. 30 | dexp dact←dots¨exp act ⍝ dots for spaces in, 31 | ⎕←tag,⊂dexp'→'dact ⍝ display of differences. 32 | 0,⊂(⍴act)↓⍵ ⍝ and continue. 33 | } 34 | 35 | dfn←{ ⍝ fix temp dfn. 36 | raw←unq∘unc¨⍵ ⍝ raw code 37 | depth←+\{⊃⌽-⌿+\'{}'∘.=⍵}¨raw ⍝ {}-nesting depth per line. 38 | lines←1++/∧\×depth ⍝ no of lines in defn. 39 | _←tmp.⎕FX↑lines↑⍵ ⍝ fix dfn in temp space. 40 | ⎕←show↑1↓lines↑⍵ ⍝ show dfn body. 41 | lines↓⍵ ⍝ continue with remaining lines. 42 | } 43 | 44 | nest←{⎕ML←0 ⍝ split line vector, 45 | nl←⊃2↓⎕TC ⍝ at nl char into, 46 | 1↓¨(1,⍵=nl)⊂nl,⍵ ⍝ vector of char vecs. 47 | } 48 | 49 | dots←{⎕IO←0 ⍝ replace ' ' with '·' in diff display. 50 | sx←⎕AV⍳' ' ⍝ index of space. 51 | to←(sx↑⎕AV),'·',1↓sx↓⎕AV ⍝ [·/ ]⎕av 52 | ↑{(⎕AV⍳⍵)⊃¨⊂to}¨⍵ ⍝ translated value. 53 | } 54 | 55 | asgn←{_←tmp⍎⊃⍵ ⋄ 1↓⍵} ⍝ assign local name. 56 | unq←{(~≠\''''=⍵){⍺\⍺/⍵}⍵} ⍝ unquoted chars. 57 | unc←{(∧\'⍝'≠unq ⍵)/⍵} ⍝ uncommented line. 58 | show←⍺∘{↑⍺/↓⎕FMT ⍵} ⍝ show progress. 59 | 60 | tmp←##.(⎕NS ⎕NL 3 4 9) ⍝ tmp space for evaluation. 61 | ''≡scr:ok←0 ⍝ bad script name. 62 | 2=≡⍵:ok←1 exec scr ⍝ vector of vectors: go ahead, 63 | 1:ok←1 exec nest scr ⍝ split line vector. 64 | } 65 | -------------------------------------------------------------------------------- /sources/milano.txt: -------------------------------------------------------------------------------- 1 | //////////////////////// // Milano Underground // //////////////////////// Metro 1 Sesto 1o Maggio FS Sesto Rondo´ Sesto Marelli Villa S.G. Precotto Gorla Turro Rovereto Pasteur Loreto Lima P.ta Venezia Palestro S.Babila Duomo Cordusio Cairoli Cadorna FNM Conciliazione Pagano Metro 1 Bisceglie Inganni Primaticcio Bande Nere Gambara De Angeli Wagner ∊Pagano Buonarroti Amendola Fiera Lotto Fiera 2 QT8 Lampugnano Uruguay Bonola S.Leonardo Molino Dorino Metro 2 Gessate Cascina Antonietta Gorgonzola Villa Pompea Bussero Cassina de´ Pecchi Villa Fiorita Cernusco sul Naviglio Cascina Burrona Vimodrone ∊Cascina Gobba Cologno Sud Cologno Centro Cologno Nord Metro 2 Cascina Gobba Crescenzago Cimiano Udine Lambrate FS Piola Loreto Caiazzo Centrale FS P.ta Garibaldi FS Moscova Lanza Brera Cadorna FNM S.Ambrogio S.Agostino P.ta Genova FS Romolo Famagosta Metro 3 Maciachini Zara Sondrio Centrale FS Repubblica Turati Montenapoleone Duomo Missori Crocetta P.ta Romana FS Lodi TIBB Brenta Corvetto Porto di Mare Rogoredo FS S.Donato Metro San Raffaele Cascina Gobba Osp.S.Raffaele S1 Passante Ferroviario P.ta Vittoria Dateo P.ta Venezia Repubblica P.ta Garibaldi Passante Lancetti-Ghisolfa Bovisa-Politecnico Quarto Oggiaro Novate Milanese Bollate Centro Bollate Nord Serenella Garbagnate Milanese Cesate Caronno Pertusella Saronno Sud Saronno S2 Passante Ferroviario P.ta Vittoria Dateo P.ta Venezia Repubblica P.ta Garibaldi Passante Lancetti-Ghisolfa Bovisa-Politecnico Affori Bruzzano Cormano-Brusuglio Cusano Milanino Paderno Dugnano Palazzolo M. Varedo Bovisio M.-Mombello Cesano M. Seveso Meda Cabiate Mariano C. Station walk Cadorna Cadorna FNM S3 Passante Ferroviario Cadorna Domodossola Bovisa-Politecnico Quarto Oggiaro Novate Milanese Bollate Centro Bollate Nord Serenella Garbagnate Milanese Cesate Caronno Pertusella Saronno Sud Saronno S4 Passante Ferroviario Cadorna Domodossola Bovisa-Politecnico Affori Bruzzano Cormano-Brusuglio Cusano Milanino Paderno Dugnano Palazzolo M. Varedo Bovisio M.-Mombello Cesano M. Seveso Station walk P.ta Garibaldi Passante P.ta Garibaldi FS S5 Passante Ferroviario Pioltello-Limito Segrate P.ta Vittoria Dateo P.ta Venezia Repubblica P.ta Garibaldi Passante Lancetti-Ghisolfa Villapizzone Certosa Rho Vanzano-Pogliano Parabiago Canegrate Legnano Busto Arsizio FS Gallarate Cavaria-Oggiona-Jerago Albizzate Castronno Gazzada-Schianno Varese FS S6 Passante Ferroviario P.ta Vittoria Dateo P.ta Venezia Repubblica P.ta Garibaldi Passante Lancetti-Ghisolfa Villapizzone Certosa Rho Vittuone-Arluno Corbetta-S.Stefano T. Magenta Trecate Novara FS Station walk Sesto S.Giovanni Sesto 1o Maggio FS Station walk Lambrate Lambrate FS Station walk P.ta Romana P.ta Romana FS S9 Passante Ferroviario S.Cristoforo P.ta Romana Lambrate Greco-Bicocca Sesto S.Giovanni Monza Lissone Desio Seregno Malpensa Express Cadorna Bovisa-Politecnico Saronno Malpensa Aeroporto Street walk Corso Europa S.Babila ATM Bus 73 Corso Europa Linate Aeroporto Station walk P.ta Genova FS P.ta Genova FS Milano-Alessandria P.ta Genova S.Cristoforo // low frequency! // //AIR Pulmann // Malpensa Aeroporto // Cormano // Cascina Gobba // Linate Aeroporto 2 | -------------------------------------------------------------------------------- /code/replaces.dyalog: -------------------------------------------------------------------------------- 1 | replaces←{ ⍝ For use with Pocket APL. 2 | ⍝ replace DAN component. 3 | fullname←{ ⍝ full file name. 4 | GetModuleFileNameW←{} ⍝ local function. 5 | 102::⍵ ⍝ running on PC? 6 | _←⎕NA'coredll|GetModuleFileNameW U >0T2 U' ⍝ associate name. 7 | exename←GetModuleFileNameW 0 255 255 ⍝ executable name. 8 | rtdir←{(⌽∨\⌽'\'=⍵)/⍵}exename ⍝ runtime directory. 9 | dvdir←'\My Documents\Pocket APL\' ⍝ development directory. 10 | isdevt←1∊'dyalog.exe'⍷lcase exename ⍝ development version? 11 | (⊃isdevt⌽rtdir dvdir),⍵ ⍝ full name. 12 | } 13 | 14 | lcase←{ ⍝ Lower-casification, 15 | lc←'abcdefghijklmnopqrstuvwxyz' ⍝ (lower case alphabet) 16 | uc←'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ⍝ (upper case alphabet) 17 | (lc,⎕AV)[(uc,⎕AV)⍳⍵] ⍝ ... of simple array. 18 | } 19 | 20 | tie←(fullname'dan.dcf')⎕FTIE 0 ⍝ open DAN component file. 21 | error←{⍵ ⎕SIGNAL ⍺⊣⎕FUNTIE tie} ⍝ error: untie and signal. 22 | elarg←'Left arg must be city namespace' ⍝ bad left arg. 23 | ecity←'Can''t find "',(⍕,⍵),'"' ⍝ mis-spelled city? 24 | get←{⎕FREAD tie ⍵} ⍝ get component from file. 25 | put←{⍵ ⎕FREPLACE tie ⍺} ⍝ replace component on file. 26 | rel←⎕FUNTIE∘⎕FRESIZE ⍝ release file. 27 | city cvec←get 1 ⍝ city status vector. 28 | names←⊃¨cvec ⍝ city names. 29 | 30 | 0=⎕NC'⍺':names{ ⍝ remove city. 31 | ~(⊂⍵)∊names:6 error ecity ⍝ abort if bad city name. 32 | cno←⍺⍳⊂⍵ ⍝ city number. 33 | cc←city⌊¯1+⍴cvec ⍝ new current city. 34 | _←1 put cc,⊂(cno≠⍳⍴cvec)/cvec ⍝ put updated state vector. 35 | pairs←{(⊂1 1),2,/(⍺≤⍵)/⍵} ⍝ component pairs. 36 | _←put∘get/¨cno pairs⍳⍴cvec ⍝ shuffle removed comp to end. 37 | rel tie⊣⎕FDROP tie ¯1 ⍝ drop comp and release file. 38 | }⍵ 39 | 40 | 9≠⎕NC'⍺':11 error elarg ⍝ not space: abort. 41 | ecomp←'compile ',⍕⍺ ⍝ must compile. 42 | 0=⍺.⎕NC'graph':11 error ecomp ⍝ no graph: must compile. 43 | graph←{{↑,/⍵}¨((⍴¨⍵)↑¨1)⍵}⍺.graph ⍝ stripped graph. 44 | stats←{(1=≡¨⍵)/⍵}⍺.labels ⍝ nested station list. 45 | stops←⊖⍉↑{0 1 0 1∘/¨(2=≡¨⍵)/⍵}⍺.labels ⍝ line-station names. 46 | lines←∪⊃↓stops ⍝ unique line names. 47 | labels←{↑,/(⊃⌽⎕TC),¨⍵}¨lines stats ⍝ nl-prefaced names. 48 | stopx←↑lines stats⍳¨↓stops ⍝ line-station indices. 49 | comp←labels stopx graph ⍝ file component. 50 | indx←⍵(5 2)⍬(1 1)({10}¨lines) ⍝ first component index. 51 | (⊂⍵)∊names:{ ⍝ replace existing component. 52 | _←(⍵+1)put comp ⍝ replace graph component. 53 | (⍵⊃cvec)←indx ⍝ update city index. 54 | _←1 put city cvec ⍝ replace index component. 55 | rel tie ⍝ release file. 56 | }names⍳⊂⍵ ⍝ city index. 57 | _←comp ⎕FAPPEND tie ⍝ append new city component. 58 | _←1 put city,⊂cvec,⊂indx ⍝ put cities index. 59 | rel tie ⍝ relesae file. 60 | } 61 | -------------------------------------------------------------------------------- /sources/madrid.txt: -------------------------------------------------------------------------------- 1 | ///////////////////// // Metro de Madrid // ///////////////////// Línea 1 Plaza de Castilla Valdeacederas Tetuán Estrecho Alvarado Cuatro Caminos Ríos Rosas Iglesia Bilbao Tribunal Gran Vía Sol Tirso de Molina Antón Martín Atocha Atocha Renfe Menéndez Pelayo Pacífico Puente de Vallecas Nueva Numancia Portazgo Buenos Aires Alto del Arenal Miguel Hernández Sierra de Guadalupe Villa de Vallecas Congosto Línea 2 Ventas Manuel Becerra Goya Príncipe de Vergara Retiro Banco de España Sevilla Sol Opera Santo Domingo Noviciado San Bernardo Quevedo Canal Cuatro Caminos Línea 3 Legazpi Delicias Palos de la Frontera Embajadores Lavapies Sol Callao Plaza de España Ventura Rodríguez Argüelles Moncloa Línea 4 Santa María San Lorenzo Mar de Cristal Canillas Esperanza Arturo Soria Avenida de la Paz Alfonso XIII Prosperidad Avenida de América (E) Diego de León (4) Lista Goya Velázquez Serrano Colón Alonso Martínez Bilbao San Bernardo Argüelles Línea 5 Canillejas Torres Arias Suanzes Ciudad Líneal Pueblo Nuevo Quintana El Carmen Ventas Diego de León (5,6) Núñez de Balboa (5) Rubén Darío Alonso Martínez Chueca Gran Vía Callao Opera La Latina Puerta de Toledo Acacias Pirámides Marqués de Vadillo Urgel Oporto Vista Alegre Carabanchel Eugenia de Montijo Aluche Empalme Campamento Casa de Campo Línea 6 Laguna Carpetana Oporto Opañel Plaza Elíptica Usera Legazpi Méndez Álvaro Pacífico Conde de Casal Sainz de Baranda O'Donnell Manuel Becerra Diego de León (5,6) Avenida de América (O) República Argentina Nuevos Ministerios Cuatro Caminos Guzmán el Bueno Metropolitano Ciudad Universitaria Moncloa Argüelles Príncipe Pío Puerta del Ángel Alto de Extremadura Lucero Laguna Línea 7 Las Musas San Blas Simancas García Noblejas Ascao Pueblo Nuevo Barrio de la Concepción Parque de las Avenidas Cartagena Avenida de América (E) Avenida de América (O) Gregorio Marañón Alonso Cano Canal Islas Filipinas Guzmán el Bueno Francos Rodríguez Valdezarza Antonio Machado Peñagrande Avenida de la Ilustración Lacoma Pitis Línea 7 Cartagena Avenida de América Gregorio Marañón Línea 8 Mar de Cristal Campo de las Naciones Aeropuerto Barajas Línea 9 Herrera Oria Barrio del Pilar Ventilla Plaza de Castilla Duque de Pastrana Pío XII Colombia Concha Espina Cruz del Rayo Avenida de América (O) Núñez de Balboa (9) Príncipe de Vergara Ibiza Sainz de Baranda Estrella Artilleros Vinateros Pavones Valdebernardo Vicálvaro San Cipriano Puerta de Arganda Rivas Urbanizaciones Rivas Vaciamadrid La Poveda Arganda del Rey Línea 10 Fuencarral Begoña Chamartín Plaza de Castilla Cuzco Santiago Bernabeu Nuevos Ministerios Gregorio Marañón Alonso Martínez Tribunal Plaza de España Príncipe Pío Lago Batán Casa de Campo Colonia Jardin Carabanchel Cuatro Vientos Joaquin Vilumbrales Puerta del Sur Línea 11 Plaza Elíptica Abrantes Pan Bendito Línea 12 Puerta del Sur San Nicasio Leganés Central Hospital Severo Ochoa Casa del Reloj Julián Besteiro El Carrascal El Bercial Los Espartales El Casar Juan de la Cierva Getafe Central Alonso de Mendoza Conservatorio Arroyo Culebro Parque de los Estados Fuenlabrada Central Parque Europa Hospital de Fuenlabrada Loranca Manuela Malasaña Hospital de Móstoles Pradillo Móstoles Central Universidad Rey Juan Carlos Parque Oeste Alcorcón Central Parque Lisboa Puerta del Sur Línea R.O.PP Opera Príncipe Pío Subway Avenida de América (E) Avenida de América (O) Subway Diego de León (4) Diego de León (5,6) Subway Plaza de España Noviciado Subway Acacias Embajadores Subway Núñez de Balboa (5) Núñez de Balboa (9) 2 | -------------------------------------------------------------------------------- /notes/trip.txt: -------------------------------------------------------------------------------- 1 | route ← subway #.trip (fm via ··· to) ⍝ Trip from/to ⍵ in network space ⍺. [subway] is a namespace containing character array: [source], a definition of the subway network. Character vectors [fm], [via] ··· [to] are the start and end points of the various "legs" of the trip. Resulting character matrix [route], shows a shortest route between [fm] and [to]. There may be other equally short routes but the graph searching code guarantees that none is shorter. [trip] examines its [subway] namespace left argument for the presence of [subway.graph] and compiles one from [subway.source], if it is missing. Technical details: [trip] uses auxiliary functions [zip] and [cat]. See: →zip_cat← for details. [trip] checks that the namespace supplied as left argument contains a compiled [graph] array. If not, it calls the compiler to build one and tries again. 0=⍺.⎕NC'graph':⍺{ ⍝ source not compiled for this space. ⎕←'compiling graph ...' ⍝ explain slight delay. (compile ⍺)trip ⍵ ⍝ try again with compiled graph. }⍵ Notice that, as the helpful message 'compiling graph ...' is on a line, separate from the recursive call to [trip], the body of the guard is enclosed in braces. This means that the recursive reference to function trip must either be explicit as above, or an implicit reference (∇) must be passed as operand to an operator, as below: 0=⍺.⎕NC'graph':⍺ ∇{ ⍝ source not compiled for this space. ⎕←'compiling graph ...' ⍝ explain slight delay. (compile ⍺)⍺⍺ ⍵ ⍝ try again with compiled graph. }⍵ Access to the subway network is via station entrances. Station labels are dist- inguished in the ⍺.labels vector, having a depth of 1. access←⍺.((1=≡¨labels)/labels) ⍝ access via station entrances. A simple-minded text-matching function locates given names within the access vector. legs←{ ⍝ start and end station indices. hits←∨/⍵⍷↑access ⍝ stations containing supplied string. best←1+⊃⍋↑⍴¨hits/access ⍝ best (tightest) fit. best⊃0,hits/⍳⍴hits ⍝ index of chosen station. }¨⍵ ⍝ for each leg of the journey. The function will match 'Islington' with 'Highbury & Islington' and 'Burrona' with 'Cascina Burrona'. It returns the index of the matching station with the shortest name, so that it is always possible to add more characters to disting- uish, for example: 'Ruislip Manor' from 'Ruislip'. If any of the names can't be found, [trip] retires with a helpful error message. 0∊legs:'Can''t find: ',↑{ ⍝ misspelled station name: ⍺,' or ',⍵ ⍝ (one or more stations) }/(0=legs)/⍵ ⍝ give up :-( Otherwise, the graph is searched for the shortest path for each leg of the trip. find←⍺.graph{⍺⍺ path ⍺ ⍵} ⍝ find one leg of the route. route←↑{⍺,1↓⍵}/2 find/legs ⍝ suggested route via all points. Notice the pairwise reduction (2 find/legs). A trip from A to D via B and C, would involve finding trips: A→B, B→C, C→D. The final route avoids duplication of stops on intermediate legs of the journey: ↑{⍺,1↓⍵}/. (It happens that the Paris Metro boasts stations containing all of the uppercase letters. For a truly epic journey, try (paris trip ⎕A). London does nearly as well with: (london trip ¯3↓⎕a)). Station and stop labels for the trip are extracted from the labels vector. labels←⍺.labels[route] ⍝ labels for all legs of route. Station labels have depth-1 and stop labels, which contain station, line and tabbing information, have depth 2. disp labels ┌→───┬───────────────────┬────────────────────┬─────────────────────┬──────┬──────────────────────┬─────────────────────┬─────┐ │ │┌→───┬────┬─┬─────┐│┌→───┬─────┬─┬─────┐│┌→───┬──────┬─┬─────┐│ │┌→───┬──────┬─┬──────┐│┌→───┬─────┬─┬──────┐│ │ │Pear││ │Pear│ │Fruit│││ │Grape│ │Fruit│││ │Tomato│ │Fruit││Tomato││ │Tomato│ │Veggie│││ │Onion│ │Veggie││Onion│ │ │└───→┴───→┴→┴────→┘│└───→┴────→┴→┴────→┘│└───→┴─────→┴→┴────→┘│ │└───→┴─────→┴→┴─────→┘│└───→┴────→┴→┴─────→┘│ │ └───→┴──────────────────→┴───────────────────→┴────────────────────→┴─────→┴─────────────────────→┴────────────────────→┴────→┘ The remainder of the code is concerned only with aligning fields in the final result, where alighting stations are exdented and intermediate stops, indented with columns aligned. Pear Pear Fruit Grape Fruit Tomato Fruit Tomato Tomato Veggie Onion Veggie Onion Station and stop labels are distinguished by their depth: masks←1 2=⊂≡¨labels ⍝ masks of stations and stops. stats stops←masks/¨⊂labels ⍝ station and stop labels. disp stats ┌→───┬──────┬─────┐ │Pear│Tomato│Onion│ └───→┴─────→┴────→┘ disp stops ┌→──────────────────┬────────────────────┬─────────────────────┬──────────────────────┬─────────────────────┐ │┌→───┬────┬─┬─────┐│┌→───┬─────┬─┬─────┐│┌→───┬──────┬─┬─────┐│┌→───┬──────┬─┬──────┐│┌→───┬─────┬─┬──────┐│ ││ │Pear│ │Fruit│││ │Grape│ │Fruit│││ │Tomato│ │Fruit│││ │Tomato│ │Veggie│││ │Onion│ │Veggie││ │└───→┴───→┴→┴────→┘│└───→┴────→┴→┴────→┘│└───→┴─────→┴→┴────→┘│└───→┴─────→┴→┴─────→┘│└───→┴────→┴→┴─────→┘│ └──────────────────→┴───────────────────→┴────────────────────→┴─────────────────────→┴────────────────────→┘ Local [zip] and [cat] functions are defined: See →zip_cat← zip←{↓⍉↑⍵} ⍝ transpose vector-of-vectors. cat←{↑,/⍵} ⍝ concatenate .. .. [pad] stretches each item in a vector-of-vectors to the same length. pad←{↓↑⍵} ⍝ pad vectors with blanks. Stop labels are aligned by stretching the station names: slabs←cat¨zip pad¨zip stops ⍝ aligned stop labels. disp slabs ┌→───────────────────┬────────────────────┬────────────────────┬─────────────────┬─────────────────┐ │ Pear Fruit │ Grape Fruit │ Tomato Fruit │ Tomato Veggie│ Onion Veggie│ └───────────────────→┴───────────────────→┴───────────────────→┴────────────────→┴────────────────→┘ Finally, the station and aligned stop labels are re-merged and mixed to return a character matrix result. ↑(stats,slabs)[⍋⍋2⊃masks] ⍝ merged stations and stops. Examples: notes trip 'Pear' 'Onion' ⍝ simple trip. compiling graph ... Pear Pear Fruit Grape Fruit Tomato Fruit Tomato Tomato Veggie Onion Veggie Onion notes trip'Apple' 'Banana' 'Cabbage' ⍝ multi-leg trip. Apple Apple Fruit Tomato Fruit Tomato Tomato Fruit Banana Fruit Banana Banana Fruit Tomato Fruit Tomato Tomato Veggie Lettuce Veggie Onion Veggie Cabbage Veggie Cabbage See also: →compile← →path← →ed← →zip_cat← 2 | -------------------------------------------------------------------------------- /notes/zip_cat.txt: -------------------------------------------------------------------------------- 1 | ---------- zip←{↓⍉↑⍵} ⎕ml<2 ---------- Suggested by Peter Donnelly, [zip] takes an N-vector of M-vectors and returns the transpose: M-vector of N-vectors. It is named after a functional programming idiom, which returns a list-of-pairs from a pair-of-lists. zip'ABCDEFGHIJKLM' 'abcdefghijklm' ⍝ zip vectors. Aa Bb Cc Dd Ee Ff Gg Hh Ii Jj Kk Ll Mm disp pairs ┌→───────────────────┬─────────────────────────┬───────────────────────┐ │┌→────────┬────────┐│┌→──────────┬───────────┐│┌→──────────┬─────────┐│ ││┌→──┬───┐│┌→──┬──┐│││┌→────┬───┐│┌→───┬────┐│││┌→───┬────┐│┌→──┬───┐││ │││one│unu│││two│du│││││three│tri│││four│kvar│││││five│kvin│││six│ses│││ ││└──→┴──→┘│└──→┴─→┘│││└────→┴──→┘│└───→┴───→┘│││└───→┴───→┘│└──→┴──→┘││ │└────────→┴───────→┘│└──────────→┴──────────→┘│└──────────→┴────────→┘│ └───────────────────→┴────────────────────────→┴──────────────────────→┘ disp zip pairs ┌→──────────────────────────────────┬────────────────────────────────┐ │┌→────────┬───────────┬───────────┐│┌→───────┬───────────┬─────────┐│ ││┌→──┬───┐│┌→────┬───┐│┌→───┬────┐│││┌→──┬──┐│┌→───┬────┐│┌→──┬───┐││ │││one│unu│││three│tri│││five│kvin│││││two│du│││four│kvar│││six│ses│││ ││└──→┴──→┘│└────→┴──→┘│└───→┴───→┘│││└──→┴─→┘│└───→┴───→┘│└──→┴──→┘││ │└────────→┴──────────→┴──────────→┘│└───────→┴──────────→┴────────→┘│ └──────────────────────────────────→┴───────────────────────────────→┘ disp zip¨pairs ┌→───────────────────┬─────────────────────────┬───────────────────────┐ │┌→────────┬────────┐│┌→───────────┬──────────┐│┌→─────────┬──────────┐│ ││┌→──┬───┐│┌→──┬──┐│││┌→────┬────┐│┌→──┬────┐│││┌→───┬───┐│┌→───┬───┐││ │││one│two│││unu│du│││││three│four│││tri│kvar│││││five│six│││kvin│ses│││ ││└──→┴──→┘│└──→┴─→┘│││└────→┴───→┘│└──→┴───→┘│││└───→┴──→┘│└───→┴──→┘││ │└────────→┴───────→┘│└───────────→┴─────────→┘│└─────────→┴─────────→┘│ └───────────────────→┴────────────────────────→┴──────────────────────→┘ disp zip¨zip pairs ┌→────────────────────────────────┬──────────────────────────────┐ │┌→───────────────┬──────────────┐│┌→─────────────┬─────────────┐│ ││┌→──┬─────┬────┐│┌→──┬───┬────┐│││┌→──┬────┬───┐│┌→─┬────┬───┐││ │││one│three│five│││unu│tri│kvin│││││two│four│six│││du│kvar│ses│││ ││└──→┴────→┴───→┘│└──→┴──→┴───→┘│││└──→┴───→┴──→┘│└─→┴───→┴──→┘││ │└───────────────→┴─────────────→┘│└─────────────→┴────────────→┘│ └────────────────────────────────→┴─────────────────────────────→┘ disp zip zip¨ pairs ┌→──────────────────────────────────┬────────────────────────────────┐ │┌→────────┬────────────┬──────────┐│┌→───────┬──────────┬──────────┐│ ││┌→──┬───┐│┌→────┬────┐│┌→───┬───┐│││┌→──┬──┐│┌→──┬────┐│┌→───┬───┐││ │││one│two│││three│four│││five│six│││││unu│du│││tri│kvar│││kvin│ses│││ ││└──→┴──→┘│└────→┴───→┘│└───→┴──→┘│││└──→┴─→┘│└──→┴───→┘│└───→┴──→┘││ │└────────→┴───────────→┴─────────→┘│└───────→┴─────────→┴─────────→┘│ └──────────────────────────────────→┴───────────────────────────────→┘ ---------- cat←{↑,/⍵} ⎕ml<2 ---------- [cat] concatenates the items in a vector (or higher rank array). It differs from enlist (∊), in that the concatenation occurs only at the top level of the array. disp pairs ┌→───────────────────┬─────────────────────────┬───────────────────────┐ │┌→────────┬────────┐│┌→──────────┬───────────┐│┌→──────────┬─────────┐│ ││┌→──┬───┐│┌→──┬──┐│││┌→────┬───┐│┌→───┬────┐│││┌→───┬────┐│┌→──┬───┐││ │││one│unu│││two│du│││││three│tri│││four│kvar│││││five│kvin│││six│ses│││ ││└──→┴──→┘│└──→┴─→┘│││└────→┴──→┘│└───→┴───→┘│││└───→┴───→┘│└──→┴──→┘││ │└────────→┴───────→┘│└──────────→┴──────────→┘│└──────────→┴────────→┘│ └───────────────────→┴────────────────────────→┴──────────────────────→┘ disp cat pairs ┌→────────┬────────┬───────────┬───────────┬───────────┬─────────┐ │┌→──┬───┐│┌→──┬──┐│┌→────┬───┐│┌→───┬────┐│┌→───┬────┐│┌→──┬───┐│ ││one│unu│││two│du│││three│tri│││four│kvar│││five│kvin│││six│ses││ │└──→┴──→┘│└──→┴─→┘│└────→┴──→┘│└───→┴───→┘│└───→┴───→┘│└──→┴──→┘│ └────────→┴───────→┴──────────→┴──────────→┴──────────→┴────────→┘ disp cat¨pairs ┌→───────────────┬─────────────────────┬───────────────────┐ │┌→──┬───┬───┬──┐│┌→────┬───┬────┬────┐│┌→───┬────┬───┬───┐│ ││one│unu│two│du│││three│tri│four│kvar│││five│kvin│six│ses││ │└──→┴──→┴──→┴─→┘│└────→┴──→┴───→┴───→┘│└───→┴───→┴──→┴──→┘│ └───────────────→┴────────────────────→┴──────────────────→┘ disp cat cat pairs ┌→──┬───┬───┬──┬─────┬───┬────┬────┬────┬────┬───┬───┐ │one│unu│two│du│three│tri│four│kvar│five│kvin│six│ses│ └──→┴──→┴──→┴─→┴────→┴──→┴───→┴───→┴───→┴───→┴──→┴──→┘ ------------ combinations ------------ disp pairs ┌→───────────────────┬─────────────────────────┬───────────────────────┐ │┌→────────┬────────┐│┌→──────────┬───────────┐│┌→──────────┬─────────┐│ ││┌→──┬───┐│┌→──┬──┐│││┌→────┬───┐│┌→───┬────┐│││┌→───┬────┐│┌→──┬───┐││ │││one│unu│││two│du│││││three│tri│││four│kvar│││││five│kvin│││six│ses│││ ││└──→┴──→┘│└──→┴─→┘│││└────→┴──→┘│└───→┴───→┘│││└───→┴───→┘│└──→┴──→┘││ │└────────→┴───────→┘│└──────────→┴──────────→┘│└──────────→┴────────→┘│ └───────────────────→┴────────────────────────→┴──────────────────────→┘ disp zip cat pairs ┌→────────────────────────────┬──────────────────────────┐ │┌→──┬───┬─────┬────┬────┬───┐│┌→──┬──┬───┬────┬────┬───┐│ ││one│two│three│four│five│six│││unu│du│tri│kvar│kvin│ses││ │└──→┴──→┴────→┴───→┴───→┴──→┘│└──→┴─→┴──→┴───→┴───→┴──→┘│ └────────────────────────────→┴─────────────────────────→┘ disp cat¨zip zip¨pairs ┌→────────────────────────────┬──────────────────────────┐ │┌→──┬───┬─────┬────┬────┬───┐│┌→──┬──┬───┬────┬────┬───┐│ ││one│two│three│four│five│six│││unu│du│tri│kvar│kvin│ses││ │└──→┴──→┴────→┴───→┴───→┴──→┘│└──→┴─→┴──→┴───→┴───→┴──→┘│ └────────────────────────────→┴─────────────────────────→┘ Technical note: Notice that [cat] applies _mix_ rather than _first_ to its reduction. This has the advantage of allowing it to accommodate higher rank arrays. disp mat ┌→───────────┬────────────┬───────────┐ ↓┌→──┬──────┐│┌→──┬──────┐│┌→──┬─────┐│ ││red│pepper│││red│letter│││red│alert││ │└──→┴─────→┘│└──→┴─────→┘│└──→┴────→┘│ ├───────────→┼───────────→┼──────────→┤ │┌→───┬────┐ │┌→───┬─────┐│┌→───┬───┐ │ ││blue│moon│ ││blue│suede│││blue│sky│ │ │└───→┴───→┘ │└───→┴────→┘│└───→┴──→┘ │ └───────────→┴───────────→┴──────────→┘ disp cat mat ┌→───┬──────┬────┬──────┬────┬─────┐ ↓red │pepper│red │letter│red │alert│ ├───→┼─────→┼───→┼─────→┼───→┼────→┤ │blue│ moon │blue│suede │blue│ sky │ └───→┴─────→┴───→┴─────→┴───→┴────→┘ disp zip mat ┌→────────────┬──────────────┬───────────┐ ↓ ┌→──┬────┐ │ ┌→──┬────┐ │┌→──┬────┐ │ │ │red│blue│ │ │red│blue│ ││red│blue│ │ │ └──→┴───→┘ │ └──→┴───→┘ │└──→┴───→┘ │ ├────────────→┼─────────────→┼──────────→┤ │┌→─────┬────┐│┌→─────┬─────┐│┌→────┬───┐│ ││pepper│moon│││letter│suede│││alert│sky││ │└─────→┴───→┘│└─────→┴────→┘│└────→┴──→┘│ └────────────→┴─────────────→┴──────────→┘ 2 | -------------------------------------------------------------------------------- /sources/paris.txt: -------------------------------------------------------------------------------- 1 | //////////////////// // Metro de Paris // //////////////////// Metro 1 Esplanade de la Défense Pont de Neuilly Les Sablons Porte Maillot Argentine Charles de Gaulle - Etoile George V Franklin D. Roosevelt Champs Elysées, Clémenceau Concorde Tuileries Palais Royal Louvre Châtelet, Les Halles Hôtel de Ville Saint Paul Bastille Gare de Lyon Reuilly Diderot Nation Porte de Vincennes Saint Mandé, Tourelle Bérault Château de Vincennes Metro 2 Porte Dauphine Victor Hugo Charles de Gaulle - Etoile Ternes Courcelles Monceau Villiers Rome Place de Clichy Blanche Pigalle Anvers Barbès Rochechouart La Chapelle Stalingrad Jaurès Colonel Fabien Belleville Couronnes Ménilmontant Père Lachaise Philippe Auguste Alexandre Dumas Avron Nation Metro 3 Pont de Levallois - Bécon Anatole France Louise Michel Porte de Champerret Péreire Wagram Malesherbes Villiers Europe Saint-Lazare Auber, Opéra, Havre Caumartin Quatre Septembre Bourse Sentier Réaumur Sébastopol Arts et Métiers Temple République Parmentier Rue Saint-Maur Père Lachaise Gambetta Porte de Bagnolet Galliéni Metro 3b Gambetta Pelleport Saint-Fargeau Porte des Lilas Metro 4 Porte de Clignancourt Simplon Marcadet Poissonniers Château Rouge Barbès Rochechouart Gare du Nord Gare de l'Est Château d'Eau Strasbourg Saint-Denis Réaumur Sébastopol Etienne Marcel Les Halles Châtelet, Les Halles Cité Saint-Michel Odéon Saint-Germain des Prés Saint-Sulpice Saint-Placide Montparnasse Bienvenue Vavin Raspail Denfert Rochereau Mouton-Duvernet Alésia Porte d'Orléans Montrouge Metro 5 Bobigny - Pablo Picasso Bobigny - Pantin Raymond Queneau Eglise de Pantin Hoche Porte de Pantin Ourcq Laumière Jaurès Stalingrad Gare du Nord Gare de l'Est, Verdun Jacques Bonsergent République Oberkampf Richard Lenoir Bréguet-Sabin Bastille Quai de la Rapée Gare d'Austerlitz Saint-Marcel Campo-Formio Place d'Italie Metro 6 Charles de Gaulle - Etoile Kléber Boissière Trocadéro Passy Bir-Hakeim Dupleix La Motte Picquet, Grenelle Cambronne Sèvres Lecourbe Pasteur Montparnasse Bienvenue Edgar Quinet Raspail Denfert Rochereau Saint-Jacques Glacière Corvisart Place d'Italie Nationale Chevaleret Quai de la Gare Bercy Dugommier Daumesnil Bel Air Picpus Nation Metro 7b Pré-Saint-Gervais Danube ∊ Botzaris Place des Fêtes Pré-Saint-Gervais Metro 7b Botzaris Buttes Chaumont Bolivar Jaurès Louis-Blanc Metro 7 La Courneuve - 8 Mai 1945 Fort d'Aubervilliers Aubervilliers-Pantin, Quatre Chemins Porte de la Villette Corentin-Cariou Crimée Riquet Stalingrad Louis-Blanc Château Landon Gare de l'Est, Verdun Poissonnière Cadet Le Peletier Chaussée d'Antin Auber, Opéra, Havre Caumartin Pyramides Palais Royal Pont-Neuf Châtelet, Les Halles Pont-Marie Sully Morland Jussieu, Paris 6, Paris 7, P6, P7 Monge Censier Daubenton Gobelins Place d'Italie Tolbiac Maison Blanche Metro 7 Mairie d'Ivry Pierre Curie Porte d'Ivry Porte de Choisy Porte d'Italie ∊ Maison Blanche Kremlin-Bicêtre Villejuif - Léo Lagrange Villejuif - Paul Vaillant-Couturier Villejuif - Louis Aragon Metro 8 Place Balard Lourmel Boucicaut Félix Faure Commerce La Motte Picquet, Grenelle Ecole Militaire Latour-Maubourg Invalides Concorde Madeleine Opéra Richelieu Drouot Rue Montmartre Bonne Nouvelle Strasbourg Saint-Denis République Filles du Calvaire Saint Sébastien-Froissart Chemin Vert Bastille Ledru Rollin Faidherbe-Chaligny Reuilly Diderot Montgallet Daumesnil Michel Bizot Porte Dorée Porte de Charenton Liberté Charenton-Ecoles Ecole Vétérinaire de Maisons-Alfort Maisons-Alfort Stade Maisons-Alfort les Juilliottes Créteil-l'Echat Créteil-Université Créteil-Préfecture Créteil-Sud Parc des Sports Metro 9 Pont de Sèvres Billancourt Marcel Sembat Porte de Saint-Cloud Exelmans Michel Ange Molitor Michel Ange Auteuil Jasmin Ranelagh La Muette Rue de la Pompe Trocadéro Iéna Alma Marceau Franklin D. Roosevelt Saint-Philippe du Roule Miromesnil Saint Augustin Havre Caumartin Chaussée d'Antin Richelieu Drouot Rue Montmartre Bonne Nouvelle Strasbourg Saint-Denis République Oberkampf Saint-Ambroise Voltaire Charonne Rue des Boulets Nation Buzenval Maraîchers Porte de Montreuil Robespierre Croix de Chavaux Mairie de Montreuil Metro 10 Boulogne - Pont de Saint-Cloud Boulogne-Jean Jaurès Metro 10 Michel Ange Molitor ∊ Boulogne-Jean Jaurès Porte d'Auteuil Michel Ange Auteuil Église d'Auteuil ∊ Javel Mirabeau Chardon Lagâche Michel Ange Molitor Metro 10 Javel Charles Michels Emile Zola La Motte Picquet, Grenelle Ségur Duroc Vaneau Sèvres Babylone Mabillon Odéon Saint-Michel - Notre Dame Maubert Mutualité Cardinal Lemoine Jussieu Gare d'Austerlitz Metro 11 Mairie des Lilas Porte des Lilas Télégraphe Place des Fêtes Jourdain Pyrénées Belleville Goncourt République Arts et Métiers Rambuteau Hôtel de Ville Châtelet, Les Halles Metro 12 Aubervilliers - Pont de Stains Porte de la Chapelle Marx Dormoy Marcadet Poissonniers Jules Joffrin Lamarck Caulaincourt Abbesses Pigalle Saint Georges Notre Dame de Lorette Trinité Saint-Lazare Madeleine Concorde Assemblée Nationale Solférino Rue du Bac Sèvres Babylone Rennes Notre Dame des Champs Montparnasse Bienvenue Falguière Pasteur Volontaires Vaugirard Convention Porte de Versailles Corentin Celton Mairie d'Issy Metro 13 Gabriel-Péri, Asnières-Gennevilliers Mairie de Clichy Porte de Clichy Brochant La Fourche Metro 13 Saint Denis-Basilique, Hôtel de Ville Saint Denis-Porte de Paris Carrefour Pleyel Mairie de Saint Ouen Garibaldi Porte de Saint Ouen Guy Môquet La Fourche Place de Clichy Liège Saint-Lazare Saint Augustin Miromesnil Champs Elysées, Clémenceau Invalides Varenne Saint-Francois Xavier Duroc Montparnasse Bienvenue Gaité Pernety Plaisance Porte de Vanves Malakoff-Plateau de Vanves Malakoff-Rue Etienne Dolet Châtillon Montrouge A1 Saint Germain en Laye Le Vésinet-Le Pecq Le Vésinet Centre Chatou-Croissy Rueil-Malmaison Nanterre-Ville Nanterre-Université Nanterre-Préfecture La Défense Charles de Gaulle - Etoile Auber, Opéra, Havre Caumartin Les Halles A1 Les Halles Gare de Lyon Nation Vincennes A1 Vincennes Fontenay sous Bois Nogent sur Marne Joinville le Pont Saint Maur-Créteil Le Parc-Saint Maur Champigny La Varenne-Chennevières Sucy-Bonneuil Boissy-Saint-Léger A4 Vincennes Val de Fontenay Neuilly-Plaisance Bry-sur-Marne Noisy le Grand, Mont d'Est Noisy 3 Noisiel Lognes Torcy B4 Saint Rémy-Lès-Chevreuse Courcelle-sur-Yvette Gif-sur-Yvette La Hacquinière Bures-sur-Yvette Orsay Le Guichet Lozère, Ecole Polytechnique, X Palaiseau-Villebon Palaiseau Massy-Palaiseau Massy-Verrières Les Bâconnets Fontaine Michalon Antony Croix de Berny Parc de Sceaux Bourg-la-Reine B4 Robinson Fontenay aux Roses Sceaux Bourg-la-Reine B4 Bourg-la-Reine Gentilly Cité Universitaire Denfert Rochereau Port Royal Luxembourg, Ecole Normale Supérieure, ENS Saint-Michel, Cluny, Cluny-les-Ecoles, Pont Saint Michel Les Halles Gare du Nord B3-B5 Gare du Nord La Plaine-Voyageurs Aubervilliers La Courneuve Le Bourget Drancy Blanc Mesnil Aulnay-sous-Bois B3 Aulnay-sous-Bois Sevran Beaudottes Villepinte Parc des Expositions Roissy-Aéroport, Charles de Gaule 1 Roissy-Aéroport, Charles de Gaule 2 B5 Aulnay-sous-Bois Sevran-Livry Vert-Galant Villeparisis Mitry-Claye 2 | -------------------------------------------------------------------------------- /sources/london.txt: -------------------------------------------------------------------------------- 1 | //////////////////////// // London Underground // //////////////////////// District Ealing Broadway Ealing Common Acton Town Chiswick Park // Chiswick Park───┐ ∊ Turnham Green // ├──Turnham Green Gunnersbury // Gunnersbury─────┘ Kew Gardens Richmond District Turnham Green Stamford Brook Ravenscourt Park Hammersmith Barons Court West Kensington ∊ Earl's Court West Brompton Fulham Broadway Parsons Green Putney Bridge East Putney Southfields Wimbledon Park Wimbledon District Upminster Upminster Bridge Hornchurch Elm Park Dagenham East Dagenham Heathway Becontree Upney Barking East Ham Upton Park Plaistow West Ham Bromley-by-Bow Bow Road Mile End Stepney Green Whitechapel Aldgate East Tower Hill Monument Cannon Street Mansion House Blackfriars Temple Embankment Westminster St James's Park Victoria Sloane Square South Kensington Gloucester Road ∊ Earl's Court High Street Kensington Notting Hill Gate Bayswater Paddington(S) Edgware Road(S) District (Olympia) Kensington Olympia Earl's Court Piccadilly Uxbridge Hillingdon Ickenham Ruislip Ruislip Manor Eastcote Rayners Lane South Harrow Sudbury Hill Sudbury Town Alperton Park Royal North Ealing Ealing Common ∊ Acton Town South Ealing Northfields Boston Manor Osterley Hounslow East Hounslow Central Hounslow West Hatton Cross Heathrow Terminal 5 // Heathrow Terminals 1-2-3 Piccadilly // ┌─→─∘─→─┐ ↓ Heathrow Terminals 1-2-3 // │ │ Hatton Cross ↓∊Hatton Cross // ↑ ├───∘─── ↓ Heathrow Terminal 4 // │ │ Heathrow Terminals 1-2-3 // └─←─∘─←─┘ // Heathrow Terminal 4 Piccadilly Cockfosters Oakwood Southgate Arnos Grove Bounds Green Wood Green Turnpike Lane Manor House Finsbury Park Arsenal Holloway Road Caledonian Road King's Cross St Pancras Russell Square Holborn Covent Garden Leicester Square Piccadilly Circus Green Park Hyde Park Corner Knightsbridge South Kensington Gloucester Road Earl's Court Barons Court Hammersmith Turnham Green Acton Town Hammersmith & City Barking East Ham Upton Park Plaistow West Ham Bromley-by-Bow Bow Road Mile End Stepney Green Whitechapel Aldgate East Liverpool Street Moorgate Barbican Farringdon King's Cross St Pancras Euston Square Great Portland Street Baker Street Edgware Road(N) Paddington (Bishop's Rd) Royal Oak Westbourne Park Ladbroke Grove Latimer Road Shepherd's Bush Market Goldhawk Road Hammersmith Subway Bow Church Bow Road Subway Tower Gateway Tower Hill Subway Bank Monument Docklands Light Railway Beckton Gallions Reach Cyprus Beckton Park Royal Albert Prince Regent Custom House // │ Royal Victoria // ∘ All Saints Canning Town // │ East India // │ Blackwall // Westferry │ Poplar + Poplar // ───∘───┬───∘───────∘─── ∊ West Ferry // └─┐ │ Blackwall ∊ West India Quay // └─┤ + Poplar // │ All Saints // ∘ West India Quay Devons Road // │ Bow Church Pudding Mill Lane Stratford Docklands Light Railway West Ferry Limehouse Shadwell Docklands Light Railway Tower Gateway ∊ Shadwell Bank Docklands Light Railway Lewisham Elverson Road Deptford Bridge Greenwich Cutty Sark Island Gardens Mudchute Crossharbour & London Arena South Quay Heron Quays Canary Wharf West India Quay Metropolitan Amersham ∊ Chalfont & Latimer Chesham Metropolitan Chalfont & Latimer Chorleywood Rickmansworth ∊ Moor Park Croxley Watford Metropolitan Moor Park Northwood Northwood Hills Pinner North Harrow ∊ Harrow-on-the-Hill West Harrow Rayners Lane Eastcote Ruislip Manor Ruislip Ickenham Hillingdon Uxbridge Metropolitan Harrow-on-the-Hill Northwick Park Preston Road Wembley Park Finchley Road Baker Street Great Portland Street Euston Square King's Cross St Pancras Farringdon Barbican Moorgate Liverpool Street Aldgate Northern Edgware Burnt Oak Colindale Hendon Central Brent Cross Golders Green Hampstead Belsize Park Chalk Farm ∊ Camden Town Kentish Town Northern Mornington Crescent ∊ Camden Town Euston (East) Northern Camden Town Mornington Crescent Euston (West) Subway Euston (East) Euston (West) Northern Euston (West) Warren Street Goodge Street Tottenham Court Road Leicester Square Charing Cross Embankment Waterloo ∊ Kennington Elephant & Castle Borough London Bridge Bank Moorgate Old Street Angel King's Cross St Pancras Euston (East) Northern Kennington Oval Stockwell Clapham North Clapham Common Clapham South Balham Tooting Bec Tooting Broadway Colliers Wood South Wimbledon Morden Northern Mill Hill East ∊ Finchley Central West Finchley Woodside Park Totteridge & Whetstone High Barnet Northern Kentish Town Tufnell Park Archway Highgate East Finchley Finchley Central Bakerloo Elephant & Castle Lambeth North Waterloo Embankment Charing Cross Piccadilly Circus Oxford Circus Regent's Park Baker Street Marylebone Edgware Road Paddington(N) Warwick Avenue Maida Vale Kilburn Park Queen's Park Kensal Green Willesden Junction Harlesden Stonebridge Park Wembley Central North Wembley South Kenton Kenton Harrow & Wealdstone Circle Hammersmith Goldhawk Road Shepherd's Bush Market Wood Lane Latimer Road Ladbroke Grove Westbourne Park Royal Oak Paddington (Bishop's Rd) Edgware Road(N) Baker Street Great Portland Street Euston Square King's Cross St Pancras Farringdon Barbican Moorgate Liverpool Street Aldgate Tower Hill Monument Cannon Street Mansion House Blackfriars Temple Embankment Westminster St James's Park Victoria Sloane Square South Kensington Gloucester Road High Street Kensington Notting Hill Gate Bayswater Paddington(S) Edgware Road(S) Jubilee Stratford West Ham Canning Town North Greenwich Canary Wharf Canada Water Bermondsey London Bridge Southwark Waterloo Westminster Green Park Bond Street Baker Street St John's Wood Swiss Cottage Finchley Road West Hampstead Kilburn Willesden Green Dollis Hill Neasden Wembley Park Kingsbury Queensbury Canons Park Stanmore Central Ongar North Weald Epping Theydon Bois Debden Loughton Buckhurst Hill ∊ Woodford Roding Valley Chigwell Grange Hill Hainault Fairlop Barkingside Newbury Park Gants Hill Redbridge Wanstead ∊ Leytonstone Snaresbrook South Woodford Woodford Central Leytonstone Leyton Stratford Mile End Bethnal Green Liverpool Street Bank St Paul's Chancery Lane Holborn Tottenham Court Road Oxford Circus Bond Street Marble Arch Lancaster Gate Queensway Notting Hill Gate Holland Park Shepherd's Bush White City East Acton North Acton Central West Ruislip Ruislip Gardens South Ruislip Northolt Greenford Perivale Hanger Lane ∊ North Acton West Acton Ealing Broadway Waterloo & City Bank Waterloo Victoria Brixton Stockwell Vauxhall Pimlico Victoria Green Park Oxford Circus Warren Street Euston (East) King's Cross St Pancras Highbury & Islington Finsbury Park Seven Sisters Tottenham Hale Blackhorse Road Walthamstow Central East London New Cross Gate ∊ Surrey Quays New Cross East London Surrey Quays Canada Water Rotherhithe Wapping Shadwell Whitechapel Shoreditch National Rail North Woolwich Silvertown Custom House Canning Town West Ham Stratford Hackney Wick Homerton Hackney Central Dalston Kingsland Canonbury Highbury & Islington Caledonian Road & Barnsbury Camden Road Kentish Town West Gospel Oak Hampstead Heath Finchley Road & Frognal West Hampstead Brondesbury Brondesbury Park Kensal Rise Willesden Junction Acton Central South Acton Gunnersbury Kew Gardens Richmond Via Mainline Station Paddington(N) Paddington (Bishop's Rd) Via Mainline Station Paddington (Bishop's Rd) Paddington(S) Change Platform Paddington(N) Paddington(S) 2 | -------------------------------------------------------------------------------- /sources/copenhagen.txt: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////// // Copenhagen Metro, S-trains, regional trains and S-buses // ///////////////////////////////////////////////////////////// M1 Nørreport station Kgs. Nytorv Christianshavn Islands Brygge Universitetet Sundby Bella Center Ørestad station Vestamager M2 Nørreport station Kgs. Nytorv Christianshavn // Connection to Christianshavns Torv-Knippelsbro? Amagerbro Lergravsparken A Hillerød station Allerød station Birkerød station Holte station Lyngby station Hellerup station Svanemøllen station Nordhavn station Østerport station Nørreport station Vesterport station København H Dybbølsbro station Sydhavn station Sjælør station Ellebjerg station Åmarken station Friheden station Avedøre station Brøndby Strand station Vallensbæk station Ishøj station Hundige station A+ Østerport station Nørreport station Vesterport station København H Sydhavn station Sjælør station Friheden station Avedøre station Brøndby Strand station Vallensbæk station Ishøj station Hundige station Greve station Karlslunde station Solrød Strand station Jersie station Ølby station Køge station B Holte station Virum station Sorgenfri station Lyngby station Jægersborg station Gentofte station Bernstorffsvej station Hellerup station Svanemøllen station Nordhavn station Østerport station Nørreport station Vesterport station København H Dybbølsbro station Enghave station Valby station Hvidovre station Rødovre station Brøndbyøster station Glostrup station Albertslund station Tåstrup station Høje Tåstrup station B+ Holte station Virum station Sorgenfri station Lyngby station Jægersborg station Gentofte station Bernstorffsvej station Hellerup station Svanemøllen station Nordhavn station Østerport station Nørreport station Vesterport station København H Dybbølsbro station Enghave station Valby station Hvidovre station Rødovre station Brøndbyøster station Glostrup station Albertslund station Tåstrup station Høje Tåstrup station C Klampenborg station Ordrup station Charlottenlund station Hellerup station Svanemøllen station Nordhavn station Østerport station Nørreport station Vesterport station København H Dybbølsbro station Enghave station Valby station Langgade station Peter Bangs Vej station Vanløse station Jyllingevej station Islev station Husum station Herlev station Skovlunde station Malmparken station Ballerup station Måløv station Kildedal station Veksø station Stenløse station Ølstykke station Frederikssund station E Hillerød station Allerød station Birkerød station Holte station Lyngby station Hellerup station Svanemøllen station Nordhavn station Østerport station Nørreport station Vesterport station København H Sjælør station Ishøj station Hundige station Greve station Karlslunde station Solrød Strand station Jersie station Ølby station Køge station F Hellerup station Ryparken station Bispebjerg station Nørrebro station Fuglebakken station Grøndal station C.F.Richs Vej station Vanløse station // Serviced by special buses until new section on this line is completed F+ Klampenborg station Ordrup station Charlottenlund station Hellerup station Ryparken station Bispebjerg station Nørrebro station Fuglebakken station Grøndal station C.F.Richs Vej station Vanløse station // Serviced by special buses until new section on this line is completed H Farum station Værløse station Hareskov station Skovbrynet station Bagsværd station Stengården station Buddinge station Kildebakke station Vangede station Dyssegård station Emdrup station Ryparken station Svanemøllen station Nordhavn station Østerport station Nørreport station Vesterport station København H Valby station Vanløse station Herlev station Ballerup station Måløv station Kildedal station Veksø station Stenløse station Ølstykke station Frederikssund station H+ Farum station Værløse station Bagsværd station Buddinge station Vangede station Emdrup station Ryparken station Østerport station Nørreport station Vesterport station København H Valby station Langgade station Peter Bangs Vej station Vanløse station Jyllingevej station Islev station Husum station Herlev station Skovlunde station Malmparken station Ballerup station Måløv station Kildedal station Veksø station Lille Nord Hillerød station Grønholt station Fredensborg station Langerød station Kvistgård station Mørdrup station Snekkersten station Helsingør station Kystbanen Helsingør station Snekkersten station Espergærde station Humlebæk station Nivå station Kokkedal station Rungsted Kyst station Vedbæk station Skodsborg station Klampenborg station Hellerup station Østerport station Nørreport station København H Ørestad station Tårnby station Kastrup Airport station Malmö Syd station // Sweden Malmö station // Sweden Nærumbanen Jægersborg station Lyngby Lokalstation Fuglevad station Brede station Ørholm station Ravnholm station Nærum station 100S Svanemøllen station Skt. Kjelds Plads Lyngbyvej Haraldsgade Aldersrogade Tagensvej Nørrebro station Borups Allé Godthåbsvej Stæhr Johansens Vej Peter Bangs Vej Roskildevej Valby station Toftegårds Plads Sankt Annæ Gymnasium Sjælør station Mozarts Plads Bådehavnsgade Sluseholmen Bella Center Røde Mellemvej Englandsvej Irlandsvej // Might not be the same as on the lines 350S&500S Vejlands Allé Sundbyvester Plads Amagerbrogade Kastrupvej Italiensvej-Backersvej Lergravsparken 150S Kokkedal station Brønsholmdalsvej Egedal Kirke Egevangen Breelte Skov Bloustrødvej Hørsholm Sygehus Kongevejs Centret Hørsholm Midtpunkt Hørsholm Posthus Venlighedsvej Dr. Neergaards Vej Øverødvej Nærum station Lundtofteparken Rævehøjvej Klampenborgvej Brogårdsvej Kildegårds Plads Ryparken station Hans Knudsens Plads Haraldsgade Vibenshus Runddel Universitetsparken Fredrik Bajers Plads Blegdamsvej Sølvtorvet Nørreport station Rådhuspladsen København H Polititorvet-Kalvebod Brygge Fisketorvet 200S Lyngby station Gammelmosevej Buddinge station Buddinge Torv Gladsaxe Ringvej-Gladsaxevej Gladsaxe Trafikplads Sydmarken TV-byen Stavnsbjerg Allé Nørre Gymnasium Husum Torv Husum station Slotsherrensvej Fortvej Jyllingevej Tæbyvej Rødovre Centrum Rødager Allé Roskildevej-Tårnvej Rødovre station Rebæk Søpark Kollegiet Tusbyvej Hvidovre Hospital A. Nielsens Boulevard Hvidovre Rådhus Brostykkevej Friheden station 250S Buddinge station Buddinge Torv Gladsaxe Ringvej-Gladsaxevej Vandtårnsvej Gyngemosevej Høje Gladsaxe Bellahøj Hillerødgade Jagtvej H. C. Ørsteds Vej Rådhuspladsen København H Amagerfælledvej Holmbladsgade Øresundsvej Sundbyvester Plads Korsvejens Skole Cypres Allé Skottegårdsskolen Bredager Torv Ved Diget Skøjtevej-Amager Strandvej Kastrup Airport station 300S Kokkedal station Breelte Skov Bloustrødvej Hørsholm Sygehus Kongevejs Centret Hørsholm Midtpunkt Hørsholm Posthus Venlighedsvej Dr. Neergaards Vej Øverødvej Nærum station Lundtofteparken Rævehøjvej DTU Lyngby Uddannelsescenter Elektrovej Lyngby Svømmehal Carlshøjvej Lyngby Storcenter Gammelmosevej Buddinge station Buddinge Torv Gladsaxe Ringvej-Gladsaxevej Gladsaxe Trafikplads Dynamovej Herlev Amtssygehus Herlev Bymidte Herlev station Mileparken Ballerup Boulevard Ejby Industrivej Ejby Torvevej Fabriksparken Mellemtoftevej Glostrup Amtssygehus Nordre Ringvej Glostrup station Åskellet Kirkebjerg Torv Park Allé-Søndre Ringvej Knudslundvej Vallensbækvej Brøndby Haveby Vejlegårdsparken Vejlegårdsvej Strandparksstien Ishøj station Vejlebrovej Hundigevej Solbakken Krogårdsvej Hundige station 350S Ballerup station Ballerup Amtssygehus Ring 4 Tempovej Malmparken station Borupvang Ingeniørhøjskolen i København Torvevej Marielundsvej Herlev Bymidte Elverhøjen Åfløjen Husum Torv Husumvej Veksøvej Brønshøj Torv Bellahøj Hulgårds Plads Nørrebro station Nørrebros Runddel Elmegade Nørreport station Kronprinsessegade Kgs. Nytorv Christianshavns Torv-Knippelsbro Holmbladsgade Øresundsvej Sundbyvester Plads Korsvejens Skole Irlandsvej // Might not be the same as on the line 100S Tårnby station Løjtegårdsvej Brønderslev Allé Tømmerup Store Magleby Fasanvænget Store Magleby Strandvej Søndre Røse Vej Vierdiget Idrætsstien Dragør Skole Dragør Stationsplads 400S Lyngby station Nybrovej Aldershvilevej Bagsværd station Tværvej Ring 4-Åvej Skinderskovvej Nordbuen Digterparken Borupvang-Ringvej 4 Bydammen-Ballerup Rådhus Ballerup station Ballerup Amtssygehus Hedegårdscentret Sydbuen Told og Skat Teknologisk Institut Høje Tåstrup station City 2 Tåstrup Valbyvej Broenge Industridalen Mosegårdsstien Ishøj station Fyrrelunden Baldersbækstien Engrøjel Hundige Storcenter Hundige station 500S Kokkedal station Ådalsparkvej Hørsholm Sygehus Kongevejs Centret Hørsholm Midtpunkt Hørsholm Posthus Mariehøj Allé Isterød Høsterkøbvej Sjælsøskolen Byagervej Birkerød Kongevej Birkerød station Bistrup Trafikplads Nordøststien Farum Midtpunkt Farum station / Farum Rådhus Fiskebæksbroen Bavnestedet Værløse station Søndergårdsvej Egebjerghuse Højagerskolen Bydammen-Ballerup Rådhus Ballerup station Ballerup Amtssygehus Hedegårdscentret Sydbuen Fabriksparken Mellemtoftevej Glostrup Amtssygehus Nordre Ringvej Glostrup station Åskellet Tranehaven Gildhøj Centret Brøndby Hallen Albjergparken Brøndby Strand station Fyrmestervej Helseholmen Avedøreholmen Center Syd Tårnby station Irlandsvej // Might not be the same as on the line 100S Korsvejens Skole Terminal 1 (Domestic) KLH Kontorhus Kastrup Airport station 550S Glostrup station Paul Bergsøes Vej Korsdalsvej Fjeldhammervej Espelunden Rødovrehallen Rødovre Centrum Rødager Allé Roskildevej-Tårnvej Damhustorvet Ålholm Plads Domus Vista Roskildevej Zoo De små Haver Enghavevej Vesterbros Torv Halmtorvet København H Stormgade Christiansborg (Parliament) Tordenskjoldsgade Nyhavn Kvæsthusbroen 600S Hillerød station Teknisk Skole Mælkevejen Freerslev Gørløse Lystrupvej Slangerup rtb. Jørlunde Skyhøj Ølstykke station Svanholm Vænge Svestrup Tangbjerg Rådalsvej Jyllingecentret Margretheskolen Risø Himmelev-Egelund Roskilde station Roskilde Sygehus Astersvej Østre Ringvej Lillevangsvej Vindinge Stenlandsvej Mindstrupgård Tune Kirke Tune Center Pilevej Lotusvej Tune Landboskole Vesterbjerg Grevetoften Greve Centervej Blågårdsvej Hedelyparken Greve station Greve Borgerhus Krogager Hundige Kirke Gersagerparken Hundige Storcenter Hundige station 650S Hellerup station Callisensvej Tuborg Boulevard Strandøre Svanemøllen station Strandboulevarden Trianglen Østerport station Kgs. Nytorv Christiansborg (Parliament) Stormgade København H Dybbølsbro station Toftegårds Plads Fengersvej Vigerslevvej Rosenhøj Hvidovre Hospital Tusbyvej Kollegiet Avedøre Havnevej Avedøre Skole Avedøre station 2 | -------------------------------------------------------------------------------- /notes/tube.txt: -------------------------------------------------------------------------------- 1 | -------------------- Subway Route Planner -------------------- This workspace demonstrates "Graph Searching". See dfns.dws/notes.Graphs for an introduction to graphs. ------------- Source Coding ------------- A subway network is coded in sections, with lists of "stops" (or stations) head- ed by an _exdented_ service or "line" label. For example, London's Circle line can be coded in one shot as there are no branches: Circle South Kensington Gloucester Road High Street Kensington ··· Victoria Sloane Square South Kensington The line label is distinguished by appearing in the _first_ column of the source and the stations that follow must be indented by at least one column. More complex lines containing branches are coded as separate simple sections, each headed by the section's line label: District Ealing Broadway Ealing Common Acton Town Chiswick Park Turnham Green District Richmond Kew Gardens Gunnersbury Turnham Green District Turnham Green Stamford Brook Ravenscourt Park Hammersmith Barons Court West Kensington Earl's Court The compiler links these sections by joining stations with the same name, for example, Turnham Green in the above. The comment '//', and all characters to its right, are ignored. ----- Forks ----- Forks, such as the one at Turnham Green, should be indicated in the source code for two reasons. Firstly, without the coding, a trip from one "tine" of the fork to another would give no indication that we must de-train [1] at the fork's handle in order to continue in the opposite direction. Secondly, there may be cases where the optimal choice of route should avoid a fork. [1] For the Brits, "de-train" means "disembark" [2] [2] For Americans, "disembark" means "un-get-on-the-boat". For example: X───────Y A trip from A to B would be quicker via X and Y than via F. │ │ A B A→X→Y→B takes 3 units, whereas A→F→[change]→F→B takes 4. It seems │ │ preferable to stay on the train for an extra stop via X and Y, └───┬───┘ than to get off at F, change platform, and then wait for a train │ to B in the opposite direction. F ┌───────────────────────────────────────────────────────────────────────┐ │ Dyalog's restricted set of line-drawing characters make it A B │ │ difficult to draw a convincing picture of a fork. The dia- │ │ │ │ gram opposite is intended to show a fork when travelling └───┬───┘ │ │ north from C to A or B. In other words, there is no direct │ │ │ connection from A to B; we must change trains at C. C │ └───────────────────────────────────────────────────────────────────────┘ The following picture shows a fork on London's Northern line. To travel from Chalk Farm to Kentish Town, we must change at Camden Town to a north-east-bound train. This configuration is indicated in the source code, by symbol '∊' on the handle of the fork: // │ │ Northern // Chalk Farm ∘ ∘ Kentish Town Chalk Farm // │ │ ∊ Camden Town // └──┬──┘ Kentish Town // │ // ∘ Camden Town // │ This coding would suggest the following trip. De-training at Camden town is in- dicated by exdentation (we should leave the train at exdented stations): london trip 'Chalk Farm' 'Kentish Town' Chalk Farm Chalk Farm Northern Camden Town Northern Camden Town Camden Town Northern Kentish Town Northern Kentish Town ------- Crosses ------- A 4-way-cross, such as the one at "Poplar" on London's Docklands Light Railway, is indicated by a '+'. A trip from All Saints to Blackwall would then show de- training at Poplar, whereas a trip from All Saints to West India Quay, wouldn't. // │ Docklands Light Railway // ∘All Saints Westferry // │ + Poplar // │ Blackwall // │Poplar // ───∘───────∘───────∘──── Docklands Light Railway // Westferry │ Blackwall All Saints // │ + Poplar // │ West India Quay // ∘West India Quay // │ This coding produces the following trip suggestions: london trip 'All Saints' 'West India Quay' All Saints All Saints Docklands Light Railway Poplar Docklands Light Railway West India Quay Docklands Light Railway West India Quay london trip 'All Saints' 'Blackwall' All Saints All Saints Docklands Light Railway Poplar Docklands Light Railway Poplar Poplar Docklands Light Railway Blackwall Docklands Light Railway Blackwall ---------------- One-Way Sections ---------------- A one-way section is indicated by an arrow ↓, on the stop at the _entrance_ to the section. An example is the loop at the south-west end of London's Picadilly line. Note that Hatton Cross is also a fork: Picadilly ↓ Heathrow 4 // ┌─H123─→┐ ↓ Heathrow 1,2,3 // ↑ ├──HX── ↓∊Hatton Cross // └─H4──←─┘ Heathrow 4 suggesting: london trip '4' 'Hat' ⍝ Heathrow: Terminal 4 → Hatton Cross. Heathrow Terminal 4 Heathrow Terminal 4 Piccadilly Heathrow Terminals 1-2-3 Piccadilly Hatton Cross Piccadilly Hatton Cross london trip '3' '4' ⍝ Heathrow: Terminal 3 → Terminal 4. (*) Heathrow Terminals 1-2-3 Heathrow Terminals 1-2-3 Piccadilly Hatton Cross Piccadilly Hatton Cross Hatton Cross Piccadilly Heathrow Terminal 4 Piccadilly Heathrow Terminal 4 london trip '4' '3' ⍝ Heathrow: Terminal 4 → Terminal 3. Heathrow Terminal 4 Heathrow Terminal 4 Piccadilly Heathrow Terminals 1-2-3 Piccadilly Heathrow Terminals 1-2-3 (*) There are better ways to travel between London Heathrow's terminals than by taking the tube via Hatton Cross. ------- Summary ------- // comment Line station station ... ∊ on handle of [fork]. ↓ at start of [one-way section]. + on [cross]. ------- Example ------- A simple network can be found in →source←. Try: ed notes ⍝ review source vector. notes trip 'Apple' 'Banana' ⍝ journey through a fork. notes trip 'Pear' 'Onion' ⍝ show one-way restrictions. --------------- Technical Notes --------------- A [line] typically passes through a number of [stations]: Circle: Paddington, Edgware Road, Baker Street, ... A [station] may host a number of [lines]: Baker Street: Circle, Bakerloo, Jubilee, ... A [stop] is a (line station) pair: (Circle Paddington) (Bakerloo Paddington) (Victoria Victoria) ... A [platform] is a (line station direction) triple: (Central Holborn Eastbound) (Northern Archway Southbound) ... A subway network is represented as a graph with platforms as vertices and tracks between platforms as edges. In addition, there is an extra vertex corresponding with each station, and extra edges between the station to each platform within. In other words, there is a notional journey between the station entrance and the platform on which the train departs or arrives. A trip that involves de-training to change lines, or in the case of a fork, to change direction on the same line, is routed via the [station] vertex. This routing has the effect of emphasising line and direction changes as exdented station names in the final output. Further, the extra edges between lines provide a weighting against the searching algorithm's suggesting indiscriminate "line jockeying". It is this extra link that models the behavioural cost of changing trains. A simpler version of this workspace used only single-track links between stat- ions. This meant that there was only a single platform per station per line, rather than one for each direction. One-way sections could be accommodated, but forks and crosses presented a problem. The current version, which represents separate station platforms for each direction, generates approximately twice as many graph vertices (but the same number of edges). ------------- Line Topology ------------- A subway network can be built from a set of primitive elements, in a way similar to a model railway. The detail of the topology is important, as it is this that directs the graph-searching algorithm to find shortest routes. For example, in the [fork] below, we can see that the shortest way from a station on one tine, to a station on the other, is via the [station] at the handle. Key: ⎕ station ∘ platform ·───→───· directional edge ┌───→───┐ ·───────· bi-directional edge, shorthand for: · · └───←───┘ Simple multi-station two-way line section: ···───→───∘───→───∘───→───∘───→───··· │ │ │ Line A: ⎕ ⎕ ⎕ │ │ │ ···───←───∘───←───∘───←───∘───←───··· One-way line section: ···───→───∘───→───∘───→───∘───→───··· │ │ │ Line A: ⎕ ⎕ ⎕ Multi-line Station: ···───→───∘───→───∘───→───∘───→───··· │ │ │ Line A: ⎕ ┌─┘ ⎕ <= Station serves line A. │ │ │ ···───←───∘───←───∘───←───∘───←───··· │ │ └─⎕─┐ <= Station serves lines A and B. │ │ ···───→───∘───→───∘───→───∘───→───··· │ │ │ Line B: ⎕ ┌─┘ ⎕ <= Station serves line B. │ │ │ ···───←───∘───←───∘───←───∘───←───··· Fork: ┌───→───∘───→───∘───→───··· │ │ │ ↑ ⎕ ⎕ Line A: │ │ │ ···───→───∘───→───∘──┐ ┌←─∘───←───∘───←───··· │ │ │ │ Line A: ⎕ ⎕ └─→──┐ │ │ │ │ ···───←───∘───←───∘──←─┘ ∘───→───∘───→───··· │ │ │ ↑ ⎕ ⎕ Line A: │ │ │ └───←───∘───←───∘───←───··· Cross: A cross is equivalent to a Multi-line station, with the difference that the station serves two (or more) sections of the _same_ line. A figure-of-eight model railway layout, might include a cross. · · ↑ ↓ │ │ Line A: ∘───⎕───∘ │ │ ···───→───∘───│───∘───────∘───→───··· │ │ │ │ │ ⎕ ∘───⎕───∘ ⎕ Line A: │ │ │ │ │ ···───←───∘───────∘───│───∘───←───··· │ │ ∘───⎕───∘ │ │ ↑ ↓ · · -------------------- Dyalog APL Navigator -------------------- DAN, the "Dyalog APL Navigator" workspace supplied with Pocket APL, uses the same line topology as this but employs "weighted" graphs to model differing train frequencies, line closures, reluctance to change trains, and so forth. See: dfns.dws/notes.wGraphs. Auxiliary function "replaces" is used to update Pocket APL's DAN component file using the following steps: )load tube ⍝ start with this workspace. gotham←⎕ns'' ⍝ create namespace for new city. ed gotham ⍝ create metro map source for new city. compile gotham ⍝ compile graph. gotham replaces 'Gotham City' ⍝ install new city in DAN.DCF. )save ⍝ remember to save changes. )load dan ⍝ load DAN workspace and ... ⍝ test changes. )load tube ⍝ reload tube workspace. ed gotham ⍝ make changes. compile gotham ⍝ recompile graph. gotham replaces 'Gotham City' ⍝ replace city. ... ⍝ test using DAN workspace and so on ... To remove a city from DAN's component file: replaces 'Gotham City' ⍝ remove city (no left argument). ------- Testing ------- #.notes.test is a function that takes test script #.notes.script to exercise the workspace. To run the test, type: notes.test'script' ⍝ run test script. No news => good news. Any differences from expected result are displayed in the session. --------------- Acknowledgments --------------- Thanks to the following people for suggestions and subway source codings: Dick Bowman Gianluigi Quario Klaus Klug Christiansen Stefano Lanzavecchia See also: →source← →trip← →compile← →path← →ed← 2 | -------------------------------------------------------------------------------- /sources/new_york.txt: -------------------------------------------------------------------------------- 1 | ///////////////////////////// // Approx. New York Subway // ///////////////////////////// //////////////////////////////////////////////////////////////// // NB: This is a "first cut" at a map of the New York subway. // // Please send corrections to: john@dyalog.com // //////////////////////////////////////////////////////////////// Line (1) Broadway - 7 Avenue Local Van Cortlandt Park-242 Street / Broadway 238 Street / Broadway 231 Street / Broadway Marble Hill-225 Street / Broadway 215 Street / 10 Avenue 207 Street / 10 Avenue Dyckman Street / Nagle Avenue 191 Street / Saint Nicholas Avenue 181 Street / Saint Nicholas Avenue 168 Street- Washington Heights / Broadway 157 Street / Broadway 145 Street / Broadway 137 Street-City College / Broadway 125 Street / Broadway 116 Street- Columbia University / Broadway Cathedral Parkway (110 Street) / Broadway 103 Street / Broadway 96 Street / Broadway 86 Street / Broadway 79 Street / Broadway 72 Street / Broadway 66 Street-Lincoln Center / Broadway 59 Street-Columbus Circle / Broadway 50 Street / Broadway Times Square-42 Street / 7 Avenue-Broadway 34 Street-Penn Station / 7 Avenue 28 Street / 7 Avenue 23 Street / 7 Avenue 18 Street / 7 Avenue 14 Street / 7 Avenue Christopher Street-Sheridan Square / 7 Avenue South Houston Street / Varick Street Canal Street / Varick Street Franklin Street / Varick Street Chambers Street / West Broadway Cortlandt Street / West Broadway Rector Street South Ferry Line (2) Seventh Avenue Local Wakefield-241 Street / White Plains Road Nereid Avenue (238 Street) / White Plains Road 233 Street / White Plains Road 225 Street / White Plains Road 219 Street / White Plains Road Gun Hill Road / White Plains Road Burke Avenue / White Plains Road Allerton Avenue / White Plains Road Pelham Parkway / White Plains Road Bronx Park East / White Plains Road East 180 Street / Morris Park Avenue West Farms Square-East Tremont Avenue / Boston Road 174 Street / Southern Boulevard Freeman Street / Southern Boulevard Simpson Street / Westcheser Avenue Intervale Avenue / Westcheser Avenue Prospect Avenue / Westcheser Avenue Jackson Avenue / Westcheser Avenue 3 Avenue-149 Street 149 Street-Grand Concourse 135 Street / Lenox Avenue 125 Street / Lenox Avenue 116 Street / Lenox Avenue Central Park North (110 Street) / Lenox Avenue 96 Street / Broadway 86 Street / Broadway 79 Street / Broadway 72 Street / Broadway 66 Street- Lincoln Center / Broadway 59 Street- Columbus Circle / Broadway 50 Street / Broadway Times Square-42 Street / 7 Avenue-Broadway 34 Street-Penn Station / 7 Avenue 28 Street / 7 Avenue 23 Street / 7 Avenue 18 Street / 7 Avenue 14 Street / 7 Avenue Christopher Street- Sheridan Sq / 7 Avenue Houston Street / Varick Street Canal Street / Varick Street Franklin Street / Varick Street Chambers Street / West Broadway Park Place / Broadway Fulton Street / William Street Wall Street / William Street Clark Street / Henry Street Borough Hall / Court Street-Montague Street Hoyt Street / Fulton Mall Nevins Street / Flatbush Avenue Atlantic Avenue / Flatbush Avenue Bergen Street / Flatbush Avenue Grand Army Plaza / Flatbush Avenue Eastern Parkway-Brooklyn Museum Franklin Avenue / Eastern Parkway President Street / Nostrand Avenue Streeterling Street / Nostrand Avenue Winthrop Street / Nostrand Avenue Church Avenue / Nostrand Avenue Beverly Road / Nostrand Avenue Newkirk Avenue / Nostrand Avenue Brooklyn College-Flatbush Avenue / Nostrand Avenue Line (3) Seventh Avenue Express Harlem-148 Street / 7 Avenue* 145 Street / Lenox Avenue* 135 Street / Lenox Avenue* 125 Street / Lenox Avenue 116 Street / Lenox Avenue Central Park North (110 Street) / Lenox Avenue 96 Street / Broadway 72 Street / Broadway Times Square-42 Street / 7 Avenue-Broadway 34 Street-Penn Station / 7 Avenue 14 Street / 7 Avenue Chambers Street / West Broadway Park Place / Broadway Fulton Street / William Street Wall Street / William Street Clark Street / Henry Street Borough Hall / Court Street-Montague Street Hoyt Street-Fulton Mall Nevins Street / Flatbush Avenue Atlantic Avenue / Flatbush Avenue Bergen Street / Flatbush Avenue Grand Army Plaza / Flatbush Avenue Eastern Parkway-Brooklyn Museum Franklin Avenue / Eastern Parkway Nostrand Avenue / Eastern Parkway Kingston Avenue / Eastern Parkway Crown Heights-Utica Avenue / Eastern Parkway Sutter Avenue-Rutland Road / East 98 Street Saratoga Avenue / Livonia Avenue Rockaway Avenue / Livonia Avenue Junius Street / Livonia Avenue Pennsylvania Avenue / Livonia Avenue Van Siclen Avenue / Livonia Avenue New Lots Avenue / Livonia Avenue Line (4) Lexington Avenue Express Woodlawn / Jerome Avenue Mosholu Parkway / Jerome Avenue Bedford Park Boulevard-Lehman College / Jerome Avenue Kingsbridge Road / Jerome Avenue Fordham Road / Jerome Avenue 183 Street / Jerome Avenue Burnside Avenue / Jerome Avenue 176 Street / Jerome Avenue Mt Eden Avenue / Jerome AvenueStation closed until July 2004 170 Street / Jerome Avenue 167 Street / River AvenueStation closed until July 2004 161 Street- Yankee Stadium / River Avenue 149 Street-Grand Concourse 138 Street / Grand Concourse 125 Street / Lexington Avenue 116 Street / Lexington Avenue 110 Street / Lexington Avenue 103 Street / Lexington Avenue 96 Street / Lexington Avenue 86 Street / Lexington Avenue 77 Street / Lexington Avenue 68 Street-Hunter College / Lexington Avenue 59 Street / Lexington Avenue 51 Street / Lexington Avenue Grand Central-42 Street / Lexington Avenue 33 Street / Park Avenue South 28 Street / Park Avenue South 23 Street / Park Avenue South 14 Street-Union Square / 4 Avenue Astor Place / 4 Avenue Bleecker Street / Lafayette Street Spring Street / Lafayette Street Canal Street / Lafayette Street Brooklyn Bridge-City Hall / Centre Street Fulton Street / Broadway Wall Street / Broadway Bowling Green / Broadway Borough Hall-Court Street / Joralemon Street (Northbound only) Nevins Street / Flatbush Avenue Atlantic Avenue / Flatbush Avenue / Brooklyn Academy of Music Bergen Street / Flatbush Avenue Grand Army Plaza / Flatbush Avenue Eastern Parkway-Brooklyn Museum Franklin Avenue / Eastern Parkway Nostrand Avenue / Eastern Parkway Kingston Avenue / Eastern Parkway Crown Heights-Utica Avenue / Eastern Parkway Sutter Avenue-Rutland Road / East 98 Street Saratoga Avenue / Livonia Avenue Rockaway Avenue / Livonia Avenue Junius Street / Livonia Avenue Pennsylvania Avenue / Livonia Avenue Van Siclen Avenue / Livonia Avenue New Lots Avenue / Livonia Avenue Line (5) Lexington Avenue Express Eastchester-Dyre Avenue / 233 Street Baychester Avenue / Tillotson Avenue Gun Hill Road / Seymour Avenue Pelham Parkway / Williamsbridge Road Morris Park / Esplanade East 180 Street / Morris Park Avenue West Farms Square- E Tremont Avenue / Boston Road-Bronx Zoo 174 Street / Southern Boulevard Freeman Street / Southern Boulevard Simpson Street / Westchester Avenue Intervale Avenue / Westchester Avenue Prospect Avenue / Westchester Avenue Jackson Avenue / Westchester Avenue 3 Avenue-149 Street 149 Street- Grand Concourse 138 Street / Grand Concourse 125 Street / Lexington Avenue 86 Street / Lexington Avenue 59 Street / Lexington Avenue Grand Central-42 Street / Lexington Avenue 14 Street - Union Square / 4 Avenue Brooklyn Bridge-City Hall / Centre Street Fulton Street / Broadway Wall Street / Broadway Bowling Green / Broadway Borough Hall / Court Street (Northbound only) Nevins Street / Flatbush Avenue Atlantic Avenue / Flatbush Avenue Franklin Avenue / Eastern Parkway President Street / Nostrand Avenue Sterling Street / Nostrand Avenue Winthrop Street / Nostrand Avenue Church Avenue / Nostrand Avenue Beverly Road / Nostrand Avenue Newkirk Avenue / Nostrand Avenue Brooklyn College-Flatbush Avenue / Nostrand Avenue Line <5> Lexington Avenue Express Nereid Av (238 St) White Plains Rd 233 Street / White Plains Road 225 Street / White Plains Road 219 Street / White Plains Road Gun Hill Road / White Plains Road Burke Avenue / White Plains Road Allerton Avenue / White Plains Road Pelham Parkway / White Plains Road Bronx Park East / White Plains Road East 180 Street / Morris Park Avenue 3 Avenue-149 Street 149 Street- Grand Concourse 138 Street / Grand Concourse 125 Street / Lexington Avenue 86 Street / Lexington Avenue 59 Street / Lexington Avenue Grand Central-42 Street / Lexington Avenue 14 Street-Union Square / 4 Avenue Brooklyn Bridge-City Hall / Centre Street Fulton Street / Broadway Wall Street / Broadway Bowling Green / Broadway Borough Hall / Court Street (Northbound only) Nevins Street / Flatbush Avenue Atlantic Avenue / Flatbush Avenue Franklin Avenue / Eastern Parkway President Street / Nostrand Avenue Sterling Street / Nostrand Avenue Winthrop Street / Nostrand Avenue Church Avenue / Nostrand Avenue Beverly Road / Nostrand Avenue Newkirk Avenue / Nostrand Avenue Brooklyn College-Flatbush Avenue / Nostrand Avenue Line (6) Lexington Avenue Local Pelham Bay Park / Bruckner Expressway Buhre Avenue / Westchester Avenue Middletown Road / Westchester Avenue Westchester Square-East Tremont Avenue / Westchester Avenue Zerega Avenue / Westchester Avenue Castle Hill Avenue / Westchester Avenue Parkchester-E 177 St / Westchester Avenue Saint Lawrence Avenue / Westchester Avenue Morrison- Sound View Avenues / Westchester Avenue Elder Avenue / Westchester Avenue Whitlock Avenue / Westchester Avenue Hunts Point Avenue / Southern Boulevard Longwood Avenue / Southern Boulevard East 149 Street / Southern Boulevard East 143 Street - Saint Mary's Street / Southern Boulevard Cypress Avenue / East 138 Street Brook Avenue / East 138 Street 3 Avenue-138 Street 125 Street / Lexington Avenue 116 Street / Lexington Avenue 110 Street / Lexington Avenue 103 Street / Lexington Avenue 96 Street / Lexington Avenue 86 Street / Lexington Avenue 77 Street / Lexington Avenue 68 Street-Hunter College / Lexington Avenue 59 Street / Lexington Avenue 51 Street / Lexington Avenue Grand Central-42 Street / Lexington Avenue 33 Street / Park Avenue South 28 Street / Park Avenue South 23 Street / Park Avenue South 14 Street-Union Square / 4 Avenue Astor Place / 4 Avenue Bleecker Street / Lafayette Street Spring Street / Lafayette Street Canal Street / Lafayette Street Brooklyn Bridge-City Hall / Centre Street Line <6> Lexington Avenue Local / Pelham Express Pelham Bay Park / Bruckner Expressway Buhre Avenue / Westchester Avenue Middletown Road / Westchester Avenue Westchester Square-East Tremont Avenue / Westchester Avenue Zerega Avenue / Westchester Avenue Castle Hill Avenue / Westchester Avenue Parkchester-E 177 St / Westchester Avenue Hunts Point Avenue / Southern Boulevard 3 Avenue-138 Street 125 Street / Lexington Avenue 116 Street / Lexington Avenue 110 Street / Lexington Avenue 103 Street / Lexington Avenue 96 Street / Lexington Avenue 86 Street / Lexington Avenue 77 Street / Lexington Avenue 68 Street-Hunter College / Lexington Avenue 59 Street / Lexington Avenue 51 Street / Lexington Avenue Grand Central-42 Street / Lexington Avenue 33 Street / Park Avenue South 28 Street / Park Avenue South 23 Street / Park Avenue South 14 Street-Union Square / 4 Avenue Astor Place / 4 Avenue Bleecker Street / Lafayette Street Spring Street / Lafayette Street Canal Street / Lafayette Street Brooklyn Bridge-City Hall / Centre Street Line (7) Flushing Local Flushing-Main Street / Roosevelt Avenue Willets Point-Shea Stadium / Roosevelt Avenue 111 Street / Roosevelt Avenue 103 Street-Corona Plaza / Roosevelt Avenue Junction Boulevard / Roosevelt Avenue 90 Street-Elmhurst Avenue / Roosevelt Avenue 82 Street-Jackson Heights / Roosevelt Avenue 74 Street-Broadway / Roosevelt Av 69 Street / Roosevelt Avenue Woodside-61Street / Roosevelt Avenue 52 Street / Roosevelt Avenue 46 Street / Queens Boulevard 40 Street / Queens Boulevard 33 Street / Queens Boulevard Queensboro Plaza / Queensboro Bridge 45 Road-Court House Square Hunters Point Avenue / 49 Avenue / 21 Street Vernon Boulevard- Jackson Avenue Grand Central-42 Street / Lexington Avenue 5 Avenue / 42 Street Times Square-42 Street / Broadway / 7 Avenue Line <7> Flushing Express Flushing- Main Street / Roosevelt Avenue Willets Point-Shea Stadium / Roosevelt Avenue Junction Boulevard / Roosevelt Avenue Woodside-61Street / Roosevelt Avenue Queensboro Plaza / Queensboro Bridge 45 Road-Courthouse Square Hunters Point Avenue / 49 Avenue / 21 Street Vernon Boulevard-Jackson Avenue Grand Central-42 Street / Lexington Avenue 5 Avenue / 42 Street Times Square-42 Street / Broadway / 7 Avenue Line (9) Broadway-7 Avenue Local Van Cortlandt Park-242 Street / Broadway 231 Street / Broadway Marble Hill-225 Street / Broadway 207 Street / 10 Avenue 191 Street / Saint Nicholas Avenue 181 Street / Saint Nicholas Avenue 168 Street- Washington Heights / Broadway 145 Street / Broadway 137 Street-City College / Broadway 125 Street / Broadway 116 Street- Columbia University / Broadway Cathedral Parkway (110 Street) / Broadway 103 Street / Broadway 96 Street / Broadway 86 Street / Broadway 79 Street / Broadway 72 Street / Broadway 66 Street-Lincoln Center / Broadway 59 Street-Columbus Circle / Broadway 50 Street / Broadway Times Square-42 Street / 7 Avenue-Broadway 34 Street-Penn Station / 7 Avenue 28 Street / 7 Avenue 23 Street / 7 Avenue 18 Street / 7 Avenue 14 Street / 7 Avenue Christopher Street-Sheridan Square / 7 Avenue South Houston Street / Varick Street Canal Street / Varick Street Franklin Street / Varick Street Chambers Street / West Broadway Cortlandt Street / West Broadway Rector Street South Ferry Line (A) 8 Avenue Express Inwood-207 Street / Broadway Dyckman Street / Broadway 190 Street / Fort Washington Avenue 181 Street / Fort Washington Avenue 175 Street / Fort Washington Avenue Washington Hts- 168 Street / Broadway 163 Street- Amsterdam Avenue / Saint Nicholas Avenue 155 Street / Saint Nicholas Avenue 145 Street / Saint Nicholas Avenue 135 Street / Saint Nicholas Avenue 125 Street / Saint Nicholas Avenue 116 Street / 8 Avenue Cathedral Parkway (110 Street) / Central Park West 103 Street / Central Park West 96 Street / Central Park West 86 Street / Central Park West 81 Street-Museum of Natural History / Central Park West 72 Street / Central Park West 59 Street- Columbus Circle / 8 Avenue 50 Street / 8 Avenue (Downtown only) 42 Street / 8 Avenue 34 Street-Penn Station / 8 Avenue 23 Street / 8 Avenue 14 Street / 8 Avenue West 4 Street / 6 Avenue Spring Street / 6 Avenue Canal Street / 6 Avenue Chambers Street / Church Street Broadway-Nassau Street / Fulton Street High Street / Cadman Plaza East Jay Street-Borough Hall / Fulton Mall Hoyt Street-Schermerhorn Street Lafayette Avenue / Fulton Street Clinton-Washington Avenues / Fulton Street Franklin Avenue / Fulton Street Nostrand Avenue / Fulton Street Kingston-Throop Avenues / Fulton Street Utica Avenue / Fulton Street Ralph Avenue / Fulton Street Rockaway Avenue / Fulton Street Broadway Junction (East New York) / Fulton Street Liberty Avenue / Pennsylvania Avenue Van Siclen Avenue / Pitkin Avenue Shepherd Avenue / Pitkin Avenue Euclid Avenue / Pitkin Avenue Grant Avenue / Pitkin Avenue 80 Street / Liberty Avenue 88 Street / Liberty Avenue Rockaway Boulevard / Liberty Avenue Rockaway Boulevard / Liberty Avenue 104 Street / Liberty Avenue 111 Street / Liberty Avenue Ozone Park-Lefferts Boulevard / Liberty Avenue Rockaway Boulevard / Liberty Avenue Aqueduct-North Conduit Avenue Howard Beach-JFK Airport / 159 Avenue Broad Channel Beach 67 Street / Rockaway Freeway Beach 60 Street / Rockaway Freeway Beach 44 Street / Rockaway Freeway Beach 36 Street / Rockaway Freeway Beach 25 Street / Rockaway Freeway Far Rockaway-Mott Avenue // Shuttle Service All Times Between Broad Channel and Rockaway Park / Beach 116 St Broad Channel Beach 90 Street / Rockaway Freeway Beach 98 Street / Rockaway Freeway Beach 105 Street / Rockaway Freeway Rockaway Park / Beach 116 Street Line (B) 6 Avenue Express Kingsbridge Road / Grand Concourse Fordham Road / Grand Concourse 182-183 Streets / Grand Concourse Tremont Avenue / Grand Concourse 174-175 Streets / Grand Concourse 170 Street / Grand Concourse 167 Street / Grand Concourse 161 Street-Yankee Stadium / River Avenue 155 Street / 8 Avenue 145 Street / Saint Nicholas Avenue 135 Street Saint Nicholas Avenue 125 Street / Saint Nicholas Avenue 116 Street / 8 Avenue Cathedral Parkway (110 Street) / Central Park West 103 Street / Central Park West 96 Street / Central Park West 86 Street / Central Park West 81 Street- Museum of Natural History / Central Park West 72 Street / Central Park West 59 Street-Columbus Circle / 8 Avenue 7 Avenue / 53 Sreet 47-50 Street- Rockefeller Center / 6 Avenue 42 St-Bryant Park / 6 Avenue 34 St-Herald Square / 6 Avenue West 4 Street-Washington Square / 6 Avenue Broadway-Lafayette Street / Houston Street Grand Street / Chrystie Street DeKalb Avenue / Flatbush Avenue Atlantic Avenue / Flatbush Avenue 7 Avenue / Flatbush Avenue Prospect Park / Empire Boulevard-Flatbush Avenue Church Avenue / East 18 Street Newkirk Avenue / East 16 Street Kings Highway / East 16 Street Sheepshead Bay / East 16 Street Brighton Beach / Brighton 6 Street Line (C) Eighth Avenue Express Washington Heights- 168 St / Broadway 163 Street-Amsterdam Avenue Saint Nicholas Avenue 155 Street / Saint Nicholas Avenue 145 Street / Saint Nicholas Avenue 135 Street / Saint Nicholas Avenue 125 Street / Saint Nicholas Avenue 116 Street / 8 Avenue Cathedral Parkway (110 Street) / Central Park West 103 Street / Central Park West 96 Street / Central Park West 86 Street / Central Park West 81 Street- Museum of Natural History / Central Park West 72 Street / Central Park West 59 Street-Columbus Circle / 8 Avenue 50 Street / 8 Avenue Downtown only 42 Street-Port Authority Bus Terminal / 8 Avenue 34 Street-Penn Station / 8 Avenue 23 Street / 8 Avenue 14 Street / 8 Avenue West 4 Street / Washington Square / 6 Avenue Spring Street / 6 Avenue Canal Street / 6 Avenue Chambers Street / Church Broadway-Nassau / Fulton Street High Street / Brooklyn Bridge / Cadman Plaza East Jay Street-Borough Hall / Fulton Mall Hoyt Street-Schermerhorn Street Lafayette Avenue / Fulton Street Clinton-Washington Avenues / Fulton Street Franklin Avenue / Fulton Street Nostrand Avenue / Fulton Street Kingston-Throop Avenues / Fulton Street Utica Avenue / Fulton Street Ralph Avenue / Fulton Street Rockaway Avenue / Fulton Street Broadway Junction (East New York) Fulton Street Liberty Avenue / Pennsylvania Avenue Van Siclen Avenue / Pitkin Avenue Shepherd Avenue / Pitkin Avenue Euclid Avenue / Pitkin Avenue Line (D) 6 Avenue Express 205 Street / Bainbridge Avenue Bedford Park Boulevard / Grand Concourse Kingsbridge Road / Grand Concourse Fordham Road / Grand Concourse 182-183 Streets / Grand Concourse Tremont Avenue / Grand Concourse 174-175 Streets / Grand Concourse 170 Street / Grand Concourse 167 Street / Grand Concourse 161 Street- Yankee Stadium / River Avenue 155 Street / 8 Avenue 145 Street / Saint Nicholas Avenue 125 Street / Saint Nicholas Avenue 59 Street- Columbus Circle / 8 Avenue 7 Avenue / 53 Street 47-50 Streets-RockfellerCenter / 6 Avenue 42 Street-Bryant Park / 6 Avenue 34 Street-Herald Square / 6 Avenue West 4 Street- Washington Square / 6 Avenue Broadway-Lafayette Street / Houston Street Grand Street / Chrystie Street DeKalb Avenue / Flatbush Avenue Pacific Street / 4 Avenue Union Street / 4 Avenue 9 Street / 4 Avenue Prospect Avenue / 4 Avenue 25 Street / 4 Avenue 36 Street / 4 Avenue 9 Avenue / 39 Street Fort Hamilton Parkway / New Utrecht Avenue 50 Street / New Utrecht Avenue 55 Street / New Utrecht Avenue 62 Street / New Utrecht Avenue 71 Street / New Utrecht Avenue 79 Street / New Utrecht Avenue 18 Avenue / New Utrecht Avenue 20 Avenue / 86 Street Bay Parkway / 86 Street 25 Avenue / 86 Street Bay 50 Street / Stillwell Avenue Line (E) 8 Avenue Local Jamaica Center-Parsons / Archer Avenue Sutphin Boulevard / Archer Avenue / JFK Airport Jamaica-Van Wyck / Queens Boulevard Briarwood-Van Wyck Boulevard / Main Street Kew Gardens, Union Turnpike / Queens Boulevard 75 Avenue / Queens Boulevard Forest Hills, 71 Avenue / Queens Boulevard 67 Avenue / Queens Boulevard 63 Drive-Rego Park / Queens Boulevard Woodhaven Boulevard / Queens Boulevard Grand Avenue-Newtown / Queens Boulevard Elmhurst Avenue / Broadway Jackson Heights-Roosevelt Avenue / Broadway 65 Street / Broadway Northern Boulevard / Broadway 46 Street / Broadway Steinway Street / Broadway 36 Street / Northern Boulevard Queens Plaza / Queens Boulevard 23 Street-Ely Avenue / 44 Drive Lexington Avenue / 53 Street 5 Avenue / 53 Street 7 Avenue / 53 Street 50 Street / 8 Avenue (downtown only) 42 Street-Port Authority Bus Terminal / 8 Avenue //wheelchair accessible 34 Street-Penn Station / 8 Avenue 23 Street / 8 Avenue 14 Street / 8 Avenue West 4 Street / 6 Avenue Spring Street / 6 Avenue Canal Street / 6 Avenue World Trade Center Line (F) 6 Avenue Local Jamaica-179 Street / Hillside Avenue 169 Street / Hillside Avenue Parsons Boulevard / Hillside Avenue Sutphin Boulevard / Hillside Avenue Briarwood / Van Wyck Boulevard / Main Street Kew Gardens,Union Turnpike / Queens Boulevard 75 Avenue / Queens Boulevard Forest Hills, 71 Av / Queens Boulevard Jackson Heights-Roosevelt Avenue / Broadway 21 Street-Queensbridge / 41 Avenue Roosevelt Island Lexington Av / 63 Street 57 Street / 6 Avenue 47-50 Streets-Rockefeller Center / 6 Avenue 42 Street-Bryant Park 34 Street-Herald Square / 6 Avenue 23 Street / 6 Avenue 14 Street / 6 Avenue West 4 Street / 6 Avenue Broadway-Lafayette Street / Houston Street Lower East Side-2 Avenue / Houston Street Delancey Street / Essex Street East Broadway / Canal Street-Rutgers Street York Street / Jay Street Jay Street-Borough Hall / Fulton Mall Bergen Street / Smith Street Carroll Street / Smith Street Smith-9 Streets 4 Avenue / 9 Street 7 Avenue / 9 Street 15 Street-Prospect Park / Prospect Park West Fort Hamilton Parkway / Prospect Avenue Church Avenue / McDonald Avenue Ditmas Avenue / McDonald Avenue 18 Avenue / McDonald Avenue Avenue I / McDonald Avenue Bay Parkway / McDonald Avenue Avenue N / McDonald Avenue Avenue P / McDonald Avenue Kings Highway / McDonald Avenue Avenue U / McDonald Avenue Avenue X / McDonald Avenue Line (G) Brooklyn-Queens Crosstown Local Forest Hills, 71 Av / Queens Boulevard 67 Avenue / Queens Boulevard 63 Drive-Rego Park / Queens Boulevard Woodhaven Boulevard / Queens Boulevard Grand Avenue-Newtown / Queens Boulevard Elmhurst Avenue / Broadway Jackson Heights-Roosevelt Avenue / Broadway 65 Street / Broadway Northern Boulevard / Broadway 46 Street / Broadway Steinway Street / Broadway 36 Street / Northern Boulevard Queens Plaza / Queens Boulevard Long Island City-Court Square / 45 Road 21 Street / Jackson Avenue Greenpoint Avenue / Manhattan Avenue Nassau Avenue / Manhattan Avenue Metropolitan Avenue / Grand Street Broadway / Union Avenue Flushing Avenue / Marcy Avenue Myrtle-Willoughby Avenues / Marcy Avenue Bedford-Nostrand Avenues / Lafayette Avenue Classon Avenue / Lafayette Avenue Clinton-Washington Avenues / Lafayette Avenue Fulton Street / Lafayette Avenue Hoyt Street-Schermerhorn Street Bergen Street / Smith Street Carroll Street / Smith Street Smith-9 Streets Line (J) Nassau Street Express Jamaica Center-Parsons / Archer Avenue Sutphin Boulevard / Archer Avenue / JFK Airport 121 Street / Jamaica Avenue 111 Street / Jamaica Avenue 104 Street / Jamaica Avenue Woodhaven Boulevard / Jamaica Avenue 85 Street-Forest Parkway / Jamaica Avenue 75 Street / Jamaica Avenue Cypress Hills / Jamaica Avenue Crescent Street / Fulton Street Norwood Avenue / Fulton Street Cleveland Street / Fulton Street Van Siclen Avenue / Fulton Street Alabama Avenue / Fulton Street Broadway Junction (Eastern Parkway) Chauncey Street / Broadway Halsey Street / Broadway Gates Avenue / Broadway Kosciuszko Street / Broadway Myrtle Avenue / Broadway Flushing Avenue / Broadway Lorimer Street / Broadway Hewes Street / Broadway Marcy Avenue / Broadway No Manhattan-bound service until June 2004 Essex Street / Delancey Street Bowery / Delancey Street Canal Street / Centre Street Chambers Street / Centre Street Fulton Street / Nassau Street Broad Street / Wall Street Line (L) 14 Street-Canarsie Local 8 Avenue / 14 Street 6 Avenue / 14 Street Union Square / Broadway - 14 Street 3 Avenue / 14 Street 1 Avenue / 14 Street Bedford Avenue / North 7 Street Lorimer Street / Metropolitan Avenue Graham Avenue / Metropolitan Avenue Grand Street / Bushwick Avenue Montrose Avenue / Bushwick Avenue Morgan Avenue / Harrison Place Jefferson Street / Wyckoff Avenue DeKalb Avenue / Wyckoff Avenue Myrtle Avenue / Wyckoff Avenue Halsey Street / Wyckoff Avenue Wilson Avenue / Moffat Street Bushwick Avenue-Aberdeen Street Broadway Junction (Eastern Parkway) Atlantic Avenue / Snediker Avenue / Van Sinderen Avenue Sutter Avenue / Van Sinderen Avenue Livonia Avenue / Van Sinderen Avenue New Lots Avenue / Van Sinderen Avenue East 105 Street / Turnbull Avenue Canarsie / Rockaway Parkway / Glenwood Road Line (M) Nassau Street Local Middle Village-Metropolitan Avenue / 67 Street Fresh Pond Road / 67 Avenue Forest Avenue / 67 Avenue Seneca Avenue / Palmetto Street Wyckoff Avenue / Myrtle Avenue Knickerbocker Avenue / Myrtle Avenue Central Avenue / Myrtle Avenue Myrtle Avenue / Broadway Flushing Avenue / Broadway Lorimer Street / Broadway Hewes Street / Broadway Marcy Avenue / Broadway No Manhattan-bound service until June 2004 Essex Street / Delancey Street Bowery / Delancey Street Canal Street / Centre Street Chambers Street / Centre Street Fulton Street / Broadway-Nassau Street Broad Street / Wall Street Court Street / Montague Street Lawrence Street- MetroTech / Willoughby Street DeKalb Avenue / Flatbush Avenue Pacific Street / 4 Avenue Union Street / 4 Avenue 9 Street / 4 Avenue Prospect Avenue / 4 Avenue 25 Street / 4 Avenue 36 Street / 4 Avenue 9 Avenue / 39 Street Fort Hamilton Parkway / New Utrecht Avenue 50 Street / New Utrecht Avenue 55 Street / New Utrecht Avenue 62 Street / New Utrecht Avenue 71 Street / New Utrecht Avenue 79 Street / New Utrecht Avenue 18 Avenue / New Utrecht Avenue 20 Avenue / 86 Street Bay Parkway / 86 Street Line (N) Broadway Express Broadway Express Astoria-Ditmars Boulevard / 31 Street Astoria Boulevard / 31 Street 30 Avenue / 31 Street Broadway / 31 Street 36 Avenue / 31 Street 39 Avenue / 31 Street Queensboro Plaza / Bridge Plaza Lexington Avenue / 59 Street 5 Avenue / 59 Street 57 Street / 7 Avenue 49 Street / 7 Avenue (North-bound only) 42 Street-Times Square / Broadway 34 Street-Herald Square / Broadway 28 Street / Broadway 23 Street / Broadway 14 Street-Union Square / Broadway 8 Street-New York University / Broadway Prince Street / Broadway Canal Street / Broadway City Hall / Broadway Cortlandt Street / Church Street (southbound only) Rector Street / Trinity Place Whitehall Street-South Ferry / Water Street Court Street-Borough Hall / Montague Street Lawrence Street-MetroTech / Willoughby Street DeKalb Avenue / Flatbush Avenue Pacific Street / 4 Avenue Union Street / 4 Avenue 9 Street / 4 Avenue Prospect Avenue / 4 Avenue 25 Street / 4 Avenue 36 Street / 4 Avenue 45 Street / 4 Avenue 53 Street / 4 Avenue 59 Street / 4 Avenue 8 Avenue / 62 Street Fort Hamilton Avenue / 62 Street New Utrecht Avenue / 62 Street 18 Avenue / 64 Street 20 Avenue / 64 Street Bay Parkway / West 7 Street Kings Highway / West 7 Street Avenue U / West 7 Street Gravesend-86 Street / West 7 Street Line (Q) Broadway Express 57 Street / 7 Avenue 42 Street / Times Square 34 Street-Herald Square / 6 Avenue 14 Street-Union Square / Broadway Canal Street / Broadway DeKalb Avenue / Flatbush Avenue Atlantic Avenue / Flatbush Avenue 7 Avenue / Flatbush Avenue Prospect Park / Empire Boulevard-Flatbush Avenue Parkside Avenue / Ocean Avenue Church Avenue / East 18 Street Beverley Road / East 16 Street Cortelyou Road / East 16 Street Newkirk Avenue / East 16 Street Avenue H / East 16 Street Avenue J / East 16 Street Avenue M / East 16 Street Kings Highway / East 16 Street Avenue U / East 16 Street Neck Road / East 16 Street Sheepshead Bay / East 16 Street Brighton Beach / Brighton 6 Street Line (R) Queens Boulevard / Broadway / 4 Avenue Local Forest Hills, 71 Avenue / Queens Boulevard 67 Avenue / Queens Boulevard 63 Drive / Rego Park / Queens Boulevard Woodhaven Boulevard / Queens Boulevard Grand Avenue / Newton / Queens Boulevard Elmhurst Avenue / Broadway Jackson Heights / Roosevelt Avenue / Broadway 65 Street / Broadway Northern Boulevard / Broadway 46 Street / Broadway Steinway Street / Broadway 36 Street / Northern Boulevard Queens Plaza / Queens Boulevard Lexington Avenue / 59 St 5 Avenue / 59-60 Streets 57 Street / 7 Avenue 49 Street / 7 Avenue (North-bound only) 42 Street-Times Square / Broadway 34 Street-Herald Square / Broadway 28 Street / Broadway 23 Street / Broadway 14 Street-Union Square / Broadway 8 Street-New York University / Broadway Prince Street / Broadway Canal Street / Broadway City Hall / Broadway Cortlandt Street / Church Street (southbound only) Rector Street / Trinity Place Whitehall Street-South Ferry / Water Street Court Street-Borough Hall / Montague Street Lawrence Street-MetroTech / Willoughby Street DeKalb Avenue / Flatbush Avenue Pacific Street / 4 Avenue Union Street / 4 Avenue 9 Street / 4 Avenue Prospect Avenue / 4 Avenue 25 Street / 4 Avenue 36 Street / 4 Avenue 45 Street / 4 Avenue // Late night northbound trains skip 45 St 53 Street / 4 Avenue // Late night northbound trains skip 53 St 59 Street / 4 Avenue Bay Ridge Avenue / 4 Avenue 77 Street / 4 Avenue 86 Street / 4 Avenue Bay Ridge-95 Street Line (S) 42 Street Shuttle 42 Street-Times Square / Broadway-7 Avenue 42 St-Grand Central / Park Avenue Line (S) Franklin Avenue Shuttle Franklin AvenueFulton Street Park PlaceFranklin AvenueClasson Avenue Botanic GardenEastern ParkwayFranklin Avenue Prospect ParkEmpire Boulevard Flatbush Avenue // (Manhattan-bound only) Line (S) Rockaway Park Shuttle Broad Channel Beach 90 StreetRockaway Freeway Beach 98 StreetRockaway Freeway Beach 105 StreetRockaway Freeway Rockaway Park-Beach 116 Street Line (V) Queens Boulevard / 6 Avenue Local Queens Boulevard / 6 Avenue Local Forest Hills, 71 Av / Queens Boulevard 67 Avenue / Queens Boulevard 63 Drive / Rego Park / Queens Boulevard Woodhaven Boulevard / Queens Boulevard Grand Avenue / Newtown / Queens Boulevard Elmhurst Avenue / Broadway Jackson Heights / Roosevelt Av / Broadway 65 Street / Broadway Northern Boulevard / Broadway 46 Street / Broadway Steinway Street / Broadway 36 Street / Northern Boulevard Queens Plaza / Queens Boulevard 23 Street-Ely Avenue / 44 Drive Lexington Avenue / 53 Street 5 Avenue / 53 Street 47-50 Streets-Rockefeller Center / 6 Avenue 42 Street-Bryant Park 34 Street-Herald Square / 6 Avenue // wheelchair accessible 23 Street / 6 Avenue 14 Street / 6 Avenue West 4 Street / 6 Avenue Broadway-Lafayette Street / Houston Street Lower East Side- 2 Avenue / Houston Street Line (W) Broadway Local Broadway Local Astoria-Ditmars Boulevard / 31 Street Astoria Boulevard / 31 Street 30 Avenue / 31 Street Broadway / 31 Street 36 Avenue / 31 Street 39 Avenue / 31 Street Queensboro Plaza / Bridge Plaza Lexington Avenue / 59 Street 5 Avenue / 59 Street 57 Street / 7 Avenue 49 Street / 7 Avenue (Northbound Only) 42 Street-Times Square / Broadway 34 Street-Herald Square / Broadway 28 Street / Broadway 23 Street / Broadway 14 Street-Union Square / Broadway 8 Street- New York University / Broadway Prince Street / Broadway Canal Street / Broadway City Hall / Broadway Cortlandt Street / Church Street // southbound only Rector Street / Trinity Place Whitehall Street- South Ferry / Broadway Line (Z) Nassau Street Express Jamaica Center-Parsons / Archer Avenue Sutphin Boulevard / Archer Avenue-JFK Airport 121 Street / Jamaica Avenue 104 Street / Jamaica Avenue Woodhaven Boulevard / Jamaica Avenue 75 Street / Jamaica Avenue Crescent Street / Fulton Street Norwood Avenue / Fulton Street Van Siclen Avenue / Fulton Street Broadway Junction (Eastern Parkway) Chauncey Street / Broadway Gates Avenue / Broadway Myrtle Avenue / Broadway Marcy Avenue / Broadway Essex Street / Delancey Street Bowery / Delancey Street Canal Street / Centre Street Chambers Street / Centre Street Fulton Street / Nassau Street Broad Street / Wall Street 2 | -------------------------------------------------------------------------------- /notes/compile.txt: -------------------------------------------------------------------------------- 1 | {subway} ← #.compile subway ⍝ Compile graph from ⍵.source. [subway] is a reference to a namespace containing a character array: [source]. The shy result is a reference to the same namespace, which after compilation contains two additional arrays: subway.graph - nested array representing the network graph. subway.labels - corresponding names of stations and subway-stops. The source editing function [ed] undoes the effect of compilation by removing subway.(graph labels). Technical notes: This description uses →source← as an example. Try: ed notes ⍝ ... to examine the source. and trace: compile notes ⍝ ... to watch it working. The workings of the compiler can be split into four phases: lex: extracts line, station identifiers, and line restriction codes from the source; extract: represents these in terms of indices into vectors of lines, stations and platforms and the links between them. merge: consolidates the various sections network-wide. install: installs graph and label arrays into the target namespace. Extensive use is made of two auxiliary functions [zip] and [cat]. zip←{↓⍉↑⍵} ⍝ transpose nested array. cat←{↑,/⍵} ⍝ concatenate arrays. See: →zip_cat← for details. Lexical phase ------------- The lexical phase results in parallel (having the same ⍴¨) nested vectors: lines - service names such as 'Circle' or 'Metro 1'. stats - station names: 'Paddington', 'Mælkevejen', ... ctrls - one-way '↓', fork '∊' or cross '+' control characters. lines stats ctrls←zip zip¨{ ⍝ first pass: source → line sections. vecs←{↓⎕FMT↑⍵} ⍝ normalise source to vector-of-vectors. rcom←{(∧\⍵≠'/')/⍵} ⍝ remove comments '/ ···' from line. rbls←{(∨/¨' '≠⍵)/⍵} ⍝ remove blanks lines: '' '' ··· segt←{(' '≠⊃¨⍵)⊂⍵} ⍝ segment at non-blank first column. trim←{(∨\⍵≠' ')/⍵}{⌽⍺⍺⌽⍺⍺ ⍵} ⍝ remove blanks, fore and aft. tupl←'+↓∊'{⍺(trim ⍵~⍺⍺)(⍺⍺∩⍵)} ⍝ tupl: (line stat ctrl). tups←{(⊂trim⊃⍵)tupl¨1↓⍵} ⍝ tuples: tupl tupl ···. tups¨segt rbls rcom¨vecs ⍵ ⍝ line segments. }⍵.source Each but the last line defines a local function and the final line applies these to the source argument. An alternative but more obscure coding would be to replace the names in the final line, with the definitions themselves, resulting in a longish one-liner. Of particular interest: vecs←{↓⎕FMT↑⍵} ⍝ normalise source to vector-of-vectors. accepts any of: a character matrix, a nested vector of vectors, or a character vector with embedded line-feeds and returns an equivalent nested vector-of- vectors. Notice also, the functions: trim←{(∨\⍵≠' ')/⍵}{⌽⍺⍺⌽⍺⍺ ⍵} ⍝ remove blanks, fore and aft. derived from function {(∨\⍵≠' ')/⍵}, bound with operator {⌽⍺⍺⌽⍺⍺ ⍵}. Note also: tupl←'+↓∊'{⍺(trim ⍵~⍺⍺)(⍺⍺∩⍵)} ⍝ tupl: (line stat ctrl). is an [array] '+↓∊', bound with an operator {⍺(trim ⍵~⍺⍺)(⍺⍺∩⍵)}. [tupl] could have been defined as the simple function {⍺(trim ⍵~'+↓∊')('+↓∊'∩⍵)}, at the expense of duplicating the constant '+↓∊' or naming it in a separate definition. Function [tups] distributes the line label at the head (⊃⍵) of each section, to each station in the remainer (1↓⍵). tups←{(⊂trim⊃⍵)tupl¨1↓⍵} ⍝ tuples: tupl tupl ···. An alternative, ⎕ML-independent, coding of (⊂trim⊃⍵), would be (trim¨1↑⍵). Compiling →source←, we get: disp lines ┌→──────────────────┬─────────────────────────┬───────────────────────────────────────────┐ │┌→────┬─────┬─────┐│┌→────┬─────┬─────┬─────┐│┌→─────┬──────┬──────┬──────┬──────┬──────┐│ ││Fruit│Fruit│Fruit│││Fruit│Fruit│Fruit│Fruit│││Veggie│Veggie│Veggie│Veggie│Veggie│Veggie││ │└────→┴────→┴────→┘│└────→┴────→┴────→┴────→┘│└─────→┴─────→┴─────→┴─────→┴─────→┴─────→┘│ └──────────────────→┴────────────────────────→┴──────────────────────────────────────────→┘ disp stats ┌→────────────────────┬─────────────────────────┬────────────────────────────────────────────┐ │┌→────┬──────┬──────┐│┌→────┬──────┬────┬─────┐│┌→──────┬─────┬──────┬───────┬─────┬───────┐│ ││Apple│Tomato│Banana│││Grape│Tomato│Pear│Grape│││Spinach│Onion│Tomato│Lettuce│Onion│Cabbage││ │└────→┴─────→┴─────→┘│└────→┴─────→┴───→┴────→┘│└──────→┴────→┴─────→┴──────→┴────→┴──────→┘│ └────────────────────→┴────────────────────────→┴───────────────────────────────────────────→┘ disp ctrls ┌→──────┬──────────┬─────────────┐ │┌→┬─┬─┐│┌→┬──┬─┬─┐│┌→┬─┬─┬─┬─┬─┐│ ││ │∊│ │││↓│↓∊│↓│ │││ │+│ │ │+│ ││ │└⊖┴→┴⊖┘│└→┴─→┴→┴⊖┘│└⊖┴→┴⊖┴⊖┴→┴⊖┘│ └──────→┴─────────→┴────────────→┘ Extraction phase ---------------- This phase generates various working arrays. A particular feature, the "cross", is processed at this stage. Crosses occur where different sections of the same line criss-cross a station in different directions. An example is London Under- ground's station at Poplar on the Docklands Light Railway (DLR). The coss stop is augmented with extra stops for each line direction. For example, the stop at Poplar (DLR Poplar) is replaced with "virtual" stops (DLR Poplar_N-S) and (DLR Poplar_E-W). We do this by marking each stop with an additional label, which is 0 for non-crossing stops and a unique sequence number [csids] for crossing stat- ions. In this way, the stops remain disctinct in the unique stops vector (see below). seqs←{(⍳¨⍵)+0,+\¯1↓⍵} ⍝ sequences of sequences. csids←{⍵\¨seqs+/¨⍵}'+'∊¨¨ctrls ⍝ stations marked as cross-tracks. disp ctrls ┌→──────┬──────────┬─────────────┐ │┌→┬─┬─┐│┌→┬──┬─┬─┐│┌→┬─┬─┬─┬─┬─┐│ ││ │∊│ │││↓│↓∊│↓│ │││ │+│ │ │+│ ││ │└⊖┴→┴⊖┘│└→┴─→┴→┴⊖┘│└⊖┴→┴⊖┴⊖┴→┴⊖┘│ └──────→┴─────────→┴────────────→┘ disp csids ┌→────┬───────┬───────────┐ │0 0 0│0 0 0 0│0 1 0 0 2 0│ └~───→┴~─────→┴~─────────→┘ Next, define [stops], a vector of stops per line section. stops←zip¨zip lines stats csids ⍝ subway stops. Notice the distinct cross stops: (Veggie Onion 1), (Veggie Onion 2): disp stops ┌→──────────────────────────────────────────────────┬─────────────────────────────────────────────────────────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │┌→──────────────┬────────────────┬────────────────┐│┌→──────────────┬────────────────┬──────────────┬───────────────┐│┌→─────────────────┬────────────────┬─────────────────┬──────────────────┬────────────────┬──────────────────┐│ ││┌→────┬─────┬─┐│┌→────┬──────┬─┐│┌→────┬──────┬─┐│││┌→────┬─────┬─┐│┌→────┬──────┬─┐│┌→────┬────┬─┐│┌→────┬─────┬─┐│││┌→─────┬───────┬─┐│┌→─────┬─────┬─┐│┌→─────┬──────┬─┐│┌→─────┬───────┬─┐│┌→─────┬─────┬─┐│┌→─────┬───────┬─┐││ │││Fruit│Apple│0│││Fruit│Tomato│0│││Fruit│Banana│0│││││Fruit│Grape│0│││Fruit│Tomato│0│││Fruit│Pear│0│││Fruit│Grape│0│││││Veggie│Spinach│0│││Veggie│Onion│1│││Veggie│Tomato│0│││Veggie│Lettuce│0│││Veggie│Onion│2│││Veggie│Cabbage│0│││ ││└────→┴────→┴─┘│└────→┴─────→┴─┘│└────→┴─────→┴─┘│││└────→┴────→┴─┘│└────→┴─────→┴─┘│└────→┴───→┴─┘│└────→┴────→┴─┘│││└─────→┴──────→┴─┘│└─────→┴────→┴─┘│└─────→┴─────→┴─┘│└─────→┴──────→┴─┘│└─────→┴────→┴─┘│└─────→┴──────→┴─┘││ │└──────────────→┴───────────────→┴───────────────→┘│└──────────────→┴───────────────→┴─────────────→┴──────────────→┘│└─────────────────→┴───────────────→┴────────────────→┴─────────────────→┴───────────────→┴─────────────────→┘│ └──────────────────────────────────────────────────→┴────────────────────────────────────────────────────────────────→┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────→┘ Most stops have a platform for each direction, the "up-line" '^', and the "down- line" '∨'. The platform vectors come from the outer product: ···∘.,'^∨'. One-way sections are processed later. plats←{↓⍵∘.,'^∨'}¨stops ⍝ platform for each direction. disp plats ┌→──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │┌→────────────────────────────────────┬───────────────────────────────────────┬───────────────────────────────────────┐│┌→────────────────────────────────────┬───────────────────────────────────────┬───────────────────────────────────┬─────────────────────────────────────┐│┌→──────────────────────────────────────────┬───────────────────────────────────────┬─────────────────────────────────────────┬───────────────────────────────────────────┬───────────────────────────────────────┬───────────────────────────────────────────┐│ ││┌→────────────────┬─────────────────┐│┌→─────────────────┬──────────────────┐│┌→─────────────────┬──────────────────┐│││┌→────────────────┬─────────────────┐│┌→─────────────────┬──────────────────┐│┌→───────────────┬────────────────┐│┌→────────────────┬─────────────────┐│││┌→───────────────────┬────────────────────┐│┌→─────────────────┬──────────────────┐│┌→──────────────────┬───────────────────┐│┌→───────────────────┬────────────────────┐│┌→─────────────────┬──────────────────┐│┌→───────────────────┬────────────────────┐││ │││┌→────┬─────┬─┬─┐│┌→────┬─────┬─┬─┐│││┌→────┬──────┬─┬─┐│┌→────┬──────┬─┬─┐│││┌→────┬──────┬─┬─┐│┌→────┬──────┬─┬─┐│││││┌→────┬─────┬─┬─┐│┌→────┬─────┬─┬─┐│││┌→────┬──────┬─┬─┐│┌→────┬──────┬─┬─┐│││┌→────┬────┬─┬─┐│┌→────┬────┬─┬─┐│││┌→────┬─────┬─┬─┐│┌→────┬─────┬─┬─┐│││││┌→─────┬───────┬─┬─┐│┌→─────┬───────┬─┬─┐│││┌→─────┬─────┬─┬─┐│┌→─────┬─────┬─┬─┐│││┌→─────┬──────┬─┬─┐│┌→─────┬──────┬─┬─┐│││┌→─────┬───────┬─┬─┐│┌→─────┬───────┬─┬─┐│││┌→─────┬─────┬─┬─┐│┌→─────┬─────┬─┬─┐│││┌→─────┬───────┬─┬─┐│┌→─────┬───────┬─┬─┐│││ ││││Fruit│Apple│0│^│││Fruit│Apple│0│∨│││││Fruit│Tomato│0│^│││Fruit│Tomato│0│∨│││││Fruit│Banana│0│^│││Fruit│Banana│0│∨│││││││Fruit│Grape│0│^│││Fruit│Grape│0│∨│││││Fruit│Tomato│0│^│││Fruit│Tomato│0│∨│││││Fruit│Pear│0│^│││Fruit│Pear│0│∨│││││Fruit│Grape│0│^│││Fruit│Grape│0│∨│││││││Veggie│Spinach│0│^│││Veggie│Spinach│0│∨│││││Veggie│Onion│1│^│││Veggie│Onion│1│∨│││││Veggie│Tomato│0│^│││Veggie│Tomato│0│∨│││││Veggie│Lettuce│0│^│││Veggie│Lettuce│0│∨│││││Veggie│Onion│2│^│││Veggie│Onion│2│∨│││││Veggie│Cabbage│0│^│││Veggie│Cabbage│0│∨││││ │││└────→┴────→┴─┴─┘│└────→┴────→┴─┴─┘│││└────→┴─────→┴─┴─┘│└────→┴─────→┴─┴─┘│││└────→┴─────→┴─┴─┘│└────→┴─────→┴─┴─┘│││││└────→┴────→┴─┴─┘│└────→┴────→┴─┴─┘│││└────→┴─────→┴─┴─┘│└────→┴─────→┴─┴─┘│││└────→┴───→┴─┴─┘│└────→┴───→┴─┴─┘│││└────→┴────→┴─┴─┘│└────→┴────→┴─┴─┘│││││└─────→┴──────→┴─┴─┘│└─────→┴──────→┴─┴─┘│││└─────→┴────→┴─┴─┘│└─────→┴────→┴─┴─┘│││└─────→┴─────→┴─┴─┘│└─────→┴─────→┴─┴─┘│││└─────→┴──────→┴─┴─┘│└─────→┴──────→┴─┴─┘│││└─────→┴────→┴─┴─┘│└─────→┴────→┴─┴─┘│││└─────→┴──────→┴─┴─┘│└─────→┴──────→┴─┴─┘│││ ││└────────────────→┴────────────────→┘│└─────────────────→┴─────────────────→┘│└─────────────────→┴─────────────────→┘│││└────────────────→┴────────────────→┘│└─────────────────→┴─────────────────→┘│└───────────────→┴───────────────→┘│└────────────────→┴────────────────→┘│││└───────────────────→┴───────────────────→┘│└─────────────────→┴─────────────────→┘│└──────────────────→┴──────────────────→┘│└───────────────────→┴───────────────────→┘│└─────────────────→┴─────────────────→┘│└───────────────────→┴───────────────────→┘││ │└────────────────────────────────────→┴──────────────────────────────────────→┴──────────────────────────────────────→┘│└────────────────────────────────────→┴──────────────────────────────────────→┴──────────────────────────────────→┴────────────────────────────────────→┘│└──────────────────────────────────────────→┴──────────────────────────────────────→┴────────────────────────────────────────→┴──────────────────────────────────────────→┴──────────────────────────────────────→┴──────────────────────────────────────────→┘│ └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────→┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────→┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────→┘ We now have enough information to label all vertices (stations and platforms) of the final graph. verts←∪cat cat¨stats(cat plats) ⍝ graph vertices. disp verts ┌→────┬──────┬──────┬─────┬────┬───────┬─────┬───────┬───────┬─────────────────┬─────────────────┬──────────────────┬──────────────────┬──────────────────┬──────────────────┬─────────────────┬─────────────────┬────────────────┬────────────────┬────────────────────┬────────────────────┬──────────────────┬──────────────────┬───────────────────┬───────────────────┬────────────────────┬────────────────────┬──────────────────┬──────────────────┬────────────────────┬────────────────────┐ │ │ │ │ │ │ │ │ │ │┌→────┬─────┬─┬─┐│┌→────┬─────┬─┬─┐│┌→────┬──────┬─┬─┐│┌→────┬──────┬─┬─┐│┌→────┬──────┬─┬─┐│┌→────┬──────┬─┬─┐│┌→────┬─────┬─┬─┐│┌→────┬─────┬─┬─┐│┌→────┬────┬─┬─┐│┌→────┬────┬─┬─┐│┌→─────┬───────┬─┬─┐│┌→─────┬───────┬─┬─┐│┌→─────┬─────┬─┬─┐│┌→─────┬─────┬─┬─┐│┌→─────┬──────┬─┬─┐│┌→─────┬──────┬─┬─┐│┌→─────┬───────┬─┬─┐│┌→─────┬───────┬─┬─┐│┌→─────┬─────┬─┬─┐│┌→─────┬─────┬─┬─┐│┌→─────┬───────┬─┬─┐│┌→─────┬───────┬─┬─┐│ │Apple│Tomato│Banana│Grape│Pear│Spinach│Onion│Lettuce│Cabbage││Fruit│Apple│0│^│││Fruit│Apple│0│∨│││Fruit│Tomato│0│^│││Fruit│Tomato│0│∨│││Fruit│Banana│0│^│││Fruit│Banana│0│∨│││Fruit│Grape│0│^│││Fruit│Grape│0│∨│││Fruit│Pear│0│^│││Fruit│Pear│0│∨│││Veggie│Spinach│0│^│││Veggie│Spinach│0│∨│││Veggie│Onion│1│^│││Veggie│Onion│1│∨│││Veggie│Tomato│0│^│││Veggie│Tomato│0│∨│││Veggie│Lettuce│0│^│││Veggie│Lettuce│0│∨│││Veggie│Onion│2│^│││Veggie│Onion│2│∨│││Veggie│Cabbage│0│^│││Veggie│Cabbage│0│∨││ │ │ │ │ │ │ │ │ │ │└────→┴────→┴─┴─┘│└────→┴────→┴─┴─┘│└────→┴─────→┴─┴─┘│└────→┴─────→┴─┴─┘│└────→┴─────→┴─┴─┘│└────→┴─────→┴─┴─┘│└────→┴────→┴─┴─┘│└────→┴────→┴─┴─┘│└────→┴───→┴─┴─┘│└────→┴───→┴─┴─┘│└─────→┴──────→┴─┴─┘│└─────→┴──────→┴─┴─┘│└─────→┴────→┴─┴─┘│└─────→┴────→┴─┴─┘│└─────→┴─────→┴─┴─┘│└─────→┴─────→┴─┴─┘│└─────→┴──────→┴─┴─┘│└─────→┴──────→┴─┴─┘│└─────→┴────→┴─┴─┘│└─────→┴────→┴─┴─┘│└─────→┴──────→┴─┴─┘│└─────→┴──────→┴─┴─┘│ └────→┴─────→┴─────→┴────→┴───→┴──────→┴────→┴──────→┴──────→┴────────────────→┴────────────────→┴─────────────────→┴─────────────────→┴─────────────────→┴─────────────────→┴────────────────→┴────────────────→┴───────────────→┴───────────────→┴───────────────────→┴───────────────────→┴─────────────────→┴─────────────────→┴──────────────────→┴──────────────────→┴───────────────────→┴───────────────────→┴─────────────────→┴─────────────────→┴───────────────────→┴───────────────────→┘ Before the merging phase, we need vectors of graph-platform indices and pairs of graph-station indices: platx←{↓verts⍳↑⍵}¨plats ⍝ platform indices within graph. statx←{2/¨verts⍳⍵}¨stats ⍝ station indices within graph. disp platx ┌→──────────────────┬─────────────────────────┬─────────────────────────────────────┐ │┌→────┬─────┬─────┐│┌→────┬─────┬─────┬─────┐│┌→────┬─────┬─────┬─────┬─────┬─────┐│ ││10 11│12 13│14 15│││16 17│12 13│18 19│16 17│││20 21│22 23│24 25│26 27│28 29│30 31││ │└~───→┴~───→┴~───→┘│└~───→┴~───→┴~───→┴~───→┘│└~───→┴~───→┴~───→┴~───→┴~───→┴~───→┘│ └──────────────────→┴────────────────────────→┴────────────────────────────────────→┘ disp statx ┌→────────────┬─────────────────┬─────────────────────────┐ │┌→──┬───┬───┐│┌→──┬───┬───┬───┐│┌→──┬───┬───┬───┬───┬───┐│ ││1 1│2 2│3 3│││4 4│2 2│5 5│4 4│││6 6│7 7│2 2│8 8│7 7│9 9││ │└~─→┴~─→┴~─→┘│└~─→┴~─→┴~─→┴~─→┘│└~─→┴~─→┴~─→┴~─→┴~─→┴~─→┘│ └────────────→┴────────────────→┴────────────────────────→┘ It is convenient at this stage to extract a vector of unique line indices, which will be used later to collect the sections of each line. (Sections of track for a particular line are not necessarily adjacent in the source code). linex←{(∪⍵)⍳⍵}⊃¨lines ⍝ line indices per segment. disp linex 1 1 2 Having accommodated cross-track restrictions, the merging phase is now interest- ed only in one-way sections and forks, so an array of 2-bools is extracted: rests←'↓∊'∘∊¨¨ctrls ⍝ restrictions: 1-way sects and forks. disp rests ┌→────────────┬─────────────────┬─────────────────────────┐ │┌→──┬───┬───┐│┌→──┬───┬───┬───┐│┌→──┬───┬───┬───┬───┬───┐│ ││0 0│0 1│0 0│││1 0│1 1│1 0│0 0│││0 0│0 0│0 0│0 0│0 0│0 0││ │└~─→┴~─→┴~─→┘│└~─→┴~─→┴~─→┴~─→┘│└~─→┴~─→┴~─→┴~─→┴~─→┴~─→┘│ └────────────→┴────────────────→┴────────────────────────→┘ Merging phase ------------- For each section of track, the stops are examined pair-wise, and links between adjacent stops established. The links take account of one-way sections and forks. plinks←cat¨2{ ⍝ platform-to-platform links / section. ··· }/¨zip¨zip platx rests ⍝ pairwise for each line section. The expression (zip¨zip platx rests) produces a vector per line section of pairs of platform indices and track restrictions. For the middle section (for example) of the sample →source←: Source Platx Map ------ ----- --- ↓ Grape 16 - 17 T ∊↓ Tomato 12 - 13 ┌─┴─┐ ↓ Pear 18 - 19 ↑ ↓ Grape 16 - 17 │ │ G─←─P this looks like: disp 2⊃zip¨zip platx rests ⍝ (middle section) ┌→──────────┬───────────┬───────────┬───────────┐ │┌→────┬───┐│┌→────┬───┐│┌→────┬───┐│┌→────┬───┐│ ││16 17│1 0│││12 13│1 1│││18 19│1 0│││16 17│0 0││ │└~───→┴~─→┘│└~───→┴~─→┘│└~───→┴~─→┘│└~───→┴~─→┘│ └──────────→┴──────────→┴──────────→┴──────────→┘ Platforms 16 and 17 at the first stop are at the entrance to a one-way section as are platforms 12 and 13 in addition to being on the handle of a fork. Items of the vector are processed two at a time, delivered as left and right arguments to the the operand function: links((ow fk)_)←zip ⍺ ⍵ ⍝ directions and restrictions. rev←{⌽⍵}\ ⍝ reverse second pair. oway←{⍺:1↑⍵ ⋄ rev ⍵} ⍝ one-way section. fork←{⍺:⌽zip rev ⍵ ⋄ zip ⍵} ⍝ fork. ow oway fk fork links ⍝ ⍺←→⍵ links. For the first call, the values of the arguments are: disp ⍺ ⍵ ┌→──────────┬───────────┐ │┌→────┬───┐│┌→────┬───┐│ ││16 17│1 0│││12 13│1 1││ │└~───→┴~─→┘│└~───→┴~─→┘│ └──────────→┴──────────→┘ Notice the use of "structure assignment" to name parts of the link structure. As restrictions on only the entry side of the link are relevant, those on the exit side are ignored by being assigned a "sink" name '_'. links((ow fk)_)←zip ⍺ ⍵ ⍝ directions and restrictions. disp links ┌→────┬─────┐ │16 17│12 13│ └~───→┴~───→┘ disp ow fk ⍝ one-way and fork markers. 1 0 Auxiliary function: rev←{⌽⍵}\ ⍝ reverse second pair. reverses the second link in a pair, to model up-line, down-line directions. In this example, platforms 16→12, and 13→17, are linked. disp rev zip links ┌→────┬─────┐ │16 12│13 17│ └~───→┴~───→┘ Auxiliary functions: [oway] and [fork] apply corresponding line restrictions: oway←{⍺:1↑⍵ ⋄ rev ⍵} ⍝ one-way section. fork←{⍺:⌽zip rev ⍵ ⋄ zip ⍵} ⍝ fork. so that expression: ow oway fk fork links ⍝ ⍺←→⍵ links. returns a vector of one or two links, in this case the single link 16→12: disp ow oway fk fork links ┌→────┐ │16 12│ └~───→┘ The resulting vector [plinks] is a set of platform-to-platform links for the whole network. disp plinks ┌→────────────────────────┬───────────────────┬─────────────────────────────────────────────────────────────┐ │┌→────┬─────┬─────┬─────┐│┌→────┬─────┬─────┐│┌→────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐│ ││10 12│13 11│13 14│15 12│││16 12│13 18│18 16│││20 22│23 21│22 24│25 23│24 26│27 25│26 28│29 27│28 30│31 29││ │└~───→┴~───→┴~───→┴~───→┘│└~───→┴~───→┴~───→┘│└~───→┴~───→┴~───→┴~───→┴~───→┴~───→┴~───→┴~───→┴~───→┴~───→┘│ └────────────────────────→┴──────────────────→┴────────────────────────────────────────────────────────────→┘ Next, using the line section index vector from above, line sections are grouped by line prior to being consolidated. clinks←((∪linex)=⊂linex)/¨⊂plinks ⍝ link sections collected by line. disp clinks ┌→──────────────────────────────────────────────┬───────────────────────────────────────────────────────────────┐ │┌→────────────────────────┬───────────────────┐│┌→────────────────────────────────────────────────────────────┐│ ││┌→────┬─────┬─────┬─────┐│┌→────┬─────┬─────┐│││┌→────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐││ │││10 12│13 11│13 14│15 12│││16 12│13 18│18 16│││││20 22│23 21│22 24│25 23│24 26│27 25│26 28│29 27│28 30│31 29│││ ││└~───→┴~───→┴~───→┴~───→┘│└~───→┴~───→┴~───→┘│││└~───→┴~───→┴~───→┴~───→┴~───→┴~───→┴~───→┴~───→┴~───→┴~───→┘││ │└────────────────────────→┴──────────────────→┘│└────────────────────────────────────────────────────────────→┘│ └──────────────────────────────────────────────→┴──────────────────────────────────────────────────────────────→┘ The final sub-phase is to connect all sections for the same line. This is achieved by applying a "connecting" reduction along the vector of sub-sections for each line, after which we can concatenate all line sections, network-wide. llinks←cat↑{ ⍝ connected sections for all lines. ··· ⍝ (connect adjacent link vectors). }/¨clinks ⍝ for each section of each line. However, connecting sections by just concatenating the vectors will not work, as this might result in the up-line of one sub-section's being connected to the down-line of its neighbour. ···───→───∘───→───∘─→ ? ←─∘───←───∘───←───··· │ │ │ │ Line A: ⎕ ⎕ ⎕ ⎕ Line A: │ │ │ │ ···───←───∘───←───∘─← ? →─∘───→───∘───→───··· In this case, we must twist the direction of links at the join. ···───→───∘───┐ ┌─∘─←───←─∘───←───∘───←───··· │ ↓ ↓ │ │ │ Line A: ⎕ ┌─│─┘ ⎕ ⎕ ⎕ Line A: │ ↓ ↓ │ │ │ ···───←───∘─┘ └─→─∘─→───→─∘───→───∘───→───··· For the first line of →source←, the two sub-sections are: disp ⊃clinks ┌→────────────────────────┬───────────────────┐ │┌→────┬─────┬─────┬─────┐│┌→────┬─────┬─────┐│ ││10 12│13 11│13 14│15 12│││16 12│13 18│18 16││ │└~───→┴~───→┴~───→┴~───→┘│└~───→┴~───→┴~───→┘│ └────────────────────────→┴──────────────────→┘ Notice that there are links: 10→12, 15→12 and 16→12, but no link [from] 12. In this case there is a clash: llinks←cat↑{ ⍝ connected sections for all lines. next←⍺~⍵ ⍝ next section, duplicates removed. disp¨next ⍵ ┌→────┬─────┬─────┬─────┐ ┌→────┬─────┬─────┐ │10 12│13 11│13 14│15 12│ │16 12│13 18│18 16│ └~───→┴~───→┴~───→┴~───→┘ └~───→┴~───→┴~───→┘ clash←↑∪zip∩⌿↑zip¨next ⍵ ⍝ incompatible directions. disp clash 13 12 We can avoid the clash if we exchange all occurrences of 13 and 12 in the first set of links. To take a slightly larger example, when connecting London's Picadilly line (as coded here), there are two clashes: disp next ┌→──────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┐ │444 446│447 445│446 448│449 447│448 450│451 449│450 452│453 451│452 454│455 453│454 456│457 455│456 458│459 457│458 460│461 459│460 462│463 461│462 464│465 463│464 466│467 465│466 468│469 467│468 470│471 469│470 472│473 471│473 474│475 472│474 476│477 475│476 478│479 477│478 480│481 479│480 482│483 481│482 484│485 483│484 486│487 485│486 488│489 487│ └~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┘ disp ⍵ ┌→──────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┐ │490 488│489 492│492 490│494 496│497 495│496 498│499 497│498 500│501 499│500 502│503 501│502 504│505 503│504 506│507 505│506 508│509 507│508 510│511 509│510 512│513 511│512 514│515 513│514 516│517 515│516 518│519 517│518 520│521 519│520 522│523 521│522 524│525 523│524 526│527 525│526 528│529 527│528 530│531 529│530 532│533 531│532 534│535 533│534 536│537 535│536 538│539 537│538 540│541 539│540 542│543 541│542 544│545 543│544 546│547 545│546 472│473 547│ └~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┴~─────→┘ disp clash 473 472 489 488 disp verts[clash] ┌→────────────────────────────┬─────────────────────────────┐ ↓ ┌→─────────┬──────────┬─┬─┐ │ ┌→─────────┬──────────┬─┬─┐ │ │ │Piccadilly│Acton Town│0│∨│ │ │Piccadilly│Acton Town│0│^│ │ │ └─────────→┴─────────→┴─┴─┘ │ └─────────→┴─────────→┴─┴─┘ │ ├────────────────────────────→┼────────────────────────────→┤ │┌→─────────┬────────────┬─┬─┐│┌→─────────┬────────────┬─┬─┐│ ││Piccadilly│Hatton Cross│0│∨│││Piccadilly│Hatton Cross│0│^││ │└─────────→┴───────────→┴─┴─┘│└─────────→┴───────────→┴─┴─┘│ └────────────────────────────→┴────────────────────────────→┘ We must exchange all occurrences of 472←→473 and 488←→489. To do this, we make a difference matrix of the values to [add] to each index. diffs←⍉¯1 1∘.×-/clash ⍝ vertex index differences. disp diffs ¯1 1 ¯1 1 [avecs] is then, a vector of adjustments to add to the [next] section indices: avecs←↑+/,diffs×clash=⊂next ⍝ adjustment vectors. disp avecs ┌→──┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬────┬────┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬────┐ │0 0│0 0│0 0│0 0│0 0│0 0│0 0│0 0│0 0│0 0│0 0│0 0│0 0│0 0│0 0│0 0│0 0│0 0│0 0│0 0│0 0│0 0│0 0│0 0│0 0│0 0│0 1│¯1 0│¯1 0│0 1│0 0│0 0│0 0│0 0│0 0│0 0│0 0│0 0│0 0│0 0│0 0│0 0│0 1│¯1 0│ └~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~──→┴~──→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~─→┴~──→┘ and finally, the adjusted indices vector is joined to the right argument accum- ulated link vector for the line. (next+avecs),⍵ ⍝ connected line subsections. As the outer function reduction proceeds, all sub-sections for each line are aligned and on exit from the reduction, sections for all lines are consolidated. llinks←cat↑{ ⍝ connected sections for all lines. For the →source← example, this results in: disp llinks ┌→────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐ │10 13│12 11│12 14│15 13│16 12│13 18│18 16│20 22│23 21│22 24│25 23│24 26│27 25│26 28│29 27│28 30│31 29│ └~───→┴~───→┴~───→┴~───→┴~───→┴~───→┴~───→┴~───→┴~───→┴~───→┴~───→┴~───→┴~───→┴~───→┴~───→┴~───→┴~───→┘ Installation phase ------------------ In this phase, the final [graph] and [labels] vectors are installed in the target namespace. [slinks] is a set of links (stat plat) (stat plat) ···, from each station to each of its platforms. slinks←cat zip¨zip cat¨statx platx ⍝ (stat plat) ··· links. disp slinks ┌→───┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┐ │1 10│1 11│2 12│2 13│3 14│3 15│4 16│4 17│2 12│2 13│5 18│5 19│4 16│4 17│6 20│6 21│7 22│7 23│2 24│2 25│8 26│8 27│7 28│7 29│9 30│9 31│ └~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┘ [elinks] is a matrix with one row for links in each direction: elinks←,0 1∘.⌽slinks ⍝ station-platform each-way links. disp elinks ┌→───┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┐ ↓1 10│1 11│2 12│2 13│3 14│3 15│4 16│4 17│2 12│2 13│5 18│5 19│4 16│4 17│6 20│6 21│7 22│7 23│2 24│2 25│8 26│8 27│7 28│7 29│9 30│9 31│ ├~──→┼~──→┼~──→┼~──→┼~──→┼~──→┼~──→┼~──→┼~──→┼~──→┼~──→┼~──→┼~──→┼~──→┼~──→┼~──→┼~──→┼~──→┼~──→┼~──→┼~──→┼~──→┼~──→┼~──→┼~──→┼~──→┤ │10 1│11 1│12 2│13 2│14 3│15 3│16 4│17 4│12 2│13 2│18 5│19 5│16 4│17 4│20 6│21 6│22 7│23 7│24 2│25 2│26 8│27 8│28 7│29 7│30 9│31 9│ └~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┘ [nlinks] is the sorted set of unique links for the whole subway network. nlinks←{⍵[⍋↑⍵]}∪(,elinks),llinks ⍝ combined network-wide links. disp nlinks ┌→───┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬─────┬────┬────┬─────┬─────┬────┬─────┬────┬────┬─────┬────┬─────┬────┬────┬─────┬────┬────┬─────┬────┬────┬─────┬────┬─────┬────┬─────┬────┬─────┬────┬─────┬────┬─────┬────┬─────┬────┬─────┬────┬────┬─────┐ │1 10│1 11│2 12│2 13│2 24│2 25│3 14│3 15│4 16│4 17│5 18│5 19│6 20│6 21│7 22│7 23│7 28│7 29│8 26│8 27│9 30│9 31│10 1│10 13│11 1│12 2│12 11│12 14│13 2│13 18│14 3│15 3│15 13│16 4│16 12│17 4│18 5│18 16│19 5│20 6│20 22│21 6│22 7│22 24│23 7│23 21│24 2│24 26│25 2│25 23│26 8│26 28│27 8│27 25│28 7│28 30│29 7│29 27│30 9│31 9│31 29│ └~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~───→┴~──→┴~──→┴~───→┴~───→┴~──→┴~───→┴~──→┴~──→┴~───→┴~──→┴~───→┴~──→┴~──→┴~───→┴~──→┴~──→┴~───→┴~──→┴~──→┴~───→┴~──→┴~───→┴~──→┴~───→┴~──→┴~───→┴~──→┴~───→┴~──→┴~───→┴~──→┴~───→┴~──→┴~───→┴~──→┴~──→┴~───→┘ Finally, [⍵.graph] is installed: ⍵.graph←↑{(⍺≠¯1⌽⍺)⊂⍵}/zip nlinks ⍝ network graph. The first item of each pair in [nlinks] determines the position within [graph] of the placement of the second item. So graph[1]←10, graph[1],←11, graph[2]←12, and so on. disp ⍵.graph ┌→────┬───────────┬─────┬─────┬─────┬─────┬───────────┬─────┬─────┬────┬─┬───────┬────┬─┬────┬────┬─┬────┬─┬────┬─┬────┬────┬────┬────┬────┬────┬────┬────┬─┬────┐ │10 11│12 13 24 25│14 15│16 17│18 19│20 21│22 23 28 29│26 27│30 31│1 13│1│2 11 14│2 18│3│3 13│4 12│4│5 16│5│6 22│6│7 24│7 21│2 26│2 23│8 28│8 25│7 30│7 27│9│9 29│ └~───→┴~─────────→┴~───→┴~───→┴~───→┴~───→┴~─────────→┴~───→┴~───→┴~──→┴→┴~─────→┴~──→┴→┴~──→┴~──→┴→┴~──→┴→┴~──→┴→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴~──→┴→┴~──→┘ The labels (or tags) vector for each vertex is now produced. Firstly, a set of labels for each stop: stags←2/⌽¨2↑¨∪cat stops ⍝ (stop line) label pairs. disp stags ┌→────────────┬─────────────┬──────────────┬──────────────┬──────────────┬──────────────┬─────────────┬─────────────┬────────────┬────────────┬────────────────┬────────────────┬──────────────┬──────────────┬───────────────┬───────────────┬────────────────┬────────────────┬──────────────┬──────────────┬────────────────┬────────────────┐ │┌→────┬─────┐│┌→────┬─────┐│┌→─────┬─────┐│┌→─────┬─────┐│┌→─────┬─────┐│┌→─────┬─────┐│┌→────┬─────┐│┌→────┬─────┐│┌→───┬─────┐│┌→───┬─────┐│┌→──────┬──────┐│┌→──────┬──────┐│┌→────┬──────┐│┌→────┬──────┐│┌→─────┬──────┐│┌→─────┬──────┐│┌→──────┬──────┐│┌→──────┬──────┐│┌→────┬──────┐│┌→────┬──────┐│┌→──────┬──────┐│┌→──────┬──────┐│ ││Apple│Fruit│││Apple│Fruit│││Tomato│Fruit│││Tomato│Fruit│││Banana│Fruit│││Banana│Fruit│││Grape│Fruit│││Grape│Fruit│││Pear│Fruit│││Pear│Fruit│││Spinach│Veggie│││Spinach│Veggie│││Onion│Veggie│││Onion│Veggie│││Tomato│Veggie│││Tomato│Veggie│││Lettuce│Veggie│││Lettuce│Veggie│││Onion│Veggie│││Onion│Veggie│││Cabbage│Veggie│││Cabbage│Veggie││ │└────→┴────→┘│└────→┴────→┘│└─────→┴────→┘│└─────→┴────→┘│└─────→┴────→┘│└─────→┴────→┘│└────→┴────→┘│└────→┴────→┘│└───→┴────→┘│└───→┴────→┘│└──────→┴─────→┘│└──────→┴─────→┘│└────→┴─────→┘│└────→┴─────→┘│└─────→┴─────→┘│└─────→┴─────→┘│└──────→┴─────→┘│└──────→┴─────→┘│└────→┴─────→┘│└────→┴─────→┘│└──────→┴─────→┘│└──────→┴─────→┘│ └────────────→┴────────────→┴─────────────→┴─────────────→┴─────────────→┴─────────────→┴────────────→┴────────────→┴───────────→┴───────────→┴───────────────→┴───────────────→┴─────────────→┴─────────────→┴──────────────→┴──────────────→┴───────────────→┴───────────────→┴─────────────→┴─────────────→┴───────────────→┴───────────────→┘ Each label is merged with indentation ' ' and separation ' ' vectors. Incorp- orating the blanks at this stage, simpilfies the merging code in the [trip] function, later. slabs←cat¨zip¨zip(⊂4 1↑¨⊂'')stags ⍝ indented stop labels. disp slabs ┌→───────────────────┬────────────────────┬─────────────────────┬─────────────────────┬─────────────────────┬─────────────────────┬────────────────────┬────────────────────┬───────────────────┬───────────────────┬───────────────────────┬───────────────────────┬─────────────────────┬─────────────────────┬──────────────────────┬──────────────────────┬───────────────────────┬───────────────────────┬─────────────────────┬─────────────────────┬───────────────────────┬───────────────────────┐ │┌→───┬─────┬─┬─────┐│┌→───┬─────┬─┬─────┐│┌→───┬──────┬─┬─────┐│┌→───┬──────┬─┬─────┐│┌→───┬──────┬─┬─────┐│┌→───┬──────┬─┬─────┐│┌→───┬─────┬─┬─────┐│┌→───┬─────┬─┬─────┐│┌→───┬────┬─┬─────┐│┌→───┬────┬─┬─────┐│┌→───┬───────┬─┬──────┐│┌→───┬───────┬─┬──────┐│┌→───┬─────┬─┬──────┐│┌→───┬─────┬─┬──────┐│┌→───┬──────┬─┬──────┐│┌→───┬──────┬─┬──────┐│┌→───┬───────┬─┬──────┐│┌→───┬───────┬─┬──────┐│┌→───┬─────┬─┬──────┐│┌→───┬─────┬─┬──────┐│┌→───┬───────┬─┬──────┐│┌→───┬───────┬─┬──────┐│ ││ │Apple│ │Fruit│││ │Apple│ │Fruit│││ │Tomato│ │Fruit│││ │Tomato│ │Fruit│││ │Banana│ │Fruit│││ │Banana│ │Fruit│││ │Grape│ │Fruit│││ │Grape│ │Fruit│││ │Pear│ │Fruit│││ │Pear│ │Fruit│││ │Spinach│ │Veggie│││ │Spinach│ │Veggie│││ │Onion│ │Veggie│││ │Onion│ │Veggie│││ │Tomato│ │Veggie│││ │Tomato│ │Veggie│││ │Lettuce│ │Veggie│││ │Lettuce│ │Veggie│││ │Onion│ │Veggie│││ │Onion│ │Veggie│││ │Cabbage│ │Veggie│││ │Cabbage│ │Veggie││ │└───→┴────→┴→┴────→┘│└───→┴────→┴→┴────→┘│└───→┴─────→┴→┴────→┘│└───→┴─────→┴→┴────→┘│└───→┴─────→┴→┴────→┘│└───→┴─────→┴→┴────→┘│└───→┴────→┴→┴────→┘│└───→┴────→┴→┴────→┘│└───→┴───→┴→┴────→┘│└───→┴───→┴→┴────→┘│└───→┴──────→┴→┴─────→┘│└───→┴──────→┴→┴─────→┘│└───→┴────→┴→┴─────→┘│└───→┴────→┴→┴─────→┘│└───→┴─────→┴→┴─────→┘│└───→┴─────→┴→┴─────→┘│└───→┴──────→┴→┴─────→┘│└───→┴──────→┴→┴─────→┘│└───→┴────→┴→┴─────→┘│└───→┴────→┴→┴─────→┘│└───→┴──────→┴→┴─────→┘│└───→┴──────→┴→┴─────→┘│ └───────────────────→┴───────────────────→┴────────────────────→┴────────────────────→┴────────────────────→┴────────────────────→┴───────────────────→┴───────────────────→┴──────────────────→┴──────────────────→┴──────────────────────→┴──────────────────────→┴────────────────────→┴────────────────────→┴─────────────────────→┴─────────────────────→┴──────────────────────→┴──────────────────────→┴────────────────────→┴────────────────────→┴──────────────────────→┴──────────────────────→┘ ... prefaced by simple station labels. ⍵.labels←(∪cat stats),slabs ⍝ station/stop labels. disp ⍵.labels ┌→────┬──────┬──────┬─────┬────┬───────┬─────┬───────┬───────┬────────────────────┬────────────────────┬─────────────────────┬─────────────────────┬─────────────────────┬─────────────────────┬────────────────────┬────────────────────┬───────────────────┬───────────────────┬───────────────────────┬───────────────────────┬─────────────────────┬─────────────────────┬──────────────────────┬──────────────────────┬───────────────────────┬───────────────────────┬─────────────────────┬─────────────────────┬───────────────────────┬───────────────────────┐ │ │ │ │ │ │ │ │ │ │┌→───┬─────┬─┬─────┐│┌→───┬─────┬─┬─────┐│┌→───┬──────┬─┬─────┐│┌→───┬──────┬─┬─────┐│┌→───┬──────┬─┬─────┐│┌→───┬──────┬─┬─────┐│┌→───┬─────┬─┬─────┐│┌→───┬─────┬─┬─────┐│┌→───┬────┬─┬─────┐│┌→───┬────┬─┬─────┐│┌→───┬───────┬─┬──────┐│┌→───┬───────┬─┬──────┐│┌→───┬─────┬─┬──────┐│┌→───┬─────┬─┬──────┐│┌→───┬──────┬─┬──────┐│┌→───┬──────┬─┬──────┐│┌→───┬───────┬─┬──────┐│┌→───┬───────┬─┬──────┐│┌→───┬─────┬─┬──────┐│┌→───┬─────┬─┬──────┐│┌→───┬───────┬─┬──────┐│┌→───┬───────┬─┬──────┐│ │Apple│Tomato│Banana│Grape│Pear│Spinach│Onion│Lettuce│Cabbage││ │Apple│ │Fruit│││ │Apple│ │Fruit│││ │Tomato│ │Fruit│││ │Tomato│ │Fruit│││ │Banana│ │Fruit│││ │Banana│ │Fruit│││ │Grape│ │Fruit│││ │Grape│ │Fruit│││ │Pear│ │Fruit│││ │Pear│ │Fruit│││ │Spinach│ │Veggie│││ │Spinach│ │Veggie│││ │Onion│ │Veggie│││ │Onion│ │Veggie│││ │Tomato│ │Veggie│││ │Tomato│ │Veggie│││ │Lettuce│ │Veggie│││ │Lettuce│ │Veggie│││ │Onion│ │Veggie│││ │Onion│ │Veggie│││ │Cabbage│ │Veggie│││ │Cabbage│ │Veggie││ │ │ │ │ │ │ │ │ │ │└───→┴────→┴→┴────→┘│└───→┴────→┴→┴────→┘│└───→┴─────→┴→┴────→┘│└───→┴─────→┴→┴────→┘│└───→┴─────→┴→┴────→┘│└───→┴─────→┴→┴────→┘│└───→┴────→┴→┴────→┘│└───→┴────→┴→┴────→┘│└───→┴───→┴→┴────→┘│└───→┴───→┴→┴────→┘│└───→┴──────→┴→┴─────→┘│└───→┴──────→┴→┴─────→┘│└───→┴────→┴→┴─────→┘│└───→┴────→┴→┴─────→┘│└───→┴─────→┴→┴─────→┘│└───→┴─────→┴→┴─────→┘│└───→┴──────→┴→┴─────→┘│└───→┴──────→┴→┴─────→┘│└───→┴────→┴→┴─────→┘│└───→┴────→┴→┴─────→┘│└───→┴──────→┴→┴─────→┘│└───→┴──────→┴→┴─────→┘│ └────→┴─────→┴─────→┴────→┴───→┴──────→┴────→┴──────→┴──────→┴───────────────────→┴───────────────────→┴────────────────────→┴────────────────────→┴────────────────────→┴────────────────────→┴───────────────────→┴───────────────────→┴──────────────────→┴──────────────────→┴──────────────────────→┴──────────────────────→┴────────────────────→┴────────────────────→┴─────────────────────→┴─────────────────────→┴──────────────────────→┴──────────────────────→┴────────────────────→┴────────────────────→┴──────────────────────→┴──────────────────────→┘ The target namespace is returned as a shy result for use by the [trip] function. 1:shy←⍵ ⍝ shy result: namespace ref. See also: →trip← →path← →ed← →zip_cat← 2 | --------------------------------------------------------------------------------