// get vertex info private GraphVertexInfo GetVertexInfo(GraphVertex vertex) { foreach (var i in _vertexInfoList) { if (i.Vertex.Equals(vertex)) { return(i); } } return(null); }
// path build private string GetPath(GraphVertex startVertex, GraphVertex endVertex) { var path = endVertex.ToString(); var way = default(string); while (startVertex != endVertex) { endVertex = GetVertexInfo(endVertex).PreviousVertex; path = endVertex + " -> " + path; } return(path); }
// Find the shortest path on vertexes public string FindShortestPath(GraphVertex startVertex, GraphVertex finishVertex) { Initialize(); var first = GetVertexInfo(startVertex); first.EdgesWeightSum = 0; while (true) { var current = FindUnvisitedVertexWithMinSum(); if (current == null) { break; } SetSumToNextVertex(current); } return(GetPath(startVertex, finishVertex)); }
// Rib addition | overload public void RibAddition(GraphVertex vertex, int ribWeight) { RibAddition(new GraphRib(vertex, ribWeight)); }