Пример #1
0
        static void PrintDistance()
        {
            WayPoint bern   = new WayPoint("Bern", 46.95, 7.44);
            WayPoint berlin = new WayPoint("Berlin", 52.52, 13.38);

            System.Console.WriteLine("Distanz {0} -> {1}: {2} km",
                                     bern.Name, berlin.Name, bern.Distance(berlin));
        }
Пример #2
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);
        }
Пример #3
0
        private void GenerateSpline(WayPoint p0, WayPoint p1, out Spline xsp, out Spline ysp)
        {
            double p0h = XeroUtils.DegreesToRadians(p0.Heading);
            double p1h = XeroUtils.DegreesToRadians(p1.Heading);

            double scale = 1.2 * p0.Distance(p1);
            double x0    = p0.X;
            double x1    = p1.X;
            double dx0   = Math.Cos(p0h) * scale;
            double dx1   = Math.Cos(p1h) * scale;
            double ddx0  = 0.0;
            double ddx1  = 0.0;

            double y0   = p0.Y;
            double y1   = p1.Y;
            double dy0  = Math.Sin(p0h) * scale;
            double dy1  = Math.Sin(p1h) * scale;
            double ddy0 = 0.0;
            double ddy1 = 0.0;

            double ax = -6 * x0 - 3 * dx0 - 0.5 * ddx0 + 0.5 * ddx1 - 3 * dx1 + 6 * x1;
            double bx = 15 * x0 + 8 * dx0 + 1.5 * ddx0 - ddx1 + 7 * dx1 - 15 * x1;
            double cx = -10 * x0 - 6 * dx0 - 1.5 * ddx0 + 0.5 * ddx1 - 4 * dx1 + 10 * x1;
            double dx = 0.5 * ddx0;
            double ex = dx0;
            double fx = x0;

            double ay = -6 * y0 - 3 * dy0 - 0.5 * ddy0 + 0.5 * ddy1 - 3 * dy1 + 6 * y1;
            double by = 15 * y0 + 8 * dy0 + 1.5 * ddy0 - ddy1 + 7 * dy1 - 15 * y1;
            double cy = -10 * y0 - 6 * dy0 - 1.5 * ddy0 + 0.5 * ddy1 - 4 * dy1 + 10 * y1;
            double dy = 0.5 * ddy0;
            double ey = dy0;
            double fy = y0;

            double dist = p0.Distance(p1);

            xsp = new Spline(dist, new double[] { fx, ex, dx, cx, bx, ax });
            ysp = new Spline(dist, new double[] { fy, ey, dy, cy, by, ay });
        }
Пример #4
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();
        }
Пример #5
0
        static void Main(string[] args)
        {
            WayPoint pratteln = new WayPoint("Pratteln", 47.5167, 7.6833);
            WayPoint bern     = new WayPoint("Bern", 46.95, 7.44);

            Console.WriteLine(
                "Distanz von {0} nach {1}: {2}km",
                bern.Name, pratteln.Name, bern.Distance(pratteln)
                );

            City cbern = new City("Bern", bern.Latitude, bern.Longitude, 160788, "Schweiz");

            ICityRepository cityRepository = new CityRepositoryFile("Resources/cities.txt");

            Console.WriteLine("Total " + cityRepository.Count + " cities");
            Console.WriteLine("Neighbors of " + pratteln.Name + ":");
            foreach (City n in cityRepository.FindNeighbors(pratteln, 60.0))
            {
                Console.WriteLine(n.Name);
            }
            Console.ReadKey();

            LinkRepositoryFile linkRepository = new LinkRepositoryFile("Resources/routes.txt", cityRepository);

            Console.WriteLine("Anzahl Verbindungen " + linkRepository.Count);

            RouteManager rmgr = new RouteManager(cityRepository, linkRepository);

            // Delegates...
            rmgr.notifiers += KeepMeInformed;    // statisch
            rmgr.notifiers += KeepMeInformedToo; // statisch

            // Nicht möglich, siehe RouteManager.cs Delegates
            // rmgr.notifiers(null, null);

            Link[] route = rmgr.FindShortestRouteBetween("Basel", "Berlin", Link.TransportModeEnum.Rail);
            foreach (Link l in route)
            {
                Console.WriteLine(l);
            }
        }
Пример #6
0
        private void GenerateSpline(WayPoint p0, WayPoint p1, out Spline xsp, out Spline ysp)
        {
            double dist    = p0.Distance(p1);
            double aoffset = Math.Atan2(p1.Y - p0.Y, p1.X - p0.X);

            double a0_delta = Math.Tan(XeroUtils.BoundRadians(XeroUtils.DegreesToRadians(p0.Heading) - aoffset));
            double a1_delta = Math.Tan(XeroUtils.BoundRadians(XeroUtils.DegreesToRadians(p1.Heading) - aoffset));

            double[] coeffs = new double[6];
            coeffs[5] = -(3 * (a0_delta + a1_delta)) / (dist * dist * dist * dist);
            coeffs[4] = (8 * a0_delta + 7 * a1_delta) / (dist * dist * dist);
            coeffs[3] = -(6 * a0_delta + 4 * a1_delta) / (dist * dist);
            coeffs[2] = 0.0;
            coeffs[1] = a0_delta;
            coeffs[0] = 0.0;

            xsp             = new Spline(dist, coeffs);
            xsp.XOffset     = p0.X;
            xsp.YOffset     = p0.Y;
            xsp.AngleOffset = XeroUtils.RadiansToDegrees(aoffset);
            ysp             = null;
        }
        static void Main(string[] args)
        {
            Console.WriteLine("My first C# Program: {0}", Assembly.GetExecutingAssembly().GetName().Version);

            var wayPoint = new WayPoint("Windisch", 47.479319847061966, 8.212966918945312);

            //Console.WriteLine($"{wayPoint.Name}: {wayPoint.Latitude}/{wayPoint.Longitude}");
            Console.WriteLine(wayPoint);

            //testing myWayPoint.distance(otherWayPoint):
            var    wpBern     = new WayPoint("Bern", 46.57266, 7.26471);
            var    wpTripolis = new WayPoint("Tripolis", 32.53270, 13.10358);
            double distance   = wpBern.Distance(wpTripolis);

            Console.WriteLine("The Distance between...");
            Console.WriteLine(wpBern + " and ");
            Console.WriteLine(wpTripolis);
            Console.WriteLine("equals: " + distance + "km.");


            //Um zu verhindern, dass Konsolenfenster gleich wieder geschlossen wird:
            Console.WriteLine("Press any key to quit");
            Console.ReadKey();
        }
Пример #8
0
        List <WayPoint> FindPathToLocation(Vector2 destination)
        {
            PixelCollider pixelCollider = transform.GetComponentInChildren <PixelCollider>();

            Debug.Assert(pixelCollider != null);
            PixelRoom pixelRoom = pixelCollider.GetPixelRoom();

            Debug.Assert(pixelRoom != null);

            // Dijkstra's Algorithm Parameters
            int   stepSize            = pixelRoom.stepSize;
            float minDistanceToTarget = stepSize * 2;

            // Initialization
            HashSet <WayPoint> Q      = pixelRoom.GetNavigationalMesh(pixelCollider);
            WayPoint           target = new WayPoint
            {
                position = destination,
                distance = float.MaxValue,
                previous = null
            };
            WayPoint current = Q.Aggregate((i1, i2) => (i1.position - (Vector2)transform.position).sqrMagnitude < (i2.position - (Vector2)transform.position).sqrMagnitude ? i1 : i2);

            current.distance = 0;

            // Propogation
            while (Q.Count > 0)
            {
                WayPoint u = Q.Aggregate((i1, i2) => i1.distance < i2.distance ? i1 : i2);
                Q.Remove(u);

                if (WayPoint.Distance(u, target) < minDistanceToTarget)
                {
                    target.previous = u;

                    List <WayPoint> path = new List <WayPoint>();
                    if (u.previous == null)
                    {
                        return(path);
                    }
                    while (u.previous != null)
                    {
                        path.Add(u);
                        u = u.previous;
                    }
                    path.Add(u);
                    path.Reverse();
                    return(path);
                }

                foreach (WayPoint v in u.neighbours)
                {
                    float alt = u.distance + WayPoint.Distance(u, v);
                    if (alt < v.distance)
                    {
                        v.distance = alt;
                        v.previous = u;
                    }
                }
            }

            return(new List <WayPoint>());
        }
Пример #9
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);
        }
Пример #10
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to RoutePlanner (" + Assembly.GetExecutingAssembly().GetName().Version.ToString() + ")");
            Console.WriteLine();

            var wayPoint = new WayPoint("Windisch", 47.479319847061966, 8.212966918945312);

            var wpBern     = new WayPoint("Bern", 46.9479222, 7.4446085);
            var wpTripolis = new WayPoint("Tripolis", 32.8084124, 13.1509672);

            Console.WriteLine(wayPoint.ToString());

            Console.WriteLine(wpBern.ToString());
            Console.WriteLine(wpTripolis.ToString());

            Console.WriteLine("Distance: {0}", wpBern.Distance(wpTripolis));

            var citiesLab2 = new Cities();

            citiesLab2.ReadCities("data\\citiesTestDataLab2.txt");

            var    bern     = new WayPoint("Bern", 46.95, 7.44);
            var    tripolis = new WayPoint("Tripolis", 32.876174, 13.187507);
            double actual   = bern.Distance(tripolis);

            Console.WriteLine();
            var findCity = citiesLab2.FindCity("Bern");

            if (findCity != null)
            {
                Console.WriteLine("City {0} was found.", findCity.Name);
            }
            else
            {
                Console.WriteLine("City not found.");
            }

            findCity = citiesLab2.FindCity("Dilli");

            if (findCity != null)
            {
                Console.WriteLine("City {0} was found.", findCity.Name);
            }
            else
            {
                Console.WriteLine("City not found.");
            }

            Console.WriteLine();
            Console.WriteLine("Test Routes");
            var citiesLab3 = new Cities();

            citiesLab3.ReadCities("data\\citiesTestDataLab3.txt");
            var reqWatcher = new RouteRequestWatcher();

            var routes = new RoutesDijkstra(citiesLab3);

            routes.RouteRequestEvent += reqWatcher.LogRouteRequests;
            routes.FindShortestRouteBetween("Bern", "Zürich", TransportModes.Bus);
            routes.FindShortestRouteBetween("Bern", "Zürich", TransportModes.Bus);

            routes.ReadRoutes("data\\linksTestDataLab3.txt");

            Console.WriteLine();
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to RoutePlanner (Version " +
                              System.Reflection.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.ToString());
            var bern     = new WayPoint("Bern", 46.949690, 7.442420);
            var tripolis = new WayPoint("Tripolis", 32.815062, 13.105445);

            Console.WriteLine(bern.Distance(tripolis));

            var cities = new Cities();

            cities.ReadCities("citiesTestDataLab4.txt");
            IRoutes routes = RoutesFactory.Create(cities);

            Console.WriteLine(routes);
            var count = routes.ReadRoutes("linksTestDataLab4.txt");

            //TestError Loading Lab9 b)
            var count2 = routes.ReadRoutes("linksTestDataLab42.txt");

            var c1 = new City("Aarau", "Switzerland", 10, 1.1, 2.2);
            var c2 = new City("Bern", "Switzerland", 10, 1.1, 2.2);

            Console.WriteLine("\nsimpleObjectWriterTest");
            var stream = new StringWriter();
            var writer = new SimpleObjectWriter(stream);

            writer.Next(c1);
            Console.WriteLine(stream.ToString());

            Console.WriteLine("readTest Lab5");
            const string cityString1   = "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 cityString2   = "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 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          stream2       = new StringReader(cityString);
            var          reader        = new SimpleObjectReader(stream2);
            var          city1         = reader.Next() as City;

            if (city1 == null)
            {
                Console.WriteLine("city was null");
            }
            Console.WriteLine(city1.ToString());

            Console.WriteLine("ActionTest Lab6");
            var actions = new Action[3];

            for (var i = 0; i < actions.Length; i++)
            {
                var z = i;
                actions[i] = () => Console.Write(z);
            }

            foreach (var a in actions)
            {
                a();
            }

            //Lab9 a1 c) Console & File Test of Readcities
            var cities3 = new Cities();

            cities3.ReadCities("citiesTestDataLab4.txt");
            IRoutes routes2 = RoutesFactory.Create(cities);

            //Lab9 a1 b) Loading from existing file
            var count3 = routes.ReadRoutes("linksTestDataLab4.txt");

            //Lab9 a1 b) Writing to file but not to console
            routesLogger.TraceEvent(TraceEventType.Information, 01, "this should not be on the console");


            //Lab9 a1 b) Loding not existing file
            var count4 = routes.ReadRoutes("linksTestDataLab42.txt");

            //Lab10 Tests
            Console.WriteLine("Lab10 Tests");
            Cities c10 = new Cities();

            c10.ReadCities(@"citiesTestDataLab10.txt");
            Console.WriteLine(c10.Count);

            Routes r10     = new RoutesFloydWarshall(cities);
            int    count10 = r10.ReadRoutes(@"linksTestDataLab10.txt");

            Console.WriteLine(count10);

            // test short routes in parallel mode
            r10.ExecuteParallel = true;
            sw.Start();
            List <Link> links = routes.FindShortestRouteBetween("Lyon", "Berlin", TransportModes.Rail, null);

            sw.Stop();
            Console.WriteLine("Parallel: " + sw.ElapsedMilliseconds);

            // test short routes in seqential mode
            r10.ExecuteParallel = false;
            sw.Restart();
            List <Link> links2 = routes.FindShortestRouteBetween("Lyon", "Berlin", TransportModes.Rail, null);

            sw.Stop();
            Console.WriteLine("Sequential: " + sw.ElapsedMilliseconds);
            //feststellung Parallel benötigt länger

            //Webpage of uploaded RoutePlannerLib
            //https://www.nuget.org/packages/FHNW-Lab11-Test/



            Console.ReadLine();
        }
        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);

            //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 2a
            new City("Bern", "Schweiz", 75000, 47.479319847061966, 8.212966918945312);

            //Lab2 Aufgabe 2b
            Cities cities = new Cities();

            Console.WriteLine("New cities: " + cities.ReadCities("citiesTestDataLab2.txt"));

            //Lab2 Aufgabe 2c

            /*
             * for (int i = 0; i < cities.Count;i++ )
             * {
             *  Console.WriteLine(cities[i].Name + ", " + cities[i].Country
             + ", " + cities[i].Population
             + ", " + cities[i].Location.Latitude
             + ", " + cities[i].Location.Longitude
             +      );
             + }
             */

            //Lab2 Aufgabe 2d
            List <City> neighbours = cities.FindNeighbours(cities[1].Location, (double)17000.0);

            for (int i = 0; i < neighbours.Count; i++)
            {
                Console.WriteLine(neighbours[i].Name + ", " + neighbours[i].Country
                                  + ", " + neighbours[i].Population
                                  + ", " + neighbours[i].Location.Latitude
                                  + ", " + neighbours[i].Location.Longitude
                                  );
            }

            //Lab3 Aufgabe 1
            City city = cities.FindCity("shanghai");

            Console.WriteLine("Name: " + city.Name + ", " + city.Country
                              + ", " + city.Population
                              + ", " + city.Location.Latitude
                              + ", " + city.Location.Longitude
                              );


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

            var routeCities = new Cities();

            cities.ReadCities("citiesTestDataLab2.txt");

            var routes = new RoutesDijkstra(routeCities);

            routes.RouteRequestEvent += reqWatch.LogRouteRequests;

            routes.FindShortestRouteBetween("Bern", "Zürich", TransportModes.Rail);
            routes.FindShortestRouteBetween("Bern", "Zürich", TransportModes.Rail);
            routes.FindShortestRouteBetween("Basel", "Bern", TransportModes.Rail);


            const string cityString1   = "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 cityString2   = "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 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;

            var city2 = reader.Next() as City;

            routes.ReadRoutes("linksTestDataLab3.txt");
            routes.ReadRoutes("linksTestDa.txt");

            Console.ReadLine();
        }