- Timestamp:
- 06/22/12 11:11:38 (12 years ago)
- Location:
- branches/ScatterSearch (trunk integration)
- Files:
-
- 1 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ScatterSearch (trunk integration)
- Property svn:ignore
-
old new 20 20 bin 21 21 protoc.exe 22 _ReSharper.HeuristicLab 3.3 Tests
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/HeuristicLab.Algorithms.ScatterSearch-3.3.csproj
r7789 r8086 58 58 <Private>False</Private> 59 59 </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>69 60 <Reference Include="HeuristicLab.Operators-3.3"> 70 61 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Operators-3.3.dll</HintPath> 71 62 <Private>False</Private> 72 63 </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" /> 77 66 <Reference Include="HeuristicLab.Parameters-3.3"> 78 67 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Parameters-3.3.dll</HintPath> … … 84 73 </Reference> 85 74 <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">95 75 <Private>False</Private> 96 76 </Reference> … … 112 92 <ItemGroup> 113 93 <Compile Include="IScatterSearchOperator.cs" /> 114 <Compile Include="SolutionPool2TierUpdateMethod.cs" />115 94 <Compile Include="OffspringProcessor.cs" /> 116 95 <None Include="HeuristicLab.snk" /> … … 124 103 <Compile Include="ScatterSearchMainLoop.cs" /> 125 104 <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>134 105 </ItemGroup> 135 106 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -
branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/IScatterSearchOperator.cs
r7789 r8086 20 20 #endregion 21 21 22 using System;23 using HeuristicLab.Common;24 22 using HeuristicLab.Core; 25 23 … … 28 26 /// An interface which represents a scatter search specific operator. 29 27 /// </summary> 30 public interface IScatterSearchOperator : IOperator, IParameterizedNamedItem, IDeepCloneable, ICloneable { 31 } 28 public interface IScatterSearchOperator : IOperator { } 32 29 } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/OffspringProcessor.cs
r7789 r8086 57 57 : base() { 58 58 #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.")); 61 61 #endregion 62 62 } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/Plugin.cs.frame
r7789 r8086 33 33 [PluginDependency("HeuristicLab.Core", "3.3")] 34 34 [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")]38 35 [PluginDependency("HeuristicLab.Operators", "3.3")] 39 36 [PluginDependency("HeuristicLab.Optimization", "3.3")] … … 41 38 [PluginDependency("HeuristicLab.Parameters", "3.3")] 42 39 [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")]46 40 [PluginDependency("HeuristicLab.Random", "3.3")] 47 41 [PluginDependency("HeuristicLab.Selection", "3.3")] -
branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/PopulationRebuildMethod.cs
r7789 r8086 80 80 : base() { 81 81 #region Create parameters 82 Parameters.Add(new ScopeParameter("CurrentScope" ));83 Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization" ));84 Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfHighQualitySolutions" ));85 Parameters.Add(new ValueLookupParameter<IItem>("Quality" ));86 Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize" ));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.")); 87 87 #endregion 88 88 } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/ReferenceSetUpdateMethod.cs
r7789 r8086 26 26 using HeuristicLab.Data; 27 27 using HeuristicLab.Operators; 28 using HeuristicLab.Optimization; 28 29 using HeuristicLab.Optimization.Operators; 29 30 using HeuristicLab.Parameters; … … 36 37 [Item("ReferenceSetUpdateMethod", "An operator that updates the reference set.")] 37 38 [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 39 44 #region Parameter properties 40 45 public ScopeParameter CurrentScopeParameter { … … 43 48 public IValueLookupParameter<IntValue> ReferenceSetSizeParameter { 44 49 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"]; }51 50 } 52 51 #endregion … … 59 58 get { return ReferenceSetSizeParameter.ActualValue; } 60 59 } 61 private SimilarityCalculator SimilarityCalculator {62 get { return SimilarityCalculatorParameter.ActualValue; }63 }64 private IItem Target {65 get { return TargetParameter.ActualValue; }66 }67 60 #endregion 68 61 … … 73 66 : base() { 74 67 #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.")); 79 70 #endregion 80 71 } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearch.cs
r7954 r8086 174 174 : base() { 175 175 #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.")); 188 188 #endregion 189 189 … … 194 194 Placeholder solutionEvaluator = new Placeholder(); 195 195 Placeholder solutionImprover = new Placeholder(); 196 SubScopesCounter subScopesCounter = new SubScopesCounter(); 196 VariableCreator variableCreator = new VariableCreator(); 197 DataReducer dataReducer = new DataReducer(); 197 198 ResultsCollector resultsCollector = new ResultsCollector(); 198 199 BestSelector bestSelector = new BestSelector(); … … 212 213 213 214 uniformSubScopesProcessor.Operator = solutionImprover; 214 uniformSubScopesProcessor.Successor = subScopesCounter;215 uniformSubScopesProcessor.Successor = variableCreator; 215 216 216 217 solutionImprover.Name = "SolutionImprover"; … … 222 223 solutionEvaluator.Successor = null; 223 224 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; 227 235 228 236 resultsCollector.Name = "ResultsCollector"; … … 239 247 mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name; 240 248 mainLoop.IterationsParameter.ActualName = "Iterations"; 249 mainLoop.EvaluatedSolutionsParameter.ActualName = "EvaluatedSolutions"; 241 250 mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name; 242 251 mainLoop.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name; … … 261 270 ParameterizeStochasticOperator(Problem.SolutionCreator); 262 271 ParameterizeStochasticOperator(Problem.Evaluator); 263 foreach (IOperator op in Problem.Operators ) ParameterizeStochasticOperator(op);272 foreach (IOperator op in Problem.Operators.OfType<IOperator>()) ParameterizeStochasticOperator(op); 264 273 ParameterizeAnalyzers(); 265 274 ParameterizeSolutionsCreator(); … … 289 298 } 290 299 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); 292 301 UpdateAnalyzers(); 293 302 UpdateCrossovers(); … … 376 385 ISimilarityCalculator defaultDiversityCalculator = Problem.Operators.OfType<ISimilarityCalculator>().FirstOrDefault(); 377 386 378 foreach (ISimilarityCalculator diversityCalculator in Problem.Operators.OfType<ISimilarityCalculator>() .OrderBy(x => x.Name))387 foreach (ISimilarityCalculator diversityCalculator in Problem.Operators.OfType<ISimilarityCalculator>()) 379 388 SimilarityCalculatorParameter.ValidValues.Add(diversityCalculator); 380 389 … … 401 410 MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 402 411 MainLoop.TargetParameter.ActualName = Improver.TargetParameter.ActualName; 403 foreach (var itemin MainLoop.OperatorGraph.Operators.OfType<IScatterSearchOperator>()) {412 foreach (var op in MainLoop.OperatorGraph.Operators.OfType<IScatterSearchOperator>()) { 404 413 // 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"); 406 415 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"); 409 418 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; 411 420 } 421 foreach (ISimilarityBasedOperator op in MainLoop.OperatorGraph.Operators.OfType<ISimilarityBasedOperator>()) 422 op.SimilarityCalculator = SimilarityCalculator; 412 423 } 413 424 } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearchMainLoop.cs
r7954 r8086 92 92 get { return (IValueLookupParameter<ISimilarityCalculator>)Parameters["SimilarityCalculator"]; } 93 93 } 94 public IValueLookupParameter<ISolutionCreator> SolutionCreatorParameter {95 get { return (IValueLookupParameter<ISolutionCreator>)Parameters["SolutionCreator"]; }96 }97 94 public IValueLookupParameter<IItem> TargetParameter { 98 95 get { return (IValueLookupParameter<IItem>)Parameters["Target"]; } … … 173 170 set { SimilarityCalculatorParameter.ActualValue = value; } 174 171 } 175 private ISolutionCreator SolutionCreator {176 get { return SolutionCreatorParameter.ActualValue; }177 set { SolutionCreatorParameter.ActualValue = value; }178 }179 172 private IItem Target { 180 173 get { return TargetParameter.ActualValue; } … … 194 187 private void Initialize() { 195 188 #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.")); 216 208 #endregion 217 209 … … 239 231 SolutionPoolUpdateMethod solutionPoolUpdateMethod = new SolutionPoolUpdateMethod(); 240 232 SolutionsCreator solutionsCreator = new SolutionsCreator(); 241 SubScopesCounter subScopesCounter1 = new SubScopesCounter();242 SubScopesCounter subScopesCounter2 = new SubScopesCounter();233 DataReducer dataReducer1 = new DataReducer(); 234 DataReducer dataReducer2 = new DataReducer(); 243 235 SubScopesProcessor subScopesProcessor1 = new SubScopesProcessor(); 244 236 SubScopesProcessor subScopesProcessor2 = new SubScopesProcessor(); 245 237 SubScopesProcessor subScopesProcessor3 = new SubScopesProcessor(); 238 SubScopesProcessor subScopesProcessor4 = new SubScopesProcessor(); 246 239 ConditionalBranch terminateBranch = new ConditionalBranch(); 247 240 UniformSubScopesProcessor uniformSubScopesProcessor1 = new UniformSubScopesProcessor(); … … 253 246 #region Create operator graph 254 247 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))); 256 249 variableCreator.CollectedValues.Add(new ValueParameter<BoolValue>("NewSolutions", new BoolValue(false))); 257 250 variableCreator.Successor = resultsCollector; … … 264 257 iterationsChecker.Name = "IterationsChecker"; 265 258 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; 268 261 iterationsChecker.ResultParameter.ActualName = "Terminate"; 269 262 iterationsChecker.Successor = terminateBranch; … … 273 266 terminateBranch.FalseBranch = referenceSetUpdateMethod; 274 267 275 referenceSetUpdateMethod.TargetParameter.ActualName = TargetParameter.ActualName;276 268 referenceSetUpdateMethod.Successor = assigner1; 277 269 … … 305 297 306 298 pathRelinker.Name = "PathRelinker"; 307 pathRelinker.OperatorParameter.ActualName = "PathRelinker";299 pathRelinker.OperatorParameter.ActualName = PathRelinkerParameter.Name; 308 300 pathRelinker.Successor = offspringProcessor; 309 301 310 302 crossover.Name = "Crossover"; 311 crossover.OperatorParameter.ActualName = "Crossover";303 crossover.OperatorParameter.ActualName = CrossoverParameter.Name; 312 304 crossover.Successor = offspringProcessor; 313 305 … … 326 318 uniformSubScopesProcessor2.DepthParameter.Value = new IntValue(2); 327 319 uniformSubScopesProcessor2.Operator = solutionImprover1; 328 uniformSubScopesProcessor2.Successor = subScopes Counter1;320 uniformSubScopesProcessor2.Successor = subScopesProcessor4; 329 321 330 322 solutionImprover1.Name = "SolutionImprover"; 331 solutionImprover1.OperatorParameter.ActualName = "Improver";323 solutionImprover1.OperatorParameter.ActualName = ImproverParameter.Name; 332 324 solutionImprover1.Successor = solutionEvaluator1; 333 325 334 326 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); 339 336 340 337 solutionPoolUpdateMethod.QualityParameter.ActualName = QualityParameter.ActualName; 341 solutionPoolUpdateMethod.TargetParameter.ActualName = TargetParameter.ActualName;342 338 solutionPoolUpdateMethod.Successor = analyzer; 343 339 344 340 analyzer.Name = "Analyzer"; 345 analyzer.OperatorParameter.ActualName = "Analyzer";341 analyzer.OperatorParameter.ActualName = AnalyzerParameter.Name; 346 342 347 343 newSolutionsBranch.Name = "NewSolutionsChecker"; … … 359 355 360 356 solutionsCreator.Name = "DiversificationGenerationMethod"; 361 solutionsCreator.NumberOfSolutionsParameter.ActualName = "PopulationSize";357 solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name; 362 358 solutionsCreator.Successor = uniformSubScopesProcessor3; 363 359 364 360 uniformSubScopesProcessor3.DepthParameter.Value = new IntValue(1); 365 361 uniformSubScopesProcessor3.Operator = solutionImprover2; 366 uniformSubScopesProcessor3.Successor = subScopesCounter2;362 uniformSubScopesProcessor3.Successor = dataReducer2; 367 363 368 364 solutionImprover2.Name = "SolutionImprover"; 369 solutionImprover2.OperatorParameter.ActualName = "Improver";365 solutionImprover2.OperatorParameter.ActualName = ImproverParameter.Name; 370 366 solutionImprover2.Successor = solutionEvaluator2; 371 367 372 368 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); 377 376 378 377 iterationsCounter.Name = "IterationCounter"; 379 378 iterationsCounter.IncrementParameter.Value = new IntValue(1); 380 iterationsCounter.ValueParameter.ActualName = "Iterations";379 iterationsCounter.ValueParameter.ActualName = IterationsParameter.Name; 381 380 iterationsCounter.Successor = resultsCollector; 382 381 #endregion -
branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/SolutionPoolUpdateMethod.cs
r7789 r8086 27 27 using HeuristicLab.Data; 28 28 using HeuristicLab.Operators; 29 using HeuristicLab.Optimization; 29 30 using HeuristicLab.Optimization.Operators; 30 31 using HeuristicLab.Parameters; … … 37 38 [Item("SolutionPoolUpdateMethod", "An operator that updates the solution pool.")] 38 39 [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 40 45 #region Parameter properties 41 46 public ScopeParameter CurrentScopeParameter { … … 53 58 public IValueLookupParameter<IntValue> ReferenceSetSizeParameter { 54 59 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"]; }61 60 } 62 61 #endregion … … 80 79 set { ReferenceSetSizeParameter.ActualValue = value; } 81 80 } 82 private SimilarityCalculator SimilarityCalculator {83 get { return SimilarityCalculatorParameter.ActualValue; }84 }85 private IItem Target {86 get { return TargetParameter.ActualValue; }87 }88 81 #endregion 89 82 … … 99 92 private void Initialize() { 100 93 #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.")); 108 99 #endregion 109 100 } 110 101 111 102 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(); 114 105 115 106 // split parents and offspring 116 107 foreach (var scope in CurrentScope.SubScopes) { 117 parents Scope.SubScopes.AddRange(scope.SubScopes.Take(scope.SubScopes.Count - 1));118 offspring Scope.SubScopes.AddRange(scope.SubScopes.Last().SubScopes);108 parents.AddRange(scope.SubScopes.Take(scope.SubScopes.Count - 1)); 109 offspring.AddRange(scope.SubScopes.Last().SubScopes); 119 110 } 120 111 121 112 CurrentScope.SubScopes.Clear(); 122 113 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); 127 121 128 122 CurrentScope.SubScopes.AddRange(orderedParents); … … 136 130 if (orderedOffspring.Any(hasBetterQuality)) { 137 131 // 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}139 132 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()) { 141 134 var orderedUnion = Maximization.Value ? union.OrderByDescending(x => x.Variables[QualityParameter.ActualName].Value) : 142 135 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)); 144 137 NewSolutions.Value = true; 145 138 } … … 149 142 } 150 143 151 p rivateclass 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; 153 146 154 public SolutionEqualityComparer(Func<T, T, double> diversityCalculator) {155 this. diversityCalculator = diversityCalculator;147 public SolutionEqualityComparer(Func<T, T, double> similarityCalculator) { 148 this.similarityCalculator = similarityCalculator; 156 149 } 157 150 158 151 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; 160 155 } 161 156 162 157 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 164 159 } 165 160 }
Note: See TracChangeset
for help on using the changeset viewer.