Changeset 11242
- Timestamp:
- 07/30/14 15:02:35 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3/Improvers/OrienteeringLocalImprovementOperator.cs
r11237 r11242 83 83 } 84 84 #region ILocalImprovementOperator Parameters 85 public IValueLookupParameter<IntValue> LocalIterationsParameter { 86 get { return (IValueLookupParameter<IntValue>)Parameters["LocalIterations"]; } 87 } 85 88 public IValueLookupParameter<IntValue> MaximumIterationsParameter { 86 89 get { return (IValueLookupParameter<IntValue>)Parameters["MaximumIterations"]; } … … 95 98 public ILookupParameter<DoubleValue> QualityParameter { 96 99 get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; } 100 } 101 public IValueParameter<IntValue> MaximumBlockLengthParmeter { 102 get { return (IValueParameter<IntValue>)Parameters["MaximumBlockLength"]; } 103 } 104 public IValueParameter<BoolValue> UseMaximumBlockLengthParmeter { 105 get { return (IValueParameter<BoolValue>)Parameters["UseMaximumBlockLength"]; } 97 106 } 98 107 #endregion … … 114 123 Parameters.Add(new LookupParameter<DoubleValue>("FixedPenalty", "The penalty for each visited vertex.")); 115 124 125 Parameters.Add(new ValueLookupParameter<IntValue>("LocalIterations", "The number of iterations that have already been performed.", new IntValue(0))); 116 126 Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(150))); 117 127 Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of evaluated moves.")); 118 128 Parameters.Add(new LookupParameter<ResultCollection>("Results", "The name of the collection where the results are stored.")); 119 129 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality value of the solution.")); 130 131 Parameters.Add(new ValueParameter<IntValue>("MaximumBlockLength", "The maximum length of the 2-opt shortening.", new IntValue(30))); 132 Parameters.Add(new ValueParameter<BoolValue>("UseMaximumBlockLength", "Use a limitation of the length for the 2-opt shortening.", new BoolValue(true))); 120 133 } 121 134 … … 130 143 double fixedPenalty = FixedPenaltyParameter.ActualValue.Value; 131 144 double maxLength = MaximumDistanceParameter.ActualValue.Value; 145 int maxIterations = MaximumIterationsParameter.ActualValue.Value; 146 int maxBlockLength = MaximumBlockLengthParmeter.Value.Value; 147 bool useMaxBlockLength = UseMaximumBlockLengthParmeter.Value.Value; 132 148 133 149 bool optimizationDone = true; … … 138 154 double tourScore = tour.Sum(point => scores[point]); 139 155 156 var localIterations = LocalIterationsParameter.ActualValue; 157 var evaluatedSolutions = EvaluatedSolutionsParameter.ActualValue; 158 int evaluations = 0; 159 140 160 // Check if the tour can be improved by adding or replacing points 141 while (optimizationDone ) {161 while (optimizationDone && localIterations.Value < maxIterations) { 142 162 optimizationDone = false; 143 163 144 164 // Try to shorten the path 145 ShortenPath(tour, distances, ref tourLength);165 ShortenPath(tour, distances, maxBlockLength, useMaxBlockLength, ref tourLength, ref evaluations); 146 166 147 167 // Determine all points that have not yet been visited by this tour … … 151 171 IncludeNewPoints(tour, visitablePoints, 152 172 distances, fixedPenalty, maxLength, scores, 153 ref tourLength, ref tourScore, ref optimizationDone);173 ref tourLength, ref tourScore, ref evaluations, ref optimizationDone); 154 174 155 175 // Determine if any of the visitable points can take the place of an already visited point in the tour to improve the scores 156 176 ReplacePoints(tour, visitablePoints, 157 177 distances, maxLength, scores, 158 ref tourLength, ref tourScore, ref optimizationDone); 159 } 178 ref tourLength, ref tourScore, ref evaluations, ref optimizationDone); 179 180 localIterations.Value++; 181 } 182 183 localIterations.Value = 0; 184 evaluatedSolutions.Value += evaluations; 160 185 161 186 // Set new tour … … 166 191 } 167 192 168 private void ShortenPath(List<int> tour, DistanceMatrix distances, ref double tourLength) {193 private void ShortenPath(List<int> tour, DistanceMatrix distances, int maxBlockLength, bool useMaxBlockLength, ref double tourLength, ref int evaluations) { 169 194 bool optimizationDone = true; 170 195 int pathSize = tour.Count; 171 int maxBlockLength = (pathSize > 31) ? 30: (pathSize - 2);196 maxBlockLength = (useMaxBlockLength && (pathSize > maxBlockLength + 1)) ? maxBlockLength : (pathSize - 2); 172 197 173 198 // Perform a 2-opt … … 182 207 // If an optimization has been done, start from the beginning 183 208 if (optimizationDone) break; 209 210 evaluations++; 184 211 185 212 double newLength = tourLength; … … 207 234 private void IncludeNewPoints(List<int> tour, List<int> visitablePoints, 208 235 DistanceMatrix distances, double fixedPenalty, double maxLength, DoubleArray scores, 209 ref double tourLength, ref double tourScore, ref bool optimizationDone) {236 ref double tourLength, ref double tourScore, ref int evaluations, ref bool optimizationDone) { 210 237 211 238 for (int tourPosition = 1; tourPosition < tour.Count; tourPosition++) { … … 216 243 // If an optimization has been done, start from the beginning 217 244 if (optimizationDone) break; 245 246 evaluations++; 218 247 219 248 double detour = distances.CalculateInsertionCosts(tour, tourPosition, visitablePoints[i], fixedPenalty); … … 236 265 private void ReplacePoints(List<int> tour, List<int> visitablePoints, 237 266 DistanceMatrix distances, double maxLength, DoubleArray scores, 238 ref double tourLength, ref double tourScore, ref bool optimizationDone) {267 ref double tourLength, ref double tourScore, ref int evaluations, ref bool optimizationDone) { 239 268 240 269 for (int tourPosition = 1; tourPosition < tour.Count - 1; tourPosition++) { … … 245 274 // If an optimization has been done, start from the beginning 246 275 if (optimizationDone) break; 276 277 evaluations++; 247 278 248 279 double detour = distances.CalculateReplacementCosts(tour, tourPosition, visitablePoints[i]);
Note: See TracChangeset
for help on using the changeset viewer.