Searches routes with FloydWarshall algorithm http://algowiki.net/wiki/index.php?title=Floyd-Warshall%27s_algorithm
Наследование: Routes
Пример #1
0
        public void TestTask1_FindRoutes()
        {
            Cities cities = new Cities();
            cities.ReadCities(@"citiesTestDataLab4.txt");
            List<Link> expectedLinks = new List<Link>();
            expectedLinks.Add(new Link(new City("Zürich", "Switzerland", 7000, 1, 2),
                                       new City("Aarau", "Switzerland", 7000, 1, 2), 0));
            expectedLinks.Add(new Link(new City("Aarau", "Switzerland", 7000, 1, 2),
                                       new City("Liestal", "Switzerland", 7000, 1, 2), 0));
            expectedLinks.Add(new Link(new City("Liestal", "Switzerland", 7000, 1, 2),
                                       new City("Basel", "Switzerland", 7000, 1, 2), 0));

            Routes routes = new RoutesFloydWarshall(cities);
            int count = routes.ReadRoutes(@"linksTestDataLab4.txt");

            Assert.AreEqual(11, cities.Count);

            // test available cities
            routes.ExecuteParallel = true;
            List<Link> links = routes.FindShortestRouteBetween("Zürich", "Basel", TransportModes.Rail);

            Assert.IsNotNull(links);
            Assert.AreEqual(expectedLinks.Count, links.Count);

            for (int i = 0; i < links.Count; i++)
            {
                Assert.AreEqual(expectedLinks[i].FromCity.Name, links[i].FromCity.Name);
                Assert.AreEqual(expectedLinks[i].ToCity.Name, links[i].ToCity.Name);
            }


            links = routes.FindShortestRouteBetween("doesNotExist", "either", TransportModes.Rail);
            Assert.IsNull(links);

        }
Пример #2
0
        static void Main(string[] args)
        {
            var assembly = Assembly.GetExecutingAssembly().FullName;
            var version = assembly.Split(',')[1].Split('=')[1];
            Console.Out.WriteLine("Welcome to RoutePlanner (Version {0})", arg0: version);

            var wayPoint = new WayPoint("Windisch", 47.479319847061966, 8.212966918945312);
            Console.WriteLine("{0}: {1}/{2}", wayPoint.Name, wayPoint.Latitude, wayPoint.Longitude);
            Console.Out.WriteLine("--------------");
            Console.Out.WriteLine(wayPoint);

            RoutesFactory.Create(new Cities());

            string excelFileName = Directory.GetCurrentDirectory() + @"\ExportTest.xlsx";
            ExcelExchange excel = new ExcelExchange();
            Console.WriteLine("Export Path is: {0}", excelFileName);
            City bern = new City("Bern", "Switzerland", 5000, 46.95, 7.44);
            City zuerich = new City("Zürich", "Switzerland", 100000, 32.876174, 13.187507);
            City aarau = new City("Aarau", "Switzerland", 10000, 35.876174, 12.187507);
            Link link1 = new Link(bern, aarau, 15, TransportModes.Ship);
            Link link2 = new Link(aarau, zuerich, 20, TransportModes.Ship);
            List<Link> links = new List<Link>();
            links.Add(link1);
            links.Add(link2);
            excel.WriteToFile(excelFileName, bern, zuerich, links);

            /* Test Logging */
            var cities = new Cities();
            Routes routes = new RoutesFloydWarshall(cities);
            //cities.ReadCities("adsf");
            //routes.ReadRoutes("adsf");
        }
Пример #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to RoutePlanner (Version {0})", Assembly.GetExecutingAssembly().GetName().Version);
            var bern = new WayPoint("Bern",46.951081, 7.438637);
            var tripolis = new WayPoint("Tripolis",32.883333333333, 13.166666666667);
            var wayPoint = new WayPoint("Windisch", 47.479319847061966, 8.212966918945312);
            var City = new City("Bern", "Schweiz", 75000, 47.479319847061966, 8.212966918945312);
            Console.WriteLine(wayPoint);
            Console.WriteLine("Distance Bern to Tripolis: "+bern.Distance(tripolis)+"km");
            Cities cities = new Cities();
            cities.ReadCities(@"..\..\..\RoutePlannerTest\data\citiesTestDataLab2.txt");
            RoutesDijkstra routes = new RoutesDijkstra(cities);
            routes.ReadRoutes(@"..\..\..\RoutePlannerTest\data\linksTestDataLab3.txt");
            Cities citiesFail = new Cities();
            citiesFail.ReadCities(@"irgendeinfile.txt");

            Console.WriteLine("Starting parallel test......");
            Cities citiesP = new Cities();
            cities.ReadCities(@"..\..\..\RoutePlannerTest\data\citiesTestDataLab10.txt");

            int warmUpRounds = 100;
            int measureRounds = 20;
            Routes routesP = new RoutesFloydWarshall(cities);
            int count = routesP.ReadRoutes(@"..\..\..\RoutePlannerTest\data\linksTestDataLab10.txt");

            Console.WriteLine("doing warmup");
            for (int i = 0; i < warmUpRounds; i++)
            {
                List<Link> links = routesP.FindShortestRouteBetween("Lyon", "Berlin", TransportModes.Rail);
            }
            Stopwatch watch = new Stopwatch();
            watch.Start();
            Console.WriteLine("sequential mode: ");
            // test short routes in parallel mode
            routesP.ExecuteParallel = false;
            for (int i = 0; i < measureRounds; i++)
            {
                List<Link> links = routesP.FindShortestRouteBetween("Lyon", "Berlin", TransportModes.Rail);
            }
            watch.Stop();
            Console.WriteLine("Elapsed Time: " + watch.ElapsedMilliseconds + "ms");

            watch.Reset();
            watch.Start();
            Console.WriteLine("parallel mode: ");
            // test short routes in parallel mode
            routesP.ExecuteParallel = true;
            for (int i = 0; i < measureRounds; i++)
            {
                List<Link> links2 = routesP.FindShortestRouteBetween("Lyon", "Berlin", TransportModes.Rail);

            }
            watch.Stop();
            Console.WriteLine("Elapsed Time: " + watch.ElapsedMilliseconds + "ms");

            Console.WriteLine("Press any key to quit");
            Console.ReadKey();
        }
Пример #4
0
        public void TestTask2_FindRoutes()
        {
            Cities cities = new Cities();
            cities.ReadCities(@"citiesTestDataLab11.txt");
            List<Link> expectedLinks = new List<Link>();

            Routes routes = new RoutesFloydWarshall(cities);
            int count = routes.ReadRoutes(@"linksTestDataLab11.txt");

            Assert.AreEqual(6372, cities.Count);

            // test available cities
            routes.ExecuteParallel = true;
            List<Link> links = routes.FindShortestRouteBetween("Lyon", "Berlin", TransportModes.Rail);
            routes.ExecuteParallel = false;
            List<Link> links2 = routes.FindShortestRouteBetween("Lyon", "Berlin", TransportModes.Rail);

            Assert.IsNotNull(links);
            Assert.AreEqual(13, links.Count);

        }
Пример #5
0
        public void TestTask3_CompareAlgorithms()
        {
            Cities cities = new Cities();

            cities.ReadCities(@"citiesTestDataLab11.txt");
            Assert.AreEqual(6372, cities.Count);

            Routes routes = new RoutesDijkstra(cities);
            long dijkstraTime = FindRoutes(routes);

            routes = new RoutesFloydWarshall(cities);
            routes.ExecuteParallel = false;
            long floydWarshallTime = FindRoutes(routes);

            // the sequentiel floydWarshal should be slower
            Assert.IsTrue(floydWarshallTime > dijkstraTime, "FloydWarshal should be slower");

        }
Пример #6
0
        public void TestTask5_CompareParallelSequential()
        {
            Cities cities = new Cities();

            cities.ReadCities(@"citiesTestDataLab11.txt");
            Assert.AreEqual(6372, cities.Count);

            Routes routes = new RoutesFloydWarshall(cities);
            routes.ExecuteParallel = true;
            long floydWarshallParallelTime = FindRoutes(routes);

            routes = new RoutesFloydWarshall(cities);
            routes.ExecuteParallel = false;
            long floydWarshallTime = FindRoutes(routes);

            // the sequentiel floydWarshal should be slower
            Assert.IsTrue(floydWarshallTime > floydWarshallParallelTime, "FloydWarshal parallel should be faster than sequential");


        }
Пример #7
0
        public void TestTask2FindRoutes()
        {
            Cities cities = new Cities();
            cities.ReadCities(@"citiesTestDataLab10.txt");
            Assert.AreEqual(6372, cities.Count);

            Routes routes = new RoutesFloydWarshall(cities);
            int count = routes.ReadRoutes(@"linksTestDataLab10.txt");
            Assert.AreEqual(118, count);

            // test short routes in parallel mode
            routes.ExecuteParallel = true;
            List<Link> links = routes.FindShortestRouteBetween("Lyon", "Berlin", TransportModes.Rail);
            Assert.IsNotNull(links);
            Assert.AreEqual(13, links.Count);

            // test short routes in non parallel mode
            routes.ExecuteParallel = false;
            List<Link> links2 = routes.FindShortestRouteBetween("Lyon", "Berlin", TransportModes.Rail);
            Assert.IsNotNull(links2);
            Assert.AreEqual(13, links2.Count);
        }