Ejemplo n.º 1
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");
        }
Ejemplo n.º 2
0
        public void TestExcelExport()
        {
            string excelFileName = Directory.GetCurrentDirectory() + @"\ExportTest.xlsx";

            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);

            // TODO: Fix starting Excel on sever (not robust)
            ExcelExchange excel = new ExcelExchange();

            Console.WriteLine("Export Path is: {0}", excelFileName);

            excel.WriteToFile(excelFileName, bern, zuerich, links);

            // first verify that file exists
            Assert.IsTrue(File.Exists(excelFileName));

            // now verify the content of the file
            // TODO: Fix reading file on sever
            VerifyExcelContent(excelFileName);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Find all cities between 2 cities 
        /// </summary>
        /// <param name="from">source city</param>
        /// <param name="to">target city</param>
        /// <returns>list of cities</returns>
        public List<City> FindCitiesBetween(City from, City to)
        {
            var foundCities = new List<City>();

            if (from == null || to == null)
            {
                return foundCities;
            }

            foundCities.Add(from);

            double minLat = Math.Min(from.Location.Latitude, to.Location.Latitude);
            double maxLat = Math.Max(from.Location.Latitude, to.Location.Latitude);
            double minLon = Math.Min(from.Location.Longitude, to.Location.Longitude);
            double maxLon = Math.Max(from.Location.Longitude, to.Location.Longitude);

            foundCities.AddRange(this.CityList.FindAll(c =>
                c.Location.Latitude > minLat && c.Location.Latitude < maxLat
                        && c.Location.Longitude > minLon && c.Location.Longitude < maxLon));

            foundCities.Add(to);

            InitIndexForAlgorithm(foundCities);

            return foundCities;
        }
Ejemplo n.º 4
0
 public int GetCityRequests(City _city)
 {
     if (DictionaryCities.ContainsKey(_city))
     {
         return DictionaryCities[_city];
     }
     return 0;
 }
Ejemplo n.º 5
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();
        }
Ejemplo n.º 6
0
        public bool Equals(City other)
        {
            // If parameter is null return false:
            if (other == null)
            {
                return false;
            }

            return IsEqualName(other) && IsEqualCountry(other);
        }
Ejemplo n.º 7
0
        public void TestSerializeSingleCityWithValues()
        {
            var c = new City("Aarau", "Switzerland", 10, 1.1, 2.2);

            var stream = new StringWriter();
            var writer = new SimpleObjectWriter(stream);
            writer.Next(c);
            var result = stream.ToString();

            Assert.AreEqual(CityWithValues, result);
        }
Ejemplo n.º 8
0
 public void TestDeserializeSingleCityWithValues()
 {
     var expectedCity = new City("Aarau", "Switzerland", 10, 1.1, 2.2);
     var stream = new StringReader(CityWithValues);
     var reader = new SimpleObjectReader(stream);
     var city = reader.Next() as City;
     Assert.IsNotNull(city);
     Assert.AreEqual(expectedCity.Name, city.Name);
     Assert.AreEqual(expectedCity.Country, city.Country);
     Assert.AreEqual(expectedCity.Location.Latitude, city.Location.Latitude);
 }
 public int GetCityRequests(City _city)
 {
     try
     {
         return count[_city];
     }
     catch
     {
         return 0;
     }
 }
Ejemplo n.º 10
0
 public void setCityRequests(City _city)
 {
     if (DictionaryCities.ContainsKey(_city))
     {
         DictionaryCities[_city] = DictionaryCities[_city] + 1;
     }
     else
     {
         DictionaryCities.Add(_city, 1);
     }
 }
Ejemplo n.º 11
0
Archivo: City.cs Proyecto: Laubeee/ecnf
        public bool Equals(City city)
        {
            // If parameter is null return false.
            if (city == null)
            {
                return false;
            }

            // Return true if the fields match:
            return (this.Name.Equals(city.Name, StringComparison.OrdinalIgnoreCase) && this.Country.Equals(city.Country, StringComparison.OrdinalIgnoreCase));
        }
Ejemplo n.º 12
0
        public bool Equal(City c)
        {
            // If parameter is null return false:
            if ((City)c == null)
            {
                return false;
            }

            // Return true if the fields match:
            return (this.Name.Equals(c.Name) && this.Country.Equals(c.Country));
        }
Ejemplo n.º 13
0
        public void TestLinkTransportMode()
        {
            var mumbai = new City("Mumbai", "India", 12383146, 18.96, 72.82);
            var buenosAires = new City("Buenos Aires", "Argentina", 12116379, -34.61, -58.37);

            var link = new Link(mumbai, buenosAires, 10);
            // verify default transport
            Assert.AreEqual(TransportModes.Car, link.TransportMode);

            link = new Link(mumbai, buenosAires, 10, TransportModes.Ship);
            Assert.AreEqual(TransportModes.Ship, link.TransportMode);
        }
Ejemplo n.º 14
0
        public void TestCityValidConstructor()
        {
            const double latitude = 47.479319847061966;
            const double longitude = 8.212966918945312;
            const int population = 75000;
            const string name = "Bern";
            const string country = "Schweiz";

            var bern = new City(name, country, population, latitude, longitude);

            Assert.AreEqual(name, bern.Name);
            Assert.AreEqual(name, bern.Location.Name); // city name == wayPoint name
            Assert.AreEqual(population, bern.Population);
            Assert.AreEqual(longitude, bern.Location.Longitude, 0.001);
            Assert.AreEqual(latitude, bern.Location.Latitude, 0.001);
        }
Ejemplo n.º 15
0
        public void TestExcelExport()
        {
            var excelFileName = Directory.GetCurrentDirectory() + @"\ExportTest.xlsx";
            var bern = new City("Bern", "Switzerland", 5000, 46.95, 7.44);
            var zuerich = new City("Zürich", "Switzerland", 100000, 32.876174, 13.187507);
            var aarau = new City("Aarau", "Switzerland", 10000, 35.876174, 12.187507);
            var link1 = new Link(bern, aarau, 15, TransportModes.Ship);
            var link2 = new Link(aarau, zuerich, 20, TransportModes.Ship);
            var links = new List<Link>();
            links.Add(link1);
            links.Add(link2);

            var excel = new ExcelExchange();

            excel.WriteToFile(excelFileName, bern, zuerich, links);

            Assert.IsTrue(File.Exists(excelFileName), excelFileName);
        }
Ejemplo n.º 16
0
 public City this[string cityName]
 {
     get
     {
         City cityFound = cities.Find(delegate (City c)
         {
             cityFound = new City(c.Name, c.Country, c.Population, c.Location.Latitude, c.Location.Longitude);
             return c.Name.Equals(cityName, StringComparison.InvariantCultureIgnoreCase);
         });
         if (cityFound == null)
         {
             throw new KeyNotFoundException("No such city was found");
         }
         else
         {
             return cityFound;
         }
     }
 }
        public void TestDeserializeMultCitiesWithValues()
        {
            const string cityString1 =
                  "Instance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.City\r\n"
                + "Country=\"Switzerland\"\r\n"
                + "Location is a nested object...\r\n"
                + "Instance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.WayPoint\r\n"
                + "Latitude=1.1\r\n"
                + "Longitude=2.2\r\n"
                + "Name=\"Aarau\"\r\n"
                + "End of instance\r\n"
                + "Name=\"Aarau\"\r\n"
                + "Population=10\r\n"
                + "End of instance\r\n";
            const string cityString2 =
                  "Instance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.City\r\n"
                + "Country=\"Switzerland\"\r\n"
                + "Location is a nested object...\r\n"
                + "Instance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.WayPoint\r\n"
                + "Latitude=1.1\r\n"
                + "Longitude=2.2\r\n"
                + "Name=\"Bern\"\r\n"
                + "End of instance\r\n"
                + "Name=\"Bern\"\r\n"
                + "Population=10\r\n"
                + "End of instance\r\n";
            const string cityString = cityString1 + cityString2;
            var expectedCity1 = new City("Aarau", "Switzerland", 10, 1.1, 2.2);
            var expectedCity2 = new City("Bern", "Switzerland", 10, 1.1, 2.2);
            var reader = new SimpleObjectReader(new StringReader(cityString));
            var city1 = reader.Next() as City;

            Assert.IsNotNull(city1);
            Assert.AreEqual(expectedCity1.Name, city1.Name);
            Assert.AreEqual(expectedCity1.Country, city1.Country);
            Assert.AreEqual(expectedCity1.Location.Latitude, city1.Location.Latitude);
            var city2 = reader.Next() as City;
            Assert.IsNotNull(city2);
            Assert.AreEqual(expectedCity2.Name, city2.Name);
            Assert.AreEqual(expectedCity2.Country, city2.Country);
            Assert.AreEqual(expectedCity2.Location.Latitude, city2.Location.Latitude);
        }
Ejemplo n.º 18
0
        static void Main(string[] args)
        {
            var c = new City("Aarau", "Switzerland", 10, 1.1, 2.2);
            //Console.WriteLine(c.Location.GetType());

            var stream = new StringWriter();
            SimpleObjectWriter w = new SimpleObjectWriter(stream);
            w.Next(c);
            var objstr = stream.ToString();
            Console.Write(objstr + "\r\n");

            var stream2 = new StringReader(objstr);
            SimpleObjectReader r = new SimpleObjectReader(stream2);
            var city = r.Next() as City;
            Console.WriteLine(city.Name);
            Console.WriteLine(city.Country);
            Console.WriteLine(city.Population);
            Console.WriteLine(city.Location);
            Console.WriteLine(city.Location.Name);
            Console.WriteLine(city.Location.Latitude);
            Console.WriteLine(city.Location.Longitude);

            Console.Write("Welcome to RoutePlanner {0}\n", Assembly.GetExecutingAssembly().GetName().Version);
            var wayPoint = new WayPoint("Windisch", 47.479319847061966, 8.212966918945312);
            //Console.WriteLine("{0}: {1}/{2}", wayPoint.Name, wayPoint.Latitude, wayPoint.Longitude);
            Console.WriteLine(wayPoint);
            wayPoint.Name = "";
            Console.WriteLine(wayPoint);
            wayPoint.Name = null;
            Console.WriteLine(wayPoint);

            var cities = new Cities();
            Console.WriteLine(cities.ReadCities(@"data\citiesTestDataLab3.txt"));

            var routes = new Routes(cities);
            var count = routes.ReadRoutes(@"data\linksTestDataLab3.txt");

            var citiesError = new Cities();
            Console.WriteLine(cities.ReadCities(@"data\citiesTestDataLab253.txt"));

            Console.ReadKey();
        }
Ejemplo n.º 19
0
        public void TestSerializeMultCitiesWithValues()
        {
            const string expectedString1 = "Instance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.City\r\nName=\"Aarau\"\r\nCountry=\"Switzerland\"\r\nPopulation=10\r\nLocation is a nested object...\r\nInstance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.WayPoint\r\nName=\"Aarau\"\r\nLongitude=2.2\r\nLatitude=1.1\r\nEnd of instance\r\nEnd of instance\r\n";
            const string expectedString2 = "Instance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.City\r\nName=\"Bern\"\r\nCountry=\"Switzerland\"\r\nPopulation=10\r\nLocation is a nested object...\r\nInstance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.WayPoint\r\nName=\"Bern\"\r\nLongitude=2.2\r\nLatitude=1.1\r\nEnd of instance\r\nEnd of instance\r\n";
            const string expectedString = expectedString1 + expectedString2;
            var c1 = new City("Aarau", "Switzerland", 10, 1.1, 2.2);
            var c2 = new City("Bern", "Switzerland", 10, 1.1, 2.2);

            var stream = new StringWriter();
            var writer = new SimpleObjectWriter(stream);
            writer.Next(c1);
            var result = stream.ToString();
            Assert.AreEqual(expectedString1, result);

            // write second city
            writer.Next(c2);

            // result is expected to contain both cities
            result = stream.ToString();
            Assert.AreEqual(expectedString, result);
        }
Ejemplo n.º 20
0
        public void TestExcelExport()
        {
            var excelFileName = Directory.GetCurrentDirectory() + @"\ExportTest.xlsx";

            var bern = new City("Bern", "Switzerland", 5000, 46.95, 7.44);
            var zuerich = new City("Zürich", "Switzerland", 100000, 32.876174, 13.187507);
            var aarau = new City("Aarau", "Switzerland", 10000, 35.876174, 12.187507);
            var links = new Link[]
            {
                new Link(bern, aarau, 15, TransportMode.Ship),
                new Link(aarau, zuerich, 20, TransportMode.Ship)
            };

            var excel = new ExcelExchange();
            excel.WriteToFile(excelFileName, links);
            Assert.IsTrue(File.Exists(excelFileName), excelFileName);

            //should not show dialog boxes or fail, should silently overwrite the file
            excel.WriteToFile(excelFileName, links);
            Assert.IsTrue(File.Exists(excelFileName), excelFileName);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Find all cities between 2 cities 
        /// </summary>
        /// <param name="from">source city</param>
        /// <param name="to">target city</param>
        /// <returns>list of cities</returns>
        public List<City> FindCitiesBetween(City from, City to)
        {
            var foundCities = new List<City>();
            if (from == null || to == null)
                return foundCities;

            foundCities.Add(from);

            var minLat = Math.Min(from.Location.Latitude, to.Location.Latitude);
            var maxLat = Math.Max(from.Location.Latitude, to.Location.Latitude);
            var minLon = Math.Min(from.Location.Longitude, to.Location.Longitude);
            var maxLon = Math.Max(from.Location.Longitude, to.Location.Longitude);

            // rename the name of the "cities" variable to your name of the internal City-List
            foundCities.AddRange(cities.FindAll(c =>
                c.Location.Latitude > minLat && c.Location.Latitude < maxLat
                        && c.Location.Longitude > minLon && c.Location.Longitude < maxLon));

            foundCities.Add(to);
            InitIndexForAlgorithm(foundCities);
            return foundCities;
        }
Ejemplo n.º 22
0
        private List<City> GetIntermediatePath(City source, City target)
        {
            if(P[source.Index, target.Index] == null)
                return new List<City>();

            var path = new List<City>();
            path.AddRange( GetIntermediatePath(source, P[source.Index, target.Index]));
            path.Add( P[source.Index, target.Index] );
            path.AddRange( GetIntermediatePath(P[source.Index, target.Index], target));
            return path;
        }
Ejemplo n.º 23
0
 private bool IsEqualName(City other)
 {
     return (this.Name == null && other.Name == null)
         || (this.Name != null && this.Name.Equals(other.Name));
 }
Ejemplo n.º 24
0
 private Boolean IsEqualCountry(City other)
 {
     return (this.Country == null && other.Country == null)
         || (this.Country != null && this.Country.Equals(other.Country));
 }
Ejemplo n.º 25
0
        private List<City> GetCitiesOnRoute(City source, City target, Dictionary<City, City> previous)
        {
            List<City> citiesOnRoute = new List<City>();
            City cr = target;
            while (previous[cr] != null)
            {
                citiesOnRoute.Add(cr);
                cr = previous[cr];
            }
            citiesOnRoute.Add(source);

            citiesOnRoute.Reverse();
            return citiesOnRoute;
        }
Ejemplo n.º 26
0
 /// <summary>
 /// Finds all neighbor cities of a city. 
 /// </summary>
 /// <param name="city">source city</param>
 /// <param name="mode">transportation mode</param>
 /// <returns>list of neighbor cities</returns>
 private List<City> FindNeighbours(City city, TransportModes mode)
 {
     List<City> neighbors = new List<City>();
     foreach (Link r in routes)
     {
         if (mode.Equals(r.TransportMode))
         {
             if (city.Equals(r.FromCity))
             {
                 neighbors.Add(r.ToCity);
             }
             else if (city.Equals(r.ToCity))
             {
                 neighbors.Add(r.FromCity);
             }
         }
     }
     return neighbors;
 }
 public RouteRequestEventArgs(City fromCity, City toCity, TransportMode transport)
 {
     this.FromCity = fromCity;
     this.ToCity = toCity;
     this.transportMode = transport;
 }
Ejemplo n.º 28
0
Archivo: Link.cs Proyecto: Laubeee/ecnf
 public Link(City _fromCity, City _toCity, double _distance)
 {
     fromCity = _fromCity;
     toCity = _toCity;
     distance = _distance;
 }
Ejemplo n.º 29
0
 public RouteRequestEventArgs(City fromCity, City toCity, TransportModes mode)
 {
     this.FromCity = fromCity;
     this.ToCity = toCity;
     this.Mode = mode;
 }
Ejemplo n.º 30
0
Archivo: Link.cs Proyecto: Laubeee/ecnf
 public Link(City _fromCity, City _toCity, double _distance, TransportMode _transportMode)
     : this(_fromCity, _toCity, _distance)
 {
     transportMode = _transportMode;
 }