private void FindNodesForPath(NodeWithParent node, List <int> endNodes, List <NodeWithParent> parentSolution) { if (!node.Connections.Any() && endNodes.Contains(node.NodeId)) { _pathSolutions.Add(parentSolution); } if (parentSolution.Count > 100) { return; } foreach (var connection in node.Connections) { var nodes = connection.Value; Parallel.ForEach(nodes, childNode => { var partialResult = parentSolution == null ? new List <NodeWithParent>() : new List <NodeWithParent>(parentSolution); var child = new NodeWithParent(childNode, node, connection.Key); partialResult.Add(child); FindNodesForPath(child, endNodes, partialResult); }); } }
public List <List <NodeWithParent> > FindPaths(Node startNode, List <int> endNodes) { _pathSolutions.Clear(); var parent = new NodeWithParent(startNode, null, null); var parentSolution = new List <NodeWithParent> { parent }; FindNodesForPath(parent, endNodes, parentSolution); return(_pathSolutions); }
public NodeWithParent(Node node, NodeWithParent parent, string parentConnection) : base(node.NodeId) { Connections = node.Connections; ParentNode = parent; ParentConnection = parentConnection; }