public static void Apply(PotvinEncoding solution, PotvinPDRearrangeMove move, IVRPProblemInstance problemInstance) { Tour tour = solution.Tours[move.Tour]; int position = tour.Stops.IndexOf(move.City); IPickupAndDeliveryProblemInstance pdp = problemInstance as IPickupAndDeliveryProblemInstance; if (pdp != null) { int location = pdp.GetPickupDeliveryLocation(move.City); Tour tour2 = solution.Tours.Find(t => t.Stops.Contains(location)); int position2 = tour2.Stops.IndexOf(location); tour.Stops.Remove(move.City); tour2.Stops.Remove(location); solution.InsertPair(tour, move.City, location, problemInstance, position, position2); } else { tour.Stops.Remove(move.City); int place = solution.FindBestInsertionPlace(tour, move.City, position); tour.Stops.Insert(place, move.City); } solution.Repair(); }
public static PotvinEncoding ConvertFrom(List <int> route, IVRPProblemInstance instance) { PotvinEncoding solution = new PotvinEncoding(instance); solution.Tours = new ItemList <Tour>(); Tour tour = new Tour(); int routeIdx = 0; for (int i = 0; i < route.Count; i++) { if (route[i] <= 0) { if (tour.Stops.Count > 0) { solution.Tours.Add(tour); tour = new Tour(); } int vehicle = -route[i]; solution.VehicleAssignment[routeIdx] = vehicle; routeIdx++; } else { tour.Stops.Add(route[i]); } } solution.Repair(); return(solution); }
protected override void PerformMove() { PotvinVehicleAssignmentMove move = VehicleAssignmentMoveParameter.ActualValue; PotvinEncoding newSolution = move.Individual.Clone() as PotvinEncoding; Apply(newSolution, move, ProblemInstance); newSolution.Repair(); VRPToursParameter.ActualValue = newSolution; }
public static void Apply(PotvinEncoding solution, PotvinCustomerRelocationMove move, IVRPProblemInstance problemInstance) { if (move.Tour >= solution.Tours.Count) solution.Tours.Add(new Tour()); Tour tour = solution.Tours[move.Tour]; Tour oldTour = solution.Tours.Find(t => t.Stops.Contains(move.City)); oldTour.Stops.Remove(move.City); /*if (oldTour.Stops.Count == 0) solution.Tours.Remove(oldTour);*/ int place = solution.FindBestInsertionPlace(tour, move.City); tour.Stops.Insert(place, move.City); solution.Repair(); }
public static void Apply(PotvinEncoding solution, PotvinPDExchangeMove move, IVRPProblemInstance problemInstance) { if (move.Tour >= solution.Tours.Count) { solution.Tours.Add(new Tour()); } Tour tour = solution.Tours[move.Tour]; Tour oldTour = solution.Tours.Find(t => t.Stops.Contains(move.City)); oldTour.Stops.Remove(move.City); if (problemInstance is IPickupAndDeliveryProblemInstance) { IPickupAndDeliveryProblemInstance pdp = problemInstance as IPickupAndDeliveryProblemInstance; int location = pdp.GetPickupDeliveryLocation(move.City); Tour oldTour2 = solution.Tours.Find(t => t.Stops.Contains(location)); oldTour2.Stops.Remove(location); location = pdp.GetPickupDeliveryLocation(move.Replaced); oldTour2 = solution.Tours.Find(t => t.Stops.Contains(location)); oldTour2.Stops.Remove(location); tour.Stops.Remove(move.Replaced); solution.InsertPair(tour, move.City, pdp.GetPickupDeliveryLocation(move.City), problemInstance); solution.InsertPair(oldTour, move.Replaced, pdp.GetPickupDeliveryLocation(move.Replaced), problemInstance); } else { tour.Stops.Remove(move.Replaced); int place = solution.FindBestInsertionPlace(tour, move.City); tour.Stops.Insert(place, move.City); place = solution.FindBestInsertionPlace(oldTour, move.Replaced); oldTour.Stops.Insert(place, move.Replaced); } solution.Repair(); }
public static void Apply(PotvinEncoding solution, PotvinCustomerRelocationMove move, IVRPProblemInstance problemInstance) { if (move.Tour >= solution.Tours.Count) { solution.Tours.Add(new Tour()); } Tour tour = solution.Tours[move.Tour]; Tour oldTour = solution.Tours.Find(t => t.Stops.Contains(move.City)); oldTour.Stops.Remove(move.City); /*if (oldTour.Stops.Count == 0) * solution.Tours.Remove(oldTour);*/ int place = solution.FindBestInsertionPlace(tour, move.City); tour.Stops.Insert(place, move.City); solution.Repair(); }
protected override void PerformMove() { PotvinCustomerRelocationMove move = CustomerRelocationMoveParameter.ActualValue; PotvinEncoding newSolution = move.Individual.Clone() as PotvinEncoding; Apply(newSolution, move, ProblemInstance); newSolution.Repair(); VRPToursParameter.ActualValue = newSolution; //reset move quality VRPEvaluation eval = ProblemInstance.Evaluate(newSolution); MoveQualityParameter.ActualValue.Value = eval.Quality; //update memory VariableCollection memory = MemoriesParameter.ActualValue; string key = AdditionFrequencyMemoryKeyParameter.Value.Value; if (memory != null) { if (!memory.ContainsKey(key)) { memory.Add(new Variable(key, new ItemDictionary <PotvinCustomerRelocationMoveAttribute, IntValue>())); } ItemDictionary <PotvinCustomerRelocationMoveAttribute, IntValue> additionFrequency = memory[key].Value as ItemDictionary <PotvinCustomerRelocationMoveAttribute, IntValue>; PotvinCustomerRelocationMoveAttribute attr = new PotvinCustomerRelocationMoveAttribute(0, move.Tour, move.City); if (!additionFrequency.ContainsKey(attr)) { additionFrequency[attr] = new IntValue(0); } additionFrequency[attr].Value++; } }
public static void Apply(PotvinEncoding solution, PotvinPDShiftMove move, IVRPProblemInstance problemInstance) { bool newTour = false; if (move.Tour >= solution.Tours.Count) { solution.Tours.Add(new Tour()); newTour = true; } Tour tour = solution.Tours[move.Tour]; Tour oldTour = solution.Tours.Find(t => t.Stops.Contains(move.City)); oldTour.Stops.Remove(move.City); if (problemInstance is IPickupAndDeliveryProblemInstance) { IPickupAndDeliveryProblemInstance pdp = problemInstance as IPickupAndDeliveryProblemInstance; int location = pdp.GetPickupDeliveryLocation(move.City); Tour oldTour2 = solution.Tours.Find(t => t.Stops.Contains(location)); oldTour2.Stops.Remove(location); solution.InsertPair(tour, move.City, location, problemInstance); } else { int place = solution.FindBestInsertionPlace(tour, move.City); tour.Stops.Insert(place, move.City); } if (newTour) { List<int> vehicles = new List<int>(); for (int i = move.Tour; i < problemInstance.Vehicles.Value; i++) { vehicles.Add(solution.GetVehicleAssignment(i)); } double bestQuality = double.MaxValue; int bestVehicle = -1; int originalVehicle = solution.GetVehicleAssignment(move.Tour); foreach (int vehicle in vehicles) { solution.VehicleAssignment[move.Tour] = vehicle; double quality = problemInstance.EvaluateTour(tour, solution).Quality; if (quality < bestQuality) { bestQuality = quality; bestVehicle = vehicle; } } solution.VehicleAssignment[move.Tour] = originalVehicle; int index = -1; for (int i = move.Tour; i < solution.VehicleAssignment.Length; i++) { if (solution.VehicleAssignment[i] == bestVehicle) { index = i; break; } } solution.VehicleAssignment[index] = originalVehicle; solution.VehicleAssignment[move.Tour] = bestVehicle; } solution.Repair(); }
public static PotvinEncoding ConvertFrom(List<int> route, IVRPProblemInstance instance) { PotvinEncoding solution = new PotvinEncoding(instance); solution.Tours = new ItemList<Tour>(); Tour tour = new Tour(); int routeIdx = 0; for (int i = 0; i < route.Count; i++) { if (route[i] <= 0) { if (tour.Stops.Count > 0) { solution.Tours.Add(tour); tour = new Tour(); } int vehicle = -route[i]; solution.VehicleAssignment[routeIdx] = vehicle; routeIdx++; } else { tour.Stops.Add(route[i]); } } solution.Repair(); return solution; }
public static void Apply(PotvinEncoding solution, PotvinPDShiftMove move, IVRPProblemInstance problemInstance) { bool newTour = false; if (move.Tour >= solution.Tours.Count) { solution.Tours.Add(new Tour()); newTour = true; } Tour tour = solution.Tours[move.Tour]; Tour oldTour = solution.Tours.Find(t => t.Stops.Contains(move.City)); oldTour.Stops.Remove(move.City); if (problemInstance is IPickupAndDeliveryProblemInstance) { IPickupAndDeliveryProblemInstance pdp = problemInstance as IPickupAndDeliveryProblemInstance; int location = pdp.GetPickupDeliveryLocation(move.City); Tour oldTour2 = solution.Tours.Find(t => t.Stops.Contains(location)); oldTour2.Stops.Remove(location); solution.InsertPair(tour, move.City, location, problemInstance); } else { int place = solution.FindBestInsertionPlace(tour, move.City); tour.Stops.Insert(place, move.City); } if (newTour) { List <int> vehicles = new List <int>(); for (int i = move.Tour; i < problemInstance.Vehicles.Value; i++) { vehicles.Add(solution.GetVehicleAssignment(i)); } double bestQuality = double.MaxValue; int bestVehicle = -1; int originalVehicle = solution.GetVehicleAssignment(move.Tour); foreach (int vehicle in vehicles) { solution.VehicleAssignment[move.Tour] = vehicle; double quality = problemInstance.EvaluateTour(tour, solution).Quality; if (quality < bestQuality) { bestQuality = quality; bestVehicle = vehicle; } } solution.VehicleAssignment[move.Tour] = originalVehicle; int index = -1; for (int i = move.Tour; i < solution.VehicleAssignment.Length; i++) { if (solution.VehicleAssignment[i] == bestVehicle) { index = i; break; } } solution.VehicleAssignment[index] = originalVehicle; solution.VehicleAssignment[move.Tour] = bestVehicle; } solution.Repair(); }
public static void Apply(PotvinEncoding solution, PotvinPDExchangeMove move, IVRPProblemInstance problemInstance) { if (move.Tour >= solution.Tours.Count) solution.Tours.Add(new Tour()); Tour tour = solution.Tours[move.Tour]; Tour oldTour = solution.Tours.Find(t => t.Stops.Contains(move.City)); oldTour.Stops.Remove(move.City); if (problemInstance is IPickupAndDeliveryProblemInstance) { IPickupAndDeliveryProblemInstance pdp = problemInstance as IPickupAndDeliveryProblemInstance; int location = pdp.GetPickupDeliveryLocation(move.City); Tour oldTour2 = solution.Tours.Find(t => t.Stops.Contains(location)); oldTour2.Stops.Remove(location); location = pdp.GetPickupDeliveryLocation(move.Replaced); oldTour2 = solution.Tours.Find(t => t.Stops.Contains(location)); oldTour2.Stops.Remove(location); tour.Stops.Remove(move.Replaced); solution.InsertPair(tour, move.City, pdp.GetPickupDeliveryLocation(move.City), problemInstance); solution.InsertPair(oldTour, move.Replaced, pdp.GetPickupDeliveryLocation(move.Replaced), problemInstance); } else { tour.Stops.Remove(move.Replaced); int place = solution.FindBestInsertionPlace(tour, move.City); tour.Stops.Insert(place, move.City); place = solution.FindBestInsertionPlace(oldTour, move.Replaced); oldTour.Stops.Insert(place, move.Replaced); } solution.Repair(); }