Changeset 7744


Ignore:
Timestamp:
04/20/12 17:00:09 (8 years ago)
Author:
jkarder
Message:

#1331:

  • added problem specific improvement operators (KnapsackImprovementOperator, TravelingSalesmanImprovementOperator)
  • added custom interface (IScatterSearchTargetProcessor) for Scatter Search specific operators that use a target parameter
  • added custom operator (OffspringProcessor) to process multiple children that were created by crossovers
  • extracted diversity calculation and added problem/encoding specific operators (BinaryVectorDiversityCalculator, PermutationDiversityCalculator) for it
  • added parameters and adjusted types
  • adjusted event handling
  • minor code improvements
Location:
branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3
Files:
8 added
2 deleted
8 edited

Legend:

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

    r7740 r7744  
    8686  </ItemGroup>
    8787  <ItemGroup>
    88     <Compile Include="Knapsack\DiversityCalculator.cs" />
     88    <Compile Include="DiversityCalculator.cs" />
     89    <Compile Include="Knapsack\BinaryVectorDiversityCalculator.cs" />
    8990    <Compile Include="Knapsack\INBinaryVectorCrossover.cs" />
     91    <Compile Include="IScatterSearchTargetProcessor.cs" />
    9092    <Compile Include="Knapsack\NBinaryVectorCrossover.cs" />
    9193    <Compile Include="Knapsack\NChildCrossover.cs" />
    9294    <Compile Include="OffspringProcessor.cs" />
    93     <Compile Include="TSPPopulationRebuildMethod.cs" />
    94     <Compile Include="TSPSolutionPoolUpdateMethod.cs" />
    95     <Compile Include="TSPReferenceSetUpdateMethod.cs" />
    96     <Compile Include="TSPScatterSearchImprovementOperator.cs" />
     95    <Compile Include="TravelingSalesman\PermutationDiversityCalculator.cs" />
     96    <Compile Include="TravelingSalesman\TravelingSalesmanImprovementOperator.cs" />
    9797    <None Include="HeuristicLab.snk" />
    9898    <None Include="Plugin.cs.frame" />
     
    103103    <Compile Include="PopulationRebuildMethod.cs" />
    104104    <Compile Include="ScatterSearch.cs" />
    105     <Compile Include="ScatterSearchImprovementOperator.cs" />
     105    <Compile Include="Knapsack\KnapsackImprovementOperator.cs" />
    106106    <Compile Include="ScatterSearchMainLoop.cs" />
    107107    <Compile Include="SolutionPoolUpdateMethod.cs" />
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/Knapsack/NBinaryVectorCrossover.cs

    r7740 r7744  
    7171
    7272    public sealed override IOperation Apply() {
    73       //ChildrenParameter.ActualValue = Cross(RandomParameter.ActualValue, ParentsParameter.ActualValue);
    7473      var offspringSolutions = Cross(RandomParameter.ActualValue, ParentsParameter.ActualValue);
    7574      for (int i = 0; i < offspringSolutions.Length; i++) {
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/Knapsack/NChildCrossover.cs

    r7740 r7744  
    3535  [StorableClass]
    3636  public sealed class NChildCrossover : NBinaryVectorCrossover {
     37    #region Parameter properties
    3738    public IValueLookupParameter<IntValue> NParameter {
    3839      get { return (IValueLookupParameter<IntValue>)Parameters["N"]; }
    3940    }
     41    #endregion
    4042
    4143    [StorableConstructor]
     
    4446    public NChildCrossover()
    4547      : base() {
     48      #region Create parameters
    4649      Parameters.Add(new ValueLookupParameter<IntValue>("N", "Number of children.", new IntValue(2)));
     50      #endregion
    4751    }
    4852
     
    5357    public static ItemArray<BinaryVector> Apply(IRandom random, BinaryVector parent1, BinaryVector parent2, IntValue n) {
    5458      if (parent1.Length != parent2.Length)
    55         throw new ArgumentException("NPointCrossover: The parents are of different length.");
     59        throw new ArgumentException("NChildCrossover: The parents are of different length.");
    5660
    5761      if (n.Value > Math.Pow(2, parent1.Length) - 2)
    58         throw new ArgumentException("NPointCrossover: There cannot be more breakpoints than the size of the parents.");
     62        throw new ArgumentException("NChildCrossover: There cannot be more children than 2^size of parents - 2.");
    5963
    6064      if (n.Value < 1)
    61         throw new ArgumentException("NPointCrossover: N cannot be < 1.");
     65        throw new ArgumentException("NChildCrossover: N cannot be < 1.");
    6266
    6367      var solutions = new BinaryVector[n.Value];
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/PopulationRebuildMethod.cs

    r7740 r7744  
    3939      get { return (ScopeParameter)Parameters["CurrentScope"]; }
    4040    }
     41    public IValueLookupParameter<BoolValue> MaximizationParameter {
     42      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
     43    }
    4144    public IValueLookupParameter<IntValue> NumberOfHighQualitySolutionsParameter {
    4245      get { return (IValueLookupParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; }
     
    5356    private IScope CurrentScope {
    5457      get { return CurrentScopeParameter.ActualValue; }
     58    }
     59    private BoolValue Maximization {
     60      get { return MaximizationParameter.ActualValue; }
     61      set { MaximizationParameter.ActualValue = value; }
    5562    }
    5663    private IntValue NumberOfHighQualitySolutions {
     
    7986      #region Create parameters
    8087      Parameters.Add(new ScopeParameter("CurrentScope"));
     88      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization"));
    8189      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfHighQualitySolutions"));
    8290      Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize"));
     
    8694
    8795    public override IOperation Apply() {
    88       var population = CurrentScope.SubScopes[0];
    89       var refSet = CurrentScope.SubScopes[1];
    90       refSet.SubScopes.Replace(refSet.SubScopes.OrderByDescending(r => r.Variables[QualityParameter.ActualName].Value)
    91                                                .Take(NumberOfHighQualitySolutions.Value).ToList());
    92       population.SubScopes.Clear();
     96      var populationScope = CurrentScope.SubScopes[0];
     97      var referenceSetScope = CurrentScope.SubScopes[1];
     98      var orderedReferenceSet = Maximization.Value ? referenceSetScope.SubScopes.OrderByDescending(r => r.Variables[QualityParameter.ActualName].Value) :
     99                                                     referenceSetScope.SubScopes.OrderBy(r => r.Variables[QualityParameter.ActualName].Value);
     100      referenceSetScope.SubScopes.Replace(orderedReferenceSet.Take(NumberOfHighQualitySolutions.Value).ToList());
     101      populationScope.SubScopes.Clear();
    93102      return base.Apply();
    94103    }
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/ReferenceSetUpdateMethod.cs

    r7740 r7744  
    4646      get { return (IValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
    4747    }
    48     public IValueLookupParameter<IItem> QualityParameter {
    49       get { return (IValueLookupParameter<IItem>)Parameters["Quality"]; }
     48    public IValueLookupParameter<IItem> TargetParameter {
     49      get { return (IValueLookupParameter<IItem>)Parameters["Target"]; }
     50    }
     51    public IValueLookupParameter<DiversityCalculator> DiversityCalculatorParameter {
     52      get { return (IValueLookupParameter<DiversityCalculator>)Parameters["DiversityCalculator"]; }
    5053    }
    5154    #endregion
     
    6164      get { return ReferenceSetSizeParameter.ActualValue; }
    6265    }
    63     private IItem Quality {
    64       get { return QualityParameter.ActualValue; }
     66    private IItem Target {
     67      get { return TargetParameter.ActualValue; }
     68    }
     69    private DiversityCalculator DiversityCalculator {
     70      get { return DiversityCalculatorParameter.ActualValue; }
    6571    }
    6672    #endregion
     
    8086      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfHighQualitySolutions"));
    8187      Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize"));
    82       Parameters.Add(new ValueLookupParameter<IItem>("Quality"));
     88      Parameters.Add(new ValueLookupParameter<IItem>("Target"));
     89      Parameters.Add(new ValueLookupParameter<DiversityCalculator>("DiversityCalculator"));
    8390      #endregion
     91      TargetParameter.ActualName = "KnapsackSolution"; // temporary solution for the knapsack problem
    8492    }
    8593
     
    8896      foreach (var pScope in CurrentScope.SubScopes[0].SubScopes) {
    8997        int diversity = 0;
    90         var pSol = pScope.Variables[QualityParameter.ActualName].Value;
     98        var pSol = pScope.Variables[TargetParameter.ActualName].Value;
    9199        foreach (var rScope in CurrentScope.SubScopes[1].SubScopes) {
    92           var rSol = rScope.Variables[QualityParameter.ActualName].Value;
    93           if (pSol != null && rSol != null) diversity += Knapsack.DiversityCalculator.CalculateDiversity(pSol, rSol);
     100          var rSol = rScope.Variables[TargetParameter.ActualName].Value;
     101          diversity += DiversityCalculator.ExecuteCalculation(pSol, rSol);
    94102        }
    95103        population[pScope] = diversity;
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearch.cs

    r7740 r7744  
    6161      get { return (ConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; }
    6262    }
    63     public IValueParameter<ILocalImprovementOperator> ImproverParameter {
    64       get { return (IValueParameter<ILocalImprovementOperator>)Parameters["Improver"]; }
     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"]; }
    6568    }
    6669    public IValueParameter<IntValue> MaximumIterationsParameter {
     
    9699      get { return ImproverParameter.Value; }
    97100      set { ImproverParameter.Value = value; }
     101    }
     102    private DiversityCalculator DiversityCalculator {
     103      get { return DiversityCalculatorParameter.Value; }
     104      set { DiversityCalculatorParameter.Value = value; }
    98105    }
    99106    private IntValue MaximumIterations {
     
    154161      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the solution and moves.", new MultiAnalyzer()));
    155162      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to combine solutions."));
    156       Parameters.Add(new ValueParameter<ILocalImprovementOperator>("Improver", "The operator used to improve solutions.", new ScatterSearchImprovementOperator()));
    157       Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(1000)));
    158       Parameters.Add(new ValueParameter<IntValue>("NumberOfHighQualitySolutions", "The number of high quality solutions that should be added to the reference set.", new IntValue(5)));
    159       Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population.", new IntValue(30)));
    160       Parameters.Add(new ValueParameter<IntValue>("ReferenceSetSize", "The size of the reference set.", new IntValue(10)));
     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)));
    161169      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
    162170      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
     
    241249      UpdateAnalyzers();
    242250      UpdateCrossovers();
     251      UpdateDiversityCalculators();
     252      UpdateImprovers();
     253      UpdateDiversityCalculators();
    243254      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    244255      base.OnProblemChanged();
     
    261272      UpdateAnalyzers();
    262273      UpdateCrossovers();
     274      UpdateDiversityCalculators();
     275      UpdateImprovers();
    263276      ParameterizeMainLoop();
    264277      ParameterizeAnalyzers();
     
    307320        CrossoverParameter.Value = defaultCrossover;
    308321    }
     322    private void UpdateDiversityCalculators() {
     323      DiversityCalculator oldDiversityCalculator = DiversityCalculatorParameter.Value;
     324      DiversityCalculatorParameter.ValidValues.Clear();
     325      DiversityCalculator defaultDiversityCalculator = Problem.Operators.OfType<DiversityCalculator>().FirstOrDefault();
     326
     327      DiversityCalculatorParameter.ValidValues.Add(new Knapsack.BinaryVectorDiversityCalculator());
     328      DiversityCalculatorParameter.ValidValues.Add(new TravelingSalesman.PermutationDiversityCalculator());
     329
     330      foreach (DiversityCalculator diversityCalculator in Problem.Operators.OfType<DiversityCalculator>().OrderBy(x => x.Name))
     331        DiversityCalculatorParameter.ValidValues.Add(diversityCalculator);
     332
     333      if (oldDiversityCalculator != null) {
     334        DiversityCalculator diversityCalculator = DiversityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldDiversityCalculator.GetType());
     335        if (diversityCalculator != null) DiversityCalculatorParameter.Value = diversityCalculator;
     336        else oldDiversityCalculator = null;
     337      }
     338      if (oldDiversityCalculator == null && defaultDiversityCalculator != null)
     339        DiversityCalculatorParameter.Value = defaultDiversityCalculator;
     340    }
     341    private void UpdateImprovers() {
     342      ILocalImprovementOperator oldImprover = ImproverParameter.Value;
     343      ImproverParameter.ValidValues.Clear();
     344      ILocalImprovementOperator defaultImprover = Problem.Operators.OfType<ILocalImprovementOperator>().FirstOrDefault();
     345
     346      ImproverParameter.ValidValues.Add(new Knapsack.KnapsackImprovementOperator());
     347      ImproverParameter.ValidValues.Add(new TravelingSalesman.TravelingSalesmanImprovementOperator());
     348
     349      foreach (ILocalImprovementOperator improver in Problem.Operators.OfType<ILocalImprovementOperator>().OrderBy(x => x.Name))
     350        ImproverParameter.ValidValues.Add(improver);
     351
     352      foreach (var improver in ImproverParameter.ValidValues.OfType<IScatterSearchTargetProcessor>())
     353        improver.TargetParameter.ActualName = "KnapsackSolution"; // temporary solution for the knapsack problem
     354
     355      if (oldImprover != null) {
     356        ILocalImprovementOperator improver = ImproverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldImprover.GetType());
     357        if (improver != null) ImproverParameter.Value = improver;
     358        else oldImprover = null;
     359      }
     360      if (oldImprover == null && defaultImprover != null)
     361        ImproverParameter.Value = defaultImprover;
     362    }
    309363    private void ParameterizeSolutionsCreator() {
    310364      SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
     
    325379      }
    326380    }
     381    //private void ParameterizeScatterSearchTargetProcessor(IOperator op) {
     382    //  if (op is IScatterSearchTargetProcessor) {
     383    //    IScatterSearchTargetProcessor ssOp = (IScatterSearchTargetProcessor)op;
     384    //    ssOp.TargetParameter.ActualName = "KnapsackSolution"; // temporary solution for the knapsack problem
     385    //    ssOp.TargetParameter.Hidden = true;
     386    //  }
     387    //}
    327388    private void ParameterizeAnalyzers() {
    328389      qualityAnalyzer.ResultsParameter.ActualName = "Results";
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearchMainLoop.cs

    r7740 r7744  
    4646      get { return (IValueLookupParameter<IOperator>)Parameters["Improver"]; }
    4747    }
     48    public IValueLookupParameter<DiversityCalculator> DiversityCalculatorParameter {
     49      get { return (IValueLookupParameter<DiversityCalculator>)Parameters["DiversityCalculator"]; }
     50    }
    4851    public IValueLookupParameter<IntValue> NumberOfHighQualitySolutionsParameter {
    4952      get { return (IValueLookupParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; }
     
    99102      get { return ImproverParameter.ActualValue; }
    100103      set { ImproverParameter.ActualValue = value; }
     104    }
     105    private DiversityCalculator DiversityCalculator {
     106      get { return DiversityCalculatorParameter.ActualValue; }
     107      set { DiversityCalculatorParameter.ActualValue = value; }
    101108    }
    102109    private IntValue NumberOfHighQualitySolutions {
     
    168175      Parameters.Add(new ValueLookupParameter<ICrossover>("Crossover", "The operator used to combine solutions."));
    169176      Parameters.Add(new ValueLookupParameter<IOperator>("Improver", "The operator used to improve solutions."));
     177      Parameters.Add(new ValueLookupParameter<DiversityCalculator>("DiversityCalculator", "The operator used to calculate the diversity of two solutions."));
    170178      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfHighQualitySolutions", "The number of high quality solutions that should be added to the reference set."));
    171179      Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population."));
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/SolutionPoolUpdateMethod.cs

    r7740 r7744  
    3636  [Item("SolutionPoolUpdateMethod", "An operator that updates the solution pool.")]
    3737  [StorableClass]
    38   public sealed class SolutionPoolUpdateMethod : SingleSuccessorOperator {
     38  public sealed class SolutionPoolUpdateMethod : SingleSuccessorOperator, IScatterSearchTargetProcessor {
    3939    #region Parameter properties
    4040    public ScopeParameter CurrentScopeParameter {
    4141      get { return (ScopeParameter)Parameters["CurrentScope"]; }
     42    }
     43    public IValueLookupParameter<BoolValue> MaximizationParameter {
     44      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
    4245    }
    4346    public IValueLookupParameter<BoolValue> NewSolutionsParameter {
     
    5053      get { return (IValueLookupParameter<IItem>)Parameters["Quality"]; }
    5154    }
    52     public IValueLookupParameter<IItem> SolutionParameter {
    53       get { return (IValueLookupParameter<IItem>)Parameters["Solution"]; }
     55    public IValueLookupParameter<IItem> TargetParameter {
     56      get { return (IValueLookupParameter<IItem>)Parameters["Target"]; }
    5457    }
    5558    #endregion
     
    5861    private IScope CurrentScope {
    5962      get { return CurrentScopeParameter.ActualValue; }
     63    }
     64    private BoolValue Maximization {
     65      get { return MaximizationParameter.ActualValue; }
     66      set { MaximizationParameter.ActualValue = value; }
    6067    }
    6168    private BoolValue NewSolutions {
     
    6875    private IItem Quality {
    6976      get { return QualityParameter.ActualValue; }
     77    }
     78    private IItem Target {
     79      get { return TargetParameter.ActualValue; }
    7080    }
    7181    #endregion
     
    8393      #region Create parameters
    8494      Parameters.Add(new ScopeParameter("CurrentScope"));
     95      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization"));
    8596      Parameters.Add(new ValueLookupParameter<BoolValue>("NewSolutions"));
    8697      Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize"));
    8798      Parameters.Add(new ValueLookupParameter<IItem>("Quality"));
    88       Parameters.Add(new ValueLookupParameter<IItem>("Solution"));
     99      Parameters.Add(new ValueLookupParameter<IItem>("Target"));
    89100      #endregion
    90       SolutionParameter.ActualName = "KnapsackSolution"; // temporary solution for the knapsack problem
     101      TargetParameter.ActualName = "KnapsackSolution"; // temporary solution for the knapsack problem
    91102    }
    92103
    93104    public override IOperation Apply() {
    94       IScope parents = new Scope("Parents");
    95       IScope offspring = new Scope("Offspring");
     105      var parentsScope = new Scope("Parents");
     106      var offspringScope = new Scope("Offspring");
     107
     108      // split parents and offspring
    96109      foreach (var scope in CurrentScope.SubScopes) {
    97         parents.SubScopes.AddRange(scope.SubScopes.Take(scope.SubScopes.Count - 1));
    98         offspring.SubScopes.AddRange(scope.SubScopes.Last().SubScopes);
     110        parentsScope.SubScopes.AddRange(scope.SubScopes.Take(scope.SubScopes.Count - 1));
     111        offspringScope.SubScopes.AddRange(scope.SubScopes.Last().SubScopes);
    99112      }
     113
    100114      CurrentScope.SubScopes.Clear();
    101       CurrentScope.SubScopes.AddRange(parents.SubScopes.OrderByDescending(o => o.Variables[QualityParameter.ActualName].Value));
    102       if ((offspring.SubScopes.OrderByDescending(o => o.Variables[QualityParameter.ActualName].Value).First().Variables[QualityParameter.ActualName].Value as DoubleValue).Value
    103           > (parents.SubScopes.OrderByDescending(o => o.Variables[QualityParameter.ActualName].Value).Last().Variables[QualityParameter.ActualName].Value as DoubleValue).Value) {
    104         CurrentScope.SubScopes.Replace(parents.SubScopes.Concat(offspring.SubScopes.Distinct(new KeyEqualityComparer<IScope>(x => x.Variables[SolutionParameter.ActualName].Value.ToString()))).OrderByDescending(o => o.Variables[QualityParameter.ActualName].Value).Take(ReferenceSetSize.Value));
    105         NewSolutions.Value = true;
     115
     116      var orderedParents = Maximization.Value ? parentsScope.SubScopes.OrderByDescending(x => x.Variables[QualityParameter.ActualName].Value) :
     117                                                parentsScope.SubScopes.OrderBy(x => x.Variables[QualityParameter.ActualName].Value);
     118      var orderedOffspring = Maximization.Value ? offspringScope.SubScopes.OrderByDescending(x => x.Variables[QualityParameter.ActualName].Value) :
     119                                                  offspringScope.SubScopes.OrderBy(x => x.Variables[QualityParameter.ActualName].Value);
     120
     121      CurrentScope.SubScopes.AddRange(orderedParents);
     122
     123      var worstParentQuality = (orderedParents.Last().Variables[QualityParameter.ActualName].Value as DoubleValue).Value;
     124
     125      var Constraint = 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; });
     127
     128      // is there any offspring better than the worst parent?
     129      if (orderedOffspring.Any(Constraint)) {
     130        // produce the set union
     131        // 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(Constraint), new KeyEqualityComparer<IScope>(x => x.Variables[TargetParameter.ActualName].Value.ToString()));
     133        if (union.Count() > orderedParents./*Distinct(new KeyEqualityComparer<IScope>(x => x.Variables[TargetParameter.ActualName].Value.ToString())).*/Count()) {
     134          var orderedUnion = Maximization.Value ? union.OrderByDescending(x => x.Variables[QualityParameter.ActualName].Value) :
     135                                                  union.OrderBy(x => x.Variables[QualityParameter.ActualName].Value);
     136          CurrentScope.SubScopes.Replace(orderedUnion.Take(ReferenceSetSize.Value).ToList());
     137          NewSolutions.Value = true;
     138        }
    106139      }
    107140
Note: See TracChangeset for help on using the changeset viewer.