Example #1
0
        /// <summary>
        /// Добавление вершины
        /// </summary>
        /// <param name="mapPoint">Имя вершины</param>
        public GraphVertex AddVertex(MapPoint mapPoint)
        {
            var grafVertex = new GraphVertex(mapPoint);

            VertexList.Add(grafVertex);
            return(grafVertex);
        }
Example #2
0
        /// <summary>
        /// Формирование пути
        /// </summary>
        /// <param name="startVertex">Начальная вершина</param>
        /// <param name="endVertex">Конечная вершина</param>
        /// <returns>Путь</returns>
        string GetPath(GraphVertex startVertex, GraphVertex endVertex)
        {
            var path = endVertex.ToString();

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

            return(path);
        }
Example #3
0
        List <MapPoint> GetPointListPath(GraphVertex startVertex, GraphVertex endVertex)
        {
            var restlt = new List <MapPoint> {
                endVertex.Point
            };

            // ReSharper disable once LoopVariableIsNeverChangedInsideLoop
            while (startVertex != endVertex)
            {
                endVertex = GetVertexInfo(endVertex).PreviousVertex;
                restlt.Add(endVertex.Point);
            }

            return(restlt);
        }
Example #4
0
        /// <summary>
        /// Поиск кратчайшего пути по вершинам
        /// </summary>
        /// <param name="startVertex">Стартовая вершина</param>
        /// <param name="finishVertex">Финишная вершина</param>
        /// <returns>Кратчайший путь</returns>
        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));
        }
Example #5
0
 /// <summary>
 /// Добавить ребро
 /// </summary>
 /// <param name="vertex">Вершина</param>
 /// <param name="edgeWeight">Вес</param>
 public void AddEdge(GraphVertex vertex, int edgeWeight)
 {
     AddEdge(new GraphEdge(vertex, edgeWeight));
 }
Example #6
0
 /// <summary>
 /// Получение информации о вершине графа
 /// </summary>
 /// <param name="v">Вершина</param>
 /// <returns>Информация о вершине</returns>
 GraphVertexInfo GetVertexInfo(GraphVertex v)
 {
     return(_infos.FirstOrDefault(i => i.Vertex.Equals(v)));
 }