Tracing a railroad line in my Kansas Railroads wiki

All,

I’ve been playing around with some code today to trace a given railroad line in a contiguous fashion from one station to the next and putting the results in a table (see code & example output below). So far, so good. Note: each track segment is in its own tiddler with a tag of trackage and a tag of the railroad that built that segment. Each tiddler has a “to” field and a “from” field to hold the names of the ends of the segment.

One of the things I’ve been trying to figure out this afternoon is how to sum all of the mileages to have a total length. I have not been able to find a way to do this yet. I’ve been looking at the reduce filter run prefix and the accumulator variable, but I don’t think that will work in this case because I’m entering and exiting the list widget multiple times.

For a railroad that has a single, contiguous line summing the mileages is easy because I would just sum up all of the trackage tiddlers in a separate step. However, there are many times where a railroad has branches that go off in different directions or the railroad has several disjointed segments. The included procedure does not handle these cases so I’m trying to think ahead. The included procedure also only handles one direction (does not handle starting in the middle).

I’m looking for assistance in how to:

  1. Extend this procedure to branches and disjointed segments.
  2. Sum the mileage for a given segment.

Thanks very much for reading and any suggestions you may have. Please let me know if you have any questions or I need to include something else.

\procedure trace-forward(trackage)
  <$let
    company={{{ [<trackage>get[company]] }}}
    nextfrom={{{ [<trackage>get[to]] }}}
    >
    <$list filter="[tag[trackage]company<company>from<nextfrom>track[C]]">
      <tr>
        <td><$transclude $tiddler=<<currentTiddler>> $field="from" /></td>
        <td><$transclude $tiddler=<<currentTiddler>> $field="to" /></td>
        <td style="text-align: right; padding-right: 1em;"><$transclude $tiddler=<<currentTiddler>> $field="mileage" /></td>
        <td><$transclude $tiddler=<<trackage>> $field="date" /></td>
      </tr>
      <$transclude $variable="trace-forward"  trackage=<<currentTiddler>> />
    </$list>
  </$let>
\end

\procedure trace(trackage)
<table style="caption-side: top;">
  <caption style="text-align: left;">Construction trace:</caption>
  <tr>
    <th>From</th>
    <th>To</th>
    <th>Miles</th>
    <th>Completed</th>
  </tr>
  <tr>
    <td><$transclude $tiddler=<<trackage>> $field="from" /></td>
    <td><$transclude $tiddler=<<trackage>> $field="to" /></td>
    <td style="text-align: right; padding-right: 1em;"><$transclude $tiddler=<<trackage>> $field="mileage" /></td>
    <td><$transclude $tiddler=<<trackage>> $field="date" /></td>
  </tr>
  <$transclude $variable="trace-forward"  trackage=<<trackage>> />
</table>
\end

image

No actual help, but it’s impressive stuff!

1 Like

I will need to give it more thought, however to handle a trace surely you need to know from where to where, and some how to decide down which path you are going to travel, and how to deal with loops.

I have long wanted to use tiddlywiki to go beyond flat, or hierarchical data but also delve into what we may call a network of data. This is infact a “train network”.

Perhaps try Einstein’s approach and imagine yourself on a train traveling down the track, what do you need to know before hand or at each step. You may be aware that in a network there are circles and loops, branches that exit and return to the main line.

  • I expect you may need to define a journey (to and from) and if necessary which of more than one route you can or choose to take.
  • With this information it should be simple to follow a route and sum the total.

Its just a train set for big boys :nerd_face:

I was originally hoping to be able to detect these traces automatically without any upfront knowledge of the beginning or end points. However, I’m starting to think that this isn’t realistic. There are just too many variables. I may need to rethink how I handle the track segments if I want this kind of functionality.

It’s also a train set for big boys whose wife isn’t keen on having the space for a real train set.

I was trying to put this into graph theory, making sure I understand your layout. Your [tag[trackage]] tiddlers are for each track segment (edges) with the From|To (nodes) as fields? Trackage tiddlers would consist of A through E in the example below?

Exactly right. Nice visualization.

I’m still trying to figure out what you are looking to end up with. Given @john.edw_gmail.com’s example, do you want to take as input, “Sublette” and “Ulysses” and return A.length + D.length + E.length, to find the minimum length from Sublette to Ulysses? Or do you want to take this whole set of stations and return A.length + B.length + C.length + D.length + E.length, to find the total length of tracks in the system? Or are you looking for something else?

If the former, it would probably be easiest to write in in a JS module, but the problem is solved by Dijkstra’s Algorithm.

If the latter, then it’s much simpler, just find the track sections, remove duplicates, and sum up their lengths.

If it’s something else, can you tell us what?

I think if you found the right algorithiums you may have solved some long standing problems in mathematics like the travling salesman problem.

However in the real world if you know where to go from (where are you now) and where are you going to its a good start. There are common ways to reduce the complexity.

  • I imagin you are familular with other rail systems like paris underground. They have lines and directions, where the direction is the end points of the line.

Wether or not the kansas railways does this or not consistently, you could introduce some information to each station about the lines and directions. With this information you will be well on your way to a solution without knowing every switch etc… Perhaps only stick to time tabled published. Journeys. If you dont have this info make it up.

The above should make the system deterministic allowing you to trace or route however networks are notorious for complexity, as Is the biggest one we know, the internet. Yet the internet works quite well. As a result it can give us clues, one of the main clues is the use of weights and costs for segments which helps choose between two paths. This may also include information about a station if you must stop or can pass through like express trains.

I have IT networking skills and may be able to help you on your “rail journey” :sunglasses:

The Traveling Salesman problem is much harder. Here it would be something like: Given a large collection of stations (in a connected graph), find the shortest path to visit all of them.

Here, I think, we just want the shortest path between just two stations.

Actualy I think it is simpler even than that;

The length of the path between two nominated locations, taking the default route.

But @HistoryBuff can answer this!

1 Like

@Scott_Sauyet and @TW_Tones

Thanks for your questions and comments. I’m going to have to noodle these for a bit as I’ve lost the bubble on why I started down this path in the first place (it’s been one of those weeks).

3 Likes