示例#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");
        }
示例#2
0
 public List<City> FindNeighbours(WayPoint location, double distance)
 {
     return CityList
         .Where(c => location.Distance(c.Location) <= distance)
         .OrderBy(c => location.Distance(c.Location))
         .ToList();
 }
示例#3
0
 public City(string _name, string _country, int _population, double _latitude, double _longitude)
 {
     Name = _name;
     Country = _country;
     Population = _population;
     Location = new WayPoint(_name, _latitude, _longitude);
 }
 static void Main(string[] args)
 {
     Console.WriteLine("Welcome to RoutePlanner (Version {0})", 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.ReadKey();
 }
示例#5
0
        public void TestWayPointValidConstructor()
        {
            var target = new WayPoint(Name, Latitude, Longitude);

            Assert.AreEqual(Name, target.Name);
            Assert.AreEqual(Latitude, target.Latitude);
            Assert.AreEqual(Longitude, target.Longitude);
        }
        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();
        }
示例#7
0
 public void TestWayPointDistanceCalculation()
 {
     var bern = new WayPoint("Bern", 46.95, 7.44);
     var tripolis = new WayPoint("Tripolis", 32.876174, 13.187507);
     const double expected = 1638.74410788167;
     double actual = bern.Distance(tripolis);
     Assert.IsFalse(double.IsNaN(actual));
     Assert.AreEqual(expected, actual, 0.001);
 }
示例#8
0
 public double Distance(WayPoint target)
 {
     int Radius = 6371;
     double LatitudeThis = ConvertToRadians(this.Latitude);
     double LongitudeThis = ConvertToRadians(this.Longitude);
     double LatitudeTarget = ConvertToRadians(target.Latitude);
     double LongitudeTarget = ConvertToRadians(target.Longitude);
     return Radius * Math.Acos(Math.Sin(LatitudeThis) * Math.Sin(LatitudeTarget) + Math.Cos(LatitudeThis) * Math.Cos(LatitudeTarget) * Math.Cos(LongitudeThis - LongitudeTarget));
 }
示例#9
0
 public double Distance(WayPoint _target)
 {
     const int radius = 6371;
     var d =
         Math.Acos(Math.Sin(Latitude * Math.PI / 180) * Math.Sin(_target.Latitude * Math.PI / 180) +
                   Math.Cos(Latitude * Math.PI / 180) * Math.Cos(_target.Latitude * Math.PI / 180) *
                   Math.Cos(Longitude * Math.PI / 180 - _target.Longitude * Math.PI / 180));
     return d * radius;
 }
示例#10
0
        /// <summary>
        /// calculates the distance to targeted WayPoint
        /// </summary>
        /// <param name="start"></param>
        /// <param name="target"></param>
        /// <returns>distance</returns>
        public double Distance(WayPoint target)
        {
            var radLatitude = Math.PI * Latitude / 180;
            var radLongitude = Math.PI * Longitude / 180;
            var tarRadLatitude = Math.PI * target.Latitude / 180;
            var tarRadLongitude = Math.PI * target.Longitude / 180;

            return RADIUS * Math.Acos(Math.Sin(radLatitude) * Math.Sin(tarRadLatitude) + 
                          Math.Cos(radLatitude) * Math.Cos(tarRadLatitude) * Math.Cos(radLongitude - tarRadLongitude));
        }
示例#11
0
 public double Distance(WayPoint target)
 {
     int radius = 6371;
     double sinStart = Math.Sin(Latitude * (Math.PI / 180));
     double sinTarget = Math.Sin(target.Latitude * (Math.PI / 180));
     double cosStart = Math.Cos(Latitude * (Math.PI / 180));
     double cosTarget = Math.Cos(target.Latitude * (Math.PI / 180));
     double cosDifference = Math.Cos(Longitude * (Math.PI / 180) - target.Longitude * (Math.PI / 180));
     double distance = radius * Math.Acos(sinStart * sinTarget + cosStart * cosTarget * cosDifference);
     return distance;
 }
示例#12
0
        public Double Distance(WayPoint target)
        {
            double R = 6371;    // earth radius
            double slat = ConvertToRadians(this.Latitude), slong = ConvertToRadians(this.Longitude);
            double tlat = ConvertToRadians(target.Latitude), tlong = ConvertToRadians(target.Longitude);
            double d = R*
                       Math.Acos(Math.Sin(slat)*Math.Sin(tlat) +
                                 Math.Cos(slat) * Math.Cos(tlat) *
                                 Math.Cos(slong - tlong));

            return d;
        }
示例#13
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to RoutePlanner (Version {0})", Assembly.GetExecutingAssembly().GetName().Version);

            var wayPointWindisch = new WayPoint("Windisch", 47.479319847061966, 8.212966918945312);
            var wayPointChicago = new WayPoint("Chicago", 41.850033, -87.6500523);
            Console.WriteLine("{0}: {1}/{2}", wayPointWindisch.Name, wayPointWindisch.Latitude, wayPointWindisch.Longitude);
            Console.WriteLine(wayPointWindisch.ToString());
            Console.WriteLine("{0}: {1}/{2}", wayPointChicago.Name, wayPointChicago.Latitude, wayPointChicago.Longitude);
            Console.WriteLine(wayPointChicago.ToString());
            double distance = wayPointWindisch.Distance(wayPointChicago);
            Console.WriteLine("Distance from {0} to {1} is {2}", wayPointWindisch.Name, wayPointChicago.Name, distance);
            Console.ReadKey();
        }
 static void Main(string[] args)
 {
     Console.WriteLine("Welcome to RoutePlanner (Version {0})", Assembly.GetExecutingAssembly().GetName().Version);
     var wayPointTest = new WayPoint("Windisch", 47.479319847061966, 8.212966918945312);
     var wayPointBern = new WayPoint("Bern", 46.947346, 7.447742);
     var wayPointTripolis = new WayPoint("Tripolis", 32.885460, 13.190739);
     Console.WriteLine(wayPointTest.ToString());
     Console.WriteLine("Distance between Bern and Tripoli: " + wayPointBern.Distance(wayPointTripolis) + " km");
     var citiesTest = new Cities();
     //citiesTest.ReadCities(@"citiesTestDataLab2.txt");
     citiesTest.ReadCities("citiesTestDataLab2.txt");
     //Console.WriteLine("{0}: {1}/{2}", wayPoint.Name, wayPoint.Latitude, wayPoint.Longitude);
     Console.ReadKey();
 }
示例#15
0
        public void TestWayPointCalculation()
        {
            WayPoint wp1 = new WayPoint("Home", 10.4, 20.8);
            WayPoint wp2 = new WayPoint("Target", 1.2, 2.4);

            WayPoint addWp = wp1 + wp2;
            Assert.AreEqual(wp1.Name, addWp.Name);
            Assert.AreEqual(wp1.Latitude + wp2.Latitude, addWp.Latitude);
            Assert.AreEqual(wp1.Longitude + wp2.Longitude, addWp.Longitude);

            WayPoint minWp = wp1 - wp2;
            Assert.AreEqual(wp1.Name, minWp.Name);
            Assert.AreEqual(wp1.Latitude - wp2.Latitude, minWp.Latitude);
            Assert.AreEqual(wp1.Longitude - wp2.Longitude, minWp.Longitude);
        }
示例#16
0
文件: Lab2Test.cs 项目: Laubeee/ecnf
        public void TestCultureHandling()
        {
            var target = new WayPoint("Windisch", 0.564, 0.646);

            // test whether formatting works correctly in all cultures
            var previousCulture = Thread.CurrentThread.CurrentCulture;
            var newCulture = Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
            Assert.AreEqual("WayPoint: Windisch 0.56/0.65", target.ToString());
            Assert.AreEqual(Thread.CurrentThread.CurrentCulture, newCulture);

            newCulture = Thread.CurrentThread.CurrentCulture = new CultureInfo("de-CH");
            Assert.AreEqual("WayPoint: Windisch 0.56/0.65", target.ToString());
            Assert.AreEqual(Thread.CurrentThread.CurrentCulture, newCulture);

            Thread.CurrentThread.CurrentCulture = previousCulture;
        }
示例#17
0
        public void TestWayPointToString()
        {
            // test complete way point
            var target = new WayPoint(Name, Latitude, Longitude);
            string wayPointOut = string.Format("WayPoint: {0} {1:N2}/{2:N2}", 
                                Name, Latitude, Longitude);

            Assert.AreEqual(wayPointOut, target.ToString());

            // test no-name case
            var targetNullName = new WayPoint(null, Latitude, Longitude);
            string wayPointOutNullName = string.Format("WayPoint: {0:N2}/{1:N2}",
                                Latitude, Longitude);
            Assert.AreEqual(wayPointOutNullName, targetNullName.ToString());
            
        }
        static void Main(string[] args)
        {
            //Lab1 Aufgabe 1
            Console.WriteLine("Welcome to RoutePlanner (Version " + Assembly.GetExecutingAssembly().GetName().Version + ")");

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

            //Lab2 Aufgabe 1a
            Console.WriteLine(wayPoint);
            var wayPoint1 = new WayPoint("", 47.479319847061966, 8.212966918945312);
            var wayPoint2 = new WayPoint(null, 47.479319847061966, 8.212966918945312);
            Console.WriteLine(wayPoint1);
            Console.WriteLine(wayPoint2);

            //Lab2 Aufgabe 1b
            var bern = new WayPoint("Bern", 46.948342, 7.442935);
            var tripolis = new WayPoint("Tripolis", 32.808858, 13.098922);
            Console.WriteLine(bern.Distance(tripolis));
            Console.WriteLine(tripolis.Distance(bern));

            //Lab2 Aufgabe 2b - FunktionsTest - Funktioniert
            Cities c = new Cities();
            c.ReadCities("citiesTestDataLab2.txt");
            Console.WriteLine("Test: {0}", c[5].Location.Latitude);

            var target = new WayPoint("Windisch", 0.564, 0.646);
            Console.WriteLine(target.ToString() + " vs. " + "WayPoint: Windisch 0.56/0.65");

            //Lab3 Aufgabe 2
            var reqWatch = new RouteRequestWatcher();

            var routeCities = new Cities();
            routeCities.ReadCities("citiesTestDataLab2.txt");

            var routes = new Routes(routeCities);

            routes.RouteRequested += reqWatch.LogRouteRequests;

            routes.FindShortestRouteBetween("mumbai", "buenos aires", TransportMode.Rail);
            routes.FindShortestRouteBetween("dilli", "mumbai", TransportMode.Rail);
            routes.FindShortestRouteBetween("mumbai", "buenos aires", TransportMode.Rail);

            Console.ReadLine();
        }
示例#19
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();
        }
示例#20
0
文件: WayPoint.cs 项目: Laubeee/ecnf
 public double Distance(WayPoint _target)
 {
     return 6371 * Math.Acos(Math.Sin(DegreeToRadian(this.Latitude)) * Math.Sin(DegreeToRadian(_target.Latitude)) + Math.Cos(DegreeToRadian(this.Latitude)) * Math.Cos(DegreeToRadian(_target.Latitude)) * Math.Cos(DegreeToRadian(this.Longitude - _target.Longitude)));
 }
示例#21
0
        public List<City> FindNeighbours(WayPoint location, double distance)
        {
            // Old Version Lab 4
            //var neighbours = new List<City>();

            //foreach (var city in _cities)
            //{
            //    if(location.Distance(city.Location) <= distance)
            //        neighbours.Add(city);
            //}

            return _cities.Where(c => location.Distance(c.Location) <= distance).ToList();
        }
示例#22
0
 /// <summary>
 /// subtracts two WayPoints
 /// </summary>
 /// <param name="first">first WayPoint</param>
 /// <param name="second">second WayPoint</param>
 /// <returns>new WayPoint difference with same name as first Waypoint</returns>
 public static WayPoint operator- (WayPoint first, WayPoint second)
 {
     WayPoint difference = new WayPoint(first.Name, first.Latitude - second.Latitude, first.Longitude - second.Longitude);
     return difference;
 }
示例#23
0
 /// <summary>
 /// adds two WayPoints
 /// </summary>
 /// <param name="first">first WayPoint</param>
 /// <param name="second">second WayPoint</param>
 /// <returns>new WayPoint sum with same name as first Waypoint</returns>
 public static WayPoint operator+ (WayPoint first, WayPoint second)
 {
     WayPoint sum = new WayPoint(first.Name, first.Latitude + second.Latitude, first.Longitude + second.Longitude);
     return sum;
 }
示例#24
0
        static void Main(string[] args)
        {
            Version version = Assembly.GetEntryAssembly().GetName().Version;
            Console.WriteLine("Welcome to RoutePlanner ({0})", version);


            WayPoint wayPoint = new WayPoint("Windisch", 47.479319847061966, 8.212966918945312);
            Console.WriteLine(wayPoint.ToString());
            WayPoint wpBern = new WayPoint("Bern", 46.9472221, 7.451202500000022);
            WayPoint wpTripolis = new WayPoint("Tripolis", 59.86062519999999, 17.650885199999948);
            Console.WriteLine("Distanz Bern-Tripolis: {0}km", wpBern.Distance(wpTripolis));

            City cBern = new City("Bern", "Schweiz", 75000, 47.479319847061966, 8.212966918945312);
            City c0 = new City("Mumbai", "India", 12383146, 18.96, 72.82);

            string serializedCity = string.Empty;
            using (StringWriter outstream = new StringWriter())
            {
                SimpleObjectWriter writer = new SimpleObjectWriter(outstream);
                writer.Next(cBern);
                serializedCity = outstream.ToString();
            }
            Console.WriteLine(serializedCity);

            using(StringReader inStream = new StringReader(serializedCity)) {
                SimpleObjectReader reader = new SimpleObjectReader(inStream);
                object o = reader.Next();
            }
        

            WayPoint wp = c0.Location;
            Cities c = new Cities();
            c.ReadCities("citiesTestDataLab2.txt");
            c.FindNeighbours(wp,2000);
            c.ReadCities("citiesTestDataLab2.txt");

            var routes = new RoutesDijkstra(c);
            var reqWatch = new RouteRequestWatcher();
            routes.RouteRequestEvent += reqWatch.LogRouteRequests;
            routes.FindShortestRouteBetween("Mumbai", "India", TransportModes.Rail);
            routes.FindShortestRouteBetween("Mumbai", "India", TransportModes.Rail);
            routes.FindShortestRouteBetween("India", "Mumbai", TransportModes.Rail);

            Console.WriteLine("City found: {0}", c.FindCity("Mumbai").Name);

            c.ReadCities("citiesTestDataLab4.txt");
            Routes r = new RoutesDijkstra(c);
            r.RouteRequestEvent += reqWatch.LogRouteRequests;
            r.ReadRoutes("linksTestDataLab4.txt");
            List<Link> l = r.FindShortestRouteBetween("Zürich", "Winterthur", TransportModes.Rail);
            foreach (Link link in l)
            {
                Console.WriteLine("from {0} to {1} in {2}", link.FromCity.Name, link.ToCity.Name, link.Distance);
            }
            Console.ReadKey();

            City zurich = c.FindCity("Zürich");
            City winterthur = c.FindCity("Winterthur");
            ExcelExchange export = new ExcelExchange();
            export.WriteToFile("Test.xls", zurich, winterthur,l);
            
        }
示例#25
0
 private List<City> SortByDistance(List<City> neighbours,WayPoint location)
 {
     return neighbours.OrderBy(n => n.Location.Distance(location)).ToList();
 }
示例#26
0
文件: Lab2Test.cs 项目: Laubeee/ecnf
        public void TestWayPointToString()
        {
            // test complete way point
            var target = new WayPoint("Windisch", 0.564, 0.646);
            Assert.AreEqual(target.ToString(), "WayPoint: Windisch 0.56/0.65");

            // test no-name case
            target = new WayPoint(null, 0.564, 0.646);
            Assert.AreEqual(target.ToString(), "WayPoint: 0.56/0.65");

            // test for correct formatting with 2 decimal places
            var targetRound = new WayPoint("Testtest", 1.0, 0.50);
            Assert.AreEqual(targetRound.ToString(), "WayPoint: Testtest 1.00/0.50");
        }
示例#27
0
文件: Cities.cs 项目: Laubeee/ecnf
 public IEnumerable<City> FindNeighbours(WayPoint _location, double _distance)
 {
     var matchedCities = cities.FindAll((City c) => c.Location.Distance(_location) <= _distance);
     matchedCities.Sort((City c1, City c2) => c1.Location.Distance(_location) > c2.Location.Distance(_location) ? 1 : -1);
     return matchedCities;
 }
示例#28
0
 public IEnumerable<City> FindNeighbours(WayPoint location, double distance)
 {
     return cities.Where(c => location.Distance(c.Location) <= distance).ToList();
 }
示例#29
0
 public double Distance(WayPoint target)
 {
     return(6371 * Math.Acos(Math.Sin(DegToRad(this.Latitude)) * Math.Sin(DegToRad(target.Latitude)) + Math.Cos(DegToRad(this.Latitude)) * Math.Cos(DegToRad(target.Latitude)) * Math.Cos(DegToRad(target.Longitude - this.Longitude))));
 }
示例#30
0
文件: Lab2Test.cs 项目: Laubeee/ecnf
        public void TestWayPointValidConstructor()
        {
            var target = new WayPoint("Windisch", 0.564, 0.646);

            Assert.AreEqual("Windisch", target.Name);
            Assert.AreEqual(0.564, target.Latitude);
            Assert.AreEqual(0.646, target.Longitude);
        }
示例#31
0
 public List<City> FindNeighbours(WayPoint location, double distance)
 {
     return (cities.Where(c => location.Distance(c.Location) < distance).OrderBy(d => location.Distance(d.Location)).ToList());
 }