Esempio n. 1
0
        public static List <string> PrintAllMinPaths(DekstraAlg da)
        {
            List <string> retListOfPontsAndPaths = new List <string>();

            foreach (Point p in da.Points)
            {
                if (p != da.BeginPoint)
                {
                    string s = string.Empty;
                    float  n = 0;
                    foreach (Point p1 in da.MinPath(p))
                    {
                        s += string.Format("{0}-", p1.Name);
                    }
                    n += p.ValueMetka;
                    string[] result = s.Split('-');
                    Array.Reverse(result);
                    string res = "A";
                    for (int i = 0; i < result.Count(); i++)
                    {
                        res += result[i].ToString();
                    }
                    retListOfPontsAndPaths.Add(string.Format("Точка = {0}, кратчайший путь от {1} : {2}, значение маршрута: {3}", p.Name, da.BeginPoint.Name, res, n));
                }
            }
            return(retListOfPontsAndPaths);
        }
Esempio n. 2
0
        static void Main()
        {
            Point        pointA = new Point(0, false, "A");
            Point        pointB = new Point(9999, false, "B");
            Point        pointC = new Point(9999, false, "C");
            Point        pointD = new Point(9999, false, "D");
            Point        pointE = new Point(9999, false, "E");
            Point        pointF = new Point(9999, false, "F");
            List <Point> points = new List <Point>
            {
                pointA,
                pointB,
                pointC,
                pointD,
                pointE,
                pointF
            };

            List <Rebro> rebra = new List <Rebro>
            {
                new Rebro(pointA, pointB, 3),
                new Rebro(pointA, pointC, 5),
                new Rebro(pointA, pointD, 9),
                new Rebro(pointB, pointC, 3),
                new Rebro(pointB, pointE, 7),
                new Rebro(pointB, pointD, 4),
                new Rebro(pointC, pointD, 2),
                new Rebro(pointC, pointE, 6),
                new Rebro(pointC, pointF, 8),
                new Rebro(pointD, pointF, 2),
                new Rebro(pointD, pointE, 2),
                new Rebro(pointE, pointF, 5)
            };

            DekstraAlg alg = new DekstraAlg(points.ToArray(), rebra.ToArray());

            alg.AlgorythmRun(pointA);

            List <string> result = PrintGraph.PrintAllPoints(alg);

            for (int i = 0; i < result.Count(); i++)
            {
                Console.WriteLine(result[i].ToString());
            }

            Console.WriteLine("\nКратчайшие пути:");
            List <string> resultPaths = PrintGraph.PrintAllMinPaths(alg);

            for (int i = 0; i < resultPaths.Count(); i++)
            {
                Console.WriteLine(resultPaths[i].ToString());
            }
            Console.Read();
        }
Esempio n. 3
0
        public static List <string> PrintAllPoints(DekstraAlg da)
        {
            List <string> retListOfPoints = new List <string>();
            float         lastPath        = 0;

            foreach (Point p in da.Points)
            {
                retListOfPoints.Add(string.Format("название точки={0}, значение точки={1}, предок={2}", p.Name, p.ValueMetka, p.PredPoint.Name ?? "нет предка"));
                lastPath = p.ValueMetka;
            }
            //string last = retListOfPoints.Last();
            //last += string.Format("\n\nЗначение кратчайшего маршрута данного графа: {0}", lastPath);
            //retListOfPoints.Remove(retListOfPoints.Last());
            //retListOfPoints.Add(last);
            return(retListOfPoints);
        }