- Timestamp:
- 10/12/11 15:45:48 (13 years ago)
- Location:
- branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/PickupDelivery/PDExchange/PotvinPDExchangeMultiMoveGenerator.cs
r6773 r6909 64 64 65 65 for (int i = 0; i < SampleSizeParameter.ActualValue.Value; i++) { 66 result.Add(PotvinPDExchangeSingleMoveGenerator.Apply(individual, ProblemInstance, RandomParameter.ActualValue)); 66 var move = PotvinPDExchangeSingleMoveGenerator.Apply(individual, ProblemInstance, RandomParameter.ActualValue); 67 if (move != null) 68 result.Add(move); 67 69 } 68 70 -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/PickupDelivery/PDExchange/PotvinPDExchangeSingleMoveGenerator.cs
r6856 r6909 66 66 } 67 67 68 PotvinPDExchangeMove move = null; 69 while (cities.Count > 0 && move == null) { 70 int city = cities[rand.Next(cities.Count)]; 71 Tour oldTour = individual.Tours.Find(t => t.Stops.Contains(city)); 72 int oldTourIndex = individual.Tours.IndexOf(oldTour); 68 if (cities.Count > 1 && individual.Tours.Count > 1) { 69 PotvinPDExchangeMove move = null; 70 while (cities.Count > 1 && move == null) { 71 int city = cities[rand.Next(cities.Count)]; 72 Tour oldTour = individual.Tours.Find(t => t.Stops.Contains(city)); 73 int oldTourIndex = individual.Tours.IndexOf(oldTour); 73 74 74 int max = individual.Tours.Count;75 if (individual.Tours.Count < problemInstance.Vehicles.Value)76 max = max - 1;75 int max = individual.Tours.Count; 76 if (individual.Tours.Count < problemInstance.Vehicles.Value) 77 max = max - 1; 77 78 78 int newTourIndex = rand.Next(max);79 if (newTourIndex >= oldTourIndex)80 newTourIndex++;79 int newTourIndex = rand.Next(max); 80 if (newTourIndex >= oldTourIndex) 81 newTourIndex++; 81 82 82 Tour newTour = individual.Tours[newTourIndex]; 83 List<int> tourCities = new List<int>(); 84 foreach (int stop in newTour.Stops) { 85 if (pdp == null || 86 (pdp.GetDemand(stop) >= 0 && 87 pdp.GetPickupDeliveryLocation(stop) != pdp.GetPickupDeliveryLocation(city) && 88 pdp.GetPickupDeliveryLocation(stop) != city && 89 pdp.GetPickupDeliveryLocation(city) != stop)) 90 tourCities.Add(stop); 83 Tour newTour = individual.Tours[newTourIndex]; 84 List<int> tourCities = new List<int>(); 85 foreach (int stop in newTour.Stops) { 86 if (pdp == null || 87 (pdp.GetDemand(stop) >= 0 && 88 pdp.GetPickupDeliveryLocation(stop) != pdp.GetPickupDeliveryLocation(city) && 89 pdp.GetPickupDeliveryLocation(stop) != city && 90 pdp.GetPickupDeliveryLocation(city) != stop)) 91 tourCities.Add(stop); 92 } 93 94 if (tourCities.Count > 0) { 95 int replaced = tourCities[rand.Next(tourCities.Count)]; 96 move = new PotvinPDExchangeMove(city, oldTourIndex, newTourIndex, replaced, individual); 97 } 91 98 } 92 99 93 if (tourCities.Count > 0) { 94 int replaced = tourCities[rand.Next(tourCities.Count)]; 95 move = new PotvinPDExchangeMove(city, oldTourIndex, newTourIndex, replaced, individual); 96 } 97 } 98 99 return move; 100 return move; 101 } else { 102 return null; 103 } 100 104 } 101 105 -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/PickupDelivery/PDRearrange/PotvinPDRearrangeMultiMoveGenerator.cs
r6773 r6909 64 64 65 65 for (int i = 0; i < SampleSizeParameter.ActualValue.Value; i++) { 66 result.Add(PotvinPDRearrangeSingleMoveGenerator.Apply(individual, ProblemInstance, RandomParameter.ActualValue)); 66 var move = PotvinPDRearrangeSingleMoveGenerator.Apply(individual, ProblemInstance, RandomParameter.ActualValue); 67 if (move != null) 68 result.Add(move); 67 69 } 68 70 -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/PickupDelivery/PDRearrange/PotvinPDRearrangeSingleMoveGenerator.cs
r6851 r6909 62 62 IPickupAndDeliveryProblemInstance pdp = problemInstance as IPickupAndDeliveryProblemInstance; 63 63 for (int i = 1; i <= individual.Cities; i++) { 64 if (pdp == null || pdp.GetDemand(i) >= 0)64 if (pdp == null || pdp.GetDemand(i) >= 0) 65 65 cities.Add(i); 66 66 } 67 67 68 int city = cities[rand.Next(cities.Count)]; 69 int tour = individual.Tours.FindIndex(t => t.Stops.Contains(city)); 70 return new PotvinPDRearrangeMove(city, tour, individual); 68 if (cities.Count > 0) { 69 int city = cities[rand.Next(cities.Count)]; 70 int tour = individual.Tours.FindIndex(t => t.Stops.Contains(city)); 71 return new PotvinPDRearrangeMove(city, tour, individual); 72 } else { 73 return null; 74 } 71 75 } 72 76 -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/PickupDelivery/PDShift/PotvinPDShiftMultiMoveGenerator.cs
r6773 r6909 64 64 65 65 for (int i = 0; i < SampleSizeParameter.ActualValue.Value; i++) { 66 result.Add(PotvinPDShiftSingleMoveGenerator.Apply(individual, ProblemInstance, RandomParameter.ActualValue)); 66 var move = PotvinPDShiftSingleMoveGenerator.Apply(individual, ProblemInstance, RandomParameter.ActualValue); 67 if (move != null) 68 result.Add(move); 67 69 } 68 70 -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/PickupDelivery/PDShift/PotvinPDShiftSingleMoveGenerator.cs
r6851 r6909 62 62 IPickupAndDeliveryProblemInstance pdp = problemInstance as IPickupAndDeliveryProblemInstance; 63 63 for (int i = 1; i <= individual.Cities; i++) { 64 if (pdp == null || pdp.GetDemand(i) >= 0)64 if (pdp == null || pdp.GetDemand(i) >= 0) 65 65 cities.Add(i); 66 66 } 67 67 68 int city = cities[rand.Next(cities.Count)]; 69 Tour oldTour = individual.Tours.Find(t => t.Stops.Contains(city)); 70 int oldTourIndex = individual.Tours.IndexOf(oldTour); 68 if (cities.Count > 1 && individual.Tours.Count > 1) { 69 int city = cities[rand.Next(cities.Count)]; 70 Tour oldTour = individual.Tours.Find(t => t.Stops.Contains(city)); 71 int oldTourIndex = individual.Tours.IndexOf(oldTour); 71 72 72 int max = individual.Tours.Count;73 if (individual.Tours.Count < problemInstance.Vehicles.Value)74 max = max - 1;73 int max = individual.Tours.Count; 74 if (individual.Tours.Count < problemInstance.Vehicles.Value) 75 max = max - 1; 75 76 76 int newTourIndex = rand.Next(max);77 if (newTourIndex >= oldTourIndex)78 newTourIndex++;77 int newTourIndex = rand.Next(max); 78 if (newTourIndex >= oldTourIndex) 79 newTourIndex++; 79 80 80 return new PotvinPDShiftMove(city, oldTourIndex, newTourIndex, individual); 81 return new PotvinPDShiftMove(city, oldTourIndex, newTourIndex, individual); 82 } else { 83 return null; 84 } 81 85 } 82 86 -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/VehicleAssignment/PotvinVehicleAssignmentMultiMoveGenerator.cs
r6857 r6909 64 64 65 65 for (int i = 0; i < SampleSizeParameter.ActualValue.Value; i++) { 66 result.Add(PotvinVehicleAssignmentSingleMoveGenerator.Apply(individual, ProblemInstance, RandomParameter.ActualValue)); 66 var move = PotvinVehicleAssignmentSingleMoveGenerator.Apply(individual, ProblemInstance, RandomParameter.ActualValue); 67 if(move != null) 68 result.Add(move); 67 69 } 68 70 -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/VehicleAssignment/PotvinVehicleAssignmentSingleMoveGenerator.cs
r6857 r6909 65 65 66 66 public static PotvinVehicleAssignmentMove Apply(PotvinEncoding individual, IVRPProblemInstance problemInstance, IRandom rand) { 67 int tour1 = rand.Next(individual.Tours.Count); 68 int tour2 = rand.Next(problemInstance.Vehicles.Value); 67 if (individual.Tours.Count > 1) { 68 int tour1 = rand.Next(individual.Tours.Count); 69 int tour2 = rand.Next(problemInstance.Vehicles.Value); 69 70 70 while (tour2 == tour1)71 tour2 = rand.Next(problemInstance.Vehicles.Value);71 while (tour2 == tour1) 72 tour2 = rand.Next(problemInstance.Vehicles.Value); 72 73 73 return new PotvinVehicleAssignmentMove(tour1, tour2, individual); 74 return new PotvinVehicleAssignmentMove(tour1, tour2, individual); 75 } else { 76 return null; 77 } 74 78 } 75 79
Note: See TracChangeset
for help on using the changeset viewer.