Changeset 7740
- Timestamp:
- 04/18/12 19:01:21 (13 years ago)
- 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 54 54 </Reference> 55 55 <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" /> 56 57 <Reference Include="HeuristicLab.Operators-3.3"> 57 58 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Operators-3.3.dll</HintPath> … … 71 72 <Reference Include="HeuristicLab.PluginInfrastructure-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" /> 72 73 <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" /> 73 75 <Reference Include="HeuristicLab.Random-3.3"> 74 76 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Random-3.3.dll</HintPath> … … 84 86 </ItemGroup> 85 87 <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" /> 86 97 <None Include="HeuristicLab.snk" /> 87 98 <None Include="Plugin.cs.frame" /> … … 94 105 <Compile Include="ScatterSearchImprovementOperator.cs" /> 95 106 <Compile Include="ScatterSearchMainLoop.cs" /> 96 <Compile Include="SolutionCombinationMethod.cs" />97 107 <Compile Include="SolutionPoolUpdateMethod.cs" /> 98 108 </ItemGroup> -
branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/PopulationRebuildMethod.cs
r7724 r7740 30 30 namespace HeuristicLab.Algorithms.ScatterSearch { 31 31 /// <summary> 32 /// An operator that updates apopulation.32 /// An operator that updates the reference set and rebuilds the population. 33 33 /// </summary> 34 [Item("PopulationRebuildMethod", "An operator that rebuilds the population.")]34 [Item("PopulationRebuildMethod", "An operator that updates the reference set and rebuilds the population.")] 35 35 [StorableClass] 36 36 public sealed class PopulationRebuildMethod : SingleSuccessorOperator { 37 37 #region Parameter properties 38 p rivateScopeParameter CurrentScopeParameter {38 public ScopeParameter CurrentScopeParameter { 39 39 get { return (ScopeParameter)Parameters["CurrentScope"]; } 40 40 } 41 p rivateValueLookupParameter<IntValue> NumberOfHighQualitySolutionsParameter {42 get { return ( ValueLookupParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; }41 public IValueLookupParameter<IntValue> NumberOfHighQualitySolutionsParameter { 42 get { return (IValueLookupParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; } 43 43 } 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"]; } 46 49 } 47 50 #endregion … … 59 62 set { ReferenceSetSizeParameter.ActualValue = value; } 60 63 } 64 private IItem Quality { 65 get { return QualityParameter.ActualValue; } 66 } 61 67 #endregion 62 68 … … 72 78 private void Initialize() { 73 79 #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")); 83 84 #endregion 84 85 } 85 86 86 87 public override IOperation Apply() { 87 IScopepopulation = CurrentScope.SubScopes[0];88 IScoperefSet = 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) 90 91 .Take(NumberOfHighQualitySolutions.Value).ToList()); 91 92 population.SubScopes.Clear(); -
branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/ReferenceSetUpdateMethod.cs
r7724 r7740 20 20 #endregion 21 21 22 using System.Collections.Generic; 23 using System.Linq; 22 24 using HeuristicLab.Common; 23 25 using HeuristicLab.Core; 24 26 using HeuristicLab.Data; 25 using HeuristicLab.Encodings.BinaryVectorEncoding;26 27 using HeuristicLab.Operators; 27 28 using HeuristicLab.Parameters; … … 36 37 public sealed class ReferenceSetUpdateMethod : SingleSuccessorOperator { 37 38 #region Parameter properties 38 p rivateScopeParameter CurrentScopeParameter {39 public ScopeParameter CurrentScopeParameter { 39 40 get { return (ScopeParameter)Parameters["CurrentScope"]; } 40 41 } 41 public ValueLookupParameter<IntValue> NumberOfHighQualitySolutionsParameter {42 get { return ( ValueLookupParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; }42 public IValueLookupParameter<IntValue> NumberOfHighQualitySolutionsParameter { 43 get { return (IValueLookupParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; } 43 44 } 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"]; } 46 50 } 47 51 #endregion 48 52 49 53 #region Properties 50 p ublicIScope CurrentScope {54 private IScope CurrentScope { 51 55 get { return CurrentScopeParameter.ActualValue; } 52 56 } 53 p ublicIntValue NumberOfHighQualitySolutions {57 private IntValue NumberOfHighQualitySolutions { 54 58 get { return NumberOfHighQualitySolutionsParameter.ActualValue; } 55 set { NumberOfHighQualitySolutionsParameter.ActualValue = value; }56 59 } 57 p ublicIntValue ReferenceSetSize {60 private IntValue ReferenceSetSize { 58 61 get { return ReferenceSetSizeParameter.ActualValue; } 59 set { ReferenceSetSizeParameter.ActualValue = value; } 62 } 63 private IItem Quality { 64 get { return QualityParameter.ActualValue; } 60 65 } 61 66 #endregion … … 72 77 private void Initialize() { 73 78 #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")); 83 83 #endregion 84 84 } 85 85 86 86 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); 101 94 } 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); 104 100 } 105 101 return base.Apply(); 106 102 } 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 }114 103 } 115 104 } -
branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearch.cs
r7727 r7740 21 21 22 22 using System; 23 using System.Collections.Generic;24 23 using System.Linq; 25 24 using HeuristicLab.Analysis; … … 56 55 57 56 #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"]; } 102 83 } 103 84 #endregion 104 85 105 86 #region Properties 106 p ublicMultiAnalyzer Analyzer {87 private MultiAnalyzer Analyzer { 107 88 get { return AnalyzerParameter.Value; } 108 89 set { AnalyzerParameter.Value = value; } 109 90 } 110 public ILocalImprovementOperator Improver { 91 private ICrossover Crossover { 92 get { return CrossoverParameter.Value; } 93 set { CrossoverParameter.Value = value; } 94 } 95 private ILocalImprovementOperator Improver { 111 96 get { return ImproverParameter.Value; } 112 97 set { ImproverParameter.Value = value; } 113 98 } 114 p ublicIntValue MaximumIterations {99 private IntValue MaximumIterations { 115 100 get { return MaximumIterationsParameter.Value; } 116 101 set { MaximumIterationsParameter.Value = value; } 117 102 } 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 { 131 104 get { return NumberOfHighQualitySolutionsParameter.Value; } 132 105 set { NumberOfHighQualitySolutionsParameter.Value = value; } 133 106 } 134 p ublicIntValue PopulationSize {107 private IntValue PopulationSize { 135 108 get { return PopulationSizeParameter.Value; } 136 109 set { PopulationSizeParameter.Value = value; } 137 110 } 138 p ublicIntValue ReferenceSetSize {111 private IntValue ReferenceSetSize { 139 112 get { return ReferenceSetSizeParameter.Value; } 140 113 set { ReferenceSetSizeParameter.Value = value; } 141 114 } 142 public IntValue SampleSize { 143 get { return SampleSizeParameter.Value; } 144 set { SampleSizeParameter.Value = value; } 145 } 146 public IntValue Seed { 115 private IntValue Seed { 147 116 get { return SeedParameter.Value; } 148 117 set { SeedParameter.Value = value; } 149 118 } 150 p ublicBoolValue SetSeedRandomly {119 private BoolValue SetSeedRandomly { 151 120 get { return SetSeedRandomlyParameter.Value; } 152 121 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); } 153 131 } 154 132 … … 175 153 #region Create parameters 176 154 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.")); 177 156 Parameters.Add(new ValueParameter<ILocalImprovementOperator>("Improver", "The operator used to improve solutions.", new ScatterSearchImprovementOperator())); 178 157 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."));182 158 Parameters.Add(new ValueParameter<IntValue>("NumberOfHighQualitySolutions", "The number of high quality solutions that should be added to the reference set.", new IntValue(5))); 183 159 Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population.", new IntValue(30))); 184 160 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)));186 161 Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0))); 187 162 Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true))); … … 239 214 mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name; 240 215 mainLoop.IterationsParameter.ActualName = "Iterations"; 216 mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name; 241 217 mainLoop.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name; 242 218 mainLoop.NumberOfHighQualitySolutionsParameter.ActualName = NumberOfHighQualitySolutionsParameter.Name; … … 252 228 253 229 public override void Prepare() { 254 if (Problem != null && MoveGenerator != null && MoveMaker != null && MoveEvaluator != null) 255 base.Prepare(); 230 base.Prepare(); 256 231 } 257 232 … … 261 236 ParameterizeStochasticOperator(Problem.Evaluator); 262 237 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(); 266 240 ParameterizeSolutionsCreator(); 267 ParameterizeMainLoop();268 UpdateMoveGenerator();269 UpdateMoveParameters();270 241 UpdateAnalyzers(); 271 ParameterizeMoveGenerators(); 272 ParameterizeMoveEvaluators(); 273 ParameterizeMoveMakers(); 274 ParameterizeAnalyzers(); 275 ParameterizeIterationBasedOperators(); 242 UpdateCrossovers(); 276 243 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 277 244 base.OnProblemChanged(); … … 286 253 ParameterizeSolutionsCreator(); 287 254 ParameterizeMainLoop(); 288 ParameterizeMoveEvaluators();289 ParameterizeMoveMakers();290 255 ParameterizeAnalyzers(); 291 256 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); … … 294 259 protected override void Problem_OperatorsChanged(object sender, EventArgs e) { 295 260 foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op); 296 // This may seem pointless, but some operators already have the eventhandler registered, others don't297 // 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();304 261 UpdateAnalyzers(); 262 UpdateCrossovers(); 305 263 ParameterizeMainLoop(); 306 ParameterizeMoveGenerators(); 307 ParameterizeMoveEvaluators(); 308 ParameterizeMoveMakers(); 309 ParameterizeAnalyzers(); 310 ParameterizeIterationBasedOperators(); 264 ParameterizeAnalyzers(); 311 265 base.Problem_OperatorsChanged(sender, e); 312 266 } 313 267 private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) { 314 268 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(); 331 270 } 332 271 #endregion … … 336 275 if (Problem != null) { 337 276 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;398 277 } 399 278 } … … 409 288 Analyzer.Operators.Add(qualityAnalyzer, qualityAnalyzer.EnabledByDefault); 410 289 } 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; 414 308 } 415 309 private void ParameterizeSolutionsCreator() { … … 423 317 MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 424 318 } 425 if (MoveEvaluator != null)426 MainLoop.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;427 319 } 428 320 private void ParameterizeStochasticOperator(IOperator op) { … … 431 323 stOp.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName; 432 324 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 }459 325 } 460 326 } … … 465 331 qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 466 332 qualityAnalyzer.MaximizationParameter.Hidden = true; 467 if (MoveEvaluator != null) { 468 qualityAnalyzer.QualityParameter.Hidden = true; 469 } else qualityAnalyzer.QualityParameter.Hidden = false; 333 qualityAnalyzer.QualityParameter.Hidden = false; 470 334 qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name; 471 335 qualityAnalyzer.BestKnownQualityParameter.Hidden = true; … … 473 337 qualityAnalyzer.MaximizationParameter.Hidden = false; 474 338 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 }485 339 } 486 340 } -
branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearchImprovementOperator.cs
r7727 r7740 79 79 80 80 #region Properties 81 p ublicIScope CurrentScope {81 private IScope CurrentScope { 82 82 get { return CurrentScopeParameter.ActualValue; } 83 83 } 84 p ublicIntArray Values {84 private IntArray Values { 85 85 get { return ValuesParameter.ActualValue; } 86 86 set { ValuesParameter.ActualValue = value; } 87 87 } 88 p ublicIntArray Weights {88 private IntArray Weights { 89 89 get { return WeightsParameter.ActualValue; } 90 90 set { WeightsParameter.ActualValue = value; } 91 91 } 92 p ublicIntValue KnapsackCapacity {92 private IntValue KnapsackCapacity { 93 93 get { return KnapsackCapacityParameter.ActualValue; } 94 94 set { KnapsackCapacityParameter.ActualValue = value; } … … 104 104 public ScatterSearchImprovementOperator() 105 105 : 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 110 112 } 111 113 -
branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearchMainLoop.cs
r7727 r7740 37 37 public sealed class ScatterSearchMainLoop : AlgorithmOperator { 38 38 #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"]; } 92 86 } 93 87 #endregion 94 88 95 89 #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 { 97 139 get { return RandomParameter.ActualValue; } 98 140 set { RandomParameter.ActualValue = value; } 99 141 } 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 { 113 147 get { return SampleSizeParameter.ActualValue; } 114 148 set { SampleSizeParameter.ActualValue = value; } 115 149 } 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; } 167 153 } 168 154 #endregion … … 179 165 private void Initialize() { 180 166 #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.")); 200 183 #endregion 201 184 … … 208 191 ConditionalBranch terminateBranch = new ConditionalBranch(); 209 192 IntCounter interationsCounter = new IntCounter(); 193 OffspringProcessor offspringProcessor = new OffspringProcessor(); 210 194 Placeholder analyzer = new Placeholder(); 195 Placeholder crossover = new Placeholder(); 211 196 Placeholder solutionEvaluator1 = new Placeholder(); 212 197 Placeholder solutionEvaluator2 = new Placeholder(); … … 216 201 ResultsCollector resultsCollector = new ResultsCollector(); 217 202 ReferenceSetUpdateMethod referenceSetUpdateMethod = new ReferenceSetUpdateMethod(); 218 SolutionCombinationMethod solutionCombinationMethod = new SolutionCombinationMethod();219 203 SolutionPoolUpdateMethod solutionPoolUpdateMethod = new SolutionPoolUpdateMethod(); 220 204 SolutionsCreator solutionsCreator = new SolutionsCreator(); … … 275 259 interationsCounter.Successor = resultsCollector; 276 260 261 offspringProcessor.Successor = subScopesProcessor2; 262 277 263 analyzer.Name = "Analyzer"; 278 264 analyzer.OperatorParameter.ActualName = "Analyzer"; 265 266 crossover.Name = "Crossover"; 267 crossover.OperatorParameter.ActualName = "Crossover"; 268 crossover.Successor = offspringProcessor; 279 269 280 270 solutionImprover1.Name = "SolutionImprover"; … … 296 286 referenceSetUpdateMethod.Successor = assigner1; 297 287 298 solutionCombinationMethod.Successor = subScopesProcessor2;299 300 288 solutionPoolUpdateMethod.Successor = analyzer; 301 289 … … 321 309 322 310 uniformSubScopesProcessor1.DepthParameter.Value = new IntValue(1); 323 uniformSubScopesProcessor1.Operator = solutionCombinationMethod;311 uniformSubScopesProcessor1.Operator = crossover; 324 312 uniformSubScopesProcessor1.Successor = solutionPoolUpdateMethod; 325 313 … … 335 323 336 324 public override IOperation Apply() { 337 if (MoveGeneratorParameter.ActualValue == null || MoveEvaluatorParameter.ActualValue == null || MoveMakerParameter.ActualValue == null)338 return null;339 325 return base.Apply(); 340 326 } -
branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/SolutionPoolUpdateMethod.cs
r7724 r7740 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 22 24 using System.Linq; 23 25 using HeuristicLab.Common; … … 36 38 public sealed class SolutionPoolUpdateMethod : SingleSuccessorOperator { 37 39 #region Parameter properties 38 p rivateScopeParameter CurrentScopeParameter {40 public ScopeParameter CurrentScopeParameter { 39 41 get { return (ScopeParameter)Parameters["CurrentScope"]; } 40 42 } 41 p rivateValueLookupParameter<BoolValue> NewSolutionsParameter {42 get { return ( ValueLookupParameter<BoolValue>)Parameters["NewSolutions"]; }43 public IValueLookupParameter<BoolValue> NewSolutionsParameter { 44 get { return (IValueLookupParameter<BoolValue>)Parameters["NewSolutions"]; } 43 45 } 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"]; } 46 54 } 47 55 #endregion … … 58 66 set { ReferenceSetSizeParameter.ActualValue = value; } 59 67 } 68 private IItem Quality { 69 get { return QualityParameter.ActualValue; } 70 } 60 71 #endregion 61 72 … … 71 82 private void Initialize() { 72 83 #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")); 76 89 #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 83 91 } 84 92 … … 91 99 } 92 100 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).Value95 > (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)); 97 105 NewSolutions.Value = true; 98 106 } 107 99 108 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 } 100 125 } 101 126 }
Note: See TracChangeset
for help on using the changeset viewer.