Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/22/12 11:11:38 (12 years ago)
Author:
jkarder
Message:

#1331:

  • synced branch with trunk
  • added custom interface (ISimilarityBasedOperator) to mark operators that conduct similarity calculation
  • similarity calculators are now parameterized by the algorithm
  • deleted SolutionPool2TierUpdateMethod
  • deleted KnapsackMultipleGuidesPathRelinker
  • moved IImprovementOperator, IPathRelinker and ISimilarityCalculator to HeuristicLab.Optimization
  • added parameter descriptions
  • fixed plugin references
  • fixed count of EvaluatedSolutions
  • fixed check for duplicate solutions
  • minor code improvements
Location:
branches/ScatterSearch (trunk integration)
Files:
1 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • branches/ScatterSearch (trunk integration)

  • branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/HeuristicLab.Algorithms.ScatterSearch-3.3.csproj

    r7789 r8086  
    5858      <Private>False</Private>
    5959    </Reference>
    60     <Reference Include="HeuristicLab.Encodings.BinaryVectorEncoding-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    61       <Private>False</Private>
    62     </Reference>
    63     <Reference Include="HeuristicLab.Encodings.PermutationEncoding-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    64       <Private>False</Private>
    65     </Reference>
    66     <Reference Include="HeuristicLab.Encodings.RealVectorEncoding-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    67       <Private>False</Private>
    68     </Reference>
    6960    <Reference Include="HeuristicLab.Operators-3.3">
    7061      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Operators-3.3.dll</HintPath>
    7162      <Private>False</Private>
    7263    </Reference>
    73     <Reference Include="HeuristicLab.Optimization-3.3">
    74       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Optimization-3.3.dll</HintPath>
    75       <Private>False</Private>
    76     </Reference>
     64    <Reference Include="HeuristicLab.Optimization-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" />
     65    <Reference Include="HeuristicLab.Optimization.Operators-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" />
    7766    <Reference Include="HeuristicLab.Parameters-3.3">
    7867      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Parameters-3.3.dll</HintPath>
     
    8473    </Reference>
    8574    <Reference Include="HeuristicLab.PluginInfrastructure-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    86       <Private>False</Private>
    87     </Reference>
    88     <Reference Include="HeuristicLab.Problems.Knapsack-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    89       <Private>False</Private>
    90     </Reference>
    91     <Reference Include="HeuristicLab.Problems.TestFunctions-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    92       <Private>False</Private>
    93     </Reference>
    94     <Reference Include="HeuristicLab.Problems.TravelingSalesman-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    9575      <Private>False</Private>
    9676    </Reference>
     
    11292  <ItemGroup>
    11393    <Compile Include="IScatterSearchOperator.cs" />
    114     <Compile Include="SolutionPool2TierUpdateMethod.cs" />
    11594    <Compile Include="OffspringProcessor.cs" />
    11695    <None Include="HeuristicLab.snk" />
     
    124103    <Compile Include="ScatterSearchMainLoop.cs" />
    125104    <Compile Include="SolutionPoolUpdateMethod.cs" />
    126   </ItemGroup>
    127   <ItemGroup />
    128   <ItemGroup>
    129     <ProjectReference Include="..\..\HeuristicLab.Optimization.Operators\3.3\HeuristicLab.Optimization.Operators-3.3.csproj">
    130       <Project>{25087811-F74C-4128-BC86-8324271DA13E}</Project>
    131       <Name>HeuristicLab.Optimization.Operators-3.3</Name>
    132       <Private>False</Private>
    133     </ProjectReference>
    134105  </ItemGroup>
    135106  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/IScatterSearchOperator.cs

    r7789 r8086  
    2020#endregion
    2121
    22 using System;
    23 using HeuristicLab.Common;
    2422using HeuristicLab.Core;
    2523
     
    2826  /// An interface which represents a scatter search specific operator.
    2927  /// </summary>
    30   public interface IScatterSearchOperator : IOperator, IParameterizedNamedItem, IDeepCloneable, ICloneable {
    31   }
     28  public interface IScatterSearchOperator : IOperator { }
    3229}
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/OffspringProcessor.cs

    r7789 r8086  
    5757      : base() {
    5858      #region Create parameters
    59       Parameters.Add(new ScopeParameter("CurrentScope"));
    60       Parameters.Add(new ValueLookupParameter<IItem>("Target"));
     59      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope that contains the offspring as variables."));
     60      Parameters.Add(new ValueLookupParameter<IItem>("Target", "This parameter is used for name translation only."));
    6161      #endregion
    6262    }
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/Plugin.cs.frame

    r7789 r8086  
    3333  [PluginDependency("HeuristicLab.Core", "3.3")]
    3434  [PluginDependency("HeuristicLab.Data", "3.3")]
    35   [PluginDependency("HeuristicLab.Encodings.BinaryVectorEncoding", "3.3")]
    36   [PluginDependency("HeuristicLab.Encodings.PermutationEncoding", "3.3")]
    37   [PluginDependency("HeuristicLab.Encodings.RealVectorEncoding", "3.3")]
    3835  [PluginDependency("HeuristicLab.Operators", "3.3")]
    3936  [PluginDependency("HeuristicLab.Optimization", "3.3")]
     
    4138  [PluginDependency("HeuristicLab.Parameters", "3.3")]
    4239  [PluginDependency("HeuristicLab.Persistence", "3.3")]
    43   [PluginDependency("HeuristicLab.Problems.Knapsack", "3.3")]
    44   [PluginDependency("HeuristicLab.Problems.TestFunctions", "3.3")]
    45   [PluginDependency("HeuristicLab.Problems.TravelingSalesman", "3.3")]
    4640  [PluginDependency("HeuristicLab.Random", "3.3")]
    4741  [PluginDependency("HeuristicLab.Selection", "3.3")]
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/PopulationRebuildMethod.cs

    r7789 r8086  
    8080      : base() {
    8181      #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"));
     82      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope that contains the population and the reference set."));
     83      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
     84      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfHighQualitySolutions", "The number of high quality solutions in the reference set."));
     85      Parameters.Add(new ValueLookupParameter<IItem>("Quality", "This parameter is used for name translation only."));
     86      Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize", "The size of the reference set."));
    8787      #endregion
    8888    }
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/ReferenceSetUpdateMethod.cs

    r7789 r8086  
    2626using HeuristicLab.Data;
    2727using HeuristicLab.Operators;
     28using HeuristicLab.Optimization;
    2829using HeuristicLab.Optimization.Operators;
    2930using HeuristicLab.Parameters;
     
    3637  [Item("ReferenceSetUpdateMethod", "An operator that updates the reference set.")]
    3738  [StorableClass]
    38   public sealed class ReferenceSetUpdateMethod : SingleSuccessorOperator, IScatterSearchOperator {
     39  public sealed class ReferenceSetUpdateMethod : SingleSuccessorOperator, ISimilarityBasedOperator {
     40    #region ISimilarityBasedOperator Members
     41    public ISimilarityCalculator SimilarityCalculator { get; set; }
     42    #endregion
     43
    3944    #region Parameter properties
    4045    public ScopeParameter CurrentScopeParameter {
     
    4348    public IValueLookupParameter<IntValue> ReferenceSetSizeParameter {
    4449      get { return (IValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
    45     }
    46     public IValueLookupParameter<SimilarityCalculator> SimilarityCalculatorParameter {
    47       get { return (IValueLookupParameter<SimilarityCalculator>)Parameters["SimilarityCalculator"]; }
    48     }
    49     public IValueLookupParameter<IItem> TargetParameter {
    50       get { return (IValueLookupParameter<IItem>)Parameters["Target"]; }
    5150    }
    5251    #endregion
     
    5958      get { return ReferenceSetSizeParameter.ActualValue; }
    6059    }
    61     private SimilarityCalculator SimilarityCalculator {
    62       get { return SimilarityCalculatorParameter.ActualValue; }
    63     }
    64     private IItem Target {
    65       get { return TargetParameter.ActualValue; }
    66     }
    6760    #endregion
    6861
     
    7366      : base() {
    7467      #region Create parameters
    75       Parameters.Add(new ScopeParameter("CurrentScope"));
    76       Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize"));
    77       Parameters.Add(new ValueLookupParameter<SimilarityCalculator>("SimilarityCalculator"));
    78       Parameters.Add(new ValueLookupParameter<IItem>("Target"));
     68      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope that contains the population and the reference set."));
     69      Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize", "The size of the reference set."));
    7970      #endregion
    8071    }
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearch.cs

    r7954 r8086  
    174174      : base() {
    175175      #region Create parameters
    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<ISimilarityCalculator>("SimilarityCalculator"));
     176      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The analyzer used to analyze each iteration.", new MultiAnalyzer()));
     177      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
     178      Parameters.Add(new ValueParameter<BoolValue>("ExecutePathRelinking", "True if path relinking should be executed instead of crossover, otherwise false.", new BoolValue(true)));
     179      Parameters.Add(new ConstrainedValueParameter<IImprovementOperator>("Improver", "The operator used to improve solutions."));
     180      Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of iterations which should be processed.", new IntValue(100)));
     181      Parameters.Add(new ValueParameter<IntValue>("NumberOfHighQualitySolutions", "The number of high quality solutions in the reference set.", new IntValue(5)));
     182      Parameters.Add(new ConstrainedValueParameter<IPathRelinker>("PathRelinker", "The operator used to execute path relinking."));
     183      Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions.", new IntValue(50)));
     184      Parameters.Add(new ValueParameter<IntValue>("ReferenceSetSize", "The size of the reference set.", new IntValue(20)));
     185      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
     186      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
     187      Parameters.Add(new ConstrainedValueParameter<ISimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions."));
    188188      #endregion
    189189
     
    194194      Placeholder solutionEvaluator = new Placeholder();
    195195      Placeholder solutionImprover = new Placeholder();
    196       SubScopesCounter subScopesCounter = new SubScopesCounter();
     196      VariableCreator variableCreator = new VariableCreator();
     197      DataReducer dataReducer = new DataReducer();
    197198      ResultsCollector resultsCollector = new ResultsCollector();
    198199      BestSelector bestSelector = new BestSelector();
     
    212213
    213214      uniformSubScopesProcessor.Operator = solutionImprover;
    214       uniformSubScopesProcessor.Successor = subScopesCounter;
     215      uniformSubScopesProcessor.Successor = variableCreator;
    215216
    216217      solutionImprover.Name = "SolutionImprover";
     
    222223      solutionEvaluator.Successor = null;
    223224
    224       subScopesCounter.Name = "Initialize EvaluatedSolutions";
    225       subScopesCounter.ValueParameter.ActualName = "EvaluatedSolutions";
    226       subScopesCounter.Successor = resultsCollector;
     225      variableCreator.Name = "Initialize EvaluatedSolutions";
     226      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedSolutions", new IntValue()));
     227      variableCreator.Successor = dataReducer;
     228
     229      dataReducer.Name = "Increment EvaluatedSolutions";
     230      dataReducer.ParameterToReduce.ActualName = "LocalEvaluatedSolutions";
     231      dataReducer.TargetParameter.ActualName = "EvaluatedSolutions";
     232      dataReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum);
     233      dataReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Sum);
     234      dataReducer.Successor = resultsCollector;
    227235
    228236      resultsCollector.Name = "ResultsCollector";
     
    239247      mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
    240248      mainLoop.IterationsParameter.ActualName = "Iterations";
     249      mainLoop.EvaluatedSolutionsParameter.ActualName = "EvaluatedSolutions";
    241250      mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
    242251      mainLoop.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
     
    261270      ParameterizeStochasticOperator(Problem.SolutionCreator);
    262271      ParameterizeStochasticOperator(Problem.Evaluator);
    263       foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
     272      foreach (IOperator op in Problem.Operators.OfType<IOperator>()) ParameterizeStochasticOperator(op);
    264273      ParameterizeAnalyzers();
    265274      ParameterizeSolutionsCreator();
     
    289298    }
    290299    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
    291       foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
     300      foreach (IOperator op in Problem.Operators.OfType<IOperator>()) ParameterizeStochasticOperator(op);
    292301      UpdateAnalyzers();
    293302      UpdateCrossovers();
     
    376385      ISimilarityCalculator defaultDiversityCalculator = Problem.Operators.OfType<ISimilarityCalculator>().FirstOrDefault();
    377386
    378       foreach (ISimilarityCalculator diversityCalculator in Problem.Operators.OfType<ISimilarityCalculator>().OrderBy(x => x.Name))
     387      foreach (ISimilarityCalculator diversityCalculator in Problem.Operators.OfType<ISimilarityCalculator>())
    379388        SimilarityCalculatorParameter.ValidValues.Add(diversityCalculator);
    380389
     
    401410        MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    402411        MainLoop.TargetParameter.ActualName = Improver.TargetParameter.ActualName;
    403         foreach (var item in MainLoop.OperatorGraph.Operators.OfType<IScatterSearchOperator>()) {
     412        foreach (var op in MainLoop.OperatorGraph.Operators.OfType<IScatterSearchOperator>()) {
    404413          // parameter should be accessed direclty (using an interface definition)
    405           PropertyInfo propInfo = item.GetType().GetProperty(MainLoop.TargetParameter.Name + "Parameter");
     414          PropertyInfo propInfo = op.GetType().GetProperty(MainLoop.TargetParameter.Name + "Parameter");
    406415          if (propInfo != null && propInfo.CanRead)
    407             (propInfo.GetValue(item, null) as IValueLookupParameter<IItem>).ActualName = MainLoop.TargetParameter.ActualName;
    408           propInfo = item.GetType().GetProperty(MainLoop.QualityParameter.Name + "Parameter");
     416            (propInfo.GetValue(op, null) as IValueLookupParameter<IItem>).ActualName = MainLoop.TargetParameter.ActualName;
     417          propInfo = op.GetType().GetProperty(MainLoop.QualityParameter.Name + "Parameter");
    409418          if (propInfo != null && propInfo.CanRead)
    410             (propInfo.GetValue(item, null) as IValueLookupParameter<IItem>).ActualName = MainLoop.QualityParameter.ActualName;
     419            (propInfo.GetValue(op, null) as IValueLookupParameter<IItem>).ActualName = MainLoop.QualityParameter.ActualName;
    411420        }
     421        foreach (ISimilarityBasedOperator op in MainLoop.OperatorGraph.Operators.OfType<ISimilarityBasedOperator>())
     422          op.SimilarityCalculator = SimilarityCalculator;
    412423      }
    413424    }
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearchMainLoop.cs

    r7954 r8086  
    9292      get { return (IValueLookupParameter<ISimilarityCalculator>)Parameters["SimilarityCalculator"]; }
    9393    }
    94     public IValueLookupParameter<ISolutionCreator> SolutionCreatorParameter {
    95       get { return (IValueLookupParameter<ISolutionCreator>)Parameters["SolutionCreator"]; }
    96     }
    9794    public IValueLookupParameter<IItem> TargetParameter {
    9895      get { return (IValueLookupParameter<IItem>)Parameters["Target"]; }
     
    173170      set { SimilarityCalculatorParameter.ActualValue = value; }
    174171    }
    175     private ISolutionCreator SolutionCreator {
    176       get { return SolutionCreatorParameter.ActualValue; }
    177       set { SolutionCreatorParameter.ActualValue = value; }
    178     }
    179172    private IItem Target {
    180173      get { return TargetParameter.ActualValue; }
     
    194187    private void Initialize() {
    195188      #region Create parameters
    196       Parameters.Add(new ValueLookupParameter<IMultiAnalyzer>("Analyzer"));
    197       Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality"));
    198       Parameters.Add(new ValueLookupParameter<ICrossover>("Crossover"));
    199       Parameters.Add(new ValueLookupParameter<IntValue>("EvaluatedSolutions"));
    200       Parameters.Add(new ValueLookupParameter<IEvaluator>("Evaluator"));
    201       Parameters.Add(new ValueLookupParameter<BoolValue>("ExecutePathRelinking"));
    202       Parameters.Add(new ValueLookupParameter<IImprovementOperator>("Improver"));
    203       Parameters.Add(new ValueLookupParameter<IntValue>("Iterations"));
    204       Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization"));
    205       Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations"));
    206       Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfHighQualitySolutions"));
    207       Parameters.Add(new ValueLookupParameter<IPathRelinker>("PathRelinker"));
    208       Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize"));
    209       Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize"));
    210       Parameters.Add(new ValueLookupParameter<DoubleValue>("Quality"));
    211       Parameters.Add(new ValueLookupParameter<IRandom>("Random"));
    212       Parameters.Add(new ValueLookupParameter<VariableCollection>("Results"));
    213       Parameters.Add(new ValueLookupParameter<ISimilarityCalculator>("SimilarityCalculator"));
    214       Parameters.Add(new ValueLookupParameter<ISolutionCreator>("SolutionCreator"));
    215       Parameters.Add(new ValueLookupParameter<IItem>("Target"));
     189      Parameters.Add(new ValueLookupParameter<IMultiAnalyzer>("Analyzer", "The analyzer used to analyze each iteration."));
     190      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
     191      Parameters.Add(new ValueLookupParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
     192      Parameters.Add(new ValueLookupParameter<IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated."));
     193      Parameters.Add(new ValueLookupParameter<IEvaluator>("Evaluator", "The operator used to evaluate solutions. This operator is executed in parallel, if an engine is used which supports parallelization."));
     194      Parameters.Add(new ValueLookupParameter<BoolValue>("ExecutePathRelinking", "True if path relinking should be executed instead of crossover, otherwise false."));
     195      Parameters.Add(new ValueLookupParameter<IImprovementOperator>("Improver", "The operator used to improve solutions."));
     196      Parameters.Add(new ValueLookupParameter<IntValue>("Iterations", "The number of iterations performed."));
     197      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
     198      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of iterations which should be processed."));
     199      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfHighQualitySolutions", "The number of high quality solutions in the reference set."));
     200      Parameters.Add(new ValueLookupParameter<IPathRelinker>("PathRelinker", "The operator used to execute path relinking."));
     201      Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population of solutions."));
     202      Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize", "The size of the reference set."));
     203      Parameters.Add(new ValueLookupParameter<DoubleValue>("Quality", "This parameter is used for name translation only."));
     204      Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator."));
     205      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored."));
     206      Parameters.Add(new ValueLookupParameter<ISimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions."));
     207      Parameters.Add(new ValueLookupParameter<IItem>("Target", "This parameter is used for name translation only."));
    216208      #endregion
    217209
     
    239231      SolutionPoolUpdateMethod solutionPoolUpdateMethod = new SolutionPoolUpdateMethod();
    240232      SolutionsCreator solutionsCreator = new SolutionsCreator();
    241       SubScopesCounter subScopesCounter1 = new SubScopesCounter();
    242       SubScopesCounter subScopesCounter2 = new SubScopesCounter();
     233      DataReducer dataReducer1 = new DataReducer();
     234      DataReducer dataReducer2 = new DataReducer();
    243235      SubScopesProcessor subScopesProcessor1 = new SubScopesProcessor();
    244236      SubScopesProcessor subScopesProcessor2 = new SubScopesProcessor();
    245237      SubScopesProcessor subScopesProcessor3 = new SubScopesProcessor();
     238      SubScopesProcessor subScopesProcessor4 = new SubScopesProcessor();
    246239      ConditionalBranch terminateBranch = new ConditionalBranch();
    247240      UniformSubScopesProcessor uniformSubScopesProcessor1 = new UniformSubScopesProcessor();
     
    253246      #region Create operator graph
    254247      OperatorGraph.InitialOperator = variableCreator;
    255       variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0)));
     248      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>(IterationsParameter.Name, new IntValue(0)));
    256249      variableCreator.CollectedValues.Add(new ValueParameter<BoolValue>("NewSolutions", new BoolValue(false)));
    257250      variableCreator.Successor = resultsCollector;
     
    264257      iterationsChecker.Name = "IterationsChecker";
    265258      iterationsChecker.Comparison.Value = ComparisonType.GreaterOrEqual;
    266       iterationsChecker.LeftSideParameter.ActualName = "Iterations";
    267       iterationsChecker.RightSideParameter.ActualName = "MaximumIterations";
     259      iterationsChecker.LeftSideParameter.ActualName = IterationsParameter.Name;
     260      iterationsChecker.RightSideParameter.ActualName = MaximumIterationsParameter.Name;
    268261      iterationsChecker.ResultParameter.ActualName = "Terminate";
    269262      iterationsChecker.Successor = terminateBranch;
     
    273266      terminateBranch.FalseBranch = referenceSetUpdateMethod;
    274267
    275       referenceSetUpdateMethod.TargetParameter.ActualName = TargetParameter.ActualName;
    276268      referenceSetUpdateMethod.Successor = assigner1;
    277269
     
    305297
    306298      pathRelinker.Name = "PathRelinker";
    307       pathRelinker.OperatorParameter.ActualName = "PathRelinker";
     299      pathRelinker.OperatorParameter.ActualName = PathRelinkerParameter.Name;
    308300      pathRelinker.Successor = offspringProcessor;
    309301
    310302      crossover.Name = "Crossover";
    311       crossover.OperatorParameter.ActualName = "Crossover";
     303      crossover.OperatorParameter.ActualName = CrossoverParameter.Name;
    312304      crossover.Successor = offspringProcessor;
    313305
     
    326318      uniformSubScopesProcessor2.DepthParameter.Value = new IntValue(2);
    327319      uniformSubScopesProcessor2.Operator = solutionImprover1;
    328       uniformSubScopesProcessor2.Successor = subScopesCounter1;
     320      uniformSubScopesProcessor2.Successor = subScopesProcessor4;
    329321
    330322      solutionImprover1.Name = "SolutionImprover";
    331       solutionImprover1.OperatorParameter.ActualName = "Improver";
     323      solutionImprover1.OperatorParameter.ActualName = ImproverParameter.Name;
    332324      solutionImprover1.Successor = solutionEvaluator1;
    333325
    334326      solutionEvaluator1.Name = "SolutionEvaluator";
    335       solutionEvaluator1.OperatorParameter.ActualName = "Evaluator";
    336 
    337       subScopesCounter1.Name = "Increment EvaluatedSolutions";
    338       subScopesCounter1.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
     327      solutionEvaluator1.OperatorParameter.ActualName = EvaluatorParameter.Name;
     328
     329      subScopesProcessor4.Operators.Add(dataReducer1);
     330
     331      dataReducer1.Name = "Increment EvaluatedSolutions";
     332      dataReducer1.ParameterToReduce.ActualName = "LocalEvaluatedSolutions";
     333      dataReducer1.TargetParameter.ActualName = EvaluatedSolutionsParameter.Name;
     334      dataReducer1.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum);
     335      dataReducer1.TargetOperation.Value = new ReductionOperation(ReductionOperations.Sum);
    339336
    340337      solutionPoolUpdateMethod.QualityParameter.ActualName = QualityParameter.ActualName;
    341       solutionPoolUpdateMethod.TargetParameter.ActualName = TargetParameter.ActualName;
    342338      solutionPoolUpdateMethod.Successor = analyzer;
    343339
    344340      analyzer.Name = "Analyzer";
    345       analyzer.OperatorParameter.ActualName = "Analyzer";
     341      analyzer.OperatorParameter.ActualName = AnalyzerParameter.Name;
    346342
    347343      newSolutionsBranch.Name = "NewSolutionsChecker";
     
    359355
    360356      solutionsCreator.Name = "DiversificationGenerationMethod";
    361       solutionsCreator.NumberOfSolutionsParameter.ActualName = "PopulationSize";
     357      solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
    362358      solutionsCreator.Successor = uniformSubScopesProcessor3;
    363359
    364360      uniformSubScopesProcessor3.DepthParameter.Value = new IntValue(1);
    365361      uniformSubScopesProcessor3.Operator = solutionImprover2;
    366       uniformSubScopesProcessor3.Successor = subScopesCounter2;
     362      uniformSubScopesProcessor3.Successor = dataReducer2;
    367363
    368364      solutionImprover2.Name = "SolutionImprover";
    369       solutionImprover2.OperatorParameter.ActualName = "Improver";
     365      solutionImprover2.OperatorParameter.ActualName = ImproverParameter.Name;
    370366      solutionImprover2.Successor = solutionEvaluator2;
    371367
    372368      solutionEvaluator2.Name = "SolutionEvaluator";
    373       solutionEvaluator2.OperatorParameter.ActualName = "Evaluator";
    374 
    375       subScopesCounter2.Name = "Increment EvaluatedSolutions";
    376       subScopesCounter2.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
     369      solutionEvaluator2.OperatorParameter.ActualName = EvaluatorParameter.Name;
     370
     371      dataReducer2.Name = "Increment EvaluatedSolutions";
     372      dataReducer2.ParameterToReduce.ActualName = "LocalEvaluatedSolutions";
     373      dataReducer2.TargetParameter.ActualName = EvaluatedSolutionsParameter.Name;
     374      dataReducer2.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum);
     375      dataReducer2.TargetOperation.Value = new ReductionOperation(ReductionOperations.Sum);
    377376
    378377      iterationsCounter.Name = "IterationCounter";
    379378      iterationsCounter.IncrementParameter.Value = new IntValue(1);
    380       iterationsCounter.ValueParameter.ActualName = "Iterations";
     379      iterationsCounter.ValueParameter.ActualName = IterationsParameter.Name;
    381380      iterationsCounter.Successor = resultsCollector;
    382381      #endregion
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/SolutionPoolUpdateMethod.cs

    r7789 r8086  
    2727using HeuristicLab.Data;
    2828using HeuristicLab.Operators;
     29using HeuristicLab.Optimization;
    2930using HeuristicLab.Optimization.Operators;
    3031using HeuristicLab.Parameters;
     
    3738  [Item("SolutionPoolUpdateMethod", "An operator that updates the solution pool.")]
    3839  [StorableClass]
    39   public sealed class SolutionPoolUpdateMethod : SingleSuccessorOperator, IScatterSearchOperator {
     40  public sealed class SolutionPoolUpdateMethod : SingleSuccessorOperator, IScatterSearchOperator, ISimilarityBasedOperator {
     41    #region ISimilarityBasedOperator Members
     42    public ISimilarityCalculator SimilarityCalculator { get; set; }
     43    #endregion
     44
    4045    #region Parameter properties
    4146    public ScopeParameter CurrentScopeParameter {
     
    5358    public IValueLookupParameter<IntValue> ReferenceSetSizeParameter {
    5459      get { return (IValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
    55     }
    56     public IValueLookupParameter<SimilarityCalculator> SimilarityCalculatorParameter {
    57       get { return (IValueLookupParameter<SimilarityCalculator>)Parameters["SimilarityCalculator"]; }
    58     }
    59     public IValueLookupParameter<IItem> TargetParameter {
    60       get { return (IValueLookupParameter<IItem>)Parameters["Target"]; }
    6160    }
    6261    #endregion
     
    8079      set { ReferenceSetSizeParameter.ActualValue = value; }
    8180    }
    82     private SimilarityCalculator SimilarityCalculator {
    83       get { return SimilarityCalculatorParameter.ActualValue; }
    84     }
    85     private IItem Target {
    86       get { return TargetParameter.ActualValue; }
    87     }
    8881    #endregion
    8982
     
    9992    private void Initialize() {
    10093      #region Create parameters
    101       Parameters.Add(new ScopeParameter("CurrentScope"));
    102       Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization"));
    103       Parameters.Add(new ValueLookupParameter<BoolValue>("NewSolutions"));
    104       Parameters.Add(new ValueLookupParameter<IItem>("Quality"));
    105       Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize"));
    106       Parameters.Add(new ValueLookupParameter<SimilarityCalculator>("SimilarityCalculator"));
    107       Parameters.Add(new ValueLookupParameter<IItem>("Target"));
     94      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope that is the reference set."));
     95      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
     96      Parameters.Add(new ValueLookupParameter<BoolValue>("NewSolutions", "True if new solutions have been found, otherwise false."));
     97      Parameters.Add(new ValueLookupParameter<IItem>("Quality", "This parameter is used for name translation only."));
     98      Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize", "The size of the reference set."));
    10899      #endregion
    109100    }
    110101
    111102    public override IOperation Apply() {
    112       IScope parentsScope = new Scope("Parents");
    113       IScope offspringScope = new Scope("Offspring");
     103      ScopeList parents = new ScopeList();
     104      ScopeList offspring = new ScopeList();
    114105
    115106      // split parents and offspring
    116107      foreach (var scope in CurrentScope.SubScopes) {
    117         parentsScope.SubScopes.AddRange(scope.SubScopes.Take(scope.SubScopes.Count - 1));
    118         offspringScope.SubScopes.AddRange(scope.SubScopes.Last().SubScopes);
     108        parents.AddRange(scope.SubScopes.Take(scope.SubScopes.Count - 1));
     109        offspring.AddRange(scope.SubScopes.Last().SubScopes);
    119110      }
    120111
    121112      CurrentScope.SubScopes.Clear();
    122113
    123       var orderedParents = Maximization.Value ? parentsScope.SubScopes.OrderByDescending(x => x.Variables[QualityParameter.ActualName].Value) :
    124                                                 parentsScope.SubScopes.OrderBy(x => x.Variables[QualityParameter.ActualName].Value);
    125       var orderedOffspring = Maximization.Value ? offspringScope.SubScopes.OrderByDescending(x => x.Variables[QualityParameter.ActualName].Value) :
    126                                                   offspringScope.SubScopes.OrderBy(x => x.Variables[QualityParameter.ActualName].Value);
     114      // attention: assumes that parents are distinct
     115      // distinction might cause a too small reference set (e.g. reference set = {1, 2, 2, 2,..., 2} -> union = {1, 2}
     116
     117      var orderedParents = Maximization.Value ? parents.OrderByDescending(x => x.Variables[QualityParameter.ActualName].Value) :
     118                                                parents.OrderBy(x => x.Variables[QualityParameter.ActualName].Value);
     119      var orderedOffspring = Maximization.Value ? offspring.OrderByDescending(x => x.Variables[QualityParameter.ActualName].Value) :
     120                                                  offspring.OrderBy(x => x.Variables[QualityParameter.ActualName].Value);
    127121
    128122      CurrentScope.SubScopes.AddRange(orderedParents);
     
    136130      if (orderedOffspring.Any(hasBetterQuality)) {
    137131        // produce the set union
    138         // attention: distinction might cause a too small reference set! (e.g. reference set = {1, 2, 2, 2, ..., 2} -> union = {1, 2}
    139132        var union = orderedParents.Union(orderedOffspring.Where(hasBetterQuality), new SolutionEqualityComparer<IScope>(SimilarityCalculator.ExecuteCalculation));
    140         if (union.Count() > orderedParents/*.Distinct(new KeyEqualityComparer<IScope>(x => x.Variables[TargetParameter.ActualName].Value.ToString()))*/.Count()) {
     133        if (union.Count() > orderedParents.Count()) {
    141134          var orderedUnion = Maximization.Value ? union.OrderByDescending(x => x.Variables[QualityParameter.ActualName].Value) :
    142135                                                  union.OrderBy(x => x.Variables[QualityParameter.ActualName].Value);
    143           CurrentScope.SubScopes.Replace(orderedUnion.Take(ReferenceSetSize.Value).ToList());
     136          CurrentScope.SubScopes.Replace(orderedUnion.Take(ReferenceSetSize.Value));
    144137          NewSolutions.Value = true;
    145138        }
     
    149142    }
    150143
    151     private class SolutionEqualityComparer<T> : EqualityComparer<T> {
    152       private readonly Func<T, T, double> diversityCalculator;
     144    public class SolutionEqualityComparer<T> : EqualityComparer<T> {
     145      private readonly Func<T, T, double> similarityCalculator;
    153146
    154       public SolutionEqualityComparer(Func<T, T, double> diversityCalculator) {
    155         this.diversityCalculator = diversityCalculator;
     147      public SolutionEqualityComparer(Func<T, T, double> similarityCalculator) {
     148        this.similarityCalculator = similarityCalculator;
    156149      }
    157150
    158151      public override bool Equals(T x, T y) {
    159         return diversityCalculator(x, y) == 0.0;
     152        if (object.ReferenceEquals(x, y)) return true;
     153        if (x == null || y == null) return false;
     154        return similarityCalculator(x, y) == 1.0;
    160155      }
    161156
    162157      public override int GetHashCode(T obj) {
    163         return obj.GetHashCode();
     158        return 0; // return the same hash code for each object, otherwise Equals will not be called
    164159      }
    165160    }
Note: See TracChangeset for help on using the changeset viewer.