Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Looking at this picture</p> <p><img src="https://i.stack.imgur.com/UDipK.png" alt="junctions"></p> <p>It appears your problem would be represented well by a <a href="http://en.wikipedia.org/wiki/Directed_graph" rel="noreferrer">directed graph</a>. Give each stop and each junction <strong>two</strong> nodes in the graph, one for each direction of the train. <a href="http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm" rel="noreferrer">Dijkstra's algorithm</a> works perfectly on directed graphs, so once you have the problem in that form, the rest is easy.</p> <p>So for example, in the picture above, starting from <code>A</code>, we move to <code>junction 1</code>. From there, there's only one place to move to, <code>junction 2</code>, so there'd be an arrow from <code>A</code> --> <code>junction 1</code> and an arrow from <code>junction 1</code> --> <code>junction 2</code>. Regardless of which choice you make, you end up at <code>junction 1</code>, but moving in the other direction, so we create a separate node from there. From there, you have the option of going to <code>A</code> or <code>B</code>.</p> <p><img src="https://i.stack.imgur.com/Ok54W.png" alt="graph"></p> <p>Notice that I removed one of the <code>J1</code>'s, since it is superfluous <em>(there's only one place to go)</em>.</p> <p>If the train can stop and turn around at stops like <code>A</code>, we can connect those two nodes by edges in both directions, or just combine them into one node.</p> <p>You can give the edges weights to specify distances.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload