FindNeighbours() public method

public FindNeighbours ( City city, double distance ) : List
city City
distance double
return List
Esempio n. 1
0
        public void TestFindNeighbours()
        {
            var cities = new Cities();
            cities.ReadCities(CitiesTestFile);

            var loc = cities[0].Location;

            var neighbors = cities.FindNeighbours(loc, 2000);

            Assert.AreEqual(4, neighbors.Count);

            //verifies if the correct cities were found
            Assert.IsNotNull(neighbors.First(c=>c.Name == "Mumbai"));
            Assert.IsNotNull(neighbors.First(c => c.Name == "Karachi"));
            Assert.IsNotNull(neighbors.First(c => c.Name == "Dhaka"));
            Assert.IsNotNull(neighbors.First(c => c.Name == "Dilli"));
        }
Esempio n. 2
0
        public void TestFindNeighbours()
        {
            var cities = new Cities();
            cities.ReadCities(citiesTestFile);

            var loc = cities[0].Location;

            IEnumerable<City> neighbors = cities.FindNeighbours(loc, 2000);

            //verifies if the correct cities were found
            Assert.AreEqual(4, neighbors.Count());
            Assert.IsTrue(neighbors.Any(c => c.Name == "Mumbai"));
            Assert.IsTrue(neighbors.Any(c => c.Name == "Karachi"));
            Assert.IsTrue(neighbors.Any(c => c.Name == "Dhaka"));
            Assert.IsTrue(neighbors.Any(c => c.Name == "Dilli"));
        }
Esempio n. 3
0
        public void TestFindNeighboursSorted()
        {
            var cities = new Cities();
            cities.ReadCities(citiesTestFile);

            var loc = cities[0].Location;

            var neighbors = cities.FindNeighbours(loc, 2000).ToArray();

            //verify the correct order (sorted  by distance)
            Assert.AreEqual(4, neighbors.Length);
            Assert.AreEqual("Mumbai", neighbors[0].Name);
            Assert.AreEqual("Karachi", neighbors[1].Name);
            Assert.IsTrue(loc.Distance(neighbors[0].Location) <= loc.Distance(neighbors[1].Location));
            Assert.AreEqual("Dilli", neighbors[2].Name);
            Assert.IsTrue(loc.Distance(neighbors[1].Location) <= loc.Distance(neighbors[2].Location));
            Assert.AreEqual("Dhaka", neighbors[3].Name);
            Assert.IsTrue(loc.Distance(neighbors[2].Location) <= loc.Distance(neighbors[3].Location));
        }
        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);
            
        }