public static (string[] path, int distance) Dijkstra(ISearchableGraph graph, string from, string to) { var startNode = new DijkstraNode(graph, from, 0, to); var result = Search <HeapPriorityQueue <SearchNode> > .Execute(startNode); var path = result.GetPath().Select(sn => { var gsn = sn as DijkstraNode; return(gsn.graphNode); }).ToArray(); return(path, result.cost); }
private static bool IsCyclic(ISearchableGraph g) { try { var dfe = new CyclicSearch(g); dfe.Search(); return(false); } catch (GraphCycleException) { return(true); } }
public static IEnumerable <int> StronglyConnectedComponents(ISearchableGraph graph, ISearchableGraph reverse) { //run dfs of reverse graph var srg = new TopologicalSort(reverse); srg.Search(); //look for v in graph in reverse post order var sg = new DepthFirstSearch(graph); var order = srg.Order; foreach (var v in order) { //if not visited => explore and mark visted vertices as new component sg.Explore(v); } return(sg.Components); }
public TopologicalSort(ISearchableGraph g) : base(g) { }
public DepthFirstSearch(ISearchableGraph g) { Graph = g; ConnectedComponent = new int[g.Size()]; ConnectedComponents = 0; }
public BreadthFirstSearchWithBipartiteDetection(ISearchableGraph g) { _graph = g; _searchData = new SearchData(g.Size()); }
public BreadthFirstSearch(ISearchableGraph g) { _visitedFrom = new SearchData(g.Size()); _graph = g; _searchData = new SearchData(g.Size()); }
public DijkstraNode(ISearchableGraph graph, string graphNode, int cost, string targetNode, DijkstraNode parent = null) : base(cost, parent) { this.graph = graph; this.graphNode = graphNode; this.targetNode = targetNode; }
public CyclicSearch(ISearchableGraph g) { _g = g; }