예제 #1
0
        // Вычисление суммы весов ребер для следующей вершины
        void SetSumToNextVertex(GraphVertexInfo info)
        {
            info.IsUnvisited = false;
            List <EdgeM> edges = new List <EdgeM>();

            edges.AddRange(info.Vertex.EdgesIn);
            edges.AddRange(info.Vertex.EdgesOut);

            foreach (var e in edges)
            {
                var nextInfo = GetVertexInfo(e.PointTo); //erwrwerwer
                var sum      = info.EdgesWeightSum + e.Weight;
                if (sum < nextInfo.EdgesWeightSum)
                {
                    nextInfo.EdgesWeightSum = sum;
                    nextInfo.PreviousVertex = info.Vertex;
                }

                nextInfo = GetVertexInfo(e.PointFrom); //erwrwerwer
                sum      = info.EdgesWeightSum + e.Weight;
                if (sum < nextInfo.EdgesWeightSum)
                {
                    nextInfo.EdgesWeightSum = sum;
                    nextInfo.PreviousVertex = info.Vertex;
                }
            }
        }
예제 #2
0
        // Поиск непосещенной вершины с минимальным значением суммы
        public GraphVertexInfo FindUnvisitedVertexWithMinSum()
        {
            double          minValue      = double.MaxValue;
            GraphVertexInfo minVertexInfo = null;

            foreach (GraphVertexInfo i in infos)
            {
                if (i.IsUnvisited && i.EdgesWeightSum < minValue)
                {
                    minVertexInfo = i;
                    minValue      = i.EdgesWeightSum;
                }
            }

            return(minVertexInfo);
        }