Exemple #1
0
 private Link FindLink(City c1, City c2, TransportModes mode)
 {
     return _routes.Find(delegate(Link lnk)
     {
         return (lnk.TransportMode == mode && ((lnk.FromCity == c1 && lnk.ToCity == c2) || (lnk.FromCity == c2 && lnk.ToCity == c1)));
     });
 }
Exemple #2
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);
 }
Exemple #3
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);
        }
Exemple #4
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);
        }
Exemple #5
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);
        }
Exemple #6
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();

            var statusMessage = excel.WriteToFile(excelFileName, bern, zuerich, links);
            excel.WriteToFile(excelFileName, bern, zuerich, links);

            Assert.IsTrue(File.Exists(excelFileName), excelFileName + " / " + statusMessage);

        }
Exemple #7
0
        public void TestDeserializeMultCitiesWithValues()
        {
            const string cityString1 = "Instance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib_JW.City\r\nName=\"Aarau\"\r\nCountry=\"Switzerland\"\r\nPopulation=10\r\nLocation is a nested object...\r\nInstance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib_JW.WayPoint\r\nName=\"Aarau\"\r\nLongitude=2.2\r\nLatitude=1.1\r\nEnd of instance\r\nEnd of instance\r\n";
            const string cityString2 = "Instance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib_JW.City\r\nName=\"Bern\"\r\nCountry=\"Switzerland\"\r\nPopulation=10\r\nLocation is a nested object...\r\nInstance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib_JW.WayPoint\r\nName=\"Bern\"\r\nLongitude=2.2\r\nLatitude=1.1\r\nEnd of instance\r\nEnd 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 stream = new StringReader(cityString);
            var reader = new SimpleObjectReader(stream);
            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);
        }
Exemple #8
0
        public void TestSerializeMultCitiesWithValues()
        {
            const string expectedString1 = "Instance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib_JW.City\r\nName=\"Aarau\"\r\nCountry=\"Switzerland\"\r\nPopulation=10\r\nLocation is a nested object...\r\nInstance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib_JW.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_JW.City\r\nName=\"Bern\"\r\nCountry=\"Switzerland\"\r\nPopulation=10\r\nLocation is a nested object...\r\nInstance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib_JW.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);
        }
Exemple #9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="fromCity">Links departing city</param>
 /// <param name="toCity">Links arriving city</param>
 /// <param name="distance">Distance between cities</param>
 /// <param name="transportMode">How link is served</param>
 public Link(City fromCity, City toCity, double distance, TransportModes transportMode)
     : this(fromCity, toCity, distance)
 {
     this.transportMode = transportMode;
 }
Exemple #10
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="fromCity">Links departing city</param>
 /// <param name="toCity">Links arriving city</param>
 /// <param name="distance">distance between cities</param>
 public Link(City fromCity, City toCity, double distance)
 {
     this.fromCity = fromCity;
     this.toCity = toCity;
     this.distance = distance;
 }
Exemple #11
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);

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

            foundCities.Add(to);

            for (int i = 0; i < foundCities.Count; i++)
                foundCities[i].Index = i;

            return foundCities;
        }
Exemple #12
0
        private List<City> GetIntermediatePath(City source, City target)
        {
           if(P[source.Index, target.Index] == null)  {
	            return new List<City>();
	        }
	        List<City> 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;
        }
Exemple #13
0
        private List<City> GetCitiesOnRoute(City source, City target, Dictionary<City, City> previous)
        {
            var citiesOnRoute = new List<City>();
            var cr = target;
            while (previous[cr] != null)
            {
                citiesOnRoute.Add(cr);
                cr = previous[cr];
            }
            citiesOnRoute.Add(source);

            citiesOnRoute.Reverse();
            return citiesOnRoute;
        }
Exemple #14
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)
        {
            var neighbors = new List<City>();
            foreach (var 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;
        }
Exemple #15
0
 public RouteRequestEventArgs(City fromCity, City toCity, TransportModes mode)
 {
     this.FromCity = fromCity;
     this.ToCity = toCity;
     this.Mode = mode;
 }