Beispiel #1
0
        /// <summary>
        /// Find unvisited vertex with minimal weight sum
        /// </summary>
        /// <returns>Vertex info</returns>
        public GraphVertexInfo FindUnvisitedVertexWithMinSum()
        {
            var             minValue      = int.MaxValue;
            GraphVertexInfo minVertexInfo = null;

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

            return(minVertexInfo);
        }
Beispiel #2
0
        /// <summary>
        /// Calculate edge weight sum for the next vertex
        /// </summary>
        /// <param name="info">Current vertex info</param>
        /// <param name="searchingField">Field of edge to search the shortest path by</param>
        private void SetSumToNextVertex(GraphVertexInfo info, PathSearchingField searchingField = PathSearchingField.Weight)
        {
            info.IsUnvisited = false;
            foreach (var e in info.Vertex.Edges)
            {
                var nextInfo = GetVertexInfo(e.ConnectedVertex);
                var sum      = info.EdgesWeightSum;
                switch (searchingField)
                {
                case PathSearchingField.Weight: { sum += e.EdgeWeight; break; }

                case PathSearchingField.Length: { sum += e.EdgeLength; break; }
                }
                if (sum < nextInfo.EdgesWeightSum)
                {
                    nextInfo.EdgesWeightSum = sum;
                    nextInfo.PreviousVertex = info.Vertex;
                }
            }
        }