Model Train-related Notes Blog -- these are personal notes and musings on the subject of model train control, automation, electronics, or whatever I find interesting. I also have more posts in a blog dedicated to the maintenance of the Randall Museum Model Railroad.
2022-04-26 - Conductor 2: Route sequence graph in Kotlin DSLCategory Rtac
Going to change the way a route sequence graph is defined in Conductor 2 from:
nodes = listOf(
listOf(B311_start, B321_fwd, B311_rev),
listOf(B321_fwd, B330_fwd, B321_rev, B311_rev),
nodes = listOf(B311_start, B321_fwd, B311_rev)
branches += listOf(B321_fwd, B330_fwd, B321_rev, B311_rev)
The current one being either a single-list or a list-of-lists is clumsy, yet more importantly it does not define what a graph really represents. In our sequence, we really have a main linear path, and then some additional extra branches. That’s really what the list-of-list represents, and all lists are not equal:
- The main linear sequence contains all the nodes to go through, from start to finish. The first node is the implicit starting node. All nodes are “new” and inserted in the graph.
- A branch is grafted on an existing graph between existing nodes. The start and the end nodes of the branch are not new nodes -- at the contrary, they must exist already.
Since these lists have different semantics, they should be defined using different keywords.
For the branches, we can use a more natural “branches +=” syntax to add them.
Graph representation in memory?
- Graph is directed. We don’t need distance/cost.
- We don’t need node vs vertex objects, only nodes.
- Do we need single or bidirectional? ⇒ have from+to, either being optional.
- [from?] → [this] → [to?]
- Using linked list with 0/1 incoming node + 0+ outgoing nodes.
- Start node has no “from” (in main sequence or branch).
- End node has no “to” (in main sequence or branch).