Changeset 6966 for branches/VRP
- Timestamp:
- 11/08/11 12:46:51 (13 years ago)
- Location:
- branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators/PotvinPairwiseOneLevelExchangeManipulator.cs
r6960 r6966 133 133 protected override void Manipulate(IRandom random, PotvinEncoding individual) { 134 134 bool allowInfeasible = AllowInfeasibleSolutions.Value.Value; 135 IPickupAndDeliveryProblemInstance pdp = ProblemInstance as IPickupAndDeliveryProblemInstance; 135 136 136 int selectedIndex = SelectRandomTourBiasedByLength(random, individual); 137 if (selectedIndex >= 0) { 138 Tour route1 = 139 individual.Tours[selectedIndex]; 137 if (pdp != null) { 138 int selectedIndex = SelectRandomTourBiasedByLength(random, individual); 139 if (selectedIndex >= 0) { 140 Tour route1 = 141 individual.Tours[selectedIndex]; 140 142 141 int count = route1.Stops.Count;143 int count = route1.Stops.Count; 142 144 143 if (count > 0) {144 int i = random.Next(0, count);145 int city = route1.Stops[i];145 if (count > 0) { 146 int i = random.Next(0, count); 147 int city = route1.Stops[i]; 146 148 147 if (!PairwiseMove(individual, city, allowInfeasible))148 i++;149 if (!PairwiseMove(individual, city, allowInfeasible)) 150 i++; 149 151 150 count = route1.Stops.Count; 152 count = route1.Stops.Count; 153 } 151 154 } 152 155 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators/PotvinPairwiseTwoLevelExchangeManipulator.cs
r6960 r6966 125 125 } 126 126 127 protected override void Manipulate(IRandom random, PotvinEncoding individual) { 127 protected override void Manipulate(IRandom random, PotvinEncoding individual) { 128 128 bool allowInfeasible = AllowInfeasibleSolutions.Value.Value; 129 129 IPickupAndDeliveryProblemInstance pdp = ProblemInstance as IPickupAndDeliveryProblemInstance; 130 130 131 int selectedIndex = SelectRandomTourBiasedByLength(random, individual); 132 if (selectedIndex >= 0) { 133 bool performed = false; 134 Tour route1 = individual.Tours[selectedIndex]; 131 if (pdp != null) { 132 int selectedIndex = SelectRandomTourBiasedByLength(random, individual); 133 if (selectedIndex >= 0) { 134 bool performed = false; 135 Tour route1 = individual.Tours[selectedIndex]; 135 136 136 if (route1.Stops.Count > 0) {137 //randomize customer selection138 Permutation perm = new Permutation(PermutationTypes.Absolute, route1.Stops.Count, random);139 int customer1Position = 0;137 if (route1.Stops.Count > 0) { 138 //randomize customer selection 139 Permutation perm = new Permutation(PermutationTypes.Absolute, route1.Stops.Count, random); 140 int customer1Position = 0; 140 141 141 while (customer1Position < route1.Stops.Count) {142 performed = false;142 while (customer1Position < route1.Stops.Count) { 143 performed = false; 143 144 144 int customer1 = route1.Stops[perm[customer1Position]];145 int customer2 = -1;145 int customer1 = route1.Stops[perm[customer1Position]]; 146 int customer2 = -1; 146 147 147 for (int i = 0; i < individual.Tours.Count; i++) {148 if (i != selectedIndex) {149 Tour tour = individual.Tours[i];150 for (int customer2Position = 0; customer2Position < tour.Stops.Count; customer2Position++) {151 customer2 = tour.Stops[customer2Position];148 for (int i = 0; i < individual.Tours.Count; i++) { 149 if (i != selectedIndex) { 150 Tour tour = individual.Tours[i]; 151 for (int customer2Position = 0; customer2Position < tour.Stops.Count; customer2Position++) { 152 customer2 = tour.Stops[customer2Position]; 152 153 153 if (pdp.GetPickupDeliveryLocation(customer1) != customer2) {154 PotvinEncoding result = ReplacePair(individual, customer2, customer1, allowInfeasible);155 if (result != null) {156 VRPToursParameter.ActualValue = result;157 individual = result;154 if (pdp.GetPickupDeliveryLocation(customer1) != customer2) { 155 PotvinEncoding result = ReplacePair(individual, customer2, customer1, allowInfeasible); 156 if (result != null) { 157 VRPToursParameter.ActualValue = result; 158 individual = result; 158 159 159 route1 = individual.Tours[selectedIndex]; 160 performed = true; 161 break; 160 route1 = individual.Tours[selectedIndex]; 161 performed = true; 162 break; 163 } 162 164 } 163 165 } 164 166 } 167 168 if (performed) { 169 break; 170 } 165 171 } 166 172 167 if (performed) { 173 if (!performed) 174 customer1Position++; 175 else 168 176 break; 169 }170 177 } 171 172 if (!performed)173 customer1Position++;174 else175 break;176 178 } 177 179 }
Note: See TracChangeset
for help on using the changeset viewer.