Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The best way to do this I think is by calculating all valid paths of length at most <em>k</em> between the source <em>S</em> and every other node, then using that information to calculate all valid paths of length at most <em>k+1</em>. You then just repeat this until you get a fixed point where no paths are modified.</p> <p>In practice, this means you should set up a list of paths at each node. At each step, you take each node <em>U</em> in turn and look at the paths that, in the previous step, terminated at some neighbour <em>V</em> of <em>U</em>. If any of those paths can be extended to be a new, distinct path to <em>U</em>, extend it and add it to <em>U</em>'s list.</p> <p>If when you execute a step you find no new paths, that's your termination state. You can then check the list of paths at the target node <em>T</em>.</p> <p>Pseudocode (in a very loose C# formalism):</p> <pre><code>var paths = graph.nodes.ToDictionary(node =&gt; node, node =&gt; new List&lt;List&lt;node&gt;&gt;()) paths[S].Add(new List&lt;node&gt; {S}) // The trivial path that'll start us off. bool notAFixedPoint = true; while (notAFixedPoint) { notAFixedPoint = false // Assume we're not gonna find any new paths. foreach (var node in graph) { var pathsToNode = paths[node] foreach (var neighbour in node.Neighbours) { var pathsToNeighbour = paths[neighbour] // ExtendPaths is where all the logic about how to recognise a valid path goes. var newPathsToNode = ExtendPaths(pathsToNeighbour, node) // The use of "Except" here is for expository purposes. It wouldn't actually work, // because collections in most languages are compared by reference rather than by value. if (newPathsToNode.Except(pathsToNode).IsNotEmpty()) { // We've found some new paths, so we can't terminate yet. notAFixedPoint = true pathsToNode.AddMany(newPathsToNode) } } } } return paths[T] </code></pre>
    singulars
    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. 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