Beispiel #1
0
 public GraphVertexInfo(GraphVertex vertex)
 {
     Vertex         = vertex;
     IsUnvisited    = true;
     EdgesWeightSum = int.MaxValue;
     PreviousVertex = null;
 }
Beispiel #2
0
 GraphVertexInfo GetVertexInfo(GraphVertex v)
 {
     foreach (var i in infos)
     {
         if (i.Vertex.Equals(v))
         {
             return(i);
         }
     }
     return(null);
 }
Beispiel #3
0
        string GetPath(GraphVertex startVertex, GraphVertex endVertex)
        {
            var path = endVertex.ToString();

            while (startVertex != endVertex)
            {
                endVertex = GetVertexInfo(endVertex).PreviousVertex;
                path      = endVertex.ToString() + path;
            }

            return(path);
        }
Beispiel #4
0
        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));
        }
Beispiel #5
0
 public void AddEdge(GraphVertex vertex, int edgeWeight)
 {
     AddEdge(new GraphEdge(vertex, edgeWeight));
 }
Beispiel #6
0
 public GraphEdge(GraphVertex connectedVertex, int weight)
 {
     ConnectedVertex = connectedVertex;
     EdgeWeight      = weight;
 }