private IEnumerable <Ride> GetMinPickup(int n) { var comparer = Ride.CreatePickUpComparer(_car); var heap = new MaxHeap <Ride>(comparer); foreach (var ride in _availableRides) { if (_car.CanMakeIt(ride) && (heap.Count < n || comparer.Compare(heap.Max, ride) > 0)) { heap.Add(ride); if (heap.Count > n) { heap.ExtractMax(); } } } return(heap); }
private IEnumerable <Ride> GetBestScore(int n) { var comparer = Ride.CreateScoreComparer(_car, _problem); var heap = new MinHeap <Ride>(comparer); foreach (var ride in _availableRides) { if (_car.CanMakeIt(ride) && (heap.Count < n || comparer.Compare(heap.Min, ride) < 0)) { heap.Add(ride); if (heap.Count > n) { heap.ExtractMin(); } } } return(heap); }
/// <summary> /// reads data from text file into an array /// </summary> /// <returns></returns> static List <Ride> ReadFromDataFile() { List <Ride> rides = new List <Ride>(); CultureInfo provider = CultureInfo.InvariantCulture; // // read from data file into an array // string[] rideStrings = File.ReadAllLines("Data\\Data.txt"); foreach (string ride in rideStrings) { // // get ride property values // string[] rideProperties = ride.Split(','); // // create a new ride with the property values // Ride newRide = new Ride(); newRide.TrailSystem = rideProperties[0]; double.TryParse(rideProperties[1], out double duration); newRide.Duration = duration; double.TryParse(rideProperties[2], out double miles); newRide.Miles = miles; Enum.TryParse(rideProperties[3], out Ride.WeatherCondition weather); newRide.Weather = weather; newRide.Date = Convert.ToDateTime(rideProperties[4]); // // add new ride to list // rides.Add(newRide); } return(rides); }
public static List <Ride> Build(string[] lines) { var rides = new List <Ride>(lines.Length); for (var i = 0; i < lines.Length; i++) { var line = lines[i]; var pars = line.Split(' '); var a = int.Parse(pars[0]); var b = int.Parse(pars[1]); var x = int.Parse(pars[2]); var y = int.Parse(pars[3]); var s = int.Parse(pars[4]); var f = int.Parse(pars[5]); var ride = new Ride(i, new Point(a, b), new Point(x, y), s, f); rides.Add(ride); } return(rides); }
public static int GetFactScore(Ride ride, Car car, int bonus) { if (car.Equals(Car.SkipRide)) { return(0); } var score = 0; var rideDistance = ride.From.Distance(ride.To); var pickDistance = car.Location.Distance(ride.From); score += rideDistance; var timeToPick = car.Time + pickDistance; var onTime = timeToPick <= ride.Start; if (onTime) { score += bonus; } return(score); }
public void Remove(Ride ride) { _lastRemoved = ride; }
/// <summary> /// add a ride /// </summary> static void DisplayAddRide(List <Ride> rides) { // todo - add option to confirm ride input Ride newRide = new Ride(); bool validResponse; DisplayScreenHeader("Add Ride"); do { Console.Write("\tDate of Ride: "); if (DateTime.TryParse(Console.ReadLine(), out DateTime date)) { newRide.Date = date; validResponse = true; } else { Console.WriteLine(); DisplayDateErrorMessage(); validResponse = false; } } while (!validResponse); Console.Write("\tTrail System: "); newRide.TrailSystem = Console.ReadLine(); while (string.IsNullOrWhiteSpace(newRide.TrailSystem)) { Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\tTrail System can not be empty."); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Black; Console.Write("\tTrail System: "); newRide.TrailSystem = Console.ReadLine().ToUpper(); } do { Console.Write("\tDuration (hours): "); if (double.TryParse(Console.ReadLine(), out double duration) & duration > 0) { newRide.Duration = duration; validResponse = true; } else { Console.WriteLine(); DisplayErrorMessage(); validResponse = false; } } while (!validResponse); do { Console.Write("\tDistance (miles): "); if (double.TryParse(Console.ReadLine(), out double miles) & miles > 0) { newRide.Miles = miles; validResponse = true; } else { Console.WriteLine(); DisplayErrorMessage(); validResponse = false; } } while (!validResponse); do { Console.Write("\tWeather: "); if (Enum.TryParse(Console.ReadLine().ToLower().Replace(" ", ""), out Ride.WeatherCondition weather)) { newRide.Weather = weather; validResponse = true; } else { Console.WriteLine(); DisplayWeatherErrorMessage(); validResponse = false; } } while (!validResponse); // // echo new ride properties // Console.WriteLine(); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("\tNew Ride's Properties"); Console.WriteLine("\t---------------------"); Console.ForegroundColor = ConsoleColor.Black; RideInfo(newRide); DisplayContinuePrompt(); rides.Add(newRide); }
/// <summary> /// update rides /// </summary> static void DisplayUpdateRide(List <Ride> rides) { /// todo - numbered menu to select ride bool validResponse = false; Ride selectedRide = null; do { DisplayScreenHeader("Update Ride"); // // display all ride names // Console.WriteLine("\tTrail System"); Console.WriteLine("\t-------------"); foreach (Ride ride in rides) { Console.WriteLine("\t" + ride.TrailSystem); } // // get user ride choice // Console.WriteLine("\t-------------"); Console.WriteLine(); Console.Write("\tEnter name:"); string rideName = Console.ReadLine().ToUpper(); // // get ride object // foreach (Ride ride in rides) { if (ride.TrailSystem == rideName) { selectedRide = ride; validResponse = true; break; } } // // feedback for wrong name choice // if (!validResponse) { Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\tPlease select a ride shown above."); Console.ForegroundColor = ConsoleColor.Black; DisplayContinuePrompt(); } } while (!validResponse); // // update ride // string userResponse; Console.WriteLine(); Console.WriteLine("\tReady to update. Press enter to keep the current info."); Console.WriteLine(); // // update trails system name // Console.WriteLine($"\tCurrent Trail System: {selectedRide.TrailSystem}"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write("\tNew Trail System: "); Console.ForegroundColor = ConsoleColor.Black; userResponse = Console.ReadLine().ToUpper(); Console.WriteLine(); if (userResponse != "") { selectedRide.TrailSystem = userResponse; } // // update date of ride // bool validDate = false; do { Console.WriteLine($"\tCurrent Date: {selectedRide.Date}"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write("\tNew Date: "); Console.ForegroundColor = ConsoleColor.Black; userResponse = Console.ReadLine(); Console.WriteLine(); if (userResponse != "") { if (DateTime.TryParse(userResponse, out DateTime date)) { selectedRide.Date = date; validDate = true; } else { DisplayDateErrorMessage(); } } if (userResponse == "") { validDate = true; } } while (!validDate); // // update duration of ride // bool validDuration = false; do { Console.WriteLine($"\tCurrent Duration (hours): {selectedRide.Duration}"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write("\tNew Duration (hours): "); Console.ForegroundColor = ConsoleColor.Black; userResponse = Console.ReadLine(); Console.WriteLine(); if (userResponse != "") { if (double.TryParse(userResponse, out double duration) & duration > 0) { selectedRide.Duration = duration; validDuration = true; } else { DisplayErrorMessage(); } } if (userResponse == "") { validDuration = true; } } while (!validDuration); // // update distance of ride // bool validDistance = false; do { Console.WriteLine($"\tCurrent Distance (miles): {selectedRide.Miles}"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write("\tNew Distance (miles): "); Console.ForegroundColor = ConsoleColor.Black; userResponse = Console.ReadLine(); Console.WriteLine(); if (userResponse != "") { if (double.TryParse(userResponse, out double miles) & miles > 0) { selectedRide.Miles = miles; validDistance = true; } else { DisplayErrorMessage(); } } if (userResponse == "") { validDistance = true; } } while (!validDistance); // // update weather of ride // bool validWeather = false; do { Console.WriteLine($"\tCurrent Weather: {selectedRide.Weather}"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write("\tNew Weather: "); Console.ForegroundColor = ConsoleColor.Black; userResponse = Console.ReadLine().ToLower().Replace(" ", ""); Console.WriteLine(); if (userResponse != "") { if (Enum.TryParse(userResponse, out Ride.WeatherCondition weather)) { selectedRide.Weather = weather; validWeather = true; } else { DisplayWeatherErrorMessage(); } } if (userResponse == "") { validWeather = true; } } while (!validWeather); DisplayContinuePrompt(); }
protected bool Equals(MakeRideAction other) { return(Ride.Equals(other.Ride) && Car.Equals(other.Car)); }
public MakeRideAction(Ride ride, Car car) { Ride = ride; Car = car; }
public bool CanMakeIt(Ride ride) { return(ride.Finish >= Time + Location.Distance(ride.From) + ride.From.Distance(ride.To)); }
public void Remove(Ride ride) { //_earliestStart.Remove(ride); _earliestFinish.Remove(ride); }