public GraphVertexInfo(GraphVertex vertex) { Vertex = vertex; IsUnvisited = true; EdgesWeightSum = int.MaxValue; PreviousVertex = null; }
GraphVertexInfo GetVertexInfo(GraphVertex v) { foreach (var i in infos) { if (i.Vertex.Equals(v)) { return(i); } } return(null); }
string GetPath(GraphVertex startVertex, GraphVertex endVertex) { var path = endVertex.ToString(); while (startVertex != endVertex) { endVertex = GetVertexInfo(endVertex).PreviousVertex; path = endVertex.ToString() + path; } return(path); }
public 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)); }
public void AddEdge(GraphVertex vertex, int edgeWeight) { AddEdge(new GraphEdge(vertex, edgeWeight)); }
public GraphEdge(GraphVertex connectedVertex, int weight) { ConnectedVertex = connectedVertex; EdgeWeight = weight; }