Changeset 7786


Ignore:
Timestamp:
05/09/12 12:22:33 (7 years ago)
Author:
jkarder
Message:

#1331:

  • fixed bug in path relinking selection
  • fixed bug in ScatterSearch.Prepare()
  • added custom interface (IImprovementOperator) for Scatter Search specific improvement operators
  • switched from diversity calculation to similarity calculation
  • separated IPathRelinker from ICrossover
  • changed TestFunctionsImprovementOperator to use reflection for evaluating functions
  • changed SolutionPoolUpdateMethod to use similarity calculation for solution comparison
  • improved TravelingSalesmanImprovementOperator
  • improved operator graph
  • removed specific operators used to evaluate TestFunctions problems
  • removed custom crossover operator (NChildCrossover)
  • added parameters and adjusted types
  • adjusted event handling
  • changed access levels
  • minor code improvements
Location:
branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3
Files:
5 added
18 deleted
20 edited

Legend:

Unmodified
Added
Removed
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/HeuristicLab.Algorithms.ScatterSearch-3.3.csproj

    r7775 r7786  
    8787  </ItemGroup>
    8888  <ItemGroup>
     89    <Compile Include="IImprovementOperator.cs" />
     90    <Compile Include="IPathRelinker.cs" />
    8991    <Compile Include="SolutionPool2TierUpdateMethod.cs" />
    90     <Compile Include="DiversityCalculator.cs" />
    91     <Compile Include="IPathRelinker.cs" />
    92     <Compile Include="Knapsack\BinaryVectorDiversityCalculator.cs" />
     92    <Compile Include="SimilarityCalculator.cs" />
     93    <Compile Include="Knapsack\KnapsackSimilarityCalculator.cs" />
    9394    <Compile Include="Knapsack\KnapsackMultipleGuidesPathRelinker.cs" />
    9495    <Compile Include="Knapsack\KnapsackSimultaneousPathRelinker.cs" />
    9596    <Compile Include="Knapsack\KnapsackPathRelinker.cs" />
    96     <Compile Include="TestFunctions\TestFunctionsZakharovImprovementOperator.cs" />
    97     <Compile Include="TestFunctions\TestFunctionsSumSquaresImprovementOperator.cs" />
    98     <Compile Include="TestFunctions\TestFunctionsSchwefelImprovementOperator.cs" />
    99     <Compile Include="TestFunctions\TestFunctionsRosenbrockImprovementOperator.cs" />
    100     <Compile Include="TestFunctions\TestFunctionsMatyasImprovementOperator.cs" />
    101     <Compile Include="TestFunctions\TestFunctionsLevyImprovementOperator.cs" />
    102     <Compile Include="TestFunctions\TestFunctionsGriewankImprovementOperator.cs" />
    103     <Compile Include="TestFunctions\TestFunctionsBoothImprovementOperator.cs" />
    104     <Compile Include="TestFunctions\TestFunctionsBealeImprovementOperator.cs" />
    105     <Compile Include="TestFunctions\TestFunctionsAckleyImprovementOperator.cs" />
    10697    <Compile Include="TestFunctions\TestFunctionsPathRelinker.cs" />
    107     <Compile Include="TestFunctions\RealVectorDiversityCalculator.cs" />
     98    <Compile Include="TestFunctions\TestFunctionsSimilarityCalculator.cs" />
    10899    <Compile Include="TestFunctions\TestFunctionsImprovementOperator.cs" />
    109100    <Compile Include="TravelingSalesman\TravelingSalesmanMultipleGuidesPathRelinker.cs" />
     
    111102    <Compile Include="TravelingSalesman\TravelingSalesmanPathRelinker.cs" />
    112103    <Compile Include="PathRelinker.cs" />
    113     <Compile Include="Knapsack\INBinaryVectorCrossover.cs" />
    114     <Compile Include="IScatterSearchTargetProcessor.cs" />
    115     <Compile Include="Knapsack\NBinaryVectorCrossover.cs" />
    116     <Compile Include="Knapsack\NChildCrossover.cs" />
    117104    <Compile Include="OffspringProcessor.cs" />
    118     <Compile Include="TravelingSalesman\PermutationDiversityCalculator.cs" />
     105    <Compile Include="TravelingSalesman\TravelingSalesmanSimilarityCalculator.cs" />
    119106    <Compile Include="TravelingSalesman\TravelingSalesmanImprovementOperator.cs" />
    120107    <None Include="HeuristicLab.snk" />
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/IPathRelinker.cs

    r7756 r7786  
    2020#endregion
    2121
     22using System;
     23using HeuristicLab.Common;
    2224using HeuristicLab.Core;
    23 using HeuristicLab.Optimization;
    2425
    2526namespace HeuristicLab.Algorithms.ScatterSearch {
     
    2728  /// An interface which represents an operator for path relinking.
    2829  /// </summary>
    29   public interface IPathRelinker : ICrossover {
    30     ILookupParameter<ItemArray<IItem>> ParentsParameter { get; }
     30  public interface IPathRelinker : IOperator, IParameterizedNamedItem, IDeepCloneable, ICloneable {
    3131  }
    3232}
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/Knapsack/KnapsackImprovementOperator.cs

    r7775 r7786  
    2020#endregion
    2121
    22 using System;
    2322using System.Linq;
    2423using HeuristicLab.Common;
     
    2726using HeuristicLab.Encodings.BinaryVectorEncoding;
    2827using HeuristicLab.Operators;
    29 using HeuristicLab.Optimization;
    3028using HeuristicLab.Parameters;
    3129using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3836  [Item("KnapsackImprovementOperator", "An operator that improves knapsack solutions.")]
    3937  [StorableClass]
    40   public sealed class KnapsackImprovementOperator : SingleSuccessorOperator, ILocalImprovementOperator, IScatterSearchTargetProcessor {
    41     #region Problem properties
    42     public Type ProblemType {
    43       get { return typeof(KnapsackProblem); }
    44     }
    45     [Storable]
    46     private KnapsackProblem problem;
    47     public IProblem Problem {
    48       get { return problem; }
    49       set { problem = (KnapsackProblem)value; }
    50     }
    51     #endregion
    52 
     38  public sealed class KnapsackImprovementOperator : SingleSuccessorOperator, IImprovementOperator {
    5339    #region Parameter properties
    5440    public ScopeParameter CurrentScopeParameter {
    5541      get { return (ScopeParameter)Parameters["CurrentScope"]; }
    5642    }
    57     public IValueLookupParameter<IntArray> ValuesParameter {
    58       get { return (IValueLookupParameter<IntArray>)Parameters["Values"]; }
     43    public ILookupParameter<IntValue> KnapsackCapacityParameter {
     44      get { return (ILookupParameter<IntValue>)Parameters["KnapsackCapacity"]; }
    5945    }
    60     public IValueLookupParameter<IntArray> WeightsParameter {
    61       get { return (IValueLookupParameter<IntArray>)Parameters["Weights"]; }
    62     }
    63     public IValueLookupParameter<IntValue> KnapsackCapacityParameter {
    64       get { return (IValueLookupParameter<IntValue>)Parameters["KnapsackCapacity"]; }
     46    public ILookupParameter<DoubleValue> PenaltyParameter {
     47      get { return (ILookupParameter<DoubleValue>)Parameters["Penalty"]; }
    6548    }
    6649    public IValueLookupParameter<IItem> TargetParameter {
    6750      get { return (IValueLookupParameter<IItem>)Parameters["Target"]; }
    6851    }
    69     public IValueLookupParameter<DoubleValue> PenaltyParameter {
    70       get { return (IValueLookupParameter<DoubleValue>)Parameters["Penalty"]; }
     52    public ILookupParameter<IntArray> ValuesParameter {
     53      get { return (ILookupParameter<IntArray>)Parameters["Values"]; }
    7154    }
    72     #region ILocalImprovementOperator Parameters
    73     public IValueLookupParameter<IntValue> MaximumIterationsParameter {
    74       get { return (IValueLookupParameter<IntValue>)Parameters["MaximumIterations"]; }
     55    public ILookupParameter<IntArray> WeightsParameter {
     56      get { return (ILookupParameter<IntArray>)Parameters["Weights"]; }
    7557    }
    76     public ILookupParameter<IntValue> EvaluatedSolutionsParameter {
    77       get { return (ILookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; }
    78     }
    79     public ILookupParameter<ResultCollection> ResultsParameter {
    80       get { return (ILookupParameter<ResultCollection>)Parameters["Results"]; }
    81     }
    82     #endregion
    8358    #endregion
    8459
     
    8661    private IScope CurrentScope {
    8762      get { return CurrentScopeParameter.ActualValue; }
     63    }
     64    private IntValue KnapsackCapacity {
     65      get { return KnapsackCapacityParameter.ActualValue; }
     66      set { KnapsackCapacityParameter.ActualValue = value; }
     67    }
     68    private DoubleValue Penalty {
     69      get { return PenaltyParameter.ActualValue; }
     70      set { PenaltyParameter.ActualValue = value; }
     71    }
     72    private IItem Target {
     73      get { return TargetParameter.ActualValue; }
    8874    }
    8975    private IntArray Values {
     
    9581      set { WeightsParameter.ActualValue = value; }
    9682    }
    97     private IntValue KnapsackCapacity {
    98       get { return KnapsackCapacityParameter.ActualValue; }
    99       set { KnapsackCapacityParameter.ActualValue = value; }
    100     }
    101     private IItem Target {
    102       get { return TargetParameter.ActualValue; }
    103     }
    104     private DoubleValue Penalty {
    105       get { return PenaltyParameter.ActualValue; }
    106       set { PenaltyParameter.ActualValue = value; }
    107     }
    10883    #endregion
    10984
    11085    [StorableConstructor]
    11186    private KnapsackImprovementOperator(bool deserializing) : base(deserializing) { }
    112     private KnapsackImprovementOperator(KnapsackImprovementOperator original, Cloner cloner)
    113       : base(original, cloner) {
    114       this.problem = cloner.Clone(original.problem);
    115     }
     87    private KnapsackImprovementOperator(KnapsackImprovementOperator original, Cloner cloner) : base(original, cloner) { }
    11688    public KnapsackImprovementOperator()
    11789      : base() {
    11890      #region Create parameters
    11991      Parameters.Add(new ScopeParameter("CurrentScope"));
    120       Parameters.Add(new ValueLookupParameter<IntArray>("Values"));
    121       Parameters.Add(new ValueLookupParameter<IntArray>("Weights"));
    122       Parameters.Add(new ValueLookupParameter<IntValue>("KnapsackCapacity"));
     92      Parameters.Add(new LookupParameter<IntValue>("KnapsackCapacity"));
     93      Parameters.Add(new LookupParameter<DoubleValue>("Penalty"));
    12394      Parameters.Add(new ValueLookupParameter<IItem>("Target"));
    124       Parameters.Add(new ValueLookupParameter<DoubleValue>("Penalty"));
     95      Parameters.Add(new LookupParameter<IntArray>("Values"));
     96      Parameters.Add(new LookupParameter<IntArray>("Weights"));
    12597      #endregion
    12698      TargetParameter.ActualName = "KnapsackSolution"; // temporary solution for the knapsack problem
     
    132104
    133105    public override IOperation Apply() {
    134       var sol = CurrentScope.Variables[TargetParameter.ActualName].Value as BinaryVector;
     106      BinaryVector sol = CurrentScope.Variables[TargetParameter.ActualName].Value as BinaryVector;
    135107
    136108      // calculate value-to-weight ratio
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/Knapsack/KnapsackMultipleGuidesPathRelinker.cs

    r7778 r7786  
    5454        throw new ArgumentException("RelinkingAccuracy must be greater than 0.");
    5555
    56       var v1 = initiator.Clone() as BinaryVector;
    57       var targets = new BinaryVector[guides.Length];
     56      BinaryVector v1 = initiator.Clone() as BinaryVector;
     57      BinaryVector[] targets = new BinaryVector[guides.Length];
    5858      Array.Copy(guides, targets, guides.Length);
    5959
     
    6161        throw new ArgumentException("At least one solution is of different length.");
    6262
    63       var solutions = new List<BinaryVector>();
     63      IList<BinaryVector> solutions = new List<BinaryVector>();
    6464      for (int i = 0; i < v1.Length; i++) {
    6565        // TODO: path relinking
    6666      }
    6767
    68       var selection = new List<IItem>();
     68      IList<IItem> selection = new List<IItem>();
    6969      if (solutions.Count > 0) {
    70         var noSol = (int)Math.Round(solutions.Count * n.Value);
     70        int noSol = (int)(solutions.Count * n.Value);
    7171        if (noSol <= 0) noSol++;
    72         var stepSize = (double)solutions.Count / (double)noSol;
     72        double stepSize = (double)solutions.Count / (double)noSol;
    7373        for (int i = 0; i < noSol; i++)
    74           selection.Add(solutions.ElementAt((int)Math.Round((i + 1) * stepSize - stepSize * 0.5)));
     74          selection.Add(solutions.ElementAt((int)((i + 1) * stepSize - stepSize * 0.5)));
    7575      }
    7676
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/Knapsack/KnapsackPathRelinker.cs

    r7775 r7786  
    5454        throw new ArgumentException("RelinkingAccuracy must be greater than 0.");
    5555
    56       var v1 = initiator.Clone() as BinaryVector;
    57       var v2 = guide as BinaryVector;
     56      BinaryVector v1 = initiator.Clone() as BinaryVector;
     57      BinaryVector v2 = guide as BinaryVector;
    5858
    5959      if (v1.Length != v2.Length)
    6060        throw new ArgumentException("The solutions are of different length.");
    6161
    62       var solutions = new List<BinaryVector>();
     62      IList<BinaryVector> solutions = new List<BinaryVector>();
    6363      for (int i = 0; i < v1.Length; i++)
    6464        if (v1[i] != v2[i]) {
     
    6767        }
    6868
    69       var selection = new List<IItem>();
     69      IList<IItem> selection = new List<IItem>();
    7070      if (solutions.Count > 0) {
    71         var noSol = (int)Math.Round(solutions.Count * n.Value);
     71        int noSol = (int)(solutions.Count * n.Value);
    7272        if (noSol <= 0) noSol++;
    73         var stepSize = (double)solutions.Count / (double)noSol;
     73        double stepSize = (double)solutions.Count / (double)noSol;
    7474        for (int i = 0; i < noSol; i++)
    75           selection.Add(solutions.ElementAt((int)Math.Round((i + 1) * stepSize - stepSize * 0.5)));
     75          selection.Add(solutions.ElementAt((int)((i + 1) * stepSize - stepSize * 0.5)));
    7676      }
    7777
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/Knapsack/KnapsackSimultaneousPathRelinker.cs

    r7775 r7786  
    5454        throw new ArgumentException("RelinkingAccuracy must be greater than 0.");
    5555
    56       var firstInitiator = initiator.Clone() as BinaryVector;
    57       var firstGuide = guide.Clone() as BinaryVector;
    58       var secondInitiator = firstGuide.Clone() as BinaryVector;
    59       var secondGuide = firstInitiator.Clone() as BinaryVector;
     56      BinaryVector firstInitiator = initiator.Clone() as BinaryVector;
     57      BinaryVector firstGuide = guide.Clone() as BinaryVector;
     58      BinaryVector secondInitiator = firstGuide.Clone() as BinaryVector;
     59      BinaryVector secondGuide = firstInitiator.Clone() as BinaryVector;
    6060
    6161      if (firstInitiator.Length != firstGuide.Length)
    6262        throw new ArgumentException("The solutions are of different length.");
    6363
    64       var solutions = new List<BinaryVector>();
     64      IList<BinaryVector> solutions = new List<BinaryVector>();
    6565      for (int i = 0; i < firstInitiator.Length / 2; i++) {
    6666        if (firstInitiator[i] != firstGuide[i]) {
     
    6868          solutions.Add(firstInitiator.Clone() as BinaryVector);
    6969        }
    70         var j = secondInitiator.Length - 1 - i;
     70        int j = secondInitiator.Length - 1 - i;
    7171        if (secondInitiator[j] != secondGuide[j]) {
    7272          secondInitiator[j] = secondGuide[j];
     
    7575      }
    7676
    77       var selection = new List<IItem>();
     77      IList<IItem> selection = new List<IItem>();
    7878      if (solutions.Count > 0) {
    79         var noSol = (int)Math.Round(solutions.Count * n.Value);
     79        int noSol = (int)(solutions.Count * n.Value);
    8080        if (noSol <= 0) noSol++;
    81         var stepSize = (double)solutions.Count / (double)noSol;
     81        double stepSize = (double)solutions.Count / (double)noSol;
    8282        for (int i = 0; i < noSol; i++)
    83           selection.Add(solutions.ElementAt((int)Math.Round((i + 1) * stepSize - stepSize * 0.5)));
     83          selection.Add(solutions.ElementAt((int)((i + 1) * stepSize - stepSize * 0.5)));
    8484      }
    8585
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/OffspringProcessor.cs

    r7744 r7786  
    3232  [Item("OffspringProcessor", "An operator that creates a subscope with subscopes for every variable in the current scope.")]
    3333  [StorableClass]
    34   public sealed class OffspringProcessor : SingleSuccessorOperator, IScatterSearchTargetProcessor {
     34  public sealed class OffspringProcessor : SingleSuccessorOperator {
    3535    #region Parameter properties
    3636    public ScopeParameter CurrentScopeParameter {
     
    5454    private OffspringProcessor(bool deserializing) : base(deserializing) { }
    5555    private OffspringProcessor(OffspringProcessor original, Cloner cloner) : base(original, cloner) { }
    56     public OffspringProcessor() : base() { Initialize(); }
     56    public OffspringProcessor()
     57      : base() {
     58      #region Create parameters
     59      Parameters.Add(new ScopeParameter("CurrentScope"));
     60      Parameters.Add(new ValueLookupParameter<IItem>("Target"));
     61      #endregion
     62    }
    5763
    5864    public override IDeepCloneable Clone(Cloner cloner) {
     
    6066    }
    6167
    62     private void Initialize() {
    63       #region Create parameters
    64       Parameters.Add(new ScopeParameter("CurrentScope"));
    65       Parameters.Add(new ValueLookupParameter<IItem>("Target"));
    66       #endregion
    67       TargetParameter.ActualName = "KnapsackSolution"; // temporary solution for the knapsack problem
    68     }
    69 
    7068    public override IOperation Apply() {
    71       var offspringSolutions = CurrentScope.Variables;
    72       var offspringScope = new Scope("Offspring");
     69      VariableCollection offspringSolutions = CurrentScope.Variables;
     70      IScope offspringScope = new Scope("Offspring");
    7371      foreach (var solution in offspringSolutions) {
    74         var scope = new Scope();
     72        IScope scope = new Scope();
    7573        scope.Variables.Add(new Variable(TargetParameter.ActualName, solution.Value));
    7674        offspringScope.SubScopes.Add(scope);
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/PathRelinker.cs

    r7775 r7786  
    3838      get { return (ScopeParameter)Parameters["CurrentScope"]; }
    3939    }
     40    public ILookupParameter<ItemArray<IItem>> ParentsParameter {
     41      get { return (IScopeTreeLookupParameter<IItem>)Parameters["Parents"]; }
     42    }
    4043    public IValueParameter<PercentValue> RelinkingAccuracyParameter {
    4144      get { return (IValueParameter<PercentValue>)Parameters["RelinkingAccuracy"]; }
    42     }
    43     public ILookupParameter<ItemArray<IItem>> ParentsParameter {
    44       get { return (IScopeTreeLookupParameter<IItem>)Parameters["Parents"]; }
    4545    }
    4646    #endregion
     
    5050      get { return CurrentScopeParameter.ActualValue; }
    5151    }
     52    private ItemArray<IItem> Parents {
     53      get { return ParentsParameter.ActualValue; }
     54    }
    5255    private PercentValue RelinkingAccuracy {
    5356      get { return RelinkingAccuracyParameter.Value; }
    54     }
    55     private ItemArray<IItem> Parents {
    56       get { return ParentsParameter.ActualValue; }
    5757    }
    5858    #endregion
     
    6565      #region Create parameters
    6666      Parameters.Add(new ScopeParameter("CurrentScope"));
     67      Parameters.Add(new ScopeTreeLookupParameter<IItem>("Parents"));
    6768      Parameters.Add(new ValueParameter<PercentValue>("RelinkingAccuracy", new PercentValue(0.25)));
    68       Parameters.Add(new ScopeTreeLookupParameter<IItem>("Parents"));
    6969      #endregion
    7070    }
    7171
    7272    public sealed override IOperation Apply() {
    73       var relinkedSolutions = Relink(Parents, RelinkingAccuracy);
     73      ItemArray<IItem> relinkedSolutions = Relink(Parents, RelinkingAccuracy);
    7474      for (int i = 0; i < relinkedSolutions.Length; i++)
    7575        CurrentScope.Variables.Add(new Variable(string.Format("Child {0}", i), relinkedSolutions[i]));
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/PopulationRebuildMethod.cs

    r7744 r7786  
    4545      get { return (IValueLookupParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; }
    4646    }
     47    public IValueLookupParameter<IItem> QualityParameter {
     48      get { return (IValueLookupParameter<IItem>)Parameters["Quality"]; }
     49    }
    4750    public IValueLookupParameter<IntValue> ReferenceSetSizeParameter {
    4851      get { return (IValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
    49     }
    50     public IValueLookupParameter<IItem> QualityParameter {
    51       get { return (IValueLookupParameter<IItem>)Parameters["Quality"]; }
    5252    }
    5353    #endregion
     
    6565      set { NumberOfHighQualitySolutionsParameter.ActualValue = value; }
    6666    }
     67    private IItem Quality {
     68      get { return QualityParameter.ActualValue; }
     69    }
    6770    private IntValue ReferenceSetSize {
    6871      get { return ReferenceSetSizeParameter.ActualValue; }
    6972      set { ReferenceSetSizeParameter.ActualValue = value; }
    70     }
    71     private IItem Quality {
    72       get { return QualityParameter.ActualValue; }
    7373    }
    7474    #endregion
     
    7777    private PopulationRebuildMethod(bool deserializing) : base(deserializing) { }
    7878    private PopulationRebuildMethod(PopulationRebuildMethod original, Cloner cloner) : base(original, cloner) { }
    79     public PopulationRebuildMethod() : base() { Initialize(); }
     79    public PopulationRebuildMethod()
     80      : base() {
     81      #region Create parameters
     82      Parameters.Add(new ScopeParameter("CurrentScope"));
     83      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization"));
     84      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfHighQualitySolutions"));
     85      Parameters.Add(new ValueLookupParameter<IItem>("Quality"));
     86      Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize"));
     87      #endregion
     88    }
    8089
    8190    public override IDeepCloneable Clone(Cloner cloner) {
     
    8392    }
    8493
    85     private void Initialize() {
    86       #region Create parameters
    87       Parameters.Add(new ScopeParameter("CurrentScope"));
    88       Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization"));
    89       Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfHighQualitySolutions"));
    90       Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize"));
    91       Parameters.Add(new ValueLookupParameter<IItem>("Quality"));
    92       #endregion
    93     }
    94 
    9594    public override IOperation Apply() {
    96       var populationScope = CurrentScope.SubScopes[0];
    97       var referenceSetScope = CurrentScope.SubScopes[1];
     95      IScope populationScope = CurrentScope.SubScopes[0];
     96      IScope referenceSetScope = CurrentScope.SubScopes[1];
    9897      var orderedReferenceSet = Maximization.Value ? referenceSetScope.SubScopes.OrderByDescending(r => r.Variables[QualityParameter.ActualName].Value) :
    9998                                                     referenceSetScope.SubScopes.OrderBy(r => r.Variables[QualityParameter.ActualName].Value);
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/ReferenceSetUpdateMethod.cs

    r7775 r7786  
    4040      get { return (ScopeParameter)Parameters["CurrentScope"]; }
    4141    }
    42     public IValueLookupParameter<IntValue> NumberOfHighQualitySolutionsParameter {
    43       get { return (IValueLookupParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; }
    44     }
    4542    public IValueLookupParameter<IntValue> ReferenceSetSizeParameter {
    4643      get { return (IValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
    4744    }
     45    public IValueLookupParameter<SimilarityCalculator> SimilarityCalculatorParameter {
     46      get { return (IValueLookupParameter<SimilarityCalculator>)Parameters["SimilarityCalculator"]; }
     47    }
    4848    public IValueLookupParameter<IItem> TargetParameter {
    4949      get { return (IValueLookupParameter<IItem>)Parameters["Target"]; }
    50     }
    51     public IValueLookupParameter<DiversityCalculator> DiversityCalculatorParameter {
    52       get { return (IValueLookupParameter<DiversityCalculator>)Parameters["DiversityCalculator"]; }
    5350    }
    5451    #endregion
     
    5855      get { return CurrentScopeParameter.ActualValue; }
    5956    }
    60     private IntValue NumberOfHighQualitySolutions {
    61       get { return NumberOfHighQualitySolutionsParameter.ActualValue; }
    62     }
    6357    private IntValue ReferenceSetSize {
    6458      get { return ReferenceSetSizeParameter.ActualValue; }
    6559    }
     60    private SimilarityCalculator SimilarityCalculator {
     61      get { return SimilarityCalculatorParameter.ActualValue; }
     62    }
    6663    private IItem Target {
    6764      get { return TargetParameter.ActualValue; }
    68     }
    69     private DiversityCalculator DiversityCalculator {
    70       get { return DiversityCalculatorParameter.ActualValue; }
    7165    }
    7266    #endregion
     
    7569    private ReferenceSetUpdateMethod(bool deserializing) : base(deserializing) { }
    7670    private ReferenceSetUpdateMethod(ReferenceSetUpdateMethod original, Cloner cloner) : base(original, cloner) { }
    77     public ReferenceSetUpdateMethod() : base() { Initialize(); }
     71    public ReferenceSetUpdateMethod()
     72      : base() {
     73      #region Create parameters
     74      Parameters.Add(new ScopeParameter("CurrentScope"));
     75      Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize"));
     76      Parameters.Add(new ValueLookupParameter<SimilarityCalculator>("SimilarityCalculator"));
     77      Parameters.Add(new ValueLookupParameter<IItem>("Target"));
     78      #endregion
     79    }
    7880
    7981    public override IDeepCloneable Clone(Cloner cloner) {
     
    8183    }
    8284
    83     private void Initialize() {
    84       #region Create parameters
    85       Parameters.Add(new ScopeParameter("CurrentScope"));
    86       Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfHighQualitySolutions"));
    87       Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize"));
    88       Parameters.Add(new ValueLookupParameter<IItem>("Target"));
    89       Parameters.Add(new ValueLookupParameter<DiversityCalculator>("DiversityCalculator"));
    90       #endregion
    91       TargetParameter.ActualName = "KnapsackSolution"; // temporary solution for the knapsack problem
    92     }
    93 
    9485    public override IOperation Apply() {
    95       var population = new Dictionary<IScope, double>();
     86      IDictionary<IScope, double> population = new Dictionary<IScope, double>();
    9687      foreach (var pScope in CurrentScope.SubScopes[0].SubScopes) {
    97         double diversity = 0;
    98         var pSol = pScope.Variables[TargetParameter.ActualName].Value;
     88        double similarity = 0;
    9989        foreach (var rScope in CurrentScope.SubScopes[1].SubScopes) {
    100           var rSol = rScope.Variables[TargetParameter.ActualName].Value;
    101           diversity += DiversityCalculator.ExecuteCalculation(pSol, rSol);
     90          similarity += SimilarityCalculator.ExecuteCalculation(pScope, rScope);
    10291        }
    103         population[pScope] = diversity;
     92        population[pScope] = similarity;
    10493      }
    105       foreach (var entry in population.OrderByDescending(x => x.Value).Take(ReferenceSetSize.Value - NumberOfHighQualitySolutions.Value)) {
     94      int numberOfHighQualitySolutions = CurrentScope.SubScopes[1].SubScopes.Count;
     95      foreach (var entry in population.OrderBy(x => x.Value).Take(ReferenceSetSize.Value - numberOfHighQualitySolutions)) {
    10696        CurrentScope.SubScopes[1].SubScopes.Add(entry.Key);
    10797        CurrentScope.SubScopes[0].SubScopes.Remove(entry.Key);
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearch.cs

    r7775 r7786  
    3131using HeuristicLab.Parameters;
    3232using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     33using HeuristicLab.PluginInfrastructure;
    3334using HeuristicLab.Random;
    3435using HeuristicLab.Selection;
     
    6162      get { return (ConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; }
    6263    }
    63     public ConstrainedValueParameter<ILocalImprovementOperator> ImproverParameter {
    64       get { return (ConstrainedValueParameter<ILocalImprovementOperator>)Parameters["Improver"]; }
    65     }
    66     public ConstrainedValueParameter<DiversityCalculator> DiversityCalculatorParameter {
    67       get { return (ConstrainedValueParameter<DiversityCalculator>)Parameters["DiversityCalculator"]; }
     64    public IValueParameter<BoolValue> ExecutePathRelinkingParameter {
     65      get { return (IValueLookupParameter<BoolValue>)Parameters["ExecutePathRelinking"]; }
     66    }
     67    public ConstrainedValueParameter<IImprovementOperator> ImproverParameter {
     68      get { return (ConstrainedValueParameter<IImprovementOperator>)Parameters["Improver"]; }
    6869    }
    6970    public IValueParameter<IntValue> MaximumIterationsParameter {
     
    7374      get { return (IValueParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; }
    7475    }
     76    public ConstrainedValueParameter<IPathRelinker> PathRelinkerParameter {
     77      get { return (ConstrainedValueParameter<IPathRelinker>)Parameters["PathRelinker"]; }
     78    }
    7579    public IValueParameter<IntValue> PopulationSizeParameter {
    7680      get { return (IValueParameter<IntValue>)Parameters["PopulationSize"]; }
     
    8488    public IValueParameter<BoolValue> SetSeedRandomlyParameter {
    8589      get { return (IValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
     90    }
     91    public ConstrainedValueParameter<SimilarityCalculator> SimilarityCalculatorParameter {
     92      get { return (ConstrainedValueParameter<SimilarityCalculator>)Parameters["SimilarityCalculator"]; }
    8693    }
    8794    #endregion
     
    96103      set { CrossoverParameter.Value = value; }
    97104    }
    98     private ILocalImprovementOperator Improver {
     105    private BoolValue ExecutePathRelinking {
     106      get { return ExecutePathRelinkingParameter.Value; }
     107      set { ExecutePathRelinkingParameter.Value = value; }
     108    }
     109    private IImprovementOperator Improver {
    99110      get { return ImproverParameter.Value; }
    100111      set { ImproverParameter.Value = value; }
    101     }
    102     private DiversityCalculator DiversityCalculator {
    103       get { return DiversityCalculatorParameter.Value; }
    104       set { DiversityCalculatorParameter.Value = value; }
    105112    }
    106113    private IntValue MaximumIterations {
     
    112119      set { NumberOfHighQualitySolutionsParameter.Value = value; }
    113120    }
     121    private IPathRelinker PathRelinker {
     122      get { return PathRelinkerParameter.Value; }
     123      set { PathRelinkerParameter.Value = value; }
     124    }
    114125    private IntValue PopulationSize {
    115126      get { return PopulationSizeParameter.Value; }
     
    128139      set { SetSeedRandomlyParameter.Value = value; }
    129140    }
    130     public RandomCreator RandomCreator {
     141    private SimilarityCalculator SimilarityCalculator {
     142      get { return SimilarityCalculatorParameter.Value; }
     143      set { SimilarityCalculatorParameter.Value = value; }
     144    }
     145    private RandomCreator RandomCreator {
    131146      get { return (RandomCreator)OperatorGraph.InitialOperator; }
    132147    }
    133     public SolutionsCreator SolutionsCreator {
     148    private SolutionsCreator SolutionsCreator {
    134149      get { return (SolutionsCreator)RandomCreator.Successor; }
    135150    }
    136     public ScatterSearchMainLoop MainLoop {
     151    private ScatterSearchMainLoop MainLoop {
    137152      get { return FindMainLoop(SolutionsCreator.Successor); }
    138153    }
     
    159174      : base() {
    160175      #region Create parameters
    161       Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the solution and moves.", new MultiAnalyzer()));
    162       Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to combine solutions."));
    163       Parameters.Add(new ConstrainedValueParameter<ILocalImprovementOperator>("Improver", "The operator used to improve solutions."));
    164       Parameters.Add(new ConstrainedValueParameter<DiversityCalculator>("DiversityCalculator", "The operator used to calculate the diversity of two solutions."));
    165       Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(100)));
    166       Parameters.Add(new ValueParameter<IntValue>("NumberOfHighQualitySolutions", "The number of high quality solutions that should be added to the reference set.", new IntValue(10)));
    167       Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population.", new IntValue(300)));
    168       Parameters.Add(new ValueParameter<IntValue>("ReferenceSetSize", "The size of the reference set.", new IntValue(100)));
    169       Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
    170       Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
     176      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", new MultiAnalyzer()));
     177      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover"));
     178      Parameters.Add(new ValueParameter<BoolValue>("ExecutePathRelinking", new BoolValue(true)));
     179      Parameters.Add(new ConstrainedValueParameter<IImprovementOperator>("Improver"));
     180      Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", new IntValue(100)));
     181      Parameters.Add(new ValueParameter<IntValue>("NumberOfHighQualitySolutions", new IntValue(10)));
     182      Parameters.Add(new ConstrainedValueParameter<IPathRelinker>("PathRelinker"));
     183      Parameters.Add(new ValueParameter<IntValue>("PopulationSize", new IntValue(300)));
     184      Parameters.Add(new ValueParameter<IntValue>("ReferenceSetSize", new IntValue(100)));
     185      Parameters.Add(new ValueParameter<IntValue>("Seed", new IntValue(0)));
     186      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", new BoolValue(true)));
     187      Parameters.Add(new ConstrainedValueParameter<SimilarityCalculator>("SimilarityCalculator"));
    171188      #endregion
    172189
     
    178195      Placeholder solutionImprover = new Placeholder();
    179196      BestSelector bestSelector = new BestSelector();
    180       VariableCreator variableCreator = new VariableCreator();
    181       ResultsCollector resultsCollector = new ResultsCollector();
    182197      ScatterSearchMainLoop mainLoop = new ScatterSearchMainLoop();
    183198      #endregion
     
    207222      bestSelector.NumberOfSelectedSubScopesParameter.ActualName = NumberOfHighQualitySolutionsParameter.Name;
    208223      bestSelector.CopySelected = new BoolValue(false);
    209       bestSelector.Successor = variableCreator;
    210 
    211       variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0)));
    212       variableCreator.CollectedValues.Add(new ValueParameter<BoolValue>("NewSolutions", new BoolValue(false)));
    213       variableCreator.Successor = resultsCollector;
    214 
    215       resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Iterations"));
    216       resultsCollector.ResultsParameter.ActualName = "Results";
    217       resultsCollector.Successor = mainLoop;
     224      bestSelector.Successor = mainLoop;
    218225
    219226      mainLoop.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name;
     
    236243
    237244    public override void Prepare() {
    238       base.Prepare();
     245      if (Problem != null) base.Prepare();
    239246    }
    240247
     
    249256      UpdateAnalyzers();
    250257      UpdateCrossovers();
    251       UpdateDiversityCalculators();
     258      UpdatePathRelinkers();
     259      UpdateSimilarityCalculators();
    252260      UpdateImprovers();
    253       UpdateDiversityCalculators();
     261      UpdateSimilarityCalculators();
    254262      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    255263      base.OnProblemChanged();
     
    272280      UpdateAnalyzers();
    273281      UpdateCrossovers();
    274       UpdateDiversityCalculators();
     282      UpdatePathRelinkers();
     283      UpdateSimilarityCalculators();
    275284      UpdateImprovers();
    276285      ParameterizeMainLoop();
     
    306315      ICrossover defaultCrossover = Problem.Operators.OfType<ICrossover>().FirstOrDefault();
    307316
    308       CrossoverParameter.ValidValues.Add(new Knapsack.KnapsackPathRelinker());
    309       CrossoverParameter.ValidValues.Add(new Knapsack.KnapsackSimultaneousPathRelinker());
    310       CrossoverParameter.ValidValues.Add(new TestFunctions.TestFunctionsPathRelinker());
    311       CrossoverParameter.ValidValues.Add(new TravelingSalesman.TravelingSalesmanPathRelinker());
    312       CrossoverParameter.ValidValues.Add(new TravelingSalesman.TravelingSalesmanSimultaneousPathRelinker());
    313       CrossoverParameter.ValidValues.Add(new TravelingSalesman.TravelingSalesmanMultipleGuidesPathRelinker());
    314 
    315317      foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
    316318        CrossoverParameter.ValidValues.Add(crossover);
    317 
    318       foreach (var crossover in CrossoverParameter.ValidValues.OfType<Knapsack.INBinaryVectorCrossover>())
    319         crossover.ParentsParameter.ActualName = "KnapsackSolution"; // temporary solution for the knapsack problem
    320319
    321320      if (oldCrossover != null) {
     
    327326        CrossoverParameter.Value = defaultCrossover;
    328327    }
    329     private void UpdateDiversityCalculators() {
    330       DiversityCalculator oldDiversityCalculator = DiversityCalculatorParameter.Value;
    331       DiversityCalculatorParameter.ValidValues.Clear();
    332       DiversityCalculator defaultDiversityCalculator = Problem.Operators.OfType<DiversityCalculator>().FirstOrDefault();
    333 
    334       DiversityCalculatorParameter.ValidValues.Add(new Knapsack.BinaryVectorDiversityCalculator());
    335       DiversityCalculatorParameter.ValidValues.Add(new TestFunctions.RealVectorDiversityCalculator());
    336       DiversityCalculatorParameter.ValidValues.Add(new TravelingSalesman.PermutationDiversityCalculator());
    337 
    338       foreach (DiversityCalculator diversityCalculator in Problem.Operators.OfType<DiversityCalculator>().OrderBy(x => x.Name))
    339         DiversityCalculatorParameter.ValidValues.Add(diversityCalculator);
    340 
    341       if (oldDiversityCalculator != null) {
    342         DiversityCalculator diversityCalculator = DiversityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldDiversityCalculator.GetType());
    343         if (diversityCalculator != null) DiversityCalculatorParameter.Value = diversityCalculator;
    344         else oldDiversityCalculator = null;
    345       }
    346       if (oldDiversityCalculator == null && defaultDiversityCalculator != null)
    347         DiversityCalculatorParameter.Value = defaultDiversityCalculator;
    348     }
    349328    private void UpdateImprovers() {
    350       ILocalImprovementOperator oldImprover = ImproverParameter.Value;
     329      IImprovementOperator oldImprover = ImproverParameter.Value;
    351330      ImproverParameter.ValidValues.Clear();
    352       ILocalImprovementOperator defaultImprover = Problem.Operators.OfType<ILocalImprovementOperator>().FirstOrDefault();
    353 
    354       ImproverParameter.ValidValues.Add(new Knapsack.KnapsackImprovementOperator());
    355       ImproverParameter.ValidValues.Add(new TestFunctions.TestFunctionsAckleyImprovementOperator());
    356       ImproverParameter.ValidValues.Add(new TestFunctions.TestFunctionsBealeImprovementOperator());
    357       ImproverParameter.ValidValues.Add(new TestFunctions.TestFunctionsBoothImprovementOperator());
    358       ImproverParameter.ValidValues.Add(new TestFunctions.TestFunctionsGriewankImprovementOperator());
    359       ImproverParameter.ValidValues.Add(new TestFunctions.TestFunctionsLevyImprovementOperator());
    360       ImproverParameter.ValidValues.Add(new TestFunctions.TestFunctionsMatyasImprovementOperator());
    361       ImproverParameter.ValidValues.Add(new TestFunctions.TestFunctionsRosenbrockImprovementOperator());
    362       ImproverParameter.ValidValues.Add(new TestFunctions.TestFunctionsSchwefelImprovementOperator());
    363       ImproverParameter.ValidValues.Add(new TestFunctions.TestFunctionsSumSquaresImprovementOperator());
    364       ImproverParameter.ValidValues.Add(new TestFunctions.TestFunctionsZakharovImprovementOperator());
    365       ImproverParameter.ValidValues.Add(new TravelingSalesman.TravelingSalesmanImprovementOperator());
    366 
    367       foreach (ILocalImprovementOperator improver in Problem.Operators.OfType<ILocalImprovementOperator>().OrderBy(x => x.Name))
     331      IImprovementOperator defaultImprover = Problem.Operators.OfType<IImprovementOperator>().FirstOrDefault();
     332
     333      foreach (IImprovementOperator improver in ApplicationManager.Manager.GetInstances<IImprovementOperator>().OrderBy(x => x.Name))
    368334        ImproverParameter.ValidValues.Add(improver);
    369335
    370       foreach (var improver in ImproverParameter.ValidValues.OfType<IScatterSearchTargetProcessor>())
    371         improver.TargetParameter.ActualName = "KnapsackSolution"; // temporary solution for the knapsack problem
     336      foreach (IImprovementOperator improver in Problem.Operators.OfType<IImprovementOperator>().OrderBy(x => x.Name))
     337        ImproverParameter.ValidValues.Add(improver);
    372338
    373339      if (oldImprover != null) {
    374         ILocalImprovementOperator improver = ImproverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldImprover.GetType());
     340        IImprovementOperator improver = ImproverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldImprover.GetType());
    375341        if (improver != null) ImproverParameter.Value = improver;
    376342        else oldImprover = null;
     
    378344      if (oldImprover == null && defaultImprover != null)
    379345        ImproverParameter.Value = defaultImprover;
     346    }
     347    private void UpdatePathRelinkers() {
     348      IPathRelinker oldPathRelinker = PathRelinkerParameter.Value;
     349      PathRelinkerParameter.ValidValues.Clear();
     350      IPathRelinker defaultPathRelinker = Problem.Operators.OfType<IPathRelinker>().FirstOrDefault();
     351
     352      foreach (IPathRelinker pathRelinker in ApplicationManager.Manager.GetInstances<IPathRelinker>().OrderBy(x => x.Name))
     353        PathRelinkerParameter.ValidValues.Add(pathRelinker);
     354
     355      foreach (IPathRelinker pathRelinker in Problem.Operators.OfType<IPathRelinker>().OrderBy(x => x.Name))
     356        PathRelinkerParameter.ValidValues.Add(pathRelinker);
     357
     358      if (oldPathRelinker != null) {
     359        IPathRelinker pathRelinker = PathRelinkerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldPathRelinker.GetType());
     360        if (pathRelinker != null) PathRelinkerParameter.Value = pathRelinker;
     361        else oldPathRelinker = null;
     362      }
     363      if (oldPathRelinker == null && defaultPathRelinker != null)
     364        PathRelinkerParameter.Value = defaultPathRelinker;
     365    }
     366    private void UpdateSimilarityCalculators() {
     367      SimilarityCalculator oldDiversityCalculator = SimilarityCalculatorParameter.Value;
     368      SimilarityCalculatorParameter.ValidValues.Clear();
     369      SimilarityCalculator defaultDiversityCalculator = Problem.Operators.OfType<SimilarityCalculator>().FirstOrDefault();
     370
     371      foreach (SimilarityCalculator diversityCalculator in ApplicationManager.Manager.GetInstances<SimilarityCalculator>().OrderBy(x => x.Name))
     372        SimilarityCalculatorParameter.ValidValues.Add(diversityCalculator);
     373
     374      foreach (SimilarityCalculator diversityCalculator in Problem.Operators.OfType<SimilarityCalculator>().OrderBy(x => x.Name))
     375        SimilarityCalculatorParameter.ValidValues.Add(diversityCalculator);
     376
     377      if (oldDiversityCalculator != null) {
     378        SimilarityCalculator diversityCalculator = SimilarityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldDiversityCalculator.GetType());
     379        if (diversityCalculator != null) SimilarityCalculatorParameter.Value = diversityCalculator;
     380        else oldDiversityCalculator = null;
     381      }
     382      if (oldDiversityCalculator == null && defaultDiversityCalculator != null)
     383        SimilarityCalculatorParameter.Value = defaultDiversityCalculator;
    380384    }
    381385    private void ParameterizeSolutionsCreator() {
     
    397401      }
    398402    }
    399     //private void ParameterizeScatterSearchTargetProcessor(IOperator op) {
    400     //  if (op is IScatterSearchTargetProcessor) {
    401     //    IScatterSearchTargetProcessor ssOp = (IScatterSearchTargetProcessor)op;
    402     //    ssOp.TargetParameter.ActualName = "KnapsackSolution"; // temporary solution for the knapsack problem
    403     //    ssOp.TargetParameter.Hidden = true;
    404     //  }
    405     //}
    406403    private void ParameterizeAnalyzers() {
    407404      qualityAnalyzer.ResultsParameter.ActualName = "Results";
     
    422419      while (mainLoop != null && !(mainLoop is ScatterSearchMainLoop))
    423420        mainLoop = ((SingleSuccessorOperator)mainLoop).Successor;
    424       if (mainLoop == null) return null;
    425       else return (ScatterSearchMainLoop)mainLoop;
     421      return mainLoop as ScatterSearchMainLoop;
    426422    }
    427423    #endregion
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearchMainLoop.cs

    r7778 r7786  
    4141      get { return (IValueLookupParameter<IMultiAnalyzer>)Parameters["Analyzer"]; }
    4242    }
     43    public IValueLookupParameter<DoubleValue> BestKnownQualityParameter {
     44      get { return (IValueLookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
     45    }
    4346    public IValueLookupParameter<ICrossover> CrossoverParameter {
    4447      get { return (IValueLookupParameter<ICrossover>)Parameters["Crossover"]; }
    4548    }
    46     public IValueLookupParameter<IOperator> ImproverParameter {
    47       get { return (IValueLookupParameter<IOperator>)Parameters["Improver"]; }
    48     }
    49     public IValueLookupParameter<DiversityCalculator> DiversityCalculatorParameter {
    50       get { return (IValueLookupParameter<DiversityCalculator>)Parameters["DiversityCalculator"]; }
     49    public IValueLookupParameter<IEvaluator> EvaluatorParameter {
     50      get { return (IValueLookupParameter<IEvaluator>)Parameters["Evaluator"]; }
     51    }
     52    public IValueLookupParameter<BoolValue> ExecutePathRelinkingParameter {
     53      get { return (IValueLookupParameter<BoolValue>)Parameters["ExecutePathRelinking"]; }
     54    }
     55    public IValueLookupParameter<IImprovementOperator> ImproverParameter {
     56      get { return (IValueLookupParameter<IImprovementOperator>)Parameters["Improver"]; }
     57    }
     58    public IValueLookupParameter<IntValue> IterationsParameter {
     59      get { return (IValueLookupParameter<IntValue>)Parameters["Iterations"]; }
     60    }
     61    public IValueLookupParameter<BoolValue> MaximizationParameter {
     62      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
     63    }
     64    public IValueLookupParameter<IntValue> MaximumIterationsParameter {
     65      get { return (IValueLookupParameter<IntValue>)Parameters["MaximumIterations"]; }
    5166    }
    5267    public IValueLookupParameter<IntValue> NumberOfHighQualitySolutionsParameter {
    5368      get { return (IValueLookupParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; }
    5469    }
     70    public IValueLookupParameter<IPathRelinker> PathRelinkerParameter {
     71      get { return (IValueLookupParameter<IPathRelinker>)Parameters["PathRelinker"]; }
     72    }
    5573    public IValueLookupParameter<IntValue> PopulationSizeParameter {
    5674      get { return (IValueLookupParameter<IntValue>)Parameters["PopulationSize"]; }
     
    5977      get { return (IValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
    6078    }
    61     public IValueLookupParameter<DoubleValue> BestKnownQualityParameter {
    62       get { return (IValueLookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
    63     }
    64     public IValueLookupParameter<IEvaluator> EvaluatorParameter {
    65       get { return (IValueLookupParameter<IEvaluator>)Parameters["Evaluator"]; }
    66     }
    67     public IValueLookupParameter<IntValue> IterationsParameter {
    68       get { return (IValueLookupParameter<IntValue>)Parameters["Iterations"]; }
    69     }
    70     public IValueLookupParameter<BoolValue> MaximizationParameter {
    71       get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
    72     }
    73     public IValueLookupParameter<IntValue> MaximumIterationsParameter {
    74       get { return (IValueLookupParameter<IntValue>)Parameters["MaximumIterations"]; }
    75     }
    7679    public IValueLookupParameter<DoubleValue> QualityParameter {
    7780      get { return (IValueLookupParameter<DoubleValue>)Parameters["Quality"]; }
     
    8386      get { return (IValueLookupParameter<VariableCollection>)Parameters["Results"]; }
    8487    }
    85     public IValueLookupParameter<IntValue> SampleSizeParameter {
    86       get { return (IValueLookupParameter<IntValue>)Parameters["SampleSize"]; }
     88    public IValueLookupParameter<SimilarityCalculator> SimilarityCalculatorParameter {
     89      get { return (IValueLookupParameter<SimilarityCalculator>)Parameters["SimilarityCalculator"]; }
    8790    }
    8891    public IValueLookupParameter<ISolutionCreator> SolutionCreatorParameter {
     
    9699      set { AnalyzerParameter.ActualValue = value; }
    97100    }
     101    private DoubleValue BestKnownQuality {
     102      get { return BestKnownQualityParameter.ActualValue; }
     103      set { BestKnownQualityParameter.ActualValue = value; }
     104    }
    98105    private ICrossover Crossover {
    99106      get { return CrossoverParameter.ActualValue; }
    100107      set { CrossoverParameter.ActualValue = value; }
    101108    }
    102     private IOperator Improver {
     109    private IEvaluator Evaluator {
     110      get { return EvaluatorParameter.ActualValue; }
     111      set { EvaluatorParameter.ActualValue = value; }
     112    }
     113    private BoolValue ExecutePathRelinking {
     114      get { return ExecutePathRelinkingParameter.ActualValue; }
     115      set { ExecutePathRelinkingParameter.ActualValue = value; }
     116    }
     117    private IImprovementOperator Improver {
    103118      get { return ImproverParameter.ActualValue; }
    104119      set { ImproverParameter.ActualValue = value; }
    105120    }
    106     private DiversityCalculator DiversityCalculator {
    107       get { return DiversityCalculatorParameter.ActualValue; }
    108       set { DiversityCalculatorParameter.ActualValue = value; }
     121    private IntValue Iterations {
     122      get { return IterationsParameter.ActualValue; }
     123      set { IterationsParameter.ActualValue = value; }
     124    }
     125    private BoolValue Maximization {
     126      get { return MaximizationParameter.ActualValue; }
     127      set { MaximizationParameter.ActualValue = value; }
     128    }
     129    private IntValue MaximumIterations {
     130      get { return MaximumIterationsParameter.ActualValue; }
     131      set { MaximumIterationsParameter.ActualValue = value; }
    109132    }
    110133    private IntValue NumberOfHighQualitySolutions {
     
    112135      set { NumberOfHighQualitySolutionsParameter.ActualValue = value; }
    113136    }
     137    private IPathRelinker PathRelinker {
     138      get { return PathRelinkerParameter.ActualValue; }
     139      set { PathRelinkerParameter.ActualValue = value; }
     140    }
    114141    private IntValue PopulationSize {
    115142      get { return PopulationSizeParameter.ActualValue; }
     
    120147      set { ReferenceSetSizeParameter.ActualValue = value; }
    121148    }
    122     private DoubleValue BestKnownQuality {
    123       get { return BestKnownQualityParameter.ActualValue; }
    124       set { BestKnownQualityParameter.ActualValue = value; }
    125     }
    126     private IEvaluator Evaluator {
    127       get { return EvaluatorParameter.ActualValue; }
    128       set { EvaluatorParameter.ActualValue = value; }
    129     }
    130     private IntValue Iterations {
    131       get { return IterationsParameter.ActualValue; }
    132       set { IterationsParameter.ActualValue = value; }
    133     }
    134     private BoolValue Maximization {
    135       get { return MaximizationParameter.ActualValue; }
    136       set { MaximizationParameter.ActualValue = value; }
    137     }
    138     private IntValue MaximumIterations {
    139       get { return MaximumIterationsParameter.ActualValue; }
    140       set { MaximumIterationsParameter.ActualValue = value; }
    141     }
    142149    private DoubleValue Quality {
    143150      get { return QualityParameter.ActualValue; }
     
    152159      set { ResultsParameter.ActualValue = value; }
    153160    }
    154     private IntValue SampleSize {
    155       get { return SampleSizeParameter.ActualValue; }
    156       set { SampleSizeParameter.ActualValue = value; }
     161    private SimilarityCalculator SimilarityCalculator {
     162      get { return SimilarityCalculatorParameter.ActualValue; }
     163      set { SimilarityCalculatorParameter.ActualValue = value; }
    157164    }
    158165    private ISolutionCreator SolutionCreator {
     
    173180    private void Initialize() {
    174181      #region Create parameters
    175       Parameters.Add(new ValueLookupParameter<IMultiAnalyzer>("Analyzer", "The operator used to analyze the solution and moves."));
    176       Parameters.Add(new ValueLookupParameter<ICrossover>("Crossover", "The operator used to combine solutions."));
    177       Parameters.Add(new ValueLookupParameter<IOperator>("Improver", "The operator used to improve solutions."));
    178       Parameters.Add(new ValueLookupParameter<DiversityCalculator>("DiversityCalculator", "The operator used to calculate the diversity of two solutions."));
    179       Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfHighQualitySolutions", "The number of high quality solutions that should be added to the reference set."));
    180       Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population."));
    181       Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize", "The size of the reference set."));
    182       Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The problem's best known quality value found so far."));
    183       Parameters.Add(new ValueLookupParameter<IEvaluator>("Evaluator", "The operator which is used to evaluate new solutions."));
    184       Parameters.Add(new ValueLookupParameter<IntValue>("Iterations", "The number of iterations performed."));
    185       Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
    186       Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed."));
    187       Parameters.Add(new ValueLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
    188       Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator."));
    189       Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored."));
    190       Parameters.Add(new ValueLookupParameter<IntValue>("SampleSize", "Number of moves that MultiMoveGenerators should create. This is ignored for Exhaustive- and SingleMoveGenerators."));
    191       Parameters.Add(new ValueLookupParameter<ISolutionCreator>("SolutionCreator", "The operator which is used to create new solutions."));
     182      Parameters.Add(new ValueLookupParameter<IMultiAnalyzer>("Analyzer"));
     183      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality"));
     184      Parameters.Add(new ValueLookupParameter<ICrossover>("Crossover"));
     185      Parameters.Add(new ValueLookupParameter<IEvaluator>("Evaluator"));
     186      Parameters.Add(new ValueLookupParameter<BoolValue>("ExecutePathRelinking"));
     187      Parameters.Add(new ValueLookupParameter<IOperator>("Improver"));
     188      Parameters.Add(new ValueLookupParameter<IntValue>("Iterations"));
     189      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization"));
     190      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations"));
     191      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfHighQualitySolutions"));
     192      Parameters.Add(new ValueLookupParameter<IPathRelinker>("PathRelinker"));
     193      Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize"));
     194      Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize"));
     195      Parameters.Add(new ValueLookupParameter<DoubleValue>("Quality"));
     196      Parameters.Add(new ValueLookupParameter<IRandom>("Random"));
     197      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results"));
     198      Parameters.Add(new ValueLookupParameter<SimilarityCalculator>("SimilarityCalculator"));
     199      Parameters.Add(new ValueLookupParameter<ISolutionCreator>("SolutionCreator"));
    192200      #endregion
    193201
    194202      #region Create operators
     203      Placeholder analyzer = new Placeholder();
    195204      Assigner assigner1 = new Assigner();
    196205      Assigner assigner2 = new Assigner();
    197206      ChildrenCreator childrenCreator = new ChildrenCreator();
     207      Placeholder crossover = new Placeholder();
    198208      Comparator iterationsChecker = new Comparator();
     209      IntCounter iterationsCounter = new IntCounter();
     210      MergingReducer mergingReducer = new MergingReducer();
     211      ConditionalBranch executePathRelinkingBranch = new ConditionalBranch();
    199212      ConditionalBranch newSolutionsBranch = new ConditionalBranch();
    200       ConditionalBranch terminateBranch = new ConditionalBranch();
    201       IntCounter interationsCounter = new IntCounter();
    202       MergingReducer mergingReducer = new MergingReducer();
    203213      OffspringProcessor offspringProcessor = new OffspringProcessor();
    204       Placeholder analyzer = new Placeholder();
    205       Placeholder crossover = new Placeholder();
     214      Placeholder pathRelinker = new Placeholder();
     215      PopulationRebuildMethod populationRebuildMethod = new PopulationRebuildMethod();
     216      ReferenceSetUpdateMethod referenceSetUpdateMethod = new ReferenceSetUpdateMethod();
     217      ResultsCollector resultsCollector = new ResultsCollector();
     218      RightSelector rightSelector = new RightSelector();
    206219      Placeholder solutionEvaluator1 = new Placeholder();
    207220      Placeholder solutionEvaluator2 = new Placeholder();
    208221      Placeholder solutionImprover1 = new Placeholder();
    209222      Placeholder solutionImprover2 = new Placeholder();
    210       PopulationRebuildMethod populationRebuildMethod = new PopulationRebuildMethod();
    211       ResultsCollector resultsCollector = new ResultsCollector();
    212       ReferenceSetUpdateMethod referenceSetUpdateMethod = new ReferenceSetUpdateMethod();
    213       RightSelector rightSelector = new RightSelector();
    214223      SolutionPoolUpdateMethod solutionPoolUpdateMethod = new SolutionPoolUpdateMethod();
    215224      SolutionsCreator solutionsCreator = new SolutionsCreator();
     
    217226      SubScopesProcessor subScopesProcessor2 = new SubScopesProcessor();
    218227      SubScopesProcessor subScopesProcessor3 = new SubScopesProcessor();
     228      ConditionalBranch terminateBranch = new ConditionalBranch();
    219229      UniformSubScopesProcessor uniformSubScopesProcessor1 = new UniformSubScopesProcessor();
    220230      UniformSubScopesProcessor uniformSubScopesProcessor2 = new UniformSubScopesProcessor();
    221231      UniformSubScopesProcessor uniformSubScopesProcessor3 = new UniformSubScopesProcessor();
     232      VariableCreator variableCreator = new VariableCreator();
    222233      #endregion
    223234
    224235      #region Create operator graph
    225       OperatorGraph.InitialOperator = interationsCounter;
    226       assigner1.Name = "NewSolutions = true";
    227       assigner1.LeftSideParameter.ActualName = "NewSolutions";
    228       assigner1.RightSideParameter.Value = new BoolValue(true);
    229       assigner1.Successor = newSolutionsBranch;
    230 
    231       assigner2.Name = "NewSolutions = false";
    232       assigner2.LeftSideParameter.ActualName = "NewSolutions";
    233       assigner2.RightSideParameter.Value = new BoolValue(false);
    234       assigner2.Successor = uniformSubScopesProcessor1;
    235 
    236       childrenCreator.Name = "SubsetGenerator";
    237       childrenCreator.ParentsPerChildParameter.Value = new IntValue(2);
    238       childrenCreator.Successor = assigner2;
     236      OperatorGraph.InitialOperator = variableCreator;
     237      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0)));
     238      variableCreator.CollectedValues.Add(new ValueParameter<BoolValue>("NewSolutions", new BoolValue(false)));
     239      variableCreator.Successor = resultsCollector;
     240
     241      resultsCollector.CopyValue = new BoolValue(false);
     242      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(IterationsParameter.Name));
     243      resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name;
     244      resultsCollector.Successor = iterationsChecker;
    239245
    240246      iterationsChecker.Name = "IterationsChecker";
     
    245251      iterationsChecker.Successor = terminateBranch;
    246252
    247       solutionImprover2.Name = "SolutionImprover";
    248       solutionImprover2.OperatorParameter.ActualName = "Improver";
    249       solutionImprover2.Successor = solutionEvaluator2;
    250 
    251       solutionEvaluator2.Name = "SolutionEvaluator";
    252       solutionEvaluator2.OperatorParameter.ActualName = "Evaluator";
    253       solutionEvaluator2.Successor = null;
    254 
    255       newSolutionsBranch.Name = "NewSolutionChecker";
    256       newSolutionsBranch.ConditionParameter.ActualName = "NewSolutions";
    257       newSolutionsBranch.TrueBranch = subScopesProcessor1;
    258       newSolutionsBranch.FalseBranch = populationRebuildMethod;
    259       newSolutionsBranch.Successor = null;
    260 
    261253      terminateBranch.Name = "TerminateChecker";
    262254      terminateBranch.ConditionParameter.ActualName = "Terminate";
    263       terminateBranch.TrueBranch = new EmptyOperator();
    264255      terminateBranch.FalseBranch = referenceSetUpdateMethod;
    265       terminateBranch.Successor = null;
    266 
    267       interationsCounter.Name = "IterationCounter";
    268       interationsCounter.IncrementParameter.Value = new IntValue(1);
    269       interationsCounter.ValueParameter.ActualName = "Iterations";
    270       interationsCounter.Successor = resultsCollector;
    271 
    272       offspringProcessor.Successor = rightSelector;
    273 
    274       rightSelector.NumberOfSelectedSubScopesParameter.Value = new IntValue(1);
    275       rightSelector.CopySelected = new BoolValue(false);
    276       rightSelector.Successor = subScopesProcessor2;
    277 
    278       analyzer.Name = "Analyzer";
    279       analyzer.OperatorParameter.ActualName = "Analyzer";
    280 
    281       crossover.Name = "Crossover";
    282       crossover.OperatorParameter.ActualName = "Crossover";
    283       crossover.Successor = offspringProcessor;
    284 
    285       solutionImprover1.Name = "SolutionImprover";
    286       solutionImprover1.OperatorParameter.ActualName = "Improver";
    287       solutionImprover1.Successor = solutionEvaluator1;
    288 
    289       solutionEvaluator1.Name = "SolutionEvaluator";
    290       solutionEvaluator1.OperatorParameter.ActualName = "Evaluator";
    291       solutionEvaluator1.Successor = null;
    292 
    293       populationRebuildMethod.Successor = subScopesProcessor3;
    294 
    295       resultsCollector.CopyValue = new BoolValue(false);
    296       resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(IterationsParameter.Name));
    297       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(BestKnownQualityParameter.Name, null, BestKnownQualityParameter.Name));
    298       resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name;
    299       resultsCollector.Successor = iterationsChecker;
    300256
    301257      referenceSetUpdateMethod.Successor = assigner1;
    302258
    303       solutionPoolUpdateMethod.Successor = analyzer;
    304 
    305       solutionsCreator.Name = "DiversificationGenerationMethod";
    306       solutionsCreator.NumberOfSolutionsParameter.ActualName = "PopulationSize";
    307       solutionsCreator.Successor = uniformSubScopesProcessor3;
     259      assigner1.Name = "NewSolutions = true";
     260      assigner1.LeftSideParameter.ActualName = "NewSolutions";
     261      assigner1.RightSideParameter.Value = new BoolValue(true);
     262      assigner1.Successor = subScopesProcessor1;
    308263
    309264      subScopesProcessor1.DepthParameter.Value = new IntValue(1);
     
    312267      subScopesProcessor1.Successor = newSolutionsBranch;
    313268
     269      childrenCreator.Name = "SubsetGenerator";
     270      childrenCreator.ParentsPerChildParameter.Value = new IntValue(2);
     271      childrenCreator.Successor = assigner2;
     272
     273      assigner2.Name = "NewSolutions = false";
     274      assigner2.LeftSideParameter.ActualName = "NewSolutions";
     275      assigner2.RightSideParameter.Value = new BoolValue(false);
     276      assigner2.Successor = uniformSubScopesProcessor1;
     277
     278      uniformSubScopesProcessor1.DepthParameter.Value = new IntValue(1);
     279      uniformSubScopesProcessor1.Operator = executePathRelinkingBranch;
     280      uniformSubScopesProcessor1.Successor = solutionPoolUpdateMethod;
     281
     282      executePathRelinkingBranch.Name = "ExecutePathRelinkingChecker";
     283      executePathRelinkingBranch.ConditionParameter.ActualName = ExecutePathRelinkingParameter.ActualName;
     284      executePathRelinkingBranch.TrueBranch = pathRelinker;
     285      executePathRelinkingBranch.FalseBranch = crossover;
     286
     287      pathRelinker.Name = "PathRelinker";
     288      pathRelinker.OperatorParameter.ActualName = "PathRelinker";
     289      pathRelinker.Successor = offspringProcessor;
     290
     291      crossover.Name = "Crossover";
     292      crossover.OperatorParameter.ActualName = "Crossover";
     293      crossover.Successor = offspringProcessor;
     294
     295      offspringProcessor.Successor = rightSelector;
     296
     297      rightSelector.NumberOfSelectedSubScopesParameter.Value = new IntValue(1);
     298      rightSelector.CopySelected = new BoolValue(false);
     299      rightSelector.Successor = subScopesProcessor2;
     300
    314301      subScopesProcessor2.DepthParameter.Value = new IntValue(1);
    315302      subScopesProcessor2.Operators.Add(new EmptyOperator());
     
    317304      subScopesProcessor2.Successor = mergingReducer;
    318305
     306      uniformSubScopesProcessor2.DepthParameter.Value = new IntValue(2);
     307      uniformSubScopesProcessor2.Operator = solutionImprover1;
     308
     309      solutionImprover1.Name = "SolutionImprover";
     310      solutionImprover1.OperatorParameter.ActualName = "Improver";
     311      solutionImprover1.Successor = solutionEvaluator1;
     312
     313      solutionEvaluator1.Name = "SolutionEvaluator";
     314      solutionEvaluator1.OperatorParameter.ActualName = "Evaluator";
     315
     316      solutionPoolUpdateMethod.Successor = analyzer;
     317
     318      analyzer.Name = "Analyzer";
     319      analyzer.OperatorParameter.ActualName = "Analyzer";
     320
     321      newSolutionsBranch.Name = "NewSolutionsChecker";
     322      newSolutionsBranch.ConditionParameter.ActualName = "NewSolutions";
     323      newSolutionsBranch.TrueBranch = subScopesProcessor1;
     324      newSolutionsBranch.FalseBranch = populationRebuildMethod;
     325
     326      populationRebuildMethod.Successor = subScopesProcessor3;
     327
    319328      subScopesProcessor3.DepthParameter.Value = new IntValue(1);
    320329      subScopesProcessor3.Operators.Add(solutionsCreator);
    321330      subScopesProcessor3.Operators.Add(new EmptyOperator());
    322       subScopesProcessor3.Successor = interationsCounter;
    323 
    324       uniformSubScopesProcessor1.DepthParameter.Value = new IntValue(1);
    325       uniformSubScopesProcessor1.Operator = crossover;
    326       uniformSubScopesProcessor1.Successor = solutionPoolUpdateMethod;
    327 
    328       uniformSubScopesProcessor2.DepthParameter.Value = new IntValue(2);
    329       uniformSubScopesProcessor2.Operator = solutionImprover1;
    330       uniformSubScopesProcessor2.Successor = null;
     331      subScopesProcessor3.Successor = iterationsCounter;
     332
     333      solutionsCreator.Name = "DiversificationGenerationMethod";
     334      solutionsCreator.NumberOfSolutionsParameter.ActualName = "PopulationSize";
     335      solutionsCreator.Successor = uniformSubScopesProcessor3;
    331336
    332337      uniformSubScopesProcessor3.DepthParameter.Value = new IntValue(1);
    333338      uniformSubScopesProcessor3.Operator = solutionImprover2;
    334       uniformSubScopesProcessor3.Successor = null;
     339
     340      solutionImprover2.Name = "SolutionImprover";
     341      solutionImprover2.OperatorParameter.ActualName = "Improver";
     342      solutionImprover2.Successor = solutionEvaluator2;
     343
     344      solutionEvaluator2.Name = "SolutionEvaluator";
     345      solutionEvaluator2.OperatorParameter.ActualName = "Evaluator";
     346
     347      iterationsCounter.Name = "IterationCounter";
     348      iterationsCounter.IncrementParameter.Value = new IntValue(1);
     349      iterationsCounter.ValueParameter.ActualName = "Iterations";
     350      iterationsCounter.Successor = resultsCollector;
    335351      #endregion
    336352    }
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/SolutionPool2TierUpdateMethod.cs

    r7775 r7786  
    3636  [Item("SolutionPool2TierUpdateMethod", "An operator that updates the solution pool using a 2-tier strategy.")]
    3737  [StorableClass]
    38   public sealed class SolutionPool2TierUpdateMethod : SingleSuccessorOperator, IScatterSearchTargetProcessor {
     38  public sealed class SolutionPool2TierUpdateMethod : SingleSuccessorOperator {
    3939    #region Parameter properties
    4040    public ScopeParameter CurrentScopeParameter {
    4141      get { return (ScopeParameter)Parameters["CurrentScope"]; }
    4242    }
    43     public IValueLookupParameter<DiversityCalculator> DiversityCalculatorParameter {
    44       get { return (IValueLookupParameter<DiversityCalculator>)Parameters["DiversityCalculator"]; }
     43    public IValueLookupParameter<SimilarityCalculator> SimilarityCalculatorParameter {
     44      get { return (IValueLookupParameter<SimilarityCalculator>)Parameters["SimilarityCalculator"]; }
    4545    }
    4646    public IValueLookupParameter<BoolValue> MaximizationParameter {
     
    5353      get { return (IValueLookupParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; }
    5454    }
     55    public IValueLookupParameter<IItem> QualityParameter {
     56      get { return (IValueLookupParameter<IItem>)Parameters["Quality"]; }
     57    }
    5558    public IValueLookupParameter<IntValue> ReferenceSetSizeParameter {
    5659      get { return (IValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
    57     }
    58     public IValueLookupParameter<IItem> QualityParameter {
    59       get { return (IValueLookupParameter<IItem>)Parameters["Quality"]; }
    6060    }
    6161    public IValueLookupParameter<IItem> TargetParameter {
     
    6868      get { return CurrentScopeParameter.ActualValue; }
    6969    }
    70     private DiversityCalculator DiversityCalculator {
    71       get { return DiversityCalculatorParameter.ActualValue; }
     70    private SimilarityCalculator SimilarityCalculator {
     71      get { return SimilarityCalculatorParameter.ActualValue; }
    7272    }
    7373    private BoolValue Maximization {
     
    8181      get { return NumberOfHighQualitySolutionsParameter.ActualValue; }
    8282    }
     83    private IItem Quality {
     84      get { return QualityParameter.ActualValue; }
     85    }
    8386    private IntValue ReferenceSetSize {
    8487      get { return ReferenceSetSizeParameter.ActualValue; }
    8588      set { ReferenceSetSizeParameter.ActualValue = value; }
    86     }
    87     private IItem Quality {
    88       get { return QualityParameter.ActualValue; }
    8989    }
    9090    private IItem Target {
     
    105105      #region Create parameters
    106106      Parameters.Add(new ScopeParameter("CurrentScope"));
    107       Parameters.Add(new ValueLookupParameter<DiversityCalculator>("DiversityCalculator"));
    108107      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization"));
    109108      Parameters.Add(new ValueLookupParameter<BoolValue>("NewSolutions"));
    110109      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfHighQualitySolutions"));
     110      Parameters.Add(new ValueLookupParameter<IItem>("Quality"));
    111111      Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize"));
    112       Parameters.Add(new ValueLookupParameter<IItem>("Quality"));
     112      Parameters.Add(new ValueLookupParameter<SimilarityCalculator>("SimilarityCalculator"));
    113113      Parameters.Add(new ValueLookupParameter<IItem>("Target"));
    114114      #endregion
    115       TargetParameter.ActualName = "KnapsackSolution"; // temporary solution for the knapsack problem
    116115    }
    117116
    118117    public override IOperation Apply() {
    119       var parentsScope = new Scope("Parents");
    120       var offspringScope = new Scope("Offspring");
     118      IScope parentsScope = new Scope("Parents");
     119      IScope offspringScope = new Scope("Offspring");
    121120
    122121      // split parents and offspring
     
    132131
    133132      var highQualityParents = orderedParents.Take(NumberOfHighQualitySolutions.Value).ToList();
    134       var highDiversityParents = new List<Tuple<IScope, double>>();
     133      IList<Tuple<IScope, double>> highSimilarityParents = new List<Tuple<IScope, double>>();
    135134      foreach (var oScope in orderedParents.Skip(NumberOfHighQualitySolutions.Value)) {
    136         double diversity = 0.0;
    137         var oSol = oScope.Variables[TargetParameter.ActualName].Value;
     135        double similarity = 0.0;
    138136        foreach (var hScope in highQualityParents) {
    139           var hSol = hScope.Variables[TargetParameter.ActualName].Value;
    140           diversity += DiversityCalculator.ExecuteCalculation(oSol, hSol);
     137          similarity += SimilarityCalculator.ExecuteCalculation(oScope, hScope);
    141138        }
    142         highDiversityParents.Add(new Tuple<IScope, double>(oScope, diversity));
     139        highSimilarityParents.Add(new Tuple<IScope, double>(oScope, similarity));
    143140      }
    144141
    145       var offspring = new List<Tuple<IScope, double>>();
     142      IList<Tuple<IScope, double>> offspring = new List<Tuple<IScope, double>>();
    146143      foreach (var oScope in orderedOffspring) {
    147         double diversity = 0.0;
    148         var oSol = oScope.Variables[TargetParameter.ActualName].Value;
     144        double similarity = 0.0;
    149145        foreach (var hScope in highQualityParents) {
    150           var hSol = hScope.Variables[TargetParameter.ActualName].Value;
    151           diversity += DiversityCalculator.ExecuteCalculation(oSol, hSol);
     146          similarity += SimilarityCalculator.ExecuteCalculation(oScope, hScope);
    152147        }
    153         offspring.Add(new Tuple<IScope, double>(oScope, diversity));
     148        offspring.Add(new Tuple<IScope, double>(oScope, similarity));
    154149      }
    155150
     
    171166
    172167      // update diversity part of the reference set
    173       var hasBetterDiversity = (Func<Tuple<IScope, double>, bool>)(x => { return x.Item2 > highDiversityParents.OrderBy(y => y.Item2).First().Item2; });
     168      var hasBetterDiversity = (Func<Tuple<IScope, double>, bool>)(x => { return x.Item2 < highSimilarityParents.OrderByDescending(y => y.Item2).First().Item2; });
    174169      if (offspring.Any(hasBetterDiversity)) NewSolutions.Value = true;
    175170      while (offspring.Any(hasBetterDiversity)) { // better offspring available
    176171        // select best offspring
    177         var bestChild = offspring.OrderByDescending(x => x.Item2).First();
     172        var bestChild = offspring.OrderBy(x => x.Item2).First();
    178173        // select worst parent
    179         var worstParent = highDiversityParents.OrderBy(x => x.Item2).First();
    180         highDiversityParents.Remove(worstParent);
    181         highDiversityParents.Add(bestChild);
     174        var worstParent = highSimilarityParents.OrderByDescending(x => x.Item2).First();
     175        highSimilarityParents.Remove(worstParent);
     176        highSimilarityParents.Add(bestChild);
    182177        offspring.Remove(bestChild);
    183178      }
    184179
    185       CurrentScope.SubScopes.Replace(highQualityParents.Concat(highDiversityParents.Select(x => x.Item1)).ToList());
     180      CurrentScope.SubScopes.Replace(highQualityParents.Concat(highSimilarityParents.Select(x => x.Item1)).ToList());
    186181
    187182      return base.Apply();
    188183    }
    189 
    190     private class KeyEqualityComparer<T> : IEqualityComparer<T> {
    191       private readonly Func<T, object> keyExtractor;
    192 
    193       public KeyEqualityComparer(Func<T, object> keyExtractor) {
    194         this.keyExtractor = keyExtractor;
    195       }
    196 
    197       public bool Equals(T x, T y) {
    198         return keyExtractor(x).Equals(keyExtractor(y));
    199       }
    200 
    201       public int GetHashCode(T obj) {
    202         return keyExtractor(obj).GetHashCode();
    203       }
    204     }
    205184  }
    206185}
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/SolutionPoolUpdateMethod.cs

    r7775 r7786  
    3636  [Item("SolutionPoolUpdateMethod", "An operator that updates the solution pool.")]
    3737  [StorableClass]
    38   public sealed class SolutionPoolUpdateMethod : SingleSuccessorOperator, IScatterSearchTargetProcessor {
     38  public sealed class SolutionPoolUpdateMethod : SingleSuccessorOperator {
    3939    #region Parameter properties
    4040    public ScopeParameter CurrentScopeParameter {
     
    4747      get { return (IValueLookupParameter<BoolValue>)Parameters["NewSolutions"]; }
    4848    }
     49    public IValueLookupParameter<IItem> QualityParameter {
     50      get { return (IValueLookupParameter<IItem>)Parameters["Quality"]; }
     51    }
    4952    public IValueLookupParameter<IntValue> ReferenceSetSizeParameter {
    5053      get { return (IValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
    5154    }
    52     public IValueLookupParameter<IItem> QualityParameter {
    53       get { return (IValueLookupParameter<IItem>)Parameters["Quality"]; }
     55    public IValueLookupParameter<SimilarityCalculator> SimilarityCalculatorParameter {
     56      get { return (IValueLookupParameter<SimilarityCalculator>)Parameters["SimilarityCalculator"]; }
    5457    }
    5558    public IValueLookupParameter<IItem> TargetParameter {
     
    6972      get { return NewSolutionsParameter.ActualValue; }
    7073    }
     74    private IItem Quality {
     75      get { return QualityParameter.ActualValue; }
     76    }
    7177    private IntValue ReferenceSetSize {
    7278      get { return ReferenceSetSizeParameter.ActualValue; }
    7379      set { ReferenceSetSizeParameter.ActualValue = value; }
    7480    }
    75     private IItem Quality {
    76       get { return QualityParameter.ActualValue; }
     81    private SimilarityCalculator SimilarityCalculator {
     82      get { return SimilarityCalculatorParameter.ActualValue; }
    7783    }
    7884    private IItem Target {
     
    95101      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization"));
    96102      Parameters.Add(new ValueLookupParameter<BoolValue>("NewSolutions"));
     103      Parameters.Add(new ValueLookupParameter<IItem>("Quality"));
    97104      Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize"));
    98       Parameters.Add(new ValueLookupParameter<IItem>("Quality"));
     105      Parameters.Add(new ValueLookupParameter<SimilarityCalculator>("SimilarityCalculator"));
    99106      Parameters.Add(new ValueLookupParameter<IItem>("Target"));
    100107      #endregion
    101       TargetParameter.ActualName = "KnapsackSolution"; // temporary solution for the knapsack problem
    102108    }
    103109
    104110    public override IOperation Apply() {
    105       var parentsScope = new Scope("Parents");
    106       var offspringScope = new Scope("Offspring");
     111      IScope parentsScope = new Scope("Parents");
     112      IScope offspringScope = new Scope("Offspring");
    107113
    108114      // split parents and offspring
     
    121127      CurrentScope.SubScopes.AddRange(orderedParents);
    122128
    123       var worstParentQuality = (orderedParents.Last().Variables[QualityParameter.ActualName].Value as DoubleValue).Value;
     129      double worstParentQuality = (orderedParents.Last().Variables[QualityParameter.ActualName].Value as DoubleValue).Value;
    124130
    125131      var hasBetterQuality = Maximization.Value ? (Func<IScope, bool>)(x => { return (x.Variables[QualityParameter.ActualName].Value as DoubleValue).Value > worstParentQuality; }) :
    126                                             (Func<IScope, bool>)(x => { return (x.Variables[QualityParameter.ActualName].Value as DoubleValue).Value < worstParentQuality; });
     132                                                  (Func<IScope, bool>)(x => { return (x.Variables[QualityParameter.ActualName].Value as DoubleValue).Value < worstParentQuality; });
    127133
    128134      // is there any offspring better than the worst parent?
     
    130136        // produce the set union
    131137        // attention: distinction might cause a too small reference set! (e.g. reference set = {1, 2, 2, 2, ..., 2} -> union = {1, 2}
    132         var union = orderedParents.Union(orderedOffspring.Where(hasBetterQuality), new KeyEqualityComparer<IScope>(x => x.Variables[TargetParameter.ActualName].Value.ToString()));
     138        var union = orderedParents.Union(orderedOffspring.Where(hasBetterQuality), new SolutionEqualityComparer<IScope>(SimilarityCalculator.ExecuteCalculation));
    133139        if (union.Count() > orderedParents/*.Distinct(new KeyEqualityComparer<IScope>(x => x.Variables[TargetParameter.ActualName].Value.ToString()))*/.Count()) {
    134140          var orderedUnion = Maximization.Value ? union.OrderByDescending(x => x.Variables[QualityParameter.ActualName].Value) :
     
    142148    }
    143149
    144     private class KeyEqualityComparer<T> : IEqualityComparer<T> {
    145       private readonly Func<T, object> keyExtractor;
     150    private class SolutionEqualityComparer<T> : EqualityComparer<T> {
     151      private readonly Func<T, T, double> diversityCalculator;
    146152
    147       public KeyEqualityComparer(Func<T, object> keyExtractor) {
    148         this.keyExtractor = keyExtractor;
     153      public SolutionEqualityComparer(Func<T, T, double> diversityCalculator) {
     154        this.diversityCalculator = diversityCalculator;
    149155      }
    150156
    151       public bool Equals(T x, T y) {
    152         return keyExtractor(x).Equals(keyExtractor(y));
     157      public override bool Equals(T x, T y) {
     158        return diversityCalculator(x, y) == 0.0;
    153159      }
    154160
    155       public int GetHashCode(T obj) {
    156         return keyExtractor(obj).GetHashCode();
     161      public override int GetHashCode(T obj) {
     162        return obj.GetHashCode();
    157163      }
    158164    }
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/TestFunctions/TestFunctionsImprovementOperator.cs

    r7775 r7786  
    2121
    2222using System;
     23using System.Reflection;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     
    2627using HeuristicLab.Encodings.RealVectorEncoding;
    2728using HeuristicLab.Operators;
    28 using HeuristicLab.Optimization;
    2929using HeuristicLab.Parameters;
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    31 using HeuristicLab.Problems.Knapsack;
    3231using HeuristicLab.Problems.TestFunctions;
    3332
     
    3837  [Item("TestFunctionsImprovementOperator", "An operator that improves test functions solutions.")]
    3938  [StorableClass]
    40   public abstract class TestFunctionsImprovementOperator : SingleSuccessorOperator, ILocalImprovementOperator, IScatterSearchTargetProcessor {
    41     #region Problem properties
    42     public Type ProblemType {
    43       get { return typeof(KnapsackProblem); }
    44     }
    45     [Storable]
    46     private KnapsackProblem problem;
    47     public IProblem Problem {
    48       get { return problem; }
    49       set { problem = (KnapsackProblem)value; }
    50     }
    51     #endregion
    52 
     39  public sealed class TestFunctionsImprovementOperator : SingleSuccessorOperator, IImprovementOperator {
    5340    #region Parameter properties
     41    public IValueParameter<DoubleValue> AlphaParameter {
     42      get { return (IValueParameter<DoubleValue>)Parameters["Alpha"]; }
     43    }
     44    public IValueParameter<DoubleValue> BetaParameter {
     45      get { return (IValueParameter<DoubleValue>)Parameters["Beta"]; }
     46    }
    5447    public ScopeParameter CurrentScopeParameter {
    5548      get { return (ScopeParameter)Parameters["CurrentScope"]; }
    5649    }
    57     public IValueLookupParameter<DoubleMatrix> CoordinatesParameter {
    58       get { return (IValueLookupParameter<DoubleMatrix>)Parameters["Coordinates"]; }
     50    public IValueParameter<DoubleValue> DeltaParameter {
     51      get { return (IValueParameter<DoubleValue>)Parameters["Delta"]; }
    5952    }
    6053    public IValueLookupParameter<ISingleObjectiveTestFunctionProblemEvaluator> EvaluatorParameter {
    6154      get { return (IValueLookupParameter<ISingleObjectiveTestFunctionProblemEvaluator>)Parameters["Evaluator"]; }
    6255    }
     56    public IValueParameter<DoubleValue> GammaParameter {
     57      get { return (IValueParameter<DoubleValue>)Parameters["Gamma"]; }
     58    }
    6359    public IValueLookupParameter<IntValue> ImprovementAttemptsParameter {
    6460      get { return (IValueLookupParameter<IntValue>)Parameters["ImprovementAttempts"]; }
     
    7066      get { return (IValueLookupParameter<IItem>)Parameters["Target"]; }
    7167    }
    72     public IValueParameter<DoubleValue> AlphaParameter {
    73       get { return (IValueParameter<DoubleValue>)Parameters["Alpha"]; }
    74     }
    75     public IValueParameter<DoubleValue> BetaParameter {
    76       get { return (IValueParameter<DoubleValue>)Parameters["Beta"]; }
    77     }
    78     public IValueParameter<DoubleValue> GammaParameter {
    79       get { return (IValueParameter<DoubleValue>)Parameters["Gamma"]; }
    80     }
    81     public IValueParameter<DoubleValue> DeltaParameter {
    82       get { return (IValueParameter<DoubleValue>)Parameters["Delta"]; }
    83     }
    84     #region ILocalImprovementOperator Parameters
    85     public IValueLookupParameter<IntValue> MaximumIterationsParameter {
    86       get { return (IValueLookupParameter<IntValue>)Parameters["MaximumIterations"]; }
    87     }
    88     public ILookupParameter<IntValue> EvaluatedSolutionsParameter {
    89       get { return (ILookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; }
    90     }
    91     public ILookupParameter<ResultCollection> ResultsParameter {
    92       get { return (ILookupParameter<ResultCollection>)Parameters["Results"]; }
    93     }
    9468    #endregion
    95     #endregion
    9669
    9770    #region Properties
    98     private IItem Target {
    99       get { return TargetParameter.ActualValue; }
    100     }
    10171    private DoubleValue Alpha {
    10272      get { return AlphaParameter.Value; }
     
    10575      get { return BetaParameter.Value; }
    10676    }
    107     private DoubleValue Gamma {
    108       get { return GammaParameter.Value; }
     77    public IScope CurrentScope {
     78      get { return CurrentScopeParameter.ActualValue; }
    10979    }
    11080    private DoubleValue Delta {
    11181      get { return DeltaParameter.Value; }
    112     }
    113     protected Func<RealVector, double> FunctionEvaluator { get; set; }
    114     public IScope CurrentScope {
    115       get { return CurrentScopeParameter.ActualValue; }
    116     }
    117     public DoubleMatrix Coordinates {
    118       get { return CoordinatesParameter.ActualValue; }
    119       set { CoordinatesParameter.ActualValue = value; }
    12082    }
    12183    public ISingleObjectiveTestFunctionProblemEvaluator Evaluator {
     
    12385      set { EvaluatorParameter.ActualValue = value; }
    12486    }
     87    private DoubleValue Gamma {
     88      get { return GammaParameter.Value; }
     89    }
    12590    public IntValue ImprovementAttempts {
    12691      get { return ImprovementAttemptsParameter.ActualValue; }
     
    13196      set { RandomParameter.ActualValue = value; }
    13297    }
     98    private IItem Target {
     99      get { return TargetParameter.ActualValue; }
     100    }
    133101    #endregion
    134102
    135103    [StorableConstructor]
    136     protected TestFunctionsImprovementOperator(bool deserializing) : base(deserializing) { }
    137     protected TestFunctionsImprovementOperator(TestFunctionsImprovementOperator original, Cloner cloner)
    138       : base(original, cloner) {
    139       this.problem = cloner.Clone(original.problem);
    140     }
     104    private TestFunctionsImprovementOperator(bool deserializing) : base(deserializing) { }
     105    private TestFunctionsImprovementOperator(TestFunctionsImprovementOperator original, Cloner cloner) : base(original, cloner) { }
    141106    public TestFunctionsImprovementOperator()
    142107      : base() {
    143108      #region Create parameters
    144       Parameters.Add(new ScopeParameter("CurrentScope"));
    145       Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Coordinates"));
    146       Parameters.Add(new ValueLookupParameter<ISingleObjectiveTestFunctionProblemEvaluator>("Evaluator"));
    147       Parameters.Add(new ValueLookupParameter<IntValue>("ImprovementAttempts", new IntValue(100)));
    148       Parameters.Add(new ValueLookupParameter<IRandom>("Random"));
    149       Parameters.Add(new ValueLookupParameter<IItem>("Target"));
    150109      Parameters.Add(new ValueParameter<DoubleValue>("Alpha", new DoubleValue(1.0)));
    151110      Parameters.Add(new ValueParameter<DoubleValue>("Beta", new DoubleValue(2.0)));
     111      Parameters.Add(new ScopeParameter("CurrentScope"));
     112      Parameters.Add(new ValueParameter<DoubleValue>("Delta", new DoubleValue(0.5)));
     113      Parameters.Add(new ValueLookupParameter<ISingleObjectiveTestFunctionProblemEvaluator>("Evaluator"));
    152114      Parameters.Add(new ValueParameter<DoubleValue>("Gamma", new DoubleValue(0.5)));
    153       Parameters.Add(new ValueParameter<DoubleValue>("Delta", new DoubleValue(0.5)));
     115      Parameters.Add(new ValueLookupParameter<IntValue>("ImprovementAttempts", new IntValue(100)));
     116      Parameters.Add(new ValueLookupParameter<IItem>("Target"));
     117      Parameters.Add(new ValueLookupParameter<IRandom>("Random"));
    154118      #endregion
    155119      TargetParameter.ActualName = "Point"; // temporary solution for the test functions problem
    156120    }
    157121
     122    public override IDeepCloneable Clone(Cloner cloner) {
     123      return new TestFunctionsImprovementOperator(this, cloner);
     124    }
     125
    158126    public override IOperation Apply() {
    159       var bestSol = CurrentScope.Variables[TargetParameter.ActualName].Value as RealVector;
    160       var bestSolQuality = FunctionEvaluator(bestSol);
     127      RealVector bestSol = CurrentScope.Variables[TargetParameter.ActualName].Value as RealVector;
     128      MethodInfo evaluationMethod = Evaluator.GetType().GetMethod("Apply",
     129                                                                  BindingFlags.Public | BindingFlags.Static,
     130                                                                  null,
     131                                                                  new Type[] { typeof(RealVector) }, null);
     132      Func<RealVector, double> functionEvaluator = x => (double)evaluationMethod.Invoke(Evaluator, new object[] { x });
     133      double bestSolQuality = functionEvaluator(bestSol);
    161134
    162135      // create perturbed solutions
    163       var simplex = new RealVector[bestSol.Length];
     136      RealVector[] simplex = new RealVector[bestSol.Length];
    164137      for (int i = 0; i < simplex.Length; i++) {
    165138        simplex[i] = bestSol.Clone() as RealVector;
     
    172145      for (int i = 0; i < ImprovementAttempts.Value; i++) {
    173146        // order according to their objective function value
    174         Array.Sort(simplex, (x, y) => FunctionEvaluator(x).CompareTo(FunctionEvaluator(y)));
     147        Array.Sort(simplex, (x, y) => functionEvaluator(x).CompareTo(functionEvaluator(y)));
    175148
    176149        // calculate centroid
    177         var centroid = new RealVector(bestSol.Length);
     150        RealVector centroid = new RealVector(bestSol.Length);
    178151        foreach (var vector in simplex)
    179152          for (int j = 0; j < centroid.Length; j++)
     
    183156
    184157        // reflection
    185         var reflectionPoint = new RealVector(bestSol.Length);
     158        RealVector reflectionPoint = new RealVector(bestSol.Length);
    186159        for (int j = 0; j < reflectionPoint.Length; j++)
    187160          reflectionPoint[j] = centroid[j] + Alpha.Value * (centroid[j] - simplex[simplex.Length - 1][j]);
    188         double reflectionPointQuality = FunctionEvaluator(reflectionPoint);
    189         if (FunctionEvaluator(simplex[0]) <= reflectionPointQuality
    190             && reflectionPointQuality < FunctionEvaluator(simplex[simplex.Length - 2]))
     161        double reflectionPointQuality = functionEvaluator(reflectionPoint);
     162        if (functionEvaluator(simplex[0]) <= reflectionPointQuality
     163            && reflectionPointQuality < functionEvaluator(simplex[simplex.Length - 2]))
    191164          simplex[simplex.Length - 1] = reflectionPoint;
    192165
    193166        // expansion
    194         if (reflectionPointQuality < FunctionEvaluator(simplex[0])) {
    195           var expansionPoint = new RealVector(bestSol.Length);
     167        if (reflectionPointQuality < functionEvaluator(simplex[0])) {
     168          RealVector expansionPoint = new RealVector(bestSol.Length);
    196169          for (int j = 0; j < expansionPoint.Length; j++)
    197170            expansionPoint[j] = centroid[j] + Beta.Value * (reflectionPoint[j] - centroid[j]);
    198           simplex[simplex.Length - 1] = FunctionEvaluator(expansionPoint) < reflectionPointQuality ? expansionPoint : reflectionPoint;
     171          simplex[simplex.Length - 1] = functionEvaluator(expansionPoint) < reflectionPointQuality ? expansionPoint : reflectionPoint;
    199172        }
    200173
    201174        // contraction
    202         if (FunctionEvaluator(simplex[simplex.Length - 2]) <= reflectionPointQuality
    203             && reflectionPointQuality < FunctionEvaluator(simplex[simplex.Length - 1])) {
    204           var outsideContractionPoint = new RealVector(bestSol.Length);
     175        if (functionEvaluator(simplex[simplex.Length - 2]) <= reflectionPointQuality
     176            && reflectionPointQuality < functionEvaluator(simplex[simplex.Length - 1])) {
     177          RealVector outsideContractionPoint = new RealVector(bestSol.Length);
    205178          for (int j = 0; j < outsideContractionPoint.Length; j++)
    206179            outsideContractionPoint[j] = centroid[j] + Gamma.Value * (reflectionPoint[j] - centroid[j]);
    207           if (FunctionEvaluator(outsideContractionPoint) <= reflectionPointQuality) {
     180          if (functionEvaluator(outsideContractionPoint) <= reflectionPointQuality) {
    208181            simplex[simplex.Length - 1] = outsideContractionPoint;
    209             if (FunctionEvaluator(reflectionPoint) >= FunctionEvaluator(simplex[simplex.Length - 1])) {
    210               var insideContractionPoint = new RealVector(bestSol.Length);
     182            if (functionEvaluator(reflectionPoint) >= functionEvaluator(simplex[simplex.Length - 1])) {
     183              RealVector insideContractionPoint = new RealVector(bestSol.Length);
    211184              for (int j = 0; j < insideContractionPoint.Length; j++)
    212185                insideContractionPoint[j] = centroid[j] - Gamma.Value * (reflectionPoint[j] - centroid[j]);
    213               if (FunctionEvaluator(insideContractionPoint) < FunctionEvaluator(simplex[simplex.Length - 1])) simplex[simplex.Length - 1] = insideContractionPoint;
     186              if (functionEvaluator(insideContractionPoint) < functionEvaluator(simplex[simplex.Length - 1])) simplex[simplex.Length - 1] = insideContractionPoint;
    214187            }
    215188          }
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/TestFunctions/TestFunctionsPathRelinker.cs

    r7775 r7786  
    7171        throw new ArgumentException("RelinkingAccuracy must be greater than 0.");
    7272
    73       var v1 = initiator.Clone() as RealVector;
    74       var v2 = guide as RealVector;
     73      RealVector v1 = initiator.Clone() as RealVector;
     74      RealVector v2 = guide as RealVector;
    7575
    7676      if (v1.Length != v2.Length)
    7777        throw new ArgumentException("The solutions are of different length.");
    7878
    79       var solutions = new List<RealVector>();
     79      IList<RealVector> solutions = new List<RealVector>();
    8080      for (int i = 0; i < k.Value; i++) {
    81         var solution = v1.Clone() as RealVector;
     81        RealVector solution = v1.Clone() as RealVector;
    8282        for (int j = 0; j < solution.Length; j++)
    8383          solution[j] = v1[j] + 1 / (k.Value - i) * (v2[j] - v1[j]);
     
    8585      }
    8686
    87       var selection = new List<IItem>();
     87      IList<IItem> selection = new List<IItem>();
    8888      if (solutions.Count > 0) {
    89         var noSol = (int)Math.Round(solutions.Count * n.Value);
     89        int noSol = (int)(solutions.Count * n.Value);
    9090        if (noSol <= 0) noSol++;
    91         var stepSize = (double)solutions.Count / (double)noSol;
     91        double stepSize = (double)solutions.Count / (double)noSol;
    9292        for (int i = 0; i < noSol; i++)
    93           selection.Add(solutions.ElementAt((int)Math.Round((i + 1) * stepSize - stepSize * 0.5)));
     93          selection.Add(solutions.ElementAt((int)((i + 1) * stepSize - stepSize * 0.5)));
    9494      }
    9595
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/TravelingSalesman/TravelingSalesmanImprovementOperator.cs

    r7775 r7786  
    2929using HeuristicLab.Parameters;
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    31 using HeuristicLab.Problems.Knapsack;
    3231using HeuristicLab.Problems.TravelingSalesman;
    3332
     
    3837  [Item("TravelingSalesmanImprovementOperator", "An operator that improves traveling salesman solutions.")]
    3938  [StorableClass]
    40   public sealed class TravelingSalesmanImprovementOperator : SingleSuccessorOperator, ILocalImprovementOperator, IScatterSearchTargetProcessor {
    41     #region Problem properties
    42     public Type ProblemType {
    43       get { return typeof(KnapsackProblem); }
    44     }
    45     [Storable]
    46     private KnapsackProblem problem;
    47     public IProblem Problem {
    48       get { return problem; }
    49       set { problem = (KnapsackProblem)value; }
    50     }
    51     #endregion
    52 
     39  public sealed class TravelingSalesmanImprovementOperator : SingleSuccessorOperator, IImprovementOperator {
    5340    #region Parameter properties
    5441    public ScopeParameter CurrentScopeParameter {
    5542      get { return (ScopeParameter)Parameters["CurrentScope"]; }
    5643    }
    57     public IValueLookupParameter<DoubleMatrix> CoordinatesParameter {
    58       get { return (IValueLookupParameter<DoubleMatrix>)Parameters["Coordinates"]; }
     44    public ILookupParameter<DistanceMatrix> DistanceMatrixParameter {
     45      get { return (ILookupParameter<DistanceMatrix>)Parameters["DistanceMatrix"]; }
    5946    }
    60     public IValueLookupParameter<IEvaluator> EvaluatorParameter {
    61       get { return (IValueLookupParameter<IEvaluator>)Parameters["Evaluator"]; }
     47    public ILookupParameter<IEvaluator> EvaluatorParameter {
     48      get { return (ILookupParameter<IEvaluator>)Parameters["Evaluator"]; }
    6249    }
    63     public IValueLookupParameter<IntValue> ImprovementAttemptsParameter {
    64       get { return (IValueLookupParameter<IntValue>)Parameters["ImprovementAttempts"]; }
     50    public IValueParameter<IntValue> ImprovementAttemptsParameter {
     51      get { return (IValueParameter<IntValue>)Parameters["ImprovementAttempts"]; }
    6552    }
    66     public IValueLookupParameter<IRandom> RandomParameter {
    67       get { return (IValueLookupParameter<IRandom>)Parameters["Random"]; }
     53    public ILookupParameter<IRandom> RandomParameter {
     54      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
    6855    }
    6956    public IValueLookupParameter<IItem> TargetParameter {
    7057      get { return (IValueLookupParameter<IItem>)Parameters["Target"]; }
    7158    }
    72     #region ILocalImprovementOperator Parameters
    73     public IValueLookupParameter<IntValue> MaximumIterationsParameter {
    74       get { return (IValueLookupParameter<IntValue>)Parameters["MaximumIterations"]; }
    75     }
    76     public ILookupParameter<IntValue> EvaluatedSolutionsParameter {
    77       get { return (ILookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; }
    78     }
    79     public ILookupParameter<ResultCollection> ResultsParameter {
    80       get { return (ILookupParameter<ResultCollection>)Parameters["Results"]; }
    81     }
    82     #endregion
    8359    #endregion
    8460
     
    8763      get { return CurrentScopeParameter.ActualValue; }
    8864    }
    89     public DoubleMatrix Coordinates {
    90       get { return CoordinatesParameter.ActualValue; }
    91       set { CoordinatesParameter.ActualValue = value; }
     65    public DistanceMatrix DistanceMatrix {
     66      get { return DistanceMatrixParameter.ActualValue; }
     67      set { DistanceMatrixParameter.ActualValue = value; }
    9268    }
    9369    public IEvaluator Evaluator {
     
    9672    }
    9773    public IntValue ImprovementAttempts {
    98       get { return ImprovementAttemptsParameter.ActualValue; }
    99       set { ImprovementAttemptsParameter.ActualValue = value; }
     74      get { return ImprovementAttemptsParameter.Value; }
     75      set { ImprovementAttemptsParameter.Value = value; }
    10076    }
    10177    public IRandom Random {
     
    11086    [StorableConstructor]
    11187    private TravelingSalesmanImprovementOperator(bool deserializing) : base(deserializing) { }
    112     private TravelingSalesmanImprovementOperator(TravelingSalesmanImprovementOperator original, Cloner cloner)
    113       : base(original, cloner) {
    114       this.problem = cloner.Clone(original.problem);
    115     }
     88    private TravelingSalesmanImprovementOperator(TravelingSalesmanImprovementOperator original, Cloner cloner) : base(original, cloner) { }
    11689    public TravelingSalesmanImprovementOperator()
    11790      : base() {
    11891      #region Create parameters
    11992      Parameters.Add(new ScopeParameter("CurrentScope"));
    120       Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Coordinates"));
    121       Parameters.Add(new ValueLookupParameter<IEvaluator>("Evaluator"));
    122       Parameters.Add(new ValueLookupParameter<IntValue>("ImprovementAttempts", new IntValue(100)));
    123       Parameters.Add(new ValueLookupParameter<IRandom>("Random"));
     93      Parameters.Add(new LookupParameter<DistanceMatrix>("DistanceMatrix"));
     94      Parameters.Add(new LookupParameter<IEvaluator>("Evaluator"));
     95      Parameters.Add(new ValueParameter<IntValue>("ImprovementAttempts", new IntValue(100)));
     96      Parameters.Add(new LookupParameter<IRandom>("Random"));
    12497      Parameters.Add(new ValueLookupParameter<IItem>("Target"));
    12598      #endregion
     
    132105
    133106    public override IOperation Apply() {
    134       var currSol = CurrentScope.Variables[TargetParameter.ActualName].Value as Permutation;
    135       var bestSol = currSol;
    136       double currLength = TSPEuclideanPathEvaluator.Apply(Evaluator as TSPCoordinatesPathEvaluator, Coordinates, currSol);
    137       double bestLength = currLength;
     107      Permutation currSol = CurrentScope.Variables[TargetParameter.ActualName].Value as Permutation;
     108      if (currSol.PermutationType != PermutationTypes.RelativeUndirected)
     109        throw new ArgumentException("Cannot improve solution because the permutation type is not supported.");
    138110
    139111      for (int i = 0; i < ImprovementAttempts.Value; i++) {
    140112        int a = Random.Next(currSol.Length);
    141113        int b = Random.Next(currSol.Length);
    142         Invert(currSol, a, b);
    143         currLength = TSPEuclideanPathEvaluator.Apply(Evaluator as TSPCoordinatesPathEvaluator, Coordinates, currSol);
    144         if (currLength < bestLength) {
    145           bestLength = currLength;
    146           bestSol = currSol.Clone() as Permutation;
    147         }
    148         Invert(currSol, a, b);
     114        double oldFirstEdgeLength = DistanceMatrix[currSol[a], currSol[(a - 1 + currSol.Length) % currSol.Length]];
     115        double oldSecondEdgeLength = DistanceMatrix[currSol[b], currSol[(b + 1) % currSol.Length]];
     116        double newFirstEdgeLength = DistanceMatrix[currSol[b], currSol[(a - 1 + currSol.Length) % currSol.Length]];
     117        double newSecondEdgeLength = DistanceMatrix[currSol[a], currSol[(b + 1 + currSol.Length) % currSol.Length]];
     118        if (newFirstEdgeLength + newSecondEdgeLength < oldFirstEdgeLength + oldSecondEdgeLength)
     119          Invert(currSol, a, b);
    149120      }
    150 
    151       CurrentScope.Variables[TargetParameter.ActualName].Value = bestSol;
    152121
    153122      return base.Apply();
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/TravelingSalesman/TravelingSalesmanMultipleGuidesPathRelinker.cs

    r7778 r7786  
    7272        throw new ArgumentException("RelinkingAccuracy must be greater than 0.");
    7373
    74       var v1 = initiator.Clone() as Permutation;
    75       var targets = new Permutation[guides.Length];
     74      Permutation v1 = initiator.Clone() as Permutation;
     75      Permutation[] targets = new Permutation[guides.Length];
    7676      Array.Copy(guides, targets, guides.Length);
    7777
     
    7979        throw new ArgumentException("At least one solution is of different length.");
    8080
    81       var solutions = new List<Permutation>();
     81      IList<Permutation> solutions = new List<Permutation>();
    8282      for (int i = 0; i < v1.Length; i++) {
    83         var currCityIndex = i;
    84         var bestCityIndex = (i + 1) % v1.Length;
    85         var currDistance = distances[v1[currCityIndex], v1[bestCityIndex]];
     83        int currCityIndex = i;
     84        int bestCityIndex = (i + 1) % v1.Length;
     85        double currDistance = distances[v1[currCityIndex], v1[bestCityIndex]];
    8686        targets.ToList().ForEach(solution => {
    8787          var node = solution.Select((x, index) => new { Id = x, Index = index }).First(x => x.Id == v1[currCityIndex]);
    88           var pred = solution[(node.Index - 1 + solution.Length) % solution.Length];
    89           var succ = solution[(node.Index + 1) % solution.Length];
     88          int pred = solution[(node.Index - 1 + solution.Length) % solution.Length];
     89          int succ = solution[(node.Index + 1) % solution.Length];
    9090          var results = new[] { pred, succ }.Select(x => new { Id = x, Distance = distances[x, node.Id] });
    9191          if (results.Any(x => x.Distance < currDistance)) {
     
    9999      }
    100100
    101       var selection = new List<IItem>();
     101      IList<IItem> selection = new List<IItem>();
    102102      if (solutions.Count > 0) {
    103         var noSol = (int)Math.Round(solutions.Count * n.Value);
     103        int noSol = (int)(solutions.Count * n.Value);
    104104        if (noSol <= 0) noSol++;
    105         var stepSize = (double)solutions.Count / (double)noSol;
     105        double stepSize = (double)solutions.Count / (double)noSol;
    106106        for (int i = 0; i < noSol; i++)
    107           selection.Add(solutions.ElementAt((int)Math.Round((i + 1) * stepSize - stepSize * 0.5)));
     107          selection.Add(solutions.ElementAt((int)((i + 1) * stepSize - stepSize * 0.5)));
    108108      }
    109109
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/TravelingSalesman/TravelingSalesmanPathRelinker.cs

    r7775 r7786  
    5454        throw new ArgumentException("RelinkingAccuracy must be greater than 0.");
    5555
    56       var v1 = initiator.Clone() as Permutation;
    57       var v2 = guide as Permutation;
     56      Permutation v1 = initiator.Clone() as Permutation;
     57      Permutation v2 = guide as Permutation;
    5858
    5959      if (v1.Length != v2.Length)
    6060        throw new ArgumentException("The solutions are of different length.");
    6161
    62       var solutions = new List<Permutation>();
     62      IList<Permutation> solutions = new List<Permutation>();
    6363      for (int i = 0; i < v1.Length; i++)
    6464        if (v1[i] != v2[i]) {
     
    7373        }
    7474
    75       var selection = new List<IItem>();
     75      IList<IItem> selection = new List<IItem>();
    7676      if (solutions.Count > 0) {
    77         var noSol = (int)Math.Round(solutions.Count * n.Value);
     77        int noSol = (int)(solutions.Count * n.Value);
    7878        if (noSol <= 0) noSol++;
    79         var stepSize = (double)solutions.Count / (double)noSol;
     79        double stepSize = (double)solutions.Count / (double)noSol;
    8080        for (int i = 0; i < noSol; i++)
    81           selection.Add(solutions.ElementAt((int)Math.Round((i + 1) * stepSize - stepSize * 0.5)));
     81          selection.Add(solutions.ElementAt((int)((i + 1) * stepSize - stepSize * 0.5)));
    8282      }
    8383
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/TravelingSalesman/TravelingSalesmanSimultaneousPathRelinker.cs

    r7775 r7786  
    5454        throw new ArgumentException("RelinkingAccuracy must be greater than 0.");
    5555
    56       var firstInitiator = initiator.Clone() as Permutation;
    57       var firstGuide = guide.Clone() as Permutation;
    58       var secondInitiator = firstGuide.Clone() as Permutation;
    59       var secondGuide = firstInitiator.Clone() as Permutation;
     56      Permutation firstInitiator = initiator.Clone() as Permutation;
     57      Permutation firstGuide = guide.Clone() as Permutation;
     58      Permutation secondInitiator = firstGuide.Clone() as Permutation;
     59      Permutation secondGuide = firstInitiator.Clone() as Permutation;
    6060
    6161      if (firstInitiator.Length != firstGuide.Length)
    6262        throw new ArgumentException("The solutions are of different length.");
    6363
    64       var solutions = new List<Permutation>();
     64      IList<Permutation> solutions = new List<Permutation>();
    6565      for (int i = 0; i < firstInitiator.Length / 2; i++) {
    6666        if (firstInitiator[i] != firstGuide[i]) {
     
    7272          solutions.Add(firstInitiator.Clone() as Permutation);
    7373        }
    74         var j = secondInitiator.Length - 1 - i;
     74        int j = secondInitiator.Length - 1 - i;
    7575        if (secondInitiator[j] != secondGuide[j]) {
    7676          var target = secondInitiator.Select((x, index) => new { Value = x, ValueIndex = index }).First(x => x.Value == secondGuide[j]);
     
    8383      }
    8484
    85       var selection = new List<IItem>();
     85      IList<IItem> selection = new List<IItem>();
    8686      if (solutions.Count > 0) {
    87         var noSol = (int)Math.Round(solutions.Count * n.Value);
     87        int noSol = (int)(solutions.Count * n.Value);
    8888        if (noSol <= 0) noSol++;
    89         var stepSize = (double)solutions.Count / (double)noSol;
     89        double stepSize = (double)solutions.Count / (double)noSol;
    9090        for (int i = 0; i < noSol; i++)
    91           selection.Add(solutions.ElementAt((int)Math.Round((i + 1) * stepSize - stepSize * 0.5)));
     91          selection.Add(solutions.ElementAt((int)((i + 1) * stepSize - stepSize * 0.5)));
    9292      }
    9393
Note: See TracChangeset for help on using the changeset viewer.