From 85220c553c6884e20a35811072c49e0807ab08eb Mon Sep 17 00:00:00 2001 From: Xie Yuheng Date: Sat, 24 Aug 2024 21:24:19 +0800 Subject: [PATCH] [cps] [subway] `createSubway` --- TODO.md | 5 +++-- src/cps/subway/Subway.ts | 26 ++++++++++++++++++++++++-- src/cps/subway/index.ts | 2 ++ src/cps/subways/bostonSubway.ts | 26 ++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 src/cps/subways/bostonSubway.ts diff --git a/TODO.md b/TODO.md index f3e36d1..cb08132 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,7 @@ -[cps] [subway] `createSubway` -[cps] [subway] `defineLine` +[cps] [subway] `defineLine` -- take a ordered list of stations + [cps] [subway] `defineStation` + [cps] [subway] define `bostonSubway` [cps] [problem-space] [subway] `SubwayProblemSpace` & `createSubwayProblemSpace` diff --git a/src/cps/subway/Subway.ts b/src/cps/subway/Subway.ts index bfac07c..6627b2c 100644 --- a/src/cps/subway/Subway.ts +++ b/src/cps/subway/Subway.ts @@ -1,7 +1,29 @@ export type Line = string export type Station = string +export type Position = string + export type Subway = { - lineMap: Map }>, - stationMap: Map }>, + name: string, + lineMap: Map< + Line, + { + stations: Array + } + > + stationMap: Map< + Station, + { + lines: Set + position: Position + } + > +} + +export function createSubway(name: string): Subway { + return { + name, + lineMap: new Map(), + stationMap: new Map(), + } } diff --git a/src/cps/subway/index.ts b/src/cps/subway/index.ts index c5f767d..92440c5 100644 --- a/src/cps/subway/index.ts +++ b/src/cps/subway/index.ts @@ -1 +1,3 @@ export * from "./Subway.js" +export * from "./defineLine.js" +export * from "./defineStation.js" diff --git a/src/cps/subways/bostonSubway.ts b/src/cps/subways/bostonSubway.ts new file mode 100644 index 0000000..dfe57ca --- /dev/null +++ b/src/cps/subways/bostonSubway.ts @@ -0,0 +1,26 @@ +import { createSubway } from "../subway/index.js" + +export const bostonSubway = createSubway("boston-subway") + +// defineLine(bostonSubway, "red-line") +// defineLine(bostonSubway, "green-line") +// defineLine(bostonSubway, "orange-line") +// defineLine(bostonSubway, "blue-line") + +// defineStation(bostonSubway, "airport", ["blue-line"], 4.0, 1.0)) +// defineStation(bostonSubway, "aquarium", ["blue-line"], 3.75, 0.1)) +// defineStation(bostonSubway, "wood-island", ["blue-line"], 5.0, 2.0)) +// defineStation(bostonSubway, "state", ["blue-line", "orange-line"], 3.1, -0.75)) + +// defineStation(bostonSubway, "park-street", ["green-line", "red-line"], 2.5, -0.5)) +// defineStation(bostonSubway, "government-center", ["green-line", "blue-line"], 2.9, -0.25)) +// defineStation(bostonSubway, "copley-square", ["green-line",], 1.0, -1.0)) +// defineStation(bostonSubway, "boston-u", ["green-line",], -1.0, -1.0)) +// defineStation(bostonSubway, "north-station", ["green-line", "orange-line"], 2.5, 0.75)) +// defineStation(bostonSubway, "haymarket", ["orange-line" "green-line",], 2.75, 0.5)) + +// defineStation(bostonSubway, "south-station", ["red-line"], 3.0, -1.0) +// defineStation(bostonSubway, "washington", ["red-line", "orange-line"], 2.75, -0.75) +// defineStation(bostonSubway, "kendall-square", ["red-line"], 1.0, 0.0) +// defineStation(bostonSubway, "central-square", ["red-line"], -1.0, 0.0) +// defineStation(bostonSubway, "harvard-square", ["red-line"], -2.0, 1.0)