- Timestamp:
- 07/25/11 18:28:10 (13 years ago)
- Location:
- branches/QAPAlgorithms/HeuristicLab.Problems.QuadraticAssignment.Algorithms/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/QAPAlgorithms/HeuristicLab.Problems.QuadraticAssignment.Algorithms/3.3/RobustTabooSeachOperator.cs
r6586 r6593 37 37 get { return (ILookupParameter<IntValue>)Parameters["Iterations"]; } 38 38 } 39 public ILookupParameter<IRandom> RandomParameter { 40 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 41 } 39 42 public ILookupParameter<Permutation> PermutationParameter { 40 43 get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; } … … 61 64 get { return (ILookupParameter<Swap2Move>)Parameters["LastMove"]; } 62 65 } 66 public ILookupParameter<BoolValue> UseNewTabuTenureAdaptionSchemeParameter { 67 get { return (ILookupParameter<BoolValue>)Parameters["UseNewTabuTenureAdaptionScheme"]; } 68 } 63 69 public ILookupParameter<ResultCollection> ResultsParameter { 64 70 get { return (ILookupParameter<ResultCollection>)Parameters["Results"]; } 65 71 } 66 72 67 public ILookupParameter<IRandom> RandomParameter {68 get { return (ILookupParameter<IRandom>)Parameters["Random"]; }69 }70 73 public IValueLookupParameter<IntValue> MaximumIterationsParameter { 71 74 get { return (IValueLookupParameter<IntValue>)Parameters["MaximumIterations"]; } … … 101 104 Parameters.Add(new LookupParameter<DoubleValue>("BestQuality", "The best quality value.")); 102 105 Parameters.Add(new LookupParameter<Swap2Move>("LastMove", "The last move that was applied.")); 106 Parameters.Add(new LookupParameter<BoolValue>("UseNewTabuTenureAdaptionScheme", "True if the new tabu tenure adaption should be used or false otherwise.")); 103 107 Parameters.Add(new LookupParameter<ResultCollection>("Results", "Collection that houses the results of the algorithm.")); 104 108 Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The number of iterations that the algorithm should run.")); … … 151 155 || shortTermMemory[move.Index2, solution[move.Index1]] < iteration; 152 156 153 bool aspired = shortTermMemory[move.Index1, solution[move.Index2]] < iteration - alternativeAspirationTenure154 || shortTermMemory[move.Index2, solution[move.Index1]] < iteration - alternativeAspirationTenure155 157 bool aspired = (shortTermMemory[move.Index1, solution[move.Index2]] < iteration - alternativeAspirationTenure 158 && shortTermMemory[move.Index2, solution[move.Index1]] < iteration - alternativeAspirationTenure) 159 || quality.Value + moveQuality < bestQuality.Value; 156 160 157 161 if ((aspired && !already_aspired) // the first alternative move is aspired … … 169 173 if (!results.ContainsKey("AspiredMoves")) { 170 174 aspiredMoves = new IntValue(already_aspired ? 1 : 0); 171 results.Add(new Result("AspiredMoves", aspiredMoves));175 results.Add(new Result("AspiredMoves", "Counts the number of moves that were selected because of the aspiration criteria.", aspiredMoves)); 172 176 } else if (already_aspired) { 173 177 aspiredMoves = (IntValue)results["AspiredMoves"].Value; … … 180 184 if (bestMove == null) return base.Apply(); 181 185 182 shortTermMemory[bestMove.Index1, solution[bestMove.Index1]] = iteration + random.Next(minTenure, maxTenure); 183 shortTermMemory[bestMove.Index2, solution[bestMove.Index2]] = iteration + random.Next(minTenure, maxTenure); 186 bool useNewAdaptionScheme = UseNewTabuTenureAdaptionSchemeParameter.ActualValue.Value; 187 if (useNewAdaptionScheme) { 188 double r = random.NextDouble(); 189 shortTermMemory[bestMove.Index1, solution[bestMove.Index1]] = (int)(iteration + r * r * r * maxTenure); 190 r = random.NextDouble(); 191 shortTermMemory[bestMove.Index2, solution[bestMove.Index2]] = (int)(iteration + r * r * r * maxTenure); 192 } else { 193 shortTermMemory[bestMove.Index1, solution[bestMove.Index1]] = iteration + random.Next(minTenure, maxTenure); 194 shortTermMemory[bestMove.Index2, solution[bestMove.Index2]] = iteration + random.Next(minTenure, maxTenure); 195 } 184 196 Swap2Manipulator.Apply(solution, bestMove.Index1, bestMove.Index2); 185 197 quality.Value += bestMoveQuality; -
branches/QAPAlgorithms/HeuristicLab.Problems.QuadraticAssignment.Algorithms/3.3/RobustTabooSearch.cs
r6586 r6593 75 75 get { return (FixedValueParameter<IntValue>)Parameters["AlternativeAspirationTenure"]; } 76 76 } 77 private FixedValueParameter<BoolValue> UseNewTabuTenureAdaptionSchemeParameter { 78 get { return (FixedValueParameter<BoolValue>)Parameters["UseNewTabuTenureAdaptionScheme"]; } 79 } 77 80 #endregion 78 81 … … 105 108 get { return AlternativeAspirationTenureParameter.Value.Value; } 106 109 set { AlternativeAspirationTenureParameter.Value.Value = value; } 110 } 111 public bool UseNewTabuTenureAdaptionScheme { 112 get { return UseNewTabuTenureAdaptionSchemeParameter.Value.Value; } 113 set { UseNewTabuTenureAdaptionSchemeParameter.Value.Value = value; } 107 114 } 108 115 #endregion … … 129 136 Parameters.Add(new FixedValueParameter<BoolValue>("SetSeedRandomly", "True whether the seed should be set randomly for each run, false if it should be fixed.", new BoolValue(true))); 130 137 Parameters.Add(new FixedValueParameter<IntValue>("MaximumIterations", "The number of iterations that the algorithm should run.", new IntValue(10000))); 131 Parameters.Add(new FixedValueParameter<IntValue>("MinimumTabuTenure", "The minimum tabu tenure.", new IntValue( 20)));132 Parameters.Add(new FixedValueParameter<IntValue>("MaximumTabuTenure", "The maximum tabu tenure.", new IntValue( 10)));138 Parameters.Add(new FixedValueParameter<IntValue>("MinimumTabuTenure", "The minimum tabu tenure.", new IntValue(10))); 139 Parameters.Add(new FixedValueParameter<IntValue>("MaximumTabuTenure", "The maximum tabu tenure.", new IntValue(20))); 133 140 Parameters.Add(new FixedValueParameter<BoolValue>("UseAlternativeAspiration", "True if the alternative aspiration condition should be used that takes moves that have not been made for some time above others.", new BoolValue(false))); 134 141 Parameters.Add(new FixedValueParameter<IntValue>("AlternativeAspirationTenure", "The time t that a move will be remembered for the alternative aspiration condition.", new IntValue(10000))); 135 142 Parameters.Add(new FixedValueParameter<BoolValue>("TerminateOnOptimalSolution", "True when the algorithm should stop if it reached a quality equal or smaller to the BestKnownQuality.", new BoolValue(true))); 143 Parameters.Add(new FixedValueParameter<BoolValue>("UseNewTabuTenureAdaptionScheme", @"In an updated version of his implementation, Eric Taillard introduced a different way to change the tabu tenure. 144 Instead of setting it uniformly between min and max, it will be set between 0 and max according to a right-skewed distribution. 145 Set this option to false if you want to optimize using the earlier 1991 version, and set to true if you want to optimize using the newer version. 146 Please note that the MinimumTabuTenure parameter has no effect in the new version.", new BoolValue(true))); 136 147 137 148 qualityAnalyzer = new BestAverageWorstQualityAnalyzer(); … … 230 241 } 231 242 243 #region Event Handlers 232 244 protected override void OnProblemChanged() { 233 245 base.OnProblemChanged(); … … 264 276 265 277 private void AlternativeAspirationTenureParameter_ValueChanged(object sender, EventArgs e) { 266 if (AlternativeAspirationTenure < MaximumIterations 267 && !UseAlternativeAspiration) { 268 UseAlternativeAspirationParameter.Value.ValueChanged -= new EventHandler(UseAlternativeAspirationParameter_ValueChanged); 269 UseAlternativeAspiration = true; 270 UseAlternativeAspirationParameter.Value.ValueChanged += new EventHandler(UseAlternativeAspirationParameter_ValueChanged); 271 } else if (AlternativeAspirationTenure >= MaximumIterations 272 && UseAlternativeAspiration) { 273 UseAlternativeAspirationParameter.Value.ValueChanged -= new EventHandler(UseAlternativeAspirationParameter_ValueChanged); 274 UseAlternativeAspiration = false; 275 UseAlternativeAspirationParameter.Value.ValueChanged += new EventHandler(UseAlternativeAspirationParameter_ValueChanged); 276 } 277 } 278 if (AlternativeAspirationTenure < MaximumIterations && !UseAlternativeAspiration) { 279 SetSilentlyUseAlternativeAspirationParameter(true); 280 } else if (AlternativeAspirationTenure >= MaximumIterations && UseAlternativeAspiration) { 281 SetSilentlyUseAlternativeAspirationParameter(false); 282 } 283 } 284 285 private void MaximumIterationsParameter_ValueChanged(object sender, EventArgs e) { 286 if (MaximumIterations >= AlternativeAspirationTenure && UseAlternativeAspiration) { 287 SetSilentlyUseAlternativeAspirationParameter(false); 288 } else if (MaximumIterations < AlternativeAspirationTenure && !UseAlternativeAspiration) { 289 SetSilentlyUseAlternativeAspirationParameter(true); 290 } 291 } 292 293 private void UseNewTabuTenureAdaptionSchemeParameter_ValueChanged(object sender, EventArgs e) { 294 UpdateProblemSpecificParameters(); 295 } 296 #endregion 278 297 279 298 [StorableHook(HookType.AfterDeserialization)] … … 285 304 UseAlternativeAspirationParameter.Value.ValueChanged += new EventHandler(UseAlternativeAspirationParameter_ValueChanged); 286 305 AlternativeAspirationTenureParameter.Value.ValueChanged += new EventHandler(AlternativeAspirationTenureParameter_ValueChanged); 306 MaximumIterationsParameter.Value.ValueChanged += new EventHandler(MaximumIterationsParameter_ValueChanged); 307 UseNewTabuTenureAdaptionSchemeParameter.Value.ValueChanged += new EventHandler(UseNewTabuTenureAdaptionSchemeParameter_ValueChanged); 287 308 } 288 309 … … 313 334 314 335 private void UpdateProblemSpecificParameters() { 315 MinimumTabuTenure = (int)(0.9 * Problem.Weights.Rows); 316 MaximumTabuTenure = (int)(1.1 * Problem.Weights.Rows); 336 UpdateTabuTenure(); 317 337 UpdateAlternativeAspirationTenure(); 338 } 339 340 private void UpdateTabuTenure() { 341 if (UseNewTabuTenureAdaptionScheme) { 342 MinimumTabuTenure = 0; 343 MaximumTabuTenure = 8 * Problem.Weights.Rows; 344 } else { 345 MinimumTabuTenure = (int)(0.9 * Problem.Weights.Rows); 346 MaximumTabuTenure = (int)(1.1 * Problem.Weights.Rows); 347 } 318 348 } 319 349 320 350 private void UpdateAlternativeAspirationTenure() { 321 351 if (UseAlternativeAspiration) { 322 AlternativeAspirationTenure = Problem.Weights.Rows * Problem.Weights.Rows / 2; 352 int n = Problem.Weights.Rows; 353 // Taillard has given two formulas for calculating default values: n^2 / 2 and later n^2 * 5 354 // However these do not really model the values he used in his original publication though 355 // The following formula is a linear regression model on the problem size and parameters 356 // given in Table 3 in Taillard1991 and was lower-bounded artificially by 100 357 AlternativeAspirationTenure = Math.Max(203 * n - 2274, 100); 323 358 } else { 324 359 AlternativeAspirationTenure = int.MaxValue; … … 351 386 } 352 387 } 388 389 private void SetSilentlyUseAlternativeAspirationParameter(bool value) { 390 UseAlternativeAspirationParameter.Value.ValueChanged -= new EventHandler(UseAlternativeAspirationParameter_ValueChanged); 391 UseAlternativeAspiration = value; 392 UseAlternativeAspirationParameter.Value.ValueChanged += new EventHandler(UseAlternativeAspirationParameter_ValueChanged); 393 } 353 394 } 354 395 }
Note: See TracChangeset
for help on using the changeset viewer.