public override List <Link> FindShortestRouteBetween(string fromCity, string toCity, TransportModes mode, IProgress <string> reportProgress) { List <City> citiesBetween = Cities.FindCitiesBetween(Cities.FindCity(fromCity), Cities.FindCity(toCity)); if (citiesBetween == null || citiesBetween.Count < 1) { return(null); } List <Link> links = FindAllLinks(citiesBetween, mode); if (links == null || links.Count < 1) { return(null); } /*var stopWatch = new Stopwatch(); * stopWatch.Start(); * long ts0=stopWatch.ElapsedMilliseconds;*/ Setup(citiesBetween, links); City source = FindCity(fromCity, citiesBetween); City target = FindCity(toCity, citiesBetween); if (D[source.Index, target.Index] == Double.MaxValue) { return(new List <Link>()); // no path between source and target } List <City> path = GetIntermediatePath(source, target); // must construct route from path var route = new List <Link>(); route.Add(new Link(source, path.ElementAt(0), D[source.Index, path.ElementAt(0).Index])); for (var i = 0; i < path.Count - 1; i++) { City from = path.ElementAt(i); City to = path.ElementAt(i + 1); route.Add(new Link(from, to, D[from.Index, to.Index])); } route.Add(new Link(path.ElementAt(path.Count - 1), target, D[path.ElementAt(path.Count - 1).Index, target.Index])); return(route); }
public void TestCorrectIndexingOfCities() { const int readCitiesExpected = 10; var cities = new Cities(); Assert.AreEqual(readCitiesExpected, cities.ReadCities(CitiesTestFile)); City from = cities.FindCity("Mumbai"); City to = cities.FindCity("Istanbul"); List<City> foundCities = cities.FindCitiesBetween(from, to); // verify that Index property is initialized int i = 0; foreach (var city in foundCities) { Assert.AreEqual(i, city.Index); i++; } }
public override List <Link> FindShortestRouteBetween(string fromCity, string toCity, TransportModes mode, IProgress <string> reportProgress) { NotifyObservers(this, new RouteRequestEventArgs(fromCity, toCity, mode)); ProgressReport(reportProgress, "<notified observers> done"); var citiesBetween = Cities.FindCitiesBetween(Cities.FindCity(fromCity), Cities.FindCity(toCity)); ProgressReport(reportProgress, "<found cities between> done"); if (citiesBetween == null || citiesBetween.Count < 1 || Links == null || Links.Count < 1) { return(null); } var source = citiesBetween[0]; var target = citiesBetween[citiesBetween.Count - 1]; Dictionary <City, double> dist; Dictionary <City, City> previous; var q = FillListOfNodes(citiesBetween, out dist, out previous); ProgressReport(reportProgress, "<created nodes> done"); dist[source] = 0.0; // the actual algorithm previous = SearchShortestPath(mode, q, dist, previous); ProgressReport(reportProgress, "<search shortest path> done"); // create a list with all cities on the route var citiesOnRoute = GetCitiesOnRoute(source, target, previous); ProgressReport(reportProgress, "<got cities on route> done"); // prepare final list if links return(FindPath(citiesOnRoute, mode)); }
protected List <City> FindCitiesBetween(string fromCity, string toCity) { return(cities.FindCitiesBetween(cities.FindCity(fromCity), cities.FindCity(toCity))); }