Changeset 5368
- Timestamp:
- 01/25/11 09:46:11 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/LambdaInterchange/AlbaStochasticLambdaInterchangeSingleMoveGenerator.cs
r4722 r5368 63 63 List<Tour> tours = individual.GetTours(); 64 64 65 int route1Index = rand.Next(tours.Count); 66 Tour route1 = tours[route1Index]; 65 if (tours.Count > 1) { 66 int route1Index = rand.Next(tours.Count); 67 Tour route1 = tours[route1Index]; 67 68 68 int route2Index = rand.Next(tours.Count - 1);69 if (route2Index >= route1Index)70 route2Index += 1;71 Tour route2 = tours[route2Index];69 int route2Index = rand.Next(tours.Count - 1); 70 if (route2Index >= route1Index) 71 route2Index += 1; 72 Tour route2 = tours[route2Index]; 72 73 73 int length1 = rand.Next(Math.Min(lambda + 1, route1.Cities.Count + 1));74 int index1 = rand.Next(route1.Cities.Count - length1 + 1);74 int length1 = rand.Next(Math.Min(lambda + 1, route1.Cities.Count + 1)); 75 int index1 = rand.Next(route1.Cities.Count - length1 + 1); 75 76 76 int l2Min = 0;77 if (length1 == 0)78 l2Min = 1;79 int length2 = rand.Next(l2Min, Math.Min(lambda + 1, route2.Cities.Count + 1));80 int index2 = rand.Next(route2.Cities.Count - length2 + 1);77 int l2Min = 0; 78 if (length1 == 0) 79 l2Min = 1; 80 int length2 = rand.Next(l2Min, Math.Min(lambda + 1, route2.Cities.Count + 1)); 81 int index2 = rand.Next(route2.Cities.Count - length2 + 1); 81 82 82 return new AlbaLambdaInterchangeMove(route1Index, index1, length1, route2Index, index2, length2, individual); 83 return new AlbaLambdaInterchangeMove(route1Index, index1, length1, route2Index, index2, length2, individual); 84 } else { 85 return new AlbaLambdaInterchangeMove(0, 0, 0, 0, 0, 0, individual); 86 } 83 87 } 84 88 -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Manipulators/PotvinTwoLevelExchangeManipulator.cs
r4722 r5368 38 38 protected override void Manipulate(IRandom random, PotvinEncoding individual) { 39 39 int selectedIndex = SelectRandomTourBiasedByLength(random, individual); 40 Tour route1 = 41 individual.Tours[selectedIndex]; 40 Tour route1 = individual.Tours[selectedIndex]; 42 41 43 for (int customer1Position = 0; customer1Position < route1.Cities.Count; customer1Position++) { 42 bool performed = false; 43 int customer1Position = 0; 44 while (customer1Position < route1.Cities.Count) { 45 performed = false; 46 44 47 foreach (Tour tour in individual.Tours) { 45 48 if (tour != route1) { … … 51 54 tour.Cities[customer2Position] = customer1; 52 55 if (Feasible(tour)) { 53 int route , place;56 int routeIdx, place; 54 57 if (FindInsertionPlace(individual, 55 customer2, selectedIndex, out route , out place)) {56 individual.Tours[route].Cities.Insert(place, customer2);57 route1.Cities.RemoveAt(customer1Position);58 customer2, selectedIndex, out routeIdx, out place)) { 59 individual.Tours[routeIdx].Cities.Insert(place, customer2); 60 route1.Cities.RemoveAt(customer1Position); 58 61 59 if (route1.Cities.Count == 0)62 if (route1.Cities.Count == 0) 60 63 individual.Tours.Remove(route1); 61 64 62 65 //two-level exchange has been performed 63 return; 66 performed = true; 67 break; 64 68 } else { 65 69 tour.Cities[customer2Position] = customer2; … … 70 74 } 71 75 } 76 77 if (performed) 78 break; 72 79 } 80 81 if (!performed) 82 customer1Position++; 73 83 } 74 84 }
Note: See TracChangeset
for help on using the changeset viewer.