/// <summary> /// Constructor /// </summary> /// <param name="name">name of the city</param> /// <param name="country">Country of the city</param> /// <param name="population">Population of the city</param> /// <param name="latitude">Latitude of the city</param> /// <param name="longitude">Longitude of the city</param> public City(string name, string country, int population, double latitude, double longitude) { Name = name; Country = country; Population = population; Location = new WayPoint(name, latitude, longitude); }
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); }
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); }
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(); }
/// <summary> /// Calculate distance between this and the parameter waypoint /// </summary> /// <param name="target">waypoint to calculate the distance to</param> /// <returns>distance</returns> public double Distance(WayPoint target) { double radianToDegree = (Math.PI / 180); double tmp1 = Math.Sin(radianToDegree * Latitude) * Math.Sin(radianToDegree * target.Latitude); double tmp2 = Math.Cos(radianToDegree * Latitude) * Math.Cos(radianToDegree * target.Latitude); double tmp3 = Math.Cos(radianToDegree * (Longitude - target.Longitude)); double tmp4 = tmp2 * tmp3; double d = 0; d = RADIUS * Math.Acos(tmp1 + tmp4); return d; }
public void TestWayPointCalculation() { var wp1 = new WayPoint("Home", 10.4, 20.8); var wp2 = new WayPoint("Target", 1.2, 2.4); var 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); var 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); }
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()); }
/// <summary> /// Find all neighbours of a city within the defined distance. /// The list is sorted by distance /// </summary> /// <param name="location"></param> /// <param name="distance"></param> /// <returns></returns> public List<City> FindNeighbours(WayPoint location, double distance) { return (_cities .Where(c => location.Distance(c.Location) < distance) .OrderBy(d => location.Distance(d.Location)).ToList()); }