private string GetPath(GraphVertex startVertex, GraphVertex endVertex) { var path = endVertex.ToString(); while (startVertex != endVertex) { endVertex = GetVertexInfo(endVertex).PreviousVertex; path = endVertex.ToString() + path; } return(path); }
private GraphVertexInfo GetVertexInfo(GraphVertex v) { foreach (var i in _infos) { if (i.Vertex.Equals(v)) { return(i); } } return(null); }
public LinkedList <GraphVertex> DFS(GraphVertex start, GraphVertex goal) { _visited = new HashSet <GraphVertex>(); _path = new LinkedList <GraphVertex>(); _goal = goal; DFS(start); if (_path.Count > 0) { _path.AddFirst(start); } return(_path); }
private string FindShortestPath(GraphVertex startVertex, GraphVertex finishVertex) { InitInfo(); var first = GetVertexInfo(startVertex); first.EdgesWeightSum = 0; while (true) { var current = FindUnvisitedVertexWithMinSum(); if (current == null) { break; } SetSumToNextVertex(current); } return(GetPath(startVertex, finishVertex)); }
private bool DFS(GraphVertex node) { if (node == _goal) { Console.WriteLine($"Vertice {node.Name} was found in dfs! Yeeeeee"); return(true); } _visited.Add(node); foreach (var child in node.Edges.Select(e => e.ConnectedVertex).Where(e => !_visited.Contains(e))) { Console.WriteLine($"Vertice child {child.Name} of {node.Name}"); if (DFS(child)) { _path.AddFirst(child); return(true); } } return(false); }
public void AddEdge(GraphVertex vertex, int edgeWeight) { AddEdge(new GraphEdge(vertex, edgeWeight)); }