Skip to content

Commit

Permalink
[cps] [refactoring] merge branch and edgeApply into sprout -- s…
Browse files Browse the repository at this point in the history
…prout a node
  • Loading branch information
xieyuheng committed Aug 25, 2024
1 parent aab09fd commit 01599e8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
7 changes: 6 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
[cps] [space] [subway] `createSubwaySpace` -- fix `branch` and `edgeApply`
[cps] [refactoring] rename `ramify` to `branch` -- branch a path

[cps] [space] [subway] `createSubwaySpace`

- `branch` -- 找到一站相邻的点
- `edgeApply` -- 平凡的根据 edge 找到下一个节点

[cps] [space] add debug options

Expand Down
9 changes: 3 additions & 6 deletions src/problems/subway/SubwaySpace.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Space } from "../../solvers/cps"
import { type Space } from "../../solvers/cps/index.js"
import { type LineId, type StationId } from "./Subway.js"

export type TakeLine = {
Expand All @@ -14,11 +14,8 @@ export function createSubwaySpace(initialStationId: StationId): SubwaySpace {
name: "SubwaySpace",
nodeIsEnd: (stationId) => stationId === initialStationId,
nodeEqual: (left, right) => left === right,
branch: (stationId) => {
throw new Error("TODO")
},
edgeApply: (takeLine, stationId) => {
throw new Error("TODO")
sprout: () => {
throw new Error()
},
}
}
5 changes: 2 additions & 3 deletions src/solvers/cps/Path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ export function pathHasLoop<Edge, Node>(path: Path<Edge, Node>): boolean {
export function ramify<Edge, Node>(
path: Path<Node, Edge>,
): Array<Path<Node, Edge>> {
const edges = path.space.branch(path.current)
const newPaths = edges.map((edge) =>
extendPath(path, edge, path.space.edgeApply(edge, path.current)),
const newPaths = path.space.sprout(path.current).map(([edge, node]) =>
extendPath(path, edge, node),
)
return newPaths.filter((newPath) => !pathHasLoop(newPath))
}
3 changes: 1 addition & 2 deletions src/solvers/cps/Space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ export type Space<Node, Edge> = {
name: string
nodeIsEnd: (node: Node) => boolean
nodeEqual: (left: Node, right: Node) => boolean
branch: (node: Node) => Array<Edge>
edgeApply: (edge: Edge, node: Node) => Node
sprout: (node: Node) => Array<[Edge, Node]>
}

0 comments on commit 01599e8

Please sign in to comment.