Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/18/12 19:01:21 (13 years ago)
Author:
jkarder
Message:

#1331:

  • added custom crossover operator (NChildCrossover)
  • added parameters and adjusted types
  • replaced SolutionCombinationMethod with a placeholder
  • adjusted event handling
  • changed access levels
  • minor code improvements
Location:
branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3
Files:
5 added
1 deleted
7 edited

Legend:

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

    r7727 r7740  
    5454    </Reference>
    5555    <Reference Include="HeuristicLab.Encodings.BinaryVectorEncoding-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" />
     56    <Reference Include="HeuristicLab.Encodings.PermutationEncoding-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" />
    5657    <Reference Include="HeuristicLab.Operators-3.3">
    5758      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Operators-3.3.dll</HintPath>
     
    7172    <Reference Include="HeuristicLab.PluginInfrastructure-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" />
    7273    <Reference Include="HeuristicLab.Problems.Knapsack-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" />
     74    <Reference Include="HeuristicLab.Problems.TravelingSalesman-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" />
    7375    <Reference Include="HeuristicLab.Random-3.3">
    7476      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Random-3.3.dll</HintPath>
     
    8486  </ItemGroup>
    8587  <ItemGroup>
     88    <Compile Include="Knapsack\DiversityCalculator.cs" />
     89    <Compile Include="Knapsack\INBinaryVectorCrossover.cs" />
     90    <Compile Include="Knapsack\NBinaryVectorCrossover.cs" />
     91    <Compile Include="Knapsack\NChildCrossover.cs" />
     92    <Compile Include="OffspringProcessor.cs" />
     93    <Compile Include="TSPPopulationRebuildMethod.cs" />
     94    <Compile Include="TSPSolutionPoolUpdateMethod.cs" />
     95    <Compile Include="TSPReferenceSetUpdateMethod.cs" />
     96    <Compile Include="TSPScatterSearchImprovementOperator.cs" />
    8697    <None Include="HeuristicLab.snk" />
    8798    <None Include="Plugin.cs.frame" />
     
    94105    <Compile Include="ScatterSearchImprovementOperator.cs" />
    95106    <Compile Include="ScatterSearchMainLoop.cs" />
    96     <Compile Include="SolutionCombinationMethod.cs" />
    97107    <Compile Include="SolutionPoolUpdateMethod.cs" />
    98108  </ItemGroup>
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/PopulationRebuildMethod.cs

    r7724 r7740  
    3030namespace HeuristicLab.Algorithms.ScatterSearch {
    3131  /// <summary>
    32   /// An operator that updates a population.
     32  /// An operator that updates the reference set and rebuilds the population.
    3333  /// </summary>
    34   [Item("PopulationRebuildMethod", "An operator that rebuilds the population.")]
     34  [Item("PopulationRebuildMethod", "An operator that updates the reference set and rebuilds the population.")]
    3535  [StorableClass]
    3636  public sealed class PopulationRebuildMethod : SingleSuccessorOperator {
    3737    #region Parameter properties
    38     private ScopeParameter CurrentScopeParameter {
     38    public ScopeParameter CurrentScopeParameter {
    3939      get { return (ScopeParameter)Parameters["CurrentScope"]; }
    4040    }
    41     private ValueLookupParameter<IntValue> NumberOfHighQualitySolutionsParameter {
    42       get { return (ValueLookupParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; }
     41    public IValueLookupParameter<IntValue> NumberOfHighQualitySolutionsParameter {
     42      get { return (IValueLookupParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; }
    4343    }
    44     private ValueLookupParameter<IntValue> ReferenceSetSizeParameter {
    45       get { return (ValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
     44    public IValueLookupParameter<IntValue> ReferenceSetSizeParameter {
     45      get { return (IValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
     46    }
     47    public IValueLookupParameter<IItem> QualityParameter {
     48      get { return (IValueLookupParameter<IItem>)Parameters["Quality"]; }
    4649    }
    4750    #endregion
     
    5962      set { ReferenceSetSizeParameter.ActualValue = value; }
    6063    }
     64    private IItem Quality {
     65      get { return QualityParameter.ActualValue; }
     66    }
    6167    #endregion
    6268
     
    7278    private void Initialize() {
    7379      #region Create parameters
    74       Parameters.Add(new ScopeParameter("CurrentScope", "The current scope to which the new solutions are added as sub-scopes."));
    75       Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfHighQualitySolutions", "The number of high quality solutions that should be added to the reference set."));
    76       Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize", "The size of the reference set."));
    77       #endregion
    78 
    79       #region Create operators
    80       #endregion
    81 
    82       #region Create operator graph
     80      Parameters.Add(new ScopeParameter("CurrentScope"));
     81      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfHighQualitySolutions"));
     82      Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize"));
     83      Parameters.Add(new ValueLookupParameter<IItem>("Quality"));
    8384      #endregion
    8485    }
    8586
    8687    public override IOperation Apply() {
    87       IScope population = CurrentScope.SubScopes[0];
    88       IScope refSet = CurrentScope.SubScopes[1];
    89       refSet.SubScopes.Replace(refSet.SubScopes.OrderByDescending(r => r.Variables["Quality"].Value)
     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)
    9091                                               .Take(NumberOfHighQualitySolutions.Value).ToList());
    9192      population.SubScopes.Clear();
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/ReferenceSetUpdateMethod.cs

    r7724 r7740  
    2020#endregion
    2121
     22using System.Collections.Generic;
     23using System.Linq;
    2224using HeuristicLab.Common;
    2325using HeuristicLab.Core;
    2426using HeuristicLab.Data;
    25 using HeuristicLab.Encodings.BinaryVectorEncoding;
    2627using HeuristicLab.Operators;
    2728using HeuristicLab.Parameters;
     
    3637  public sealed class ReferenceSetUpdateMethod : SingleSuccessorOperator {
    3738    #region Parameter properties
    38     private ScopeParameter CurrentScopeParameter {
     39    public ScopeParameter CurrentScopeParameter {
    3940      get { return (ScopeParameter)Parameters["CurrentScope"]; }
    4041    }
    41     public ValueLookupParameter<IntValue> NumberOfHighQualitySolutionsParameter {
    42       get { return (ValueLookupParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; }
     42    public IValueLookupParameter<IntValue> NumberOfHighQualitySolutionsParameter {
     43      get { return (IValueLookupParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; }
    4344    }
    44     public ValueLookupParameter<IntValue> ReferenceSetSizeParameter {
    45       get { return (ValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
     45    public IValueLookupParameter<IntValue> ReferenceSetSizeParameter {
     46      get { return (IValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
     47    }
     48    public IValueLookupParameter<IItem> QualityParameter {
     49      get { return (IValueLookupParameter<IItem>)Parameters["Quality"]; }
    4650    }
    4751    #endregion
    4852
    4953    #region Properties
    50     public IScope CurrentScope {
     54    private IScope CurrentScope {
    5155      get { return CurrentScopeParameter.ActualValue; }
    5256    }
    53     public IntValue NumberOfHighQualitySolutions {
     57    private IntValue NumberOfHighQualitySolutions {
    5458      get { return NumberOfHighQualitySolutionsParameter.ActualValue; }
    55       set { NumberOfHighQualitySolutionsParameter.ActualValue = value; }
    5659    }
    57     public IntValue ReferenceSetSize {
     60    private IntValue ReferenceSetSize {
    5861      get { return ReferenceSetSizeParameter.ActualValue; }
    59       set { ReferenceSetSizeParameter.ActualValue = value; }
     62    }
     63    private IItem Quality {
     64      get { return QualityParameter.ActualValue; }
    6065    }
    6166    #endregion
     
    7277    private void Initialize() {
    7378      #region Create parameters
    74       Parameters.Add(new ScopeParameter("CurrentScope", "The current scope to which the new solutions are added as sub-scopes."));
    75       Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfHighQualitySolutions", "The number of high quality solutions that should be added to the reference set."));
    76       Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize", "The size of the reference set."));
    77       #endregion
    78 
    79       #region Create operators
    80       #endregion
    81 
    82       #region Create operator graph
     79      Parameters.Add(new ScopeParameter("CurrentScope"));
     80      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfHighQualitySolutions"));
     81      Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize"));
     82      Parameters.Add(new ValueLookupParameter<IItem>("Quality"));
    8383      #endregion
    8484    }
    8585
    8686    public override IOperation Apply() {
    87       for (int i = 0; i < ReferenceSetSize.Value - NumberOfHighQualitySolutions.Value; i++) {
    88         IScope mostDiverseSolution = null;
    89         int maxDiversity = 0;
    90         foreach (var p in CurrentScope.SubScopes[0].SubScopes) {
    91           int diversity = 0;
    92           BinaryVector pSol = p.Variables["KnapsackSolution"].Value as BinaryVector;
    93           foreach (var r in CurrentScope.SubScopes[1].SubScopes) {
    94             BinaryVector rSol = r.Variables["KnapsackSolution"].Value as BinaryVector;
    95             if (pSol != null && rSol != null) diversity += CalculateDiversity(pSol, rSol);
    96           }
    97           if (mostDiverseSolution == null || diversity > maxDiversity) {
    98             mostDiverseSolution = p;
    99             maxDiversity = diversity;
    100           }
     87      var population = new Dictionary<IScope, double>();
     88      foreach (var pScope in CurrentScope.SubScopes[0].SubScopes) {
     89        int diversity = 0;
     90        var pSol = pScope.Variables[QualityParameter.ActualName].Value;
     91        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);
    10194        }
    102         CurrentScope.SubScopes[1].SubScopes.Add(mostDiverseSolution); // Update parent?
    103         CurrentScope.SubScopes[0].SubScopes.Remove(mostDiverseSolution); // Update parent?
     95        population[pScope] = diversity;
     96      }
     97      foreach (var entry in population.OrderByDescending(x => x.Value).Take(ReferenceSetSize.Value - NumberOfHighQualitySolutions.Value)) {
     98        CurrentScope.SubScopes[1].SubScopes.Add(entry.Key);
     99        CurrentScope.SubScopes[0].SubScopes.Remove(entry.Key);
    104100      }
    105101      return base.Apply();
    106102    }
    107 
    108     private int CalculateDiversity(BinaryVector pSol, BinaryVector rSol) {
    109       int diversity = 0;
    110       for (int i = 0; i < pSol.Length; i++)
    111         if (pSol[i] != rSol[i]) diversity++;
    112       return diversity;
    113     }
    114103  }
    115104}
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearch.cs

    r7727 r7740  
    2121
    2222using System;
    23 using System.Collections.Generic;
    2423using System.Linq;
    2524using HeuristicLab.Analysis;
     
    5655
    5756    #region Parameter Properties
    58     private ValueParameter<MultiAnalyzer> AnalyzerParameter {
    59       get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
    60     }
    61     private ValueParameter<ILocalImprovementOperator> ImproverParameter {
    62       get { return (ValueParameter<ILocalImprovementOperator>)Parameters["Improver"]; }
    63     }
    64     private ValueParameter<IntValue> MaximumIterationsParameter {
    65       get { return (ValueParameter<IntValue>)Parameters["MaximumIterations"]; }
    66     }
    67     private ConstrainedValueParameter<ISingleObjectiveMoveEvaluator> MoveEvaluatorParameter {
    68       get { return (ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>)Parameters["MoveEvaluator"]; }
    69     }
    70     private ConstrainedValueParameter<IMoveGenerator> MoveGeneratorParameter {
    71       get { return (ConstrainedValueParameter<IMoveGenerator>)Parameters["MoveGenerator"]; }
    72     }
    73     private ConstrainedValueParameter<IMoveMaker> MoveMakerParameter {
    74       get { return (ConstrainedValueParameter<IMoveMaker>)Parameters["MoveMaker"]; }
    75     }
    76     private ValueParameter<IntValue> NumberOfHighQualitySolutionsParameter {
    77       get { return (ValueParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; }
    78     }
    79     private ValueParameter<IntValue> PopulationSizeParameter {
    80       get { return (ValueParameter<IntValue>)Parameters["PopulationSize"]; }
    81     }
    82     private ValueParameter<IntValue> ReferenceSetSizeParameter {
    83       get { return (ValueParameter<IntValue>)Parameters["ReferenceSetSize"]; }
    84     }
    85     private ValueParameter<IntValue> SampleSizeParameter {
    86       get { return (ValueParameter<IntValue>)Parameters["SampleSize"]; }
    87     }
    88     private ValueParameter<IntValue> SeedParameter {
    89       get { return (ValueParameter<IntValue>)Parameters["Seed"]; }
    90     }
    91     private ValueParameter<BoolValue> SetSeedRandomlyParameter {
    92       get { return (ValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
    93     }
    94     private RandomCreator RandomCreator {
    95       get { return (RandomCreator)OperatorGraph.InitialOperator; }
    96     }
    97     private SolutionsCreator SolutionsCreator {
    98       get { return (SolutionsCreator)RandomCreator.Successor; }
    99     }
    100     private ScatterSearchMainLoop MainLoop {
    101       get { return FindMainLoop(SolutionsCreator.Successor); }
     57    public IValueParameter<MultiAnalyzer> AnalyzerParameter {
     58      get { return (IValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
     59    }
     60    public ConstrainedValueParameter<ICrossover> CrossoverParameter {
     61      get { return (ConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; }
     62    }
     63    public IValueParameter<ILocalImprovementOperator> ImproverParameter {
     64      get { return (IValueParameter<ILocalImprovementOperator>)Parameters["Improver"]; }
     65    }
     66    public IValueParameter<IntValue> MaximumIterationsParameter {
     67      get { return (IValueParameter<IntValue>)Parameters["MaximumIterations"]; }
     68    }
     69    public IValueParameter<IntValue> NumberOfHighQualitySolutionsParameter {
     70      get { return (IValueParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; }
     71    }
     72    public IValueParameter<IntValue> PopulationSizeParameter {
     73      get { return (IValueParameter<IntValue>)Parameters["PopulationSize"]; }
     74    }
     75    public IValueParameter<IntValue> ReferenceSetSizeParameter {
     76      get { return (IValueParameter<IntValue>)Parameters["ReferenceSetSize"]; }
     77    }
     78    public IValueParameter<IntValue> SeedParameter {
     79      get { return (IValueParameter<IntValue>)Parameters["Seed"]; }
     80    }
     81    public IValueParameter<BoolValue> SetSeedRandomlyParameter {
     82      get { return (IValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
    10283    }
    10384    #endregion
    10485
    10586    #region Properties
    106     public MultiAnalyzer Analyzer {
     87    private MultiAnalyzer Analyzer {
    10788      get { return AnalyzerParameter.Value; }
    10889      set { AnalyzerParameter.Value = value; }
    10990    }
    110     public ILocalImprovementOperator Improver {
     91    private ICrossover Crossover {
     92      get { return CrossoverParameter.Value; }
     93      set { CrossoverParameter.Value = value; }
     94    }
     95    private ILocalImprovementOperator Improver {
    11196      get { return ImproverParameter.Value; }
    11297      set { ImproverParameter.Value = value; }
    11398    }
    114     public IntValue MaximumIterations {
     99    private IntValue MaximumIterations {
    115100      get { return MaximumIterationsParameter.Value; }
    116101      set { MaximumIterationsParameter.Value = value; }
    117102    }
    118     public ISingleObjectiveMoveEvaluator MoveEvaluator {
    119       get { return MoveEvaluatorParameter.Value; }
    120       set { MoveEvaluatorParameter.Value = value; }
    121     }
    122     public IMoveGenerator MoveGenerator {
    123       get { return MoveGeneratorParameter.Value; }
    124       set { MoveGeneratorParameter.Value = value; }
    125     }
    126     public IMoveMaker MoveMaker {
    127       get { return MoveMakerParameter.Value; }
    128       set { MoveMakerParameter.Value = value; }
    129     }
    130     public IntValue NumberOfHighQualitySolutions {
     103    private IntValue NumberOfHighQualitySolutions {
    131104      get { return NumberOfHighQualitySolutionsParameter.Value; }
    132105      set { NumberOfHighQualitySolutionsParameter.Value = value; }
    133106    }
    134     public IntValue PopulationSize {
     107    private IntValue PopulationSize {
    135108      get { return PopulationSizeParameter.Value; }
    136109      set { PopulationSizeParameter.Value = value; }
    137110    }
    138     public IntValue ReferenceSetSize {
     111    private IntValue ReferenceSetSize {
    139112      get { return ReferenceSetSizeParameter.Value; }
    140113      set { ReferenceSetSizeParameter.Value = value; }
    141114    }
    142     public IntValue SampleSize {
    143       get { return SampleSizeParameter.Value; }
    144       set { SampleSizeParameter.Value = value; }
    145     }
    146     public IntValue Seed {
     115    private IntValue Seed {
    147116      get { return SeedParameter.Value; }
    148117      set { SeedParameter.Value = value; }
    149118    }
    150     public BoolValue SetSeedRandomly {
     119    private BoolValue SetSeedRandomly {
    151120      get { return SetSeedRandomlyParameter.Value; }
    152121      set { SetSeedRandomlyParameter.Value = value; }
     122    }
     123    public RandomCreator RandomCreator {
     124      get { return (RandomCreator)OperatorGraph.InitialOperator; }
     125    }
     126    public SolutionsCreator SolutionsCreator {
     127      get { return (SolutionsCreator)RandomCreator.Successor; }
     128    }
     129    public ScatterSearchMainLoop MainLoop {
     130      get { return FindMainLoop(SolutionsCreator.Successor); }
    153131    }
    154132
     
    175153      #region Create parameters
    176154      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the solution and moves.", new MultiAnalyzer()));
     155      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to combine solutions."));
    177156      Parameters.Add(new ValueParameter<ILocalImprovementOperator>("Improver", "The operator used to improve solutions.", new ScatterSearchImprovementOperator()));
    178157      Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(1000)));
    179       Parameters.Add(new ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>("MoveEvaluator", "The operator used to evaluate a move."));
    180       Parameters.Add(new ConstrainedValueParameter<IMoveGenerator>("MoveGenerator", "The operator used to generate moves to the neighborhood of the current solution."));
    181       Parameters.Add(new ConstrainedValueParameter<IMoveMaker>("MoveMaker", "The operator used to perform a move."));
    182158      Parameters.Add(new ValueParameter<IntValue>("NumberOfHighQualitySolutions", "The number of high quality solutions that should be added to the reference set.", new IntValue(5)));
    183159      Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population.", new IntValue(30)));
    184160      Parameters.Add(new ValueParameter<IntValue>("ReferenceSetSize", "The size of the reference set.", new IntValue(10)));
    185       Parameters.Add(new ValueParameter<IntValue>("SampleSize", "Number of moves that MultiMoveGenerators should create. This is ignored for Exhaustive- and SingleMoveGenerators.", new IntValue(100)));
    186161      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
    187162      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
     
    239214      mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
    240215      mainLoop.IterationsParameter.ActualName = "Iterations";
     216      mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
    241217      mainLoop.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
    242218      mainLoop.NumberOfHighQualitySolutionsParameter.ActualName = NumberOfHighQualitySolutionsParameter.Name;
     
    252228
    253229    public override void Prepare() {
    254       if (Problem != null && MoveGenerator != null && MoveMaker != null && MoveEvaluator != null)
    255         base.Prepare();
     230      base.Prepare();
    256231    }
    257232
     
    261236      ParameterizeStochasticOperator(Problem.Evaluator);
    262237      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
    263       foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
    264         op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
    265       }
     238      ParameterizeAnalyzers();
     239      ParameterizeMainLoop();
    266240      ParameterizeSolutionsCreator();
    267       ParameterizeMainLoop();
    268       UpdateMoveGenerator();
    269       UpdateMoveParameters();
    270241      UpdateAnalyzers();
    271       ParameterizeMoveGenerators();
    272       ParameterizeMoveEvaluators();
    273       ParameterizeMoveMakers();
    274       ParameterizeAnalyzers();
    275       ParameterizeIterationBasedOperators();
     242      UpdateCrossovers();
    276243      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    277244      base.OnProblemChanged();
     
    286253      ParameterizeSolutionsCreator();
    287254      ParameterizeMainLoop();
    288       ParameterizeMoveEvaluators();
    289       ParameterizeMoveMakers();
    290255      ParameterizeAnalyzers();
    291256      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
     
    294259    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
    295260      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
    296       // This may seem pointless, but some operators already have the eventhandler registered, others don't
    297       // FIXME: Is there another way to solve this problem?
    298       foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
    299         op.MoveQualityParameter.ActualNameChanged -= new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
    300         op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
    301       }
    302       UpdateMoveGenerator();
    303       UpdateMoveParameters();
    304261      UpdateAnalyzers();
     262      UpdateCrossovers();
    305263      ParameterizeMainLoop();
    306       ParameterizeMoveGenerators();
    307       ParameterizeMoveEvaluators();
    308       ParameterizeMoveMakers();
    309       ParameterizeAnalyzers();
    310       ParameterizeIterationBasedOperators();
     264      ParameterizeAnalyzers();
    311265      base.Problem_OperatorsChanged(sender, e);
    312266    }
    313267    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
    314268      ParameterizeMainLoop();
    315       ParameterizeMoveEvaluators();
    316       ParameterizeMoveMakers();
    317     }
    318     private void MoveGeneratorParameter_ValueChanged(object sender, EventArgs e) {
    319       UpdateMoveParameters();
    320     }
    321     private void MoveEvaluatorParameter_ValueChanged(object sender, EventArgs e) {
    322       ParameterizeMainLoop();
    323       ParameterizeMoveEvaluators();
    324       ParameterizeMoveMakers();
    325       ParameterizeAnalyzers();
    326     }
    327     private void MoveEvaluator_MoveQualityParameter_ActualNameChanged(object sender, EventArgs e) {
    328       ParameterizeMainLoop();
    329       ParameterizeMoveEvaluators();
    330       ParameterizeMoveMakers();
     269      ParameterizeAnalyzers();
    331270    }
    332271    #endregion
     
    336275      if (Problem != null) {
    337276        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    338         foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
    339           op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
    340         }
    341       }
    342       MoveGeneratorParameter.ValueChanged += new EventHandler(MoveGeneratorParameter_ValueChanged);
    343       MoveEvaluatorParameter.ValueChanged += new EventHandler(MoveEvaluatorParameter_ValueChanged);
    344     }
    345     private void UpdateMoveGenerator() {
    346       IMoveGenerator oldMoveGenerator = MoveGenerator;
    347       IMoveGenerator defaultMoveGenerator = Problem.Operators.OfType<IMoveGenerator>().FirstOrDefault();
    348       MoveGeneratorParameter.ValidValues.Clear();
    349       if (Problem != null) {
    350         foreach (IMoveGenerator generator in Problem.Operators.OfType<IMoveGenerator>().OrderBy(x => x.Name))
    351           MoveGeneratorParameter.ValidValues.Add(generator);
    352       }
    353       if (oldMoveGenerator != null) {
    354         IMoveGenerator newMoveGenerator = MoveGeneratorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveGenerator.GetType());
    355         if (newMoveGenerator != null) MoveGenerator = newMoveGenerator;
    356         else oldMoveGenerator = null;
    357       }
    358       if (oldMoveGenerator == null && defaultMoveGenerator != null)
    359         MoveGenerator = defaultMoveGenerator;
    360       if (MoveGenerator == null) {
    361         ClearMoveParameters();
    362       }
    363     }
    364     private void UpdateMoveParameters() {
    365       IMoveMaker oldMoveMaker = MoveMaker;
    366       ISingleObjectiveMoveEvaluator oldMoveEvaluator = MoveEvaluator;
    367       ClearMoveParameters();
    368       if (MoveGenerator != null) {
    369         List<Type> moveTypes = MoveGenerator.GetType().GetInterfaces().Where(x => typeof(IMoveOperator).IsAssignableFrom(x)).ToList();
    370         foreach (Type type in moveTypes.ToList()) {
    371           if (moveTypes.Any(t => t != type && type.IsAssignableFrom(t)))
    372             moveTypes.Remove(type);
    373         }
    374 
    375         var operators = Problem.Operators.Where(op => moveTypes.Any(m => m.IsInstanceOfType(op))).ToList();
    376         IMoveMaker defaultMoveMaker = operators.OfType<IMoveMaker>().FirstOrDefault();
    377         ISingleObjectiveMoveEvaluator defaultMoveEvaluator = operators.OfType<ISingleObjectiveMoveEvaluator>().FirstOrDefault();
    378         foreach (IMoveMaker moveMaker in operators.OfType<IMoveMaker>().OrderBy(op => op.Name))
    379           MoveMakerParameter.ValidValues.Add(moveMaker);
    380         foreach (ISingleObjectiveMoveEvaluator moveEvaluator in operators.OfType<ISingleObjectiveMoveEvaluator>().OrderBy(op => op.Name))
    381           MoveEvaluatorParameter.ValidValues.Add(moveEvaluator);
    382 
    383         if (oldMoveMaker != null) {
    384           IMoveMaker mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
    385           if (mm != null) MoveMaker = mm;
    386           else oldMoveMaker = null;
    387         }
    388         if (oldMoveMaker == null && defaultMoveMaker != null)
    389           MoveMaker = defaultMoveMaker;
    390 
    391         if (oldMoveEvaluator != null) {
    392           ISingleObjectiveMoveEvaluator me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
    393           if (me != null) MoveEvaluator = me;
    394           else oldMoveEvaluator = null;
    395         }
    396         if (oldMoveEvaluator == null && defaultMoveEvaluator != null)
    397           MoveEvaluator = defaultMoveEvaluator;
    398277      }
    399278    }
     
    409288      Analyzer.Operators.Add(qualityAnalyzer, qualityAnalyzer.EnabledByDefault);
    410289    }
    411     private void ClearMoveParameters() {
    412       MoveMakerParameter.ValidValues.Clear();
    413       MoveEvaluatorParameter.ValidValues.Clear();
     290    private void UpdateCrossovers() {
     291      ICrossover oldCrossover = CrossoverParameter.Value;
     292      CrossoverParameter.ValidValues.Clear();
     293      ICrossover defaultCrossover = Problem.Operators.OfType<ICrossover>().FirstOrDefault();
     294
     295      foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
     296        CrossoverParameter.ValidValues.Add(crossover);
     297
     298      foreach (var crossover in CrossoverParameter.ValidValues.OfType<Knapsack.INBinaryVectorCrossover>())
     299        crossover.ParentsParameter.ActualName = "KnapsackSolution"; // temporary solution for the knapsack problem
     300
     301      if (oldCrossover != null) {
     302        ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
     303        if (crossover != null) CrossoverParameter.Value = crossover;
     304        else oldCrossover = null;
     305      }
     306      if (oldCrossover == null && defaultCrossover != null)
     307        CrossoverParameter.Value = defaultCrossover;
    414308    }
    415309    private void ParameterizeSolutionsCreator() {
     
    423317        MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    424318      }
    425       if (MoveEvaluator != null)
    426         MainLoop.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
    427319    }
    428320    private void ParameterizeStochasticOperator(IOperator op) {
     
    431323        stOp.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
    432324        stOp.RandomParameter.Hidden = true;
    433       }
    434     }
    435     private void ParameterizeMoveGenerators() {
    436       if (Problem != null) {
    437         foreach (IMultiMoveGenerator generator in Problem.Operators.OfType<IMultiMoveGenerator>()) {
    438           generator.SampleSizeParameter.ActualName = SampleSizeParameter.Name;
    439           generator.SampleSizeParameter.Hidden = true;
    440         }
    441       }
    442     }
    443     private void ParameterizeMoveEvaluators() {
    444       foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
    445         op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    446         op.QualityParameter.Hidden = true;
    447       }
    448     }
    449     private void ParameterizeMoveMakers() {
    450       foreach (IMoveMaker op in Problem.Operators.OfType<IMoveMaker>()) {
    451         op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    452         op.QualityParameter.Hidden = true;
    453         if (MoveEvaluator != null) {
    454           op.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
    455           op.MoveQualityParameter.Hidden = true;
    456         } else {
    457           op.MoveQualityParameter.Hidden = false;
    458         }
    459325      }
    460326    }
     
    465331        qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    466332        qualityAnalyzer.MaximizationParameter.Hidden = true;
    467         if (MoveEvaluator != null) {
    468           qualityAnalyzer.QualityParameter.Hidden = true;
    469         } else qualityAnalyzer.QualityParameter.Hidden = false;
     333        qualityAnalyzer.QualityParameter.Hidden = false;
    470334        qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
    471335        qualityAnalyzer.BestKnownQualityParameter.Hidden = true;
     
    473337        qualityAnalyzer.MaximizationParameter.Hidden = false;
    474338        qualityAnalyzer.BestKnownQualityParameter.Hidden = false;
    475       }
    476     }
    477     private void ParameterizeIterationBasedOperators() {
    478       if (Problem != null) {
    479         foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) {
    480           op.IterationsParameter.ActualName = "Iterations";
    481           op.IterationsParameter.Hidden = true;
    482           op.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name;
    483           op.MaximumIterationsParameter.Hidden = true;
    484         }
    485339      }
    486340    }
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearchImprovementOperator.cs

    r7727 r7740  
    7979
    8080    #region Properties
    81     public IScope CurrentScope {
     81    private IScope CurrentScope {
    8282      get { return CurrentScopeParameter.ActualValue; }
    8383    }
    84     public IntArray Values {
     84    private IntArray Values {
    8585      get { return ValuesParameter.ActualValue; }
    8686      set { ValuesParameter.ActualValue = value; }
    8787    }
    88     public IntArray Weights {
     88    private IntArray Weights {
    8989      get { return WeightsParameter.ActualValue; }
    9090      set { WeightsParameter.ActualValue = value; }
    9191    }
    92     public IntValue KnapsackCapacity {
     92    private IntValue KnapsackCapacity {
    9393      get { return KnapsackCapacityParameter.ActualValue; }
    9494      set { KnapsackCapacityParameter.ActualValue = value; }
     
    104104    public ScatterSearchImprovementOperator()
    105105      : base() {
    106       Parameters.Add(new ScopeParameter("CurrentScope", "The current scope."));
    107       Parameters.Add(new LookupParameter<IntArray>("Values", "The values of the items."));
    108       Parameters.Add(new LookupParameter<IntArray>("Weights", "The weights of the items."));
    109       Parameters.Add(new LookupParameter<IntValue>("KnapsackCapacity", "The size of the knapsack."));
     106      #region Create parameters
     107      Parameters.Add(new ScopeParameter("CurrentScope"));
     108      Parameters.Add(new LookupParameter<IntArray>("Values"));
     109      Parameters.Add(new LookupParameter<IntArray>("Weights"));
     110      Parameters.Add(new LookupParameter<IntValue>("KnapsackCapacity"));
     111      #endregion
    110112    }
    111113
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearchMainLoop.cs

    r7727 r7740  
    3737  public sealed class ScatterSearchMainLoop : AlgorithmOperator {
    3838    #region Parameter properties
    39     internal LookupParameter<IRandom> RandomParameter {
    40       get { return (LookupParameter<IRandom>)Parameters["Random"]; }
    41     }
    42     internal LookupParameter<IntValue> IterationsParameter {
    43       get { return (LookupParameter<IntValue>)Parameters["Iterations"]; }
    44     }
    45     internal LookupParameter<IntValue> MaximumIterationsParameter {
    46       get { return (LookupParameter<IntValue>)Parameters["MaximumIterations"]; }
    47     }
    48     internal LookupParameter<BoolValue> MaximizationParameter {
    49       get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; }
    50     }
    51     internal LookupParameter<IntValue> SampleSizeParameter {
    52       get { return (LookupParameter<IntValue>)Parameters["SampleSize"]; }
    53     }
    54     internal LookupParameter<IntValue> PopulationSizeParameter {
    55       get { return (LookupParameter<IntValue>)Parameters["PopulationSize"]; }
    56     }
    57     internal LookupParameter<IntValue> ReferenceSetSizeParameter {
    58       get { return (LookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
    59     }
    60     internal LookupParameter<IntValue> NumberOfHighQualitySolutionsParameter {
    61       get { return (LookupParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; }
    62     }
    63     internal LookupParameter<DoubleValue> QualityParameter {
    64       get { return (LookupParameter<DoubleValue>)Parameters["Quality"]; }
    65     }
    66     internal LookupParameter<DoubleValue> BestKnownQualityParameter {
    67       get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
    68     }
    69     internal LookupParameter<DoubleValue> MoveQualityParameter {
    70       get { return (LookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
    71     }
    72     internal LookupParameter<VariableCollection> ResultsParameter {
    73       get { return (LookupParameter<VariableCollection>)Parameters["Results"]; }
    74     }
    75     internal LookupParameter<ISingleObjectiveMoveEvaluator> MoveEvaluatorParameter {
    76       get { return (LookupParameter<ISingleObjectiveMoveEvaluator>)Parameters["MoveEvaluator"]; }
    77     }
    78     internal LookupParameter<IMoveGenerator> MoveGeneratorParameter {
    79       get { return (LookupParameter<IMoveGenerator>)Parameters["MoveGenerator"]; }
    80     }
    81     internal LookupParameter<IMoveMaker> MoveMakerParameter {
    82       get { return (LookupParameter<IMoveMaker>)Parameters["MoveMaker"]; }
    83     }
    84     internal LookupParameter<IOperator> ImproverParameter {
    85       get { return (LookupParameter<IOperator>)Parameters["Improver"]; }
    86     }
    87     internal LookupParameter<IOperator> EvaluatorParameter {
    88       get { return (LookupParameter<IOperator>)Parameters["Evaluator"]; }
    89     }
    90     internal LookupParameter<IMultiAnalyzer> AnalyzerParameter {
    91       get { return (LookupParameter<IMultiAnalyzer>)Parameters["Analyzer"]; }
     39    public IValueLookupParameter<IMultiAnalyzer> AnalyzerParameter {
     40      get { return (IValueLookupParameter<IMultiAnalyzer>)Parameters["Analyzer"]; }
     41    }
     42    public IValueLookupParameter<ICrossover> CrossoverParameter {
     43      get { return (IValueLookupParameter<ICrossover>)Parameters["Crossover"]; }
     44    }
     45    public IValueLookupParameter<IOperator> ImproverParameter {
     46      get { return (IValueLookupParameter<IOperator>)Parameters["Improver"]; }
     47    }
     48    public IValueLookupParameter<IntValue> NumberOfHighQualitySolutionsParameter {
     49      get { return (IValueLookupParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; }
     50    }
     51    public IValueLookupParameter<IntValue> PopulationSizeParameter {
     52      get { return (IValueLookupParameter<IntValue>)Parameters["PopulationSize"]; }
     53    }
     54    public IValueLookupParameter<IntValue> ReferenceSetSizeParameter {
     55      get { return (IValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
     56    }
     57    public IValueLookupParameter<DoubleValue> BestKnownQualityParameter {
     58      get { return (IValueLookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
     59    }
     60    public IValueLookupParameter<IEvaluator> EvaluatorParameter {
     61      get { return (IValueLookupParameter<IEvaluator>)Parameters["Evaluator"]; }
     62    }
     63    public IValueLookupParameter<IntValue> IterationsParameter {
     64      get { return (IValueLookupParameter<IntValue>)Parameters["Iterations"]; }
     65    }
     66    public IValueLookupParameter<BoolValue> MaximizationParameter {
     67      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
     68    }
     69    public IValueLookupParameter<IntValue> MaximumIterationsParameter {
     70      get { return (IValueLookupParameter<IntValue>)Parameters["MaximumIterations"]; }
     71    }
     72    public IValueLookupParameter<DoubleValue> QualityParameter {
     73      get { return (IValueLookupParameter<DoubleValue>)Parameters["Quality"]; }
     74    }
     75    public IValueLookupParameter<IRandom> RandomParameter {
     76      get { return (IValueLookupParameter<IRandom>)Parameters["Random"]; }
     77    }
     78    public IValueLookupParameter<VariableCollection> ResultsParameter {
     79      get { return (IValueLookupParameter<VariableCollection>)Parameters["Results"]; }
     80    }
     81    public IValueLookupParameter<IntValue> SampleSizeParameter {
     82      get { return (IValueLookupParameter<IntValue>)Parameters["SampleSize"]; }
     83    }
     84    public IValueLookupParameter<ISolutionCreator> SolutionCreatorParameter {
     85      get { return (IValueLookupParameter<ISolutionCreator>)Parameters["SolutionCreator"]; }
    9286    }
    9387    #endregion
    9488
    9589    #region Properties
    96     public IRandom Random {
     90    private IMultiAnalyzer Analyzer {
     91      get { return AnalyzerParameter.ActualValue; }
     92      set { AnalyzerParameter.ActualValue = value; }
     93    }
     94    private ICrossover Crossover {
     95      get { return CrossoverParameter.ActualValue; }
     96      set { CrossoverParameter.ActualValue = value; }
     97    }
     98    private IOperator Improver {
     99      get { return ImproverParameter.ActualValue; }
     100      set { ImproverParameter.ActualValue = value; }
     101    }
     102    private IntValue NumberOfHighQualitySolutions {
     103      get { return NumberOfHighQualitySolutionsParameter.ActualValue; }
     104      set { NumberOfHighQualitySolutionsParameter.ActualValue = value; }
     105    }
     106    private IntValue PopulationSize {
     107      get { return PopulationSizeParameter.ActualValue; }
     108      set { PopulationSizeParameter.ActualValue = value; }
     109    }
     110    private IntValue ReferenceSetSize {
     111      get { return ReferenceSetSizeParameter.ActualValue; }
     112      set { ReferenceSetSizeParameter.ActualValue = value; }
     113    }
     114    private DoubleValue BestKnownQuality {
     115      get { return BestKnownQualityParameter.ActualValue; }
     116      set { BestKnownQualityParameter.ActualValue = value; }
     117    }
     118    private IEvaluator Evaluator {
     119      get { return EvaluatorParameter.ActualValue; }
     120      set { EvaluatorParameter.ActualValue = value; }
     121    }
     122    private IntValue Iterations {
     123      get { return IterationsParameter.ActualValue; }
     124      set { IterationsParameter.ActualValue = value; }
     125    }
     126    private BoolValue Maximization {
     127      get { return MaximizationParameter.ActualValue; }
     128      set { MaximizationParameter.ActualValue = value; }
     129    }
     130    private IntValue MaximumIterations {
     131      get { return MaximumIterationsParameter.ActualValue; }
     132      set { MaximumIterationsParameter.ActualValue = value; }
     133    }
     134    private DoubleValue Quality {
     135      get { return QualityParameter.ActualValue; }
     136      set { QualityParameter.ActualValue = value; }
     137    }
     138    private IRandom Random {
    97139      get { return RandomParameter.ActualValue; }
    98140      set { RandomParameter.ActualValue = value; }
    99141    }
    100     public IntValue Iterations {
    101       get { return IterationsParameter.ActualValue; }
    102       set { IterationsParameter.ActualValue = value; }
    103     }
    104     public IntValue MaximumIterations {
    105       get { return MaximumIterationsParameter.ActualValue; }
    106       set { MaximumIterationsParameter.ActualValue = value; }
    107     }
    108     public BoolValue Maximization {
    109       get { return MaximizationParameter.ActualValue; }
    110       set { MaximizationParameter.ActualValue = value; }
    111     }
    112     public IntValue SampleSize {
     142    private VariableCollection Results {
     143      get { return ResultsParameter.ActualValue; }
     144      set { ResultsParameter.ActualValue = value; }
     145    }
     146    private IntValue SampleSize {
    113147      get { return SampleSizeParameter.ActualValue; }
    114148      set { SampleSizeParameter.ActualValue = value; }
    115149    }
    116     public IntValue PopulationSize {
    117       get { return PopulationSizeParameter.ActualValue; }
    118       set { PopulationSizeParameter.ActualValue = value; }
    119     }
    120     public IntValue ReferenceSetSize {
    121       get { return ReferenceSetSizeParameter.ActualValue; }
    122       set { ReferenceSetSizeParameter.ActualValue = value; }
    123     }
    124     public IntValue NumberOfHighQualitySolutions {
    125       get { return NumberOfHighQualitySolutionsParameter.ActualValue; }
    126       set { NumberOfHighQualitySolutionsParameter.ActualValue = value; }
    127     }
    128     public DoubleValue Quality {
    129       get { return QualityParameter.ActualValue; }
    130       set { QualityParameter.ActualValue = value; }
    131     }
    132     public DoubleValue BestKnownQuality {
    133       get { return BestKnownQualityParameter.ActualValue; }
    134       set { BestKnownQualityParameter.ActualValue = value; }
    135     }
    136     public DoubleValue MoveQuality {
    137       get { return MoveQualityParameter.ActualValue; }
    138       set { MoveQualityParameter.ActualValue = value; }
    139     }
    140     public VariableCollection Results {
    141       get { return ResultsParameter.ActualValue; }
    142       set { ResultsParameter.ActualValue = value; }
    143     }
    144     public ISingleObjectiveMoveEvaluator MoveEvaluator {
    145       get { return MoveEvaluatorParameter.ActualValue; }
    146       set { MoveEvaluatorParameter.ActualValue = value; }
    147     }
    148     public IMoveGenerator MoveGenerator {
    149       get { return MoveGeneratorParameter.ActualValue; }
    150       set { MoveGeneratorParameter.ActualValue = value; }
    151     }
    152     public IMoveMaker MoveMaker {
    153       get { return MoveMakerParameter.ActualValue; }
    154       set { MoveMakerParameter.ActualValue = value; }
    155     }
    156     public IOperator Improver {
    157       get { return ImproverParameter.ActualValue; }
    158       set { ImproverParameter.ActualValue = value; }
    159     }
    160     public IOperator Evaluator {
    161       get { return EvaluatorParameter.ActualValue; }
    162       set { EvaluatorParameter.ActualValue = value; }
    163     }
    164     public IMultiAnalyzer Analyzer {
    165       get { return AnalyzerParameter.ActualValue; }
    166       set { AnalyzerParameter.ActualValue = value; }
     150    private ISolutionCreator SolutionCreator {
     151      get { return SolutionCreatorParameter.ActualValue; }
     152      set { SolutionCreatorParameter.ActualValue = value; }
    167153    }
    168154    #endregion
     
    179165    private void Initialize() {
    180166      #region Create parameters
    181       Parameters.Add(new LookupParameter<IRandom>("Random", "A pseudo random number generator."));
    182       Parameters.Add(new LookupParameter<IntValue>("Iterations", "The number of iterations performed."));
    183       Parameters.Add(new LookupParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed."));
    184       Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
    185       Parameters.Add(new LookupParameter<IntValue>("SampleSize", "Number of moves that MultiMoveGenerators should create. This is ignored for Exhaustive- and SingleMoveGenerators."));
    186       Parameters.Add(new LookupParameter<IntValue>("PopulationSize", "The size of the population."));
    187       Parameters.Add(new LookupParameter<IntValue>("ReferenceSetSize", "The size of the reference set."));
    188       Parameters.Add(new LookupParameter<IntValue>("NumberOfHighQualitySolutions", "The number of high quality solutions that should be added to the reference set."));
    189       Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
    190       Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The problem's best known quality value found so far."));
    191       Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The value which represents the quality of a move."));
    192       Parameters.Add(new LookupParameter<IOperator>("SolutionCreator", "The operator which is used to create new solutions."));
    193       Parameters.Add(new LookupParameter<IOperator>("Evaluator", "The operator which is used to evaluate new solutions."));
    194       Parameters.Add(new LookupParameter<VariableCollection>("Results", "The variable collection where results should be stored."));
    195       Parameters.Add(new LookupParameter<ISingleObjectiveMoveEvaluator>("MoveEvaluator", "The operator used to evaluate a move."));
    196       Parameters.Add(new LookupParameter<IMoveGenerator>("MoveGenerator", "The operator that generates the moves."));
    197       Parameters.Add(new LookupParameter<IMoveMaker>("MoveMaker", "The operator that performs a move and updates the quality."));
    198       Parameters.Add(new LookupParameter<IOperator>("Improver", "The operator used to improve solutions."));
    199       Parameters.Add(new LookupParameter<IMultiAnalyzer>("Analyzer", "The operator used to analyze the solution and moves."));
     167      Parameters.Add(new ValueLookupParameter<IMultiAnalyzer>("Analyzer", "The operator used to analyze the solution and moves."));
     168      Parameters.Add(new ValueLookupParameter<ICrossover>("Crossover", "The operator used to combine solutions."));
     169      Parameters.Add(new ValueLookupParameter<IOperator>("Improver", "The operator used to improve solutions."));
     170      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfHighQualitySolutions", "The number of high quality solutions that should be added to the reference set."));
     171      Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population."));
     172      Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize", "The size of the reference set."));
     173      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The problem's best known quality value found so far."));
     174      Parameters.Add(new ValueLookupParameter<IEvaluator>("Evaluator", "The operator which is used to evaluate new solutions."));
     175      Parameters.Add(new ValueLookupParameter<IntValue>("Iterations", "The number of iterations performed."));
     176      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
     177      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed."));
     178      Parameters.Add(new ValueLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
     179      Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator."));
     180      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored."));
     181      Parameters.Add(new ValueLookupParameter<IntValue>("SampleSize", "Number of moves that MultiMoveGenerators should create. This is ignored for Exhaustive- and SingleMoveGenerators."));
     182      Parameters.Add(new ValueLookupParameter<ISolutionCreator>("SolutionCreator", "The operator which is used to create new solutions."));
    200183      #endregion
    201184
     
    208191      ConditionalBranch terminateBranch = new ConditionalBranch();
    209192      IntCounter interationsCounter = new IntCounter();
     193      OffspringProcessor offspringProcessor = new OffspringProcessor();
    210194      Placeholder analyzer = new Placeholder();
     195      Placeholder crossover = new Placeholder();
    211196      Placeholder solutionEvaluator1 = new Placeholder();
    212197      Placeholder solutionEvaluator2 = new Placeholder();
     
    216201      ResultsCollector resultsCollector = new ResultsCollector();
    217202      ReferenceSetUpdateMethod referenceSetUpdateMethod = new ReferenceSetUpdateMethod();
    218       SolutionCombinationMethod solutionCombinationMethod = new SolutionCombinationMethod();
    219203      SolutionPoolUpdateMethod solutionPoolUpdateMethod = new SolutionPoolUpdateMethod();
    220204      SolutionsCreator solutionsCreator = new SolutionsCreator();
     
    275259      interationsCounter.Successor = resultsCollector;
    276260
     261      offspringProcessor.Successor = subScopesProcessor2;
     262
    277263      analyzer.Name = "Analyzer";
    278264      analyzer.OperatorParameter.ActualName = "Analyzer";
     265
     266      crossover.Name = "Crossover";
     267      crossover.OperatorParameter.ActualName = "Crossover";
     268      crossover.Successor = offspringProcessor;
    279269
    280270      solutionImprover1.Name = "SolutionImprover";
     
    296286      referenceSetUpdateMethod.Successor = assigner1;
    297287
    298       solutionCombinationMethod.Successor = subScopesProcessor2;
    299 
    300288      solutionPoolUpdateMethod.Successor = analyzer;
    301289
     
    321309
    322310      uniformSubScopesProcessor1.DepthParameter.Value = new IntValue(1);
    323       uniformSubScopesProcessor1.Operator = solutionCombinationMethod;
     311      uniformSubScopesProcessor1.Operator = crossover;
    324312      uniformSubScopesProcessor1.Successor = solutionPoolUpdateMethod;
    325313
     
    335323
    336324    public override IOperation Apply() {
    337       if (MoveGeneratorParameter.ActualValue == null || MoveEvaluatorParameter.ActualValue == null || MoveMakerParameter.ActualValue == null)
    338         return null;
    339325      return base.Apply();
    340326    }
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/SolutionPoolUpdateMethod.cs

    r7724 r7740  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
    2224using System.Linq;
    2325using HeuristicLab.Common;
     
    3638  public sealed class SolutionPoolUpdateMethod : SingleSuccessorOperator {
    3739    #region Parameter properties
    38     private ScopeParameter CurrentScopeParameter {
     40    public ScopeParameter CurrentScopeParameter {
    3941      get { return (ScopeParameter)Parameters["CurrentScope"]; }
    4042    }
    41     private ValueLookupParameter<BoolValue> NewSolutionsParameter {
    42       get { return (ValueLookupParameter<BoolValue>)Parameters["NewSolutions"]; }
     43    public IValueLookupParameter<BoolValue> NewSolutionsParameter {
     44      get { return (IValueLookupParameter<BoolValue>)Parameters["NewSolutions"]; }
    4345    }
    44     private ValueLookupParameter<IntValue> ReferenceSetSizeParameter {
    45       get { return (ValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
     46    public IValueLookupParameter<IntValue> ReferenceSetSizeParameter {
     47      get { return (IValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
     48    }
     49    public IValueLookupParameter<IItem> QualityParameter {
     50      get { return (IValueLookupParameter<IItem>)Parameters["Quality"]; }
     51    }
     52    public IValueLookupParameter<IItem> SolutionParameter {
     53      get { return (IValueLookupParameter<IItem>)Parameters["Solution"]; }
    4654    }
    4755    #endregion
     
    5866      set { ReferenceSetSizeParameter.ActualValue = value; }
    5967    }
     68    private IItem Quality {
     69      get { return QualityParameter.ActualValue; }
     70    }
    6071    #endregion
    6172
     
    7182    private void Initialize() {
    7283      #region Create parameters
    73       Parameters.Add(new ScopeParameter("CurrentScope", "The current scope to which the new solutions are added as sub-scopes."));
    74       Parameters.Add(new ValueLookupParameter<BoolValue>("NewSolutions", "Indicates if new solutions have been found."));
    75       Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize", "The size of the reference set."));
     84      Parameters.Add(new ScopeParameter("CurrentScope"));
     85      Parameters.Add(new ValueLookupParameter<BoolValue>("NewSolutions"));
     86      Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize"));
     87      Parameters.Add(new ValueLookupParameter<IItem>("Quality"));
     88      Parameters.Add(new ValueLookupParameter<IItem>("Solution"));
    7689      #endregion
    77 
    78       #region Create operators
    79       #endregion
    80 
    81       #region Create operator graph
    82       #endregion
     90      SolutionParameter.ActualName = "KnapsackSolution"; // temporary solution for the knapsack problem
    8391    }
    8492
     
    9199      }
    92100      CurrentScope.SubScopes.Clear();
    93       CurrentScope.SubScopes.AddRange(parents.SubScopes.OrderByDescending(o => o.Variables["Quality"].Value));
    94       if ((offspring.SubScopes.OrderByDescending(o => o.Variables["Quality"].Value).First().Variables["Quality"].Value as DoubleValue).Value
    95           > (parents.SubScopes.OrderByDescending(o => o.Variables["Quality"].Value).First().Variables["Quality"].Value as DoubleValue).Value) {
    96         CurrentScope.SubScopes.Replace(CurrentScope.SubScopes.Union(offspring.SubScopes).OrderByDescending(o => o.Variables["Quality"].Value).Take(ReferenceSetSize.Value));
     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));
    97105        NewSolutions.Value = true;
    98106      }
     107
    99108      return base.Apply();
     109    }
     110
     111    private class KeyEqualityComparer<T> : IEqualityComparer<T> {
     112      private readonly Func<T, object> keyExtractor;
     113
     114      public KeyEqualityComparer(Func<T, object> keyExtractor) {
     115        this.keyExtractor = keyExtractor;
     116      }
     117
     118      public bool Equals(T x, T y) {
     119        return keyExtractor(x).Equals(keyExtractor(y));
     120      }
     121
     122      public int GetHashCode(T obj) {
     123        return keyExtractor(obj).GetHashCode();
     124      }
    100125    }
    101126  }
Note: See TracChangeset for help on using the changeset viewer.