Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/25/11 18:28:10 (13 years ago)
Author:
abeham
Message:

#1541

  • Changed aspiration criterion after contacting Taillard, added option to choose between old or new adaption scheme
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  
    3737      get { return (ILookupParameter<IntValue>)Parameters["Iterations"]; }
    3838    }
     39    public ILookupParameter<IRandom> RandomParameter {
     40      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
     41    }
    3942    public ILookupParameter<Permutation> PermutationParameter {
    4043      get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; }
     
    6164      get { return (ILookupParameter<Swap2Move>)Parameters["LastMove"]; }
    6265    }
     66    public ILookupParameter<BoolValue> UseNewTabuTenureAdaptionSchemeParameter {
     67      get { return (ILookupParameter<BoolValue>)Parameters["UseNewTabuTenureAdaptionScheme"]; }
     68    }
    6369    public ILookupParameter<ResultCollection> ResultsParameter {
    6470      get { return (ILookupParameter<ResultCollection>)Parameters["Results"]; }
    6571    }
    6672
    67     public ILookupParameter<IRandom> RandomParameter {
    68       get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
    69     }
    7073    public IValueLookupParameter<IntValue> MaximumIterationsParameter {
    7174      get { return (IValueLookupParameter<IntValue>)Parameters["MaximumIterations"]; }
     
    101104      Parameters.Add(new LookupParameter<DoubleValue>("BestQuality", "The best quality value."));
    102105      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."));
    103107      Parameters.Add(new LookupParameter<ResultCollection>("Results", "Collection that houses the results of the algorithm."));
    104108      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The number of iterations that the algorithm should run."));
     
    151155                      || shortTermMemory[move.Index2, solution[move.Index1]] < iteration;
    152156
    153         bool aspired = shortTermMemory[move.Index1, solution[move.Index2]] < iteration - alternativeAspirationTenure
    154                     || shortTermMemory[move.Index2, solution[move.Index1]] < iteration - alternativeAspirationTenure
    155                     || quality.Value + moveQuality < bestQuality.Value;
     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;
    156160
    157161        if ((aspired && !already_aspired) // the first alternative move is aspired
     
    169173        if (!results.ContainsKey("AspiredMoves")) {
    170174          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));
    172176        } else if (already_aspired) {
    173177          aspiredMoves = (IntValue)results["AspiredMoves"].Value;
     
    180184      if (bestMove == null) return base.Apply();
    181185
    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      }
    184196      Swap2Manipulator.Apply(solution, bestMove.Index1, bestMove.Index2);
    185197      quality.Value += bestMoveQuality;
  • branches/QAPAlgorithms/HeuristicLab.Problems.QuadraticAssignment.Algorithms/3.3/RobustTabooSearch.cs

    r6586 r6593  
    7575      get { return (FixedValueParameter<IntValue>)Parameters["AlternativeAspirationTenure"]; }
    7676    }
     77    private FixedValueParameter<BoolValue> UseNewTabuTenureAdaptionSchemeParameter {
     78      get { return (FixedValueParameter<BoolValue>)Parameters["UseNewTabuTenureAdaptionScheme"]; }
     79    }
    7780    #endregion
    7881
     
    105108      get { return AlternativeAspirationTenureParameter.Value.Value; }
    106109      set { AlternativeAspirationTenureParameter.Value.Value = value; }
     110    }
     111    public bool UseNewTabuTenureAdaptionScheme {
     112      get { return UseNewTabuTenureAdaptionSchemeParameter.Value.Value; }
     113      set { UseNewTabuTenureAdaptionSchemeParameter.Value.Value = value; }
    107114    }
    108115    #endregion
     
    129136      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)));
    130137      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)));
    133140      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)));
    134141      Parameters.Add(new FixedValueParameter<IntValue>("AlternativeAspirationTenure", "The time t that a move will be remembered for the alternative aspiration condition.", new IntValue(10000)));
    135142      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.
     144Instead of setting it uniformly between min and max, it will be set between 0 and max according to a right-skewed distribution.
     145Set 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.
     146Please note that the MinimumTabuTenure parameter has no effect in the new version.", new BoolValue(true)));
    136147
    137148      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
     
    230241    }
    231242
     243    #region Event Handlers
    232244    protected override void OnProblemChanged() {
    233245      base.OnProblemChanged();
     
    264276
    265277    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
    278297
    279298    [StorableHook(HookType.AfterDeserialization)]
     
    285304      UseAlternativeAspirationParameter.Value.ValueChanged += new EventHandler(UseAlternativeAspirationParameter_ValueChanged);
    286305      AlternativeAspirationTenureParameter.Value.ValueChanged += new EventHandler(AlternativeAspirationTenureParameter_ValueChanged);
     306      MaximumIterationsParameter.Value.ValueChanged += new EventHandler(MaximumIterationsParameter_ValueChanged);
     307      UseNewTabuTenureAdaptionSchemeParameter.Value.ValueChanged += new EventHandler(UseNewTabuTenureAdaptionSchemeParameter_ValueChanged);
    287308    }
    288309
     
    313334
    314335    private void UpdateProblemSpecificParameters() {
    315       MinimumTabuTenure = (int)(0.9 * Problem.Weights.Rows);
    316       MaximumTabuTenure = (int)(1.1 * Problem.Weights.Rows);
     336      UpdateTabuTenure();
    317337      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      }
    318348    }
    319349
    320350    private void UpdateAlternativeAspirationTenure() {
    321351      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);
    323358      } else {
    324359        AlternativeAspirationTenure = int.MaxValue;
     
    351386      }
    352387    }
     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    }
    353394  }
    354395}
Note: See TracChangeset for help on using the changeset viewer.