Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/11/10 02:23:25 (14 years ago)
Author:
abeham
Message:

Updated tabu search and added an engine for the berlin52 TSP #840
Also added a BestQualityMemorizer operator in HeuristicLab.Analysis-3.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.TS/3.3/TabuSelector.cs

    r2994 r2997  
    4040  public class TabuSelector : Selector {
    4141    /// <summary>
    42     /// The quality of the current solution.
    43     /// </summary>
    44     public LookupParameter<DoubleData> QualityParameter {
    45       get { return (LookupParameter<DoubleData>)Parameters["Quality"]; }
    46     }
    47     /// <summary>
    4842    /// The best found quality so far.
    4943    /// </summary>
     
    7670    }
    7771
     72    public IntData NumberOfSelectedSubScopes {
     73      set { NumberOfSelectedSubScopesParameter.Value = value; }
     74    }
     75
    7876    /// <summary>
    7977    /// Initializes a new intsance with 6 parameters (<c>Quality</c>, <c>BestQuality</c>,
     
    8280    public TabuSelector()
    8381      : base() {
    84       Parameters.Add(new LookupParameter<DoubleData>("Quality", "The quality of the current solution."));
    8582      Parameters.Add(new LookupParameter<DoubleData>("BestQuality", "The best found quality so far."));
    8683      Parameters.Add(new ValueLookupParameter<BoolData>("Aspiration", "Whether the default aspiration criterion should be used or not. The default aspiration criterion accepts a tabu move if it results in a better solution than the best solution found so far.", new BoolData(true)));
     
    10198      bool maximization = MaximizationParameter.ActualValue.Value;
    10299      double bestQuality = BestQualityParameter.ActualValue.Value;
    103       double quality = QualityParameter.ActualValue.Value;
    104100      ItemArray<DoubleData> moveQualities = MoveQualityParameter.ActualValue;
    105101      ItemArray<BoolData> moveTabus = MoveTabuParameter.ActualValue;
     
    110106      List<int> scopesToRemove = new List<int>();
    111107      for (int i = 0; i < scopes.Count; i++) {
    112         if (count > 0 && (!moveTabus[i].Value || aspiration &&
    113           (maximization && moveQualities[i].Value + quality > bestQuality
    114           || !maximization && moveQualities[i].Value + quality < bestQuality))) {
     108        if (count > 0 && (!moveTabus[i].Value
     109          || aspiration && IsBetter(maximization, moveQualities[i].Value, bestQuality))) {
    115110          scopesToRemove.Add(i);
    116111          if (copy) selected[selected.Length - count] = (IScope)scopes[i].Clone();
     
    133128      return selected;
    134129    }
     130
     131    private bool IsBetter(bool maximization, double moveQuality, double bestQuality) {
     132      return (maximization && moveQuality > bestQuality || !maximization && moveQuality < bestQuality);
     133    }
    135134  }
    136135}
Note: See TracChangeset for help on using the changeset viewer.