コード例 #1
0
        // get vertex info
        private GraphVertexInfo GetVertexInfo(GraphVertex vertex)
        {
            foreach (var i in _vertexInfoList)
            {
                if (i.Vertex.Equals(vertex))
                {
                    return(i);
                }
            }

            return(null);
        }
コード例 #2
0
        // 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);
        }
コード例 #3
0
        // 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));
        }
コード例 #4
0
 // Rib addition | overload
 public void RibAddition(GraphVertex vertex, int ribWeight)
 {
     RibAddition(new GraphRib(vertex, ribWeight));
 }