Changeset 7151
 Timestamp:
 12/07/11 17:39:39 (12 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape.VRP/Manipulators/TwoOptStarManipulator.cs
r7145 r7151 58 58 bool feasible; 59 59 60 //consider creating new tour 61 individual.Tours.Add(new Tour()); 62 60 63 do { 61 64 feasible = true; 62 65 63 if (individual.Tours.Count > 1) { 64 int route1Idx = random.Next(individual.Tours.Count); 65 int route2Idx = random.Next(individual.Tours.Count  1); 66 if (route2Idx >= route1Idx) 67 route2Idx++; 66 int route1Idx = random.Next(individual.Tours.Count); 67 int route2Idx = random.Next(individual.Tours.Count  1); 68 if (route2Idx >= route1Idx) 69 route2Idx++; 68 70 69 70 71 Tour route1 = individual.Tours[route1Idx]; 72 Tour route2 = individual.Tours[route2Idx]; 71 73 72 73 74 int x1 = random.Next(route1.Cities.Count + 1); 75 int x2 = random.Next(route2.Cities.Count + 1); 74 76 75 76 77 78 77 if (!allowInfeasible) { 78 bool originalFeasible = 79 RouteFeasible(route1, demand, capacity) && 80 RouteFeasible(route2, demand, capacity); 79 81 80 if (originalFeasible) { 81 double routeLoad = 0; 82 for (int i = 0; i < x1; i++) 82 if (originalFeasible) { 83 double routeLoad = 0; 84 for (int i = 0; i < x1; i++) 85 routeLoad += demand[route1.Cities[i]]; 86 for (int i = x2; i < route2.Cities.Count; i++) 87 routeLoad += demand[route2.Cities[i]]; 88 89 if (routeLoad > capacity.Value) { 90 feasible = false; 91 } else { 92 routeLoad = 0; 93 for (int i = 0; i < x2; i++) 94 routeLoad += demand[route2.Cities[i]]; 95 for (int i = x1; i < route1.Cities.Count; i++) 83 96 routeLoad += demand[route1.Cities[i]]; 84 for (int i = x2; i < route2.Cities.Count; i++)85 routeLoad += demand[route2.Cities[i]];86 97 87 98 if (routeLoad > capacity.Value) { 88 99 feasible = false; 89 } else {90 routeLoad = 0;91 for (int i = 0; i < x2; i++)92 routeLoad += demand[route2.Cities[i]];93 for (int i = x1; i < route1.Cities.Count; i++)94 routeLoad += demand[route1.Cities[i]];95 96 if (routeLoad > capacity.Value) {97 feasible = false;98 }99 100 } 100 101 } 101 102 } 103 } 102 104 103 104 105 106 107 108 109 105 if (feasible) { 106 int count = route1.Cities.Count  x1; 107 List<int> segmentX1 = new List<int>(); 108 if (count > 0) { 109 segmentX1 = route1.Cities.GetRange(x1, count); 110 route1.Cities.RemoveRange(x1, count); 111 } 110 112 111 112 113 114 115 116 113 count = route2.Cities.Count  x2; 114 List<int> segmentX2 = new List<int>(); 115 if (count > 0) { 116 segmentX2 = route2.Cities.GetRange(x2, count); 117 route2.Cities.RemoveRange(x2, count); 118 } 117 119 118 route1.Cities.AddRange(segmentX2); 119 route2.Cities.AddRange(segmentX1); 120 121 individual.Tours.RemoveAll(t => t.Cities.Count == 0); 122 } 120 route1.Cities.AddRange(segmentX2); 121 route2.Cities.AddRange(segmentX1); 123 122 } 124 123 } while (!feasible); 124 125 individual.Tours.RemoveAll(t => t.Cities.Count == 0); 125 126 } 126 127
Note: See TracChangeset
for help on using the changeset viewer.