public static IPath FindPath(this IGraph graph, Node source, Node target, Dfs.Direction direction)
 {
     return(graph.FindPath(new Node[1]
     {
         source
     }, (Node x) => x == target, direction));
 }
예제 #2
0
        /// \anchor FindPath_Main Finds a path in a graph from a source node to a target node.
        /// \param source The set of source nodes.
        /// \param target A function determining whether a node belongs to the set of target nodes.
        /// \param direction The direction of the Dfs used to search for the path.
        /// \return A path from a source node to a target node, or \e null if none exists.
        public static IPath FindPath(this IGraph graph, IEnumerable <Node> source, Func <Node, bool> target,
                                     Dfs.Direction direction)
        {
            var dfs = new PathDfs()
            {
                PathDirection = direction, IsTarget = target
            };

            dfs.Run(graph, source);
            if (dfs.EndNode == Node.Invalid)
            {
                return(null);
            }

            var result = new Path(graph);

            result.Begin(dfs.StartNode);
            foreach (var arc in dfs.Path)
            {
                result.AddLast(arc);
            }
            return(result);
        }
예제 #3
0
 /// Convenience function for finding a path between two nodes. Details: \ref FindPath_Main "here".
 public static IPath FindPath(this IGraph graph, Node source, Node target,
                              Dfs.Direction direction)
 {
     return(FindPath(graph, new Node[] { source }, x => x == target, direction));
 }
        public static IPath FindPath(this IGraph graph, IEnumerable <Node> source, Func <Node, bool> target, Dfs.Direction direction)
        {
            PathDfs pathDfs = new PathDfs();

            pathDfs.PathDirection = direction;
            pathDfs.IsTarget      = target;
            PathDfs pathDfs2 = pathDfs;

            pathDfs2.Run(graph, source);
            if (pathDfs2.EndNode == Node.Invalid)
            {
                return(null);
            }
            Path path = new Path(graph);

            path.Begin(pathDfs2.StartNode);
            foreach (Arc item in pathDfs2.Path)
            {
                path.AddLast(item);
            }
            return(path);
        }