Exemplo n.º 1
0
        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);
                });
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 public NodeWithParent(Node node, NodeWithParent parent, string parentConnection) : base(node.NodeId)
 {
     Connections      = node.Connections;
     ParentNode       = parent;
     ParentConnection = parentConnection;
 }