Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2997


Ignore:
Timestamp:
03/11/10 02:23:25 (15 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

Location:
trunk/sources
Files:
14 added
3 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab 3.3/Files.txt

    r2945 r2997  
    66HeuristicLab.Algorithms.SGA\3.3:HeuristicLab.Algorithms.SGA-3.3.dll
    77HeuristicLab.Algorithms.SGA.Views\3.3:HeuristicLab.Algorithms.SGA.Views-3.3.dll
     8HeuristicLab.Algorithms.TS\3.3:HeuristicLab.Algorithms.TS-3.3.dll
    89HeuristicLab.Analysis\3.3:HeuristicLab.Analysis-3.3.dll
    910HeuristicLab.Analysis.Views\3.3:HeuristicLab.Analysis.Views-3.3.dll
  • trunk/sources/HeuristicLab.Algorithms.TS/3.3/HeuristicLab.Algorithms.TS-3.3.csproj

    r2981 r2997  
    8383    <Compile Include="HeuristicLabAlgorithmsTSPlugin.cs" />
    8484    <Compile Include="Properties\AssemblyInfo.cs" />
    85     <Compile Include="TabuSelector.cs" />
    86     <Compile Include="TSOperator.cs" />
     85    <Compile Include="TabuListCreator.cs">
     86      <SubType>Code</SubType>
     87    </Compile>
     88    <Compile Include="TabuSelector.cs">
     89      <SubType>Code</SubType>
     90    </Compile>
     91    <Compile Include="TSOperator.cs">
     92      <SubType>Code</SubType>
     93    </Compile>
    8794  </ItemGroup>
    8895  <ItemGroup>
  • trunk/sources/HeuristicLab.Algorithms.TS/3.3/TSOperator.cs

    r2982 r2997  
    2525using HeuristicLab.Operators;
    2626using HeuristicLab.Parameters;
     27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     28using HeuristicLab.Selection;
    2729
    2830namespace HeuristicLab.Algorithms.TS {
     
    3133  /// </summary>
    3234  [Item("TSOperator", "An operator which represents a Tabu Search.")]
     35  [StorableClass(StorableClassType.Empty)]
    3336  public class TSOperator : AlgorithmOperator {
    3437    #region Parameter properties
     
    5154      get { return (ValueLookupParameter<VariableCollection>)Parameters["Results"]; }
    5255    }
     56    public ValueLookupParameter<IOperator> MoveGeneratorParameter {
     57      get { return (ValueLookupParameter<IOperator>)Parameters["MoveGenerator"]; }
     58    }
     59    public ValueLookupParameter<IOperator> MoveQualityEvaluatorParameter {
     60      get { return (ValueLookupParameter<IOperator>)Parameters["MoveQualityEvaluator"]; }
     61    }
     62    public ValueLookupParameter<IOperator> MoveTabuEvaluatorParameter {
     63      get { return (ValueLookupParameter<IOperator>)Parameters["MoveTabuEvaluator"]; }
     64    }
     65    public ValueLookupParameter<IOperator> TabuSelectorParameter {
     66      get { return (ValueLookupParameter<IOperator>)Parameters["TabuSelector"]; }
     67    }
     68    public ValueLookupParameter<IOperator> MoveTabuMakerParameter {
     69      get { return (ValueLookupParameter<IOperator>)Parameters["MoveTabuMaker"]; }
     70    }
     71    public ValueLookupParameter<IOperator> MoveMakerParameter {
     72      get { return (ValueLookupParameter<IOperator>)Parameters["MoveMaker"]; }
     73    }
     74
    5375    private ScopeParameter CurrentScopeParameter {
    5476      get { return (ScopeParameter)Parameters["CurrentScope"]; }
    5577    }
    56 
    5778    public IScope CurrentScope {
    5879      get { return CurrentScopeParameter.ActualValue; }
     
    6990      Parameters.Add(new ValueLookupParameter<IntData>("TabuTenure", "The length of the tabu list, and also means the number of iterations a move is kept tabu"));
    7091      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored."));
     92
     93      Parameters.Add(new ValueLookupParameter<IOperator>("MoveGenerator", "The operator that generates the moves."));
     94      Parameters.Add(new ValueLookupParameter<IOperator>("MoveQualityEvaluator", "The operator that evaluates the quality of a move."));
     95      Parameters.Add(new ValueLookupParameter<IOperator>("MoveTabuEvaluator", "The operator that evaluates whether a move is tabu."));
     96      TabuSelector tabuSelectorOp = new TabuSelector();
     97      tabuSelectorOp.NumberOfSelectedSubScopes = new IntData(1);
     98      Parameters.Add(new ValueLookupParameter<IOperator>("TabuSelector", "The operator that selects among the moves the next best.", tabuSelectorOp));
     99      Parameters.Add(new ValueLookupParameter<IOperator>("MoveTabuMaker", "The operator that declares a move tabu."));
     100      Parameters.Add(new ValueLookupParameter<IOperator>("MoveMaker", "The operator that performs a move and updates the quality."));
     101
    71102      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope which represents a population of solutions on which the TS should be applied."));
    72103      #endregion
    73104
    74105      #region Create operators
     106      TabuListCreator tabuListCreator = new TabuListCreator();
    75107      VariableCreator variableCreator = new VariableCreator();
     108      BestQualityMemorizer bestQualityMemorizer = new BestQualityMemorizer();
    76109      ResultsCollector resultsCollector = new ResultsCollector();
     110      UniformSequentialSubScopesProcessor mainProcessor = new UniformSequentialSubScopesProcessor();
    77111      Placeholder moveGenerator = new Placeholder();
    78112      UniformSequentialSubScopesProcessor moveEvaluationProcessor = new UniformSequentialSubScopesProcessor();
     
    80114      Placeholder moveTabuEvaluator = new Placeholder();
    81115      SubScopesSorter moveQualitySorter = new SubScopesSorter();
     116      BestAverageWorstQualityCalculator bestAverageWorstMoveQualityCalculator = new BestAverageWorstQualityCalculator();
    82117      Placeholder tabuSelector = new Placeholder();
    83       SequentialSubScopesProcessor moveMakingProcessor = new SequentialSubScopesProcessor();
    84       EmptyOperator emptyOp = new EmptyOperator();
    85       UniformSequentialSubScopesProcessor actualMoveMakingProcessor = new UniformSequentialSubScopesProcessor();
     118      RightReducer rightReducer = new RightReducer();
     119      UniformSequentialSubScopesProcessor moveMakingProcessor = new UniformSequentialSubScopesProcessor();
     120      Placeholder moveTabuMaker = new Placeholder();
    86121      Placeholder moveMaker = new Placeholder();
    87       Placeholder moveTabuMaker = new Placeholder();
     122      DataTableValuesCollector valuesCollector = new DataTableValuesCollector();
    88123      SubScopesRemover subScopesRemover = new SubScopesRemover();
    89124      IntCounter iterationsCounter = new IntCounter();
     
    93128
    94129      variableCreator.CollectedValues.Add(new ValueParameter<IntData>("Iterations", new IntData(0)));
    95       variableCreator.CollectedValues.Add(new ValueParameter<DoubleData>("Best Quality", new DoubleData(0)));
    96130      variableCreator.CollectedValues.Add(new ValueParameter<DoubleData>("Best Move Quality", new DoubleData(0)));
    97131      variableCreator.CollectedValues.Add(new ValueParameter<DoubleData>("Average Move Quality", new DoubleData(0)));
    98132      variableCreator.CollectedValues.Add(new ValueParameter<DoubleData>("Worst Move Quality", new DoubleData(0)));
    99       variableCreator.CollectedValues.Add(new ValueParameter<DataTable>("Qualities", new DataTable("Qualities")));
    100133      variableCreator.CollectedValues.Add(new ValueParameter<DataTable>("MoveQualities", new DataTable("MoveQualities")));
    101134
    102135      resultsCollector.CollectedValues.Add(new LookupParameter<IntData>("Iterations"));
    103       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleData>("Best Quality"));
     136      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleData>("Best Quality") { ActualName = "BestQuality" });
    104137      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleData>("Best Move Quality"));
    105138      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleData>("Average Move Quality"));
    106139      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleData>("Worst Move Quality"));
    107       resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("Qualities"));
    108140      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("MoveQualities"));
    109141      resultsCollector.ResultsParameter.ActualName = "Results";
    110142
     143      mainProcessor.Name = "Solution processor (UniformSequentialSubScopesProcessor)";
     144
    111145      moveGenerator.Name = "MoveGenerator (placeholder)";
    112146      moveGenerator.OperatorParameter.ActualName = "MoveGenerator";
     
    121155      moveQualitySorter.ValueParameter.ActualName = "MoveQuality";
    122156
     157      bestAverageWorstMoveQualityCalculator.AverageQualityParameter.ActualName = "Average Move Quality";
     158      bestAverageWorstMoveQualityCalculator.BestQualityParameter.ActualName = "Best Move Quality";
     159      bestAverageWorstMoveQualityCalculator.MaximizationParameter.ActualName = "Maximization";
     160      bestAverageWorstMoveQualityCalculator.QualityParameter.ActualName = "MoveQuality";
     161      bestAverageWorstMoveQualityCalculator.WorstQualityParameter.ActualName = "Worst Move Quality";
     162
    123163      tabuSelector.Name = "TabuSelector (placeholder)";
    124164      tabuSelector.OperatorParameter.ActualName = "TabuSelector";
    125165
     166      moveMakingProcessor.Name = "MoveMaking processor (UniformSequentialSubScopesProcessor)";
     167
     168      moveTabuMaker.Name = "MoveTabuMaker (placeholder)";
     169      moveTabuMaker.OperatorParameter.ActualName = "MoveTabuMaker";
     170
    126171      moveMaker.Name = "MoveMaker (placeholder)";
    127172      moveMaker.OperatorParameter.ActualName = "MoveMaker";
    128173
    129       moveTabuMaker.Name = "MoveTabuMaker (placeholder)";
    130       moveTabuMaker.OperatorParameter.ActualName = "MoveTabuMaker";
     174      valuesCollector.CollectedValues.Add(new LookupParameter<DoubleData>("Best Move Quality"));
     175      valuesCollector.CollectedValues.Add(new LookupParameter<DoubleData>("Average Move Quality"));
     176      valuesCollector.CollectedValues.Add(new LookupParameter<DoubleData>("Worst Move Quality"));
     177      valuesCollector.DataTableParameter.ActualName = "MoveQualities";
    131178
    132179      subScopesRemover.RemoveAllSubScopes = true;
    133180
     181      iterationsCounter.Name = "Iterations Counter";
    134182      iterationsCounter.Increment = new IntData(1);
    135       iterationsCounter.IncrementParameter.ActualName = "Iterations";
    136 
     183      iterationsCounter.ValueParameter.ActualName = "Iterations";
     184
     185      iterationsComparator.Name = "Iterations Comparator";
    137186      iterationsComparator.Comparison = new ComparisonData(Comparison.Less);
    138187      iterationsComparator.LeftSideParameter.ActualName = "Iterations";
     
    140189      iterationsComparator.ResultParameter.ActualName = "IterationsCondition";
    141190
     191      iterationsTermination.Name = "Iterations Termination Condition";
    142192      iterationsTermination.ConditionParameter.ActualName = "IterationsCondition";
    143193      #endregion
    144194
    145195      #region Create operator graph
    146       OperatorGraph.InitialOperator = variableCreator;
    147       variableCreator.Successor = resultsCollector;
    148       resultsCollector.Successor = moveGenerator;
     196      OperatorGraph.InitialOperator = tabuListCreator;
     197      tabuListCreator.Successor = variableCreator;
     198      variableCreator.Successor = bestQualityMemorizer;
     199      bestQualityMemorizer.Successor = resultsCollector;
     200      resultsCollector.Successor = mainProcessor;
     201      mainProcessor.Operator = moveGenerator;
     202      mainProcessor.Successor = valuesCollector;
    149203      moveGenerator.Successor = moveEvaluationProcessor;
    150204      moveEvaluationProcessor.Operator = moveQualityEvaluator;
     205      moveEvaluationProcessor.Successor = moveQualitySorter;
    151206      moveQualityEvaluator.Successor = moveTabuEvaluator;
    152       moveEvaluationProcessor.Successor = moveQualitySorter;
    153       moveQualitySorter.Successor = tabuSelector;
    154       tabuSelector.Successor = moveMakingProcessor;
    155       moveMakingProcessor.Operators.AddRange(new Operator[] { emptyOp, actualMoveMakingProcessor });
    156       actualMoveMakingProcessor.Operator = moveTabuMaker;
     207      moveQualitySorter.Successor = bestAverageWorstMoveQualityCalculator;
     208      bestAverageWorstMoveQualityCalculator.Successor = tabuSelector;
     209      tabuSelector.Successor = rightReducer;
     210      rightReducer.Successor = moveMakingProcessor;
     211      moveMakingProcessor.Operator = moveTabuMaker;
     212      moveMakingProcessor.Successor = subScopesRemover;
    157213      moveTabuMaker.Successor = moveMaker;
    158       moveMakingProcessor.Successor = subScopesRemover;
    159       subScopesRemover.Successor = iterationsCounter;
     214      valuesCollector.Successor = iterationsCounter;
    160215      iterationsCounter.Successor = iterationsComparator;
    161216      iterationsComparator.Successor = iterationsTermination;
    162       iterationsTermination.TrueBranch = resultsCollector;
     217      iterationsTermination.TrueBranch = bestQualityMemorizer;
    163218      iterationsTermination.FalseBranch = finished;
    164219      #endregion
  • 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}
  • trunk/sources/HeuristicLab.Analysis/3.3/HeuristicLab.Analysis-3.3.csproj

    r2908 r2997  
    8585    <None Include="HeuristicLabAnalysisPlugin.cs.frame" />
    8686    <Compile Include="BestAverageWorstQualityCalculator.cs" />
     87    <Compile Include="BestQualityMemorizer.cs" />
    8788    <Compile Include="DataRow.cs" />
    8889    <Compile Include="HeuristicLabAnalysisPlugin.cs" />
  • trunk/sources/HeuristicLab.Encodings.Permutation/3.3/HeuristicLab.Encodings.Permutation-3.3.csproj

    r2984 r2997  
    9696    <Compile Include="Interfaces\IPermutationCrossover.cs" />
    9797    <Compile Include="Interfaces\IPermutationManipulator.cs" />
     98    <Compile Include="Interfaces\IPermutationMoveGenerator.cs" />
    9899    <Compile Include="Interfaces\IPermutationOperator.cs" />
    99100    <Compile Include="Manipulators\InsertionManipulator.cs" />
     
    104105    <Compile Include="Manipulators\TranslocationInversionManipulator.cs" />
    105106    <Compile Include="Manipulators\TranslocationManipulator.cs" />
    106     <Compile Include="Moves\Permutation2IndexMove.cs" />
    107     <Compile Include="Moves\Permutation2OptExhaustiveMoveGenerator.cs" />
    108     <Compile Include="Moves\Permutation2OptMove.cs" />
     107    <Compile Include="Moves\ExhaustiveTwoOptMoveGenerator.cs">
     108      <SubType>Code</SubType>
     109    </Compile>
     110    <Compile Include="Moves\TwoIndexMove.cs">
     111      <SubType>Code</SubType>
     112    </Compile>
     113    <Compile Include="Moves\TwoOptMove.cs">
     114      <SubType>Code</SubType>
     115    </Compile>
     116    <Compile Include="Moves\TwoOptMoveMaker.cs">
     117      <SubType>Code</SubType>
     118    </Compile>
     119    <Compile Include="Moves\TwoOptMoveTabuAttribute.cs">
     120      <SubType>Code</SubType>
     121    </Compile>
     122    <Compile Include="Moves\TwoOptMoveTabuEvaluator.cs">
     123      <SubType>Code</SubType>
     124    </Compile>
     125    <Compile Include="Moves\TwoOptMoveTabuMaker.cs">
     126      <SubType>Code</SubType>
     127    </Compile>
    109128    <Compile Include="PermutationManipulator.cs" />
    110129    <Compile Include="PermutationCrossover.cs" />
  • trunk/sources/HeuristicLab.Encodings.Permutation/3.3/Manipulators/InversionManipulator.cs

    r2994 r2997  
    4747      } while (breakPoint2 == breakPoint1);
    4848      if (breakPoint2 < breakPoint1) { int h = breakPoint1; breakPoint1 = breakPoint2; breakPoint2 = h; }
     49      Apply(permutation, breakPoint1, breakPoint2);
     50    }
    4951
     52    public static void Apply(Permutation permutation, int breakPoint1, int breakPoint2) {
    5053      for (int i = 0; i <= (breakPoint2 - breakPoint1) / 2; i++) {  // invert permutation between breakpoints
    5154        int temp = permutation[breakPoint1 + i];
  • trunk/sources/HeuristicLab.Encodings.Permutation/3.3/Permutation.cs

    r2994 r2997  
    8585    }
    8686
     87    public int GetCircular(int position) {
     88      if (position >= Length) position = position % Length;
     89      while (position < 0) position += Length;
     90      return this[position];
     91    }
     92
    8793    #region IStringConvertibleArrayData Members
    8894    int IStringConvertibleArrayData.Length {
  • trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

    r2900 r2997  
    8686    <None Include="HeuristicLabOptimizationPlugin.cs.frame" />
    8787    <Compile Include="Algorithm.cs" />
     88    <Compile Include="Interfaces\IMoveGenerator.cs" />
    8889    <Compile Include="Interfaces\IMultiObjectiveSelector.cs" />
    8990    <Compile Include="Interfaces\ISingleObjectiveSelector.cs" />
  • trunk/sources/HeuristicLab.Problems.TSP/3.3/HeuristicLab.Problems.TSP-3.3.csproj

    r2988 r2997  
    9393    <Compile Include="Interfaces\ITSPPathEvaluator.cs" />
    9494    <Compile Include="HeuristicLabProblemsTSPPlugin.cs" />
     95    <Compile Include="MoveEvaluators\TwoOptMoveTSPEvaluator.cs">
     96      <SubType>Code</SubType>
     97    </Compile>
    9598    <Compile Include="TSPLIBParser.cs" />
    9699    <Compile Include="TSP.cs" />
Note: See TracChangeset for help on using the changeset viewer.