Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="firstName"></param>
        /// <param name="secondName"></param>
        /// <param name="weight"></param>
        public void AddEdge(string firstName, string secondName, double weight)
        {
            var v1 = FindVertex(firstName);
            var v2 = FindVertex(secondName);

            if (v2 != null && v1 != null)
            {
                v1.AddEdge(v2, weight);
                v2.AddEdge(v1, weight);
            }
            else
            {
                NotFoundEdgeExeption exeption = new NotFoundEdgeExeption();

                if (v1 == null)
                {
                    exeption.NotFoundFirstEdge = firstName;
                }

                if (v2 == null)
                {
                    exeption.NotFoundSecondEdge = secondName;
                }

                throw exeption;
            }
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="startname"></param>
        /// <param name="finishName"></param>
        /// <returns></returns>
        public string FindShortestPath(string startname, string finishName)
        {
            var foundStart = graph.FindVertex(startname);
            var foundEnd   = graph.FindVertex(finishName);

            if (foundStart == null || foundEnd == null)
            {
                NotFoundEdgeExeption exeption = new NotFoundEdgeExeption();

                if (foundStart == null)
                {
                    exeption.NotFoundFirstEdge = startname;
                }

                if (foundEnd == null)
                {
                    exeption.NotFoundSecondEdge = finishName;
                }

                throw exeption;
            }

            return(FindShortestPath(graph.FindVertex(startname), graph.FindVertex(finishName)));
        }