public Dictionary <string, double> ShortestPath(Vehicle vehicle, WeatherType weatherType, List <WeatherImpact> weatherImpactList, List <List <Orbit> > possiblePaths) { if (!vehicle.SupportedWeather.Contains(weatherType)) { return(null); } WeatherImpact wi = weatherImpactList.FirstOrDefault(a => a.Weather == weatherType); Dictionary <string, double> result = new Dictionary <string, double>(); foreach (List <Orbit> orbits in possiblePaths) { double time = 0.0; string path = ""; foreach (Orbit orbit in orbits) { time += TimeToCrossTheOrbit(vehicle, wi, orbit, weatherType).Value; path = path + "->" + orbit.Name; } result.Add(path, time); } double min = result.Min(a => a.Value); string key = result.FirstOrDefault(a => a.Value == min).Key; var res = new Dictionary <string, double>(); res.Add(key, min); return(res); }
public void FastestPath(Vehicle vehicle, WeatherType weatherType) { if (!vehicle.SupportedWeather.Contains(weatherType)) { Console.WriteLine("Not Supported by {0}", vehicle.Name); return; } WeatherImpact wi = _weatherImpactList.FirstOrDefault(a => a.Weather == weatherType); var source = _destArr[0]; Dictionary <string, double> result = new Dictionary <string, double>(); for (int i = 1; i < _destArr.Length; i++) { var res = ShortestPath(vehicle, weatherType, _weatherImpactList, _graph.GetAllPossiblePaths(source, _destArr[i])); result.Add(res.First().Key, res.First().Value); source = _destArr[i]; } double totalTime = result.Sum(a => a.Value); string route = ""; foreach (var d in result) { route = route + "->" + d.Key; } Console.WriteLine("By {0},", vehicle.Name); Console.WriteLine(" {0} minutes - {1}", totalTime, route); }
public double?TimeToCrossTheOrbit(Vehicle vehicle, WeatherImpact weatherImpact, Orbit orbit, WeatherType weatherType) { double time = (orbit.Distance / vehicle.Speed); if (weatherImpact == null) { time = time + (orbit.NumberOfCraters * vehicle.TimeRequiredToCrossCrater); } else { time = time + ((orbit.NumberOfCraters + (orbit.NumberOfCraters * weatherImpact.PercentageChangeInNumberOfCraters / 100)) * vehicle.TimeRequiredToCrossCrater); } return(time); }