- Timestamp:
- 11/05/15 16:20:55 (9 years ago)
- Location:
- branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3
- Files:
-
- 1 added
- 6 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithm.cs
r13117 r13124 114 114 get { return (IValueParameter<IntValue>)Parameters["MatingPoolRange"]; } 115 115 } 116 private IValueParameter<BoolValue> ReduceToPopulationSizeParameter { 117 get { return (IValueParameter<BoolValue>)Parameters["ReduceToPopulationSize"]; } 118 } 116 119 117 120 private IValueParameter<MultiTerminator> TerminatorParameter { … … 290 293 Parameters.Add(new ValueParameter<IntValue>("AgeGap", "The frequency of reseeding the lowest layer and scaling factor for the age-limits for the layers", new IntValue(20))); 291 294 Parameters.Add(new ValueParameter<DoubleValue>("AgeInheritance", "A weight that determines the age of a child after crossover based on the older (1.0) and younger (0.0) parent.", new DoubleValue(1.0)) { Hidden = true }); 292 Parameters.Add(new ValueParameter<IntArray>("AgeLimits", new IntArray(new int[0])) { Hidden = true });295 Parameters.Add(new ValueParameter<IntArray>("AgeLimits", "The maximum ages for the Layers.", new IntArray(new int[0])) { Hidden = true }); 293 296 294 297 Parameters.Add(new ValueParameter<IntValue>("MatingPoolRange", "The range of layers used for creating a mating pool. (1 = current + previous layer)", new IntValue(1)) { Hidden = true }); … … 357 360 resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Solutions", null, "EvaluatedSolutions")); 358 361 resultsCollector.Successor = mainLoop; 362 363 mainLoop.GlobalRandomParameter.ActualName = "GlobalRandom"; 364 mainLoop.LocalRandomParameter.ActualName = "LocalRandom"; 365 mainLoop.EvaluatedSolutionsParameter.ActualName = "EvaluatedSolutions"; 366 mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name; 367 mainLoop.LayerAnalyzerParameter.ActualName = LayerAnalyzerParameter.Name; 368 mainLoop.NumberOfLayersParameter.ActualName = NumberOfLayersParameter.Name; 369 mainLoop.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name; 370 mainLoop.CurrentPopulationSizeParameter.ActualName = "CurrentPopulationSize"; 371 mainLoop.SelectorParameter.ActualName = SelectorParameter.Name; 372 mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name; 373 mainLoop.MutatorParameter.ActualName = MutatorParameter.Name; 374 mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name; 375 mainLoop.ElitesParameter.ActualName = ElitesParameter.Name; 376 mainLoop.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name; 377 mainLoop.PlusSelectionParameter.ActualName = PlusSelectionParameter.Name; 378 mainLoop.AgeParameter.ActualName = "Age"; 379 mainLoop.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name; 380 mainLoop.AgeLimitsParameter.ActualName = AgeLimitsParameter.Name; 381 mainLoop.MatingPoolRangeParameter.ActualName = MatingPoolRangeParameter.Name; 382 mainLoop.ReduceToPopulationSizeParameter.ActualName = ReduceToPopulationSizeParameter.Name; 359 383 #endregion 360 384 … … 364 388 var defaultSelector = SelectorParameter.ValidValues.OfType<GeneralizedRankSelector>().FirstOrDefault(); 365 389 if (defaultSelector != null) { 366 defaultSelector.PressureParameter.Value = new DoubleValue(4 );390 defaultSelector.PressureParameter.Value = new DoubleValue(4.0); 367 391 SelectorParameter.Value = defaultSelector; 368 392 } … … 546 570 } 547 571 private void ParameterizeMainLoop() { 572 MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name; 573 MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 548 574 MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 549 MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;550 MainLoop.MainOperator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;551 MainLoop.MainOperator.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;552 MainLoop.MainOperator.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;553 575 } 554 576 private void ParameterizeAnalyzers() { -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithmMainLoop.cs
r13117 r13124 20 20 #endregion 21 21 22 using System.Linq;23 using HeuristicLab.Algorithms.GeneticAlgorithm;24 22 using HeuristicLab.Common; 25 23 using HeuristicLab.Core; … … 38 36 public sealed class AlpsGeneticAlgorithmMainLoop : AlgorithmOperator { 39 37 #region Parameter Properties 40 public ValueLookupParameter<BoolValue> MaximizationParameter { 41 get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; } 42 } 43 public ScopeTreeLookupParameter<DoubleValue> QualityParameter { 44 get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 45 } 38 public IValueLookupParameter<IRandom> GlobalRandomParameter { 39 get { return (IValueLookupParameter<IRandom>)Parameters["GlobalRandom"]; } 40 } 41 public IValueLookupParameter<IRandom> LocalRandomParameter { 42 get { return (IValueLookupParameter<IRandom>)Parameters["LocalRandom"]; } 43 } 44 45 public IValueLookupParameter<IOperator> EvaluatorParameter { 46 get { return (IValueLookupParameter<IOperator>)Parameters["Evaluator"]; } 47 } 48 public IValueLookupParameter<IntValue> EvaluatedSolutionsParameter { 49 get { return (IValueLookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; } 50 } 51 public IScopeTreeLookupParameter<DoubleValue> QualityParameter { 52 get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 53 } 54 public IValueLookupParameter<BoolValue> MaximizationParameter { 55 get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; } 56 } 57 46 58 public ILookupParameter<IOperator> AnalyzerParameter { 47 59 get { return (ILookupParameter<IOperator>)Parameters["Analyzer"]; } … … 50 62 get { return (ILookupParameter<IOperator>)Parameters["LayerAnalyzer"]; } 51 63 } 64 65 public IValueLookupParameter<IntValue> NumberOfLayersParameter { 66 get { return (IValueLookupParameter<IntValue>)Parameters["NumberOfLayers"]; } 67 } 68 public IValueLookupParameter<IntValue> PopulationSizeParameter { 69 get { return (IValueLookupParameter<IntValue>)Parameters["PopulationSize"]; } 70 } 71 public ILookupParameter<IntValue> CurrentPopulationSizeParameter { 72 get { return (ILookupParameter<IntValue>)Parameters["CurrentPopulationSize"]; } 73 } 74 75 public IValueLookupParameter<IOperator> SelectorParameter { 76 get { return (IValueLookupParameter<IOperator>)Parameters["Selector"]; } 77 } 78 public IValueLookupParameter<IOperator> CrossoverParameter { 79 get { return (IValueLookupParameter<IOperator>)Parameters["Crossover"]; } 80 } 81 public IValueLookupParameter<IOperator> MutatorParameter { 82 get { return (IValueLookupParameter<IOperator>)Parameters["Mutator"]; } 83 } 84 public IValueLookupParameter<PercentValue> MutationProbabilityParameter { 85 get { return (IValueLookupParameter<PercentValue>)Parameters["MutationProbability"]; } 86 } 87 public IValueLookupParameter<IntValue> ElitesParameter { 88 get { return (IValueLookupParameter<IntValue>)Parameters["Elites"]; } 89 } 90 public IValueLookupParameter<BoolValue> ReevaluateElitesParameter { 91 get { return (IValueLookupParameter<BoolValue>)Parameters["ReevaluateElites"]; } 92 } 93 public IValueLookupParameter<BoolValue> PlusSelectionParameter { 94 get { return (IValueLookupParameter<BoolValue>)Parameters["PlusSelection"]; } 95 } 96 97 public IScopeTreeLookupParameter<DoubleValue> AgeParameter { 98 get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Age"]; } 99 } 100 public IValueLookupParameter<DoubleValue> AgeInheritanceParameter { 101 get { return (IValueLookupParameter<DoubleValue>)Parameters["AgeInheritance"]; } 102 } 103 public IValueLookupParameter<IntArray> AgeLimitsParameter { 104 get { return (IValueLookupParameter<IntArray>)Parameters["AgeLimits"]; } 105 } 106 107 public IValueLookupParameter<IntValue> MatingPoolRangeParameter { 108 get { return (IValueLookupParameter<IntValue>)Parameters["MatingPoolRange"]; } 109 } 110 public IValueLookupParameter<BoolValue> ReduceToPopulationSizeParameter { 111 get { return (IValueLookupParameter<BoolValue>)Parameters["ReduceToPopulationSize"]; } 112 } 52 113 #endregion 53 54 public GeneticAlgorithmMainLoop MainOperator {55 get { return OperatorGraph.Iterate().OfType<GeneticAlgorithmMainLoop>().First(); }56 }57 114 58 115 [StorableConstructor] … … 66 123 public AlpsGeneticAlgorithmMainLoop() 67 124 : base() { 68 Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false.") { Hidden = true }); 125 Parameters.Add(new ValueLookupParameter<IRandom>("GlobalRandom", "A pseudo random number generator.")); 126 Parameters.Add(new ValueLookupParameter<IRandom>("LocalRandom", "A pseudo random number generator.")); 127 128 Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions. This operator is executed in parallel, if an engine is used which supports parallelization.")); 129 Parameters.Add(new ValueLookupParameter<IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated.")); 69 130 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution.")); 70 Parameters.Add(new LookupParameter<IntValue>("MaximumGenerations", "The maximum number of generations that the algorithm should process.")); 71 Parameters.Add(new LookupParameter<IOperator>("Analyzer", "The operator used to the analyze all individuals.")); 72 Parameters.Add(new LookupParameter<IOperator>("LayerAnalyzer", "The operator used to analyze each layer.")); 131 Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false.")); 132 133 Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze the islands.")); 134 Parameters.Add(new ValueLookupParameter<IOperator>("LayerAnalyzer", "The operator used to analyze each layer.")); 135 136 Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfLayers", "The number of layers.")); 137 Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population.")); 138 Parameters.Add(new LookupParameter<IntValue>("CurrentPopulationSize", "The current size of the population.")); 139 140 Parameters.Add(new ValueLookupParameter<IOperator>("Selector", "The operator used to select solutions for reproduction.")); 141 Parameters.Add(new ValueLookupParameter<IOperator>("Crossover", "The operator used to cross solutions.")); 142 Parameters.Add(new ValueLookupParameter<IOperator>("Mutator", "The operator used to mutate solutions.")); 143 Parameters.Add(new ValueLookupParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.")); 144 Parameters.Add(new ValueLookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.")); 145 Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)")); 146 Parameters.Add(new ValueLookupParameter<BoolValue>("PlusSelection", "Include the parents in the selection of the invividuals for the next generation.")); 147 148 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Age", "The age of individuals.")); 149 Parameters.Add(new ValueLookupParameter<DoubleValue>("AgeInheritance", "A weight that determines the age of a child after crossover based on the older (1.0) and younger (0.0) parent.")); 150 Parameters.Add(new ValueLookupParameter<IntArray>("AgeLimits", "The maximum ages for the Layers.")); 151 152 Parameters.Add(new ValueLookupParameter<IntValue>("MatingPoolRange", "The range of sub - populations used for creating a mating pool. (1 = current + previous sub-population)")); 153 Parameters.Add(new ValueLookupParameter<BoolValue>("ReduceToPopulationSize", "Reduce the LayerPopulationSize after elder migration to PopulationSize")); 154 73 155 74 156 var variableCreator = new VariableCreator() { Name = "Initialize" }; … … 81 163 var matingPoolProcessor = new UniformSubScopesProcessor() { Name = "Process Mating Pools" }; 82 164 var initializeLayer = new Assigner() { Name = "Reset LayerEvaluatedSolutions" }; 83 var mainOperator = AlpsGeneticAlgorithmMainOperator.Create();165 var mainOperator = new AlpsGeneticAlgorithmMainOperator(); 84 166 var generationsIcrementor = new IntCounter() { Name = "Increment Generations" }; 85 167 var evaluatedSolutionsReducer = new DataReducer() { Name = "Increment EvaluatedSolutions" }; … … 112 194 113 195 resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Generations")); 114 resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("LayerResults", "Result set for each layer", "LayerResults"));196 resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("LayerResults", "Result set for each Layer", "LayerResults")); 115 197 resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("OpenLayers")); 116 198 resultsCollector.CopyValue = new BoolValue(false); 117 199 resultsCollector.Successor = matingPoolCreator; 118 200 201 matingPoolCreator.MatingPoolRangeParameter.Value = null; 202 matingPoolCreator.MatingPoolRangeParameter.ActualName = MatingPoolRangeParameter.Name; 119 203 matingPoolCreator.Successor = matingPoolProcessor; 120 204 … … 127 211 initializeLayer.Successor = mainOperator; 128 212 213 mainOperator.RandomParameter.ActualName = LocalRandomParameter.Name; 214 mainOperator.EvaluatorParameter.ActualName = EvaluatorParameter.Name; 215 mainOperator.EvaluatedSolutionsParameter.ActualName = "LayerEvaluatedSolutions"; 216 mainOperator.QualityParameter.ActualName = QualityParameter.Name; 217 mainOperator.MaximizationParameter.ActualName = MaximizationParameter.Name; 218 mainOperator.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name; 219 mainOperator.SelectorParameter.ActualName = SelectorParameter.Name; 220 mainOperator.CrossoverParameter.ActualName = CrossoverParameter.Name; 221 mainOperator.MutatorParameter.ActualName = MutatorParameter.ActualName; 222 mainOperator.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name; 223 mainOperator.ElitesParameter.ActualName = ElitesParameter.Name; 224 mainOperator.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name; 225 mainOperator.PlusSelectionParameter.ActualName = PlusSelectionParameter.Name; 226 mainOperator.AgeParameter.ActualName = AgeParameter.Name; 227 mainOperator.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name; 228 mainOperator.AgeIncrementParameter.Value = new DoubleValue(1.0); 229 mainOperator.Successor = null; 230 129 231 generationsIcrementor.ValueParameter.ActualName = "Generations"; 130 232 generationsIcrementor.Increment = new IntValue(1); … … 132 234 133 235 evaluatedSolutionsReducer.ParameterToReduce.ActualName = "LayerEvaluatedSolutions"; 134 evaluatedSolutionsReducer.TargetParameter.ActualName = "EvaluatedSolutions";236 evaluatedSolutionsReducer.TargetParameter.ActualName = EvaluatedSolutionsParameter.Name; 135 237 evaluatedSolutionsReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum); 136 238 evaluatedSolutionsReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Sum); … … 154 256 } 155 257 156 private staticCombinedOperator CreateEldersEmigrator() {258 private CombinedOperator CreateEldersEmigrator() { 157 259 var eldersEmigrator = new CombinedOperator() { Name = "Emigrate Elders" }; 158 260 var selectorProsessor = new UniformSubScopesProcessor(); … … 163 265 var subScopesCounter = new SubScopesCounter(); 164 266 var reduceToPopulationSizeBranch = new ConditionalBranch() { Name = "ReduceToPopulationSize?" }; 165 var countCalculator = new ExpressionCalculator() { Name = " LayerPopulationSize = Min(LayerPopulationSize, PopulationSize)" };267 var countCalculator = new ExpressionCalculator() { Name = "CurrentPopulationSize = Min(CurrentPopulationSize, PopulationSize)" }; 166 268 var bestSelector = new BestSelector(); 167 269 var rightReducer = new RightReducer(); … … 179 281 mergingReducer.Successor = subScopesCounter; 180 282 181 subScopesCounter.ValueParameter.ActualName = "LayerPopulationSize";283 subScopesCounter.ValueParameter.ActualName = CurrentPopulationSizeParameter.Name; 182 284 subScopesCounter.AccumulateParameter.Value = new BoolValue(false); 183 285 subScopesCounter.Successor = reduceToPopulationSizeBranch; 184 286 185 reduceToPopulationSizeBranch.ConditionParameter.ActualName = "ReduceToPopulationSize";287 reduceToPopulationSizeBranch.ConditionParameter.ActualName = ReduceToPopulationSizeParameter.Name; 186 288 reduceToPopulationSizeBranch.TrueBranch = countCalculator; 187 289 188 countCalculator.CollectedValues.Add(new LookupParameter<IntValue>( "PopulationSize"));189 countCalculator.CollectedValues.Add(new LookupParameter<IntValue>( "LayerPopulationSize"));190 countCalculator.ExpressionParameter.Value = new StringValue(" LayerPopulationSize PopulationSize LayerPopulationSize PopulationSize < if toint");191 countCalculator.ExpressionResultParameter.ActualName = "LayerPopulationSize";290 countCalculator.CollectedValues.Add(new LookupParameter<IntValue>(PopulationSizeParameter.Name)); 291 countCalculator.CollectedValues.Add(new LookupParameter<IntValue>(CurrentPopulationSizeParameter.Name)); 292 countCalculator.ExpressionParameter.Value = new StringValue("CurrentPopulationSize PopulationSize CurrentPopulationSize PopulationSize < if toint"); 293 countCalculator.ExpressionResultParameter.ActualName = CurrentPopulationSizeParameter.Name; 192 294 countCalculator.Successor = bestSelector; 193 295 194 bestSelector.NumberOfSelectedSubScopesParameter.ActualName = "LayerPopulationSize";296 bestSelector.NumberOfSelectedSubScopesParameter.ActualName = CurrentPopulationSizeParameter.Name; 195 297 bestSelector.CopySelected = new BoolValue(false); 196 298 bestSelector.Successor = rightReducer; … … 199 301 } 200 302 201 private staticCombinedOperator CreateLayerOpener() {303 private CombinedOperator CreateLayerOpener() { 202 304 var layerOpener = new CombinedOperator() { Name = "Open new Layer if needed" }; 203 305 var maxLayerReached = new Comparator() { Name = "MaxLayersReached = OpenLayers >= NumberOfLayers" }; … … 205 307 var openNewLayerCalculator = new ExpressionCalculator() { Name = "OpenNewLayer = Generations >= AgeLimits[OpenLayers - 1]" }; 206 308 var openNewLayerBranch = new ConditionalBranch() { Name = "OpenNewLayer?" }; 207 var layerCreator = new LayerCreator() { Name = "Create Layer" }; 208 var createChildrenViaCrossover = AlpsGeneticAlgorithmMainOperator.Create(); 309 var layerCreator = new LastScopeCloner() { Name = "Create Layer" }; 310 var updateLayerNumber = new Assigner() { Name = "Layer = OpenLayers" }; 311 var historyWiper = new ResultsHistoryWiper() { Name = "Clear History in Results" }; 312 var createChildrenViaCrossover = new AlpsGeneticAlgorithmMainOperator(); 209 313 var incrEvaluatedSolutionsForNewLayer = new SubScopesCounter() { Name = "Update EvaluatedSolutions" }; 210 314 var incrOpenLayers = new IntCounter() { Name = "Incr. OpenLayers" }; … … 214 318 215 319 maxLayerReached.LeftSideParameter.ActualName = "OpenLayers"; 216 maxLayerReached.RightSideParameter.ActualName = "NumberOfLayers";320 maxLayerReached.RightSideParameter.ActualName = NumberOfLayersParameter.Name; 217 321 maxLayerReached.ResultParameter.ActualName = "MaxLayerReached"; 218 322 maxLayerReached.Comparison = new Comparison(ComparisonType.GreaterOrEqual); … … 222 326 maxLayerReachedBranch.FalseBranch = openNewLayerCalculator; 223 327 224 openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntArray>( "AgeLimits"));328 openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntArray>(AgeLimitsParameter.Name)); 225 329 openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("Generations")); 226 openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>( "NumberOfLayers"));330 openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>(NumberOfLayersParameter.Name)); 227 331 openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("OpenLayers")); 228 332 openNewLayerCalculator.ExpressionResultParameter.ActualName = "OpenNewLayer"; … … 233 337 openNewLayerBranch.TrueBranch = layerCreator; 234 338 235 layerCreator.New LayerOperator = createChildrenViaCrossover;339 layerCreator.NewScopeOperator = updateLayerNumber; 236 340 layerCreator.Successor = incrOpenLayers; 237 341 342 updateLayerNumber.LeftSideParameter.ActualName = "Layer"; 343 updateLayerNumber.RightSideParameter.ActualName = "OpenLayers"; 344 updateLayerNumber.Successor = historyWiper; 345 346 historyWiper.ResultsParameter.ActualName = "LayerResults"; 347 historyWiper.Successor = createChildrenViaCrossover; 348 349 // Maybe use only crossover and no elitism instead of "default operator" 350 createChildrenViaCrossover.RandomParameter.ActualName = LocalRandomParameter.Name; 351 createChildrenViaCrossover.EvaluatorParameter.ActualName = EvaluatorParameter.Name; 352 createChildrenViaCrossover.EvaluatedSolutionsParameter.ActualName = "LayerEvaluatedSolutions"; 353 createChildrenViaCrossover.QualityParameter.ActualName = QualityParameter.Name; 354 createChildrenViaCrossover.MaximizationParameter.ActualName = MaximizationParameter.Name; 355 createChildrenViaCrossover.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name; 356 createChildrenViaCrossover.SelectorParameter.ActualName = SelectorParameter.Name; 357 createChildrenViaCrossover.CrossoverParameter.ActualName = CrossoverParameter.Name; 358 createChildrenViaCrossover.MutatorParameter.ActualName = MutatorParameter.Name; 359 createChildrenViaCrossover.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name; 360 createChildrenViaCrossover.ElitesParameter.ActualName = ElitesParameter.Name; 361 createChildrenViaCrossover.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name; 362 createChildrenViaCrossover.PlusSelectionParameter.ActualName = PlusSelectionParameter.Name; 363 createChildrenViaCrossover.AgeParameter.ActualName = AgeParameter.Name; 364 createChildrenViaCrossover.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name; 365 createChildrenViaCrossover.AgeIncrementParameter.Value = new DoubleValue(0.0); 238 366 createChildrenViaCrossover.Successor = incrEvaluatedSolutionsForNewLayer; 239 367 240 incrEvaluatedSolutionsForNewLayer.ValueParameter.ActualName = "EvaluatedSolutions";368 incrEvaluatedSolutionsForNewLayer.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name; 241 369 incrEvaluatedSolutionsForNewLayer.AccumulateParameter.Value = new BoolValue(true); 242 370 … … 252 380 } 253 381 254 private staticCombinedOperator CreateReseeder() {382 private CombinedOperator CreateReseeder() { 255 383 var reseeder = new CombinedOperator() { Name = "Reseed Layer Zero if needed" }; 256 384 var reseedingController = new ReseedingController() { Name = "Reseeding needed (Generation % AgeGap == 0)?" }; … … 267 395 removeIndividuals.Successor = createIndividuals; 268 396 269 createIndividuals.NumberOfSolutionsParameter.ActualName = "PopulationSize";397 createIndividuals.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name; 270 398 createIndividuals.Successor = initializeAgeProsessor; 271 399 … … 273 401 initializeAgeProsessor.Successor = incrEvaluatedSolutionsAfterReseeding; 274 402 275 initializeAge.CollectedValues.Add(new ValueParameter<DoubleValue>( "Age", new DoubleValue(0)));276 277 incrEvaluatedSolutionsAfterReseeding.ValueParameter.ActualName = "EvaluatedSolutions";403 initializeAge.CollectedValues.Add(new ValueParameter<DoubleValue>(AgeParameter.Name, new DoubleValue(0))); 404 405 incrEvaluatedSolutionsAfterReseeding.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name; 278 406 incrEvaluatedSolutionsAfterReseeding.AccumulateParameter.Value = new BoolValue(true); 279 407 -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithmMainOperator.cs
r13113 r13124 20 20 #endregion 21 21 22 using System.Linq;23 using HeuristicLab. Algorithms.GeneticAlgorithm;22 using HeuristicLab.Common; 23 using HeuristicLab.Core; 24 24 using HeuristicLab.Data; 25 25 using HeuristicLab.Operators; 26 using HeuristicLab.Optimization;27 26 using HeuristicLab.Optimization.Operators; 28 27 using HeuristicLab.Parameters; 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 29 using HeuristicLab.Selection; 30 30 31 31 namespace HeuristicLab.Algorithms.ALPS { 32 public static class AlpsGeneticAlgorithmMainOperator { 33 public static GeneticAlgorithmMainLoop Create() { 34 var mainLoop = new GeneticAlgorithmMainLoop(); 35 36 var selector = mainLoop.OperatorGraph.Iterate().OfType<Placeholder>().First(o => o.OperatorParameter.ActualName == "Selector"); 37 var crossover = mainLoop.OperatorGraph.Iterate().OfType<Placeholder>().First(o => o.OperatorParameter.ActualName == "Crossover"); 38 var subScopesCounter = mainLoop.OperatorGraph.Iterate().OfType<SubScopesCounter>().First(); 39 var elitesMerger = mainLoop.OperatorGraph.Iterate().OfType<MergingReducer>().First(); 40 41 // Operator starts with calculating number of selected scopes base on plus/comma-selection replacement scheme 42 var numberOfSelectedSubScopesCalculator = new ExpressionCalculator() { Name = "NumberOfSelectedSubScopes = 2 * (PopulationSize - (PlusSelection ? 0 : Elites))" }; 32 [Item("AlpsGeneticAlgorithmMainOperator", "An operator that represents the core of an ALPS genetic algorithm.")] 33 [StorableClass] 34 public sealed class AlpsGeneticAlgorithmMainOperator : AlgorithmOperator { 35 #region Parameter properties 36 public IValueLookupParameter<IRandom> RandomParameter { 37 get { return (IValueLookupParameter<IRandom>)Parameters["Random"]; } 38 } 39 40 public IValueLookupParameter<IOperator> EvaluatorParameter { 41 get { return (IValueLookupParameter<IOperator>)Parameters["Evaluator"]; } 42 } 43 public IValueLookupParameter<IntValue> EvaluatedSolutionsParameter { 44 get { return (IValueLookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; } 45 } 46 public IScopeTreeLookupParameter<DoubleValue> QualityParameter { 47 get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 48 } 49 public IValueLookupParameter<BoolValue> MaximizationParameter { 50 get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; } 51 } 52 53 public IValueLookupParameter<IntValue> PopulationSizeParameter { 54 get { return (IValueLookupParameter<IntValue>)Parameters["PopulationSize"]; } 55 } 56 public IValueLookupParameter<IOperator> SelectorParameter { 57 get { return (IValueLookupParameter<IOperator>)Parameters["Selector"]; } 58 } 59 public IValueLookupParameter<IOperator> CrossoverParameter { 60 get { return (IValueLookupParameter<IOperator>)Parameters["Crossover"]; } 61 } 62 public IValueLookupParameter<IOperator> MutatorParameter { 63 get { return (IValueLookupParameter<IOperator>)Parameters["Mutator"]; } 64 } 65 public IValueLookupParameter<PercentValue> MutationProbabilityParameter { 66 get { return (IValueLookupParameter<PercentValue>)Parameters["MutationProbability"]; } 67 } 68 public IValueLookupParameter<IntValue> ElitesParameter { 69 get { return (IValueLookupParameter<IntValue>)Parameters["Elites"]; } 70 } 71 public IValueLookupParameter<BoolValue> ReevaluateElitesParameter { 72 get { return (IValueLookupParameter<BoolValue>)Parameters["ReevaluateElites"]; } 73 } 74 public IValueLookupParameter<BoolValue> PlusSelectionParameter { 75 get { return (IValueLookupParameter<BoolValue>)Parameters["PlusSelection"]; } 76 } 77 78 public IScopeTreeLookupParameter<DoubleValue> AgeParameter { 79 get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Age"]; } 80 } 81 public IValueLookupParameter<DoubleValue> AgeInheritanceParameter { 82 get { return (IValueLookupParameter<DoubleValue>)Parameters["AgeInheritance"]; } 83 } 84 public IValueLookupParameter<DoubleValue> AgeIncrementParameter { 85 get { return (IValueLookupParameter<DoubleValue>)Parameters["AgeIncrement"]; } 86 } 87 #endregion 88 89 [StorableConstructor] 90 private AlpsGeneticAlgorithmMainOperator(bool deserializing) : base(deserializing) { } 91 private AlpsGeneticAlgorithmMainOperator(AlpsGeneticAlgorithmMainOperator original, Cloner cloner) 92 : base(original, cloner) { 93 } 94 public override IDeepCloneable Clone(Cloner cloner) { 95 return new AlpsGeneticAlgorithmMainOperator(this, cloner); 96 } 97 public AlpsGeneticAlgorithmMainOperator() 98 : base() { 99 Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator.")); 100 101 Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions. This operator is executed in parallel, if an engine is used which supports parallelization.")); 102 Parameters.Add(new ValueLookupParameter<IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated.")); 103 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution.")); 104 Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false.")); 105 106 Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population.")); 107 Parameters.Add(new ValueLookupParameter<IOperator>("Selector", "The operator used to select solutions for reproduction.")); 108 Parameters.Add(new ValueLookupParameter<IOperator>("Crossover", "The operator used to cross solutions.")); 109 Parameters.Add(new ValueLookupParameter<IOperator>("Mutator", "The operator used to mutate solutions.")); 110 Parameters.Add(new ValueLookupParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.")); 111 Parameters.Add(new ValueLookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.")); 112 Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)")); 113 Parameters.Add(new ValueLookupParameter<BoolValue>("PlusSelection", "Include the parents in the selection of the invividuals for the next generation.")); 114 115 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Age", "The age of individuals.")); 116 Parameters.Add(new ValueLookupParameter<DoubleValue>("AgeInheritance", "A weight that determines the age of a child after crossover based on the older (1.0) and younger (0.0) parent.")); 117 Parameters.Add(new ValueLookupParameter<DoubleValue>("AgeIncrement", "The value the age the individuals is incremented if they survives a generation.")); 118 119 120 var numberOfSelectedParentsCalculator = new ExpressionCalculator() { Name = "NumberOfSelectedParents = 2 * (PopulationSize - (PlusSelection ? 0 : Elites))" }; 121 var selector = new Placeholder() { Name = "Selector (Placeholder)" }; 122 var subScopesProcessor1 = new SubScopesProcessor(); 123 var childrenCreator = new ChildrenCreator(); 124 var uniformSubScopesProcessor1 = new UniformSubScopesProcessor(); 125 var crossover = new Placeholder() { Name = "Crossover (Placeholder)" }; 126 var stochasticBranch = new StochasticBranch() { Name = "MutationProbability" }; 127 var mutator = new Placeholder() { Name = "Mutator (Placeholder)" }; 128 var ageCalculator = new WeightingReducer() { Name = "Calculate Age" }; 129 var subScopesRemover = new SubScopesRemover(); 130 var uniformSubScopesProcessor2 = new UniformSubScopesProcessor(); 131 var evaluator = new Placeholder() { Name = "Evaluator (Placeholder)" }; 132 var subScopesCounter = new SubScopesCounter() { Name = "Increment EvaluatedSolutions" }; 43 133 var replacementBranch = new ConditionalBranch() { Name = "PlusSelection?" }; 44 45 // Set new initial operator46 mainLoop.OperatorGraph.InitialOperator = numberOfSelectedSubScopesCalculator;47 48 numberOfSelectedSubScopesCalculator.CollectedValues.Add(new LookupParameter<IntValue>("PopulationSize"));49 numberOfSelectedSubScopesCalculator.CollectedValues.Add(new LookupParameter<IntValue>("Elites"));50 numberOfSelectedSubScopesCalculator.CollectedValues.Add(new LookupParameter<BoolValue>("PlusSelection"));51 numberOfSelectedSubScopesCalculator.ExpressionResultParameter.ActualName = "NumberOfSelectedSubScopes";52 numberOfSelectedSubScopesCalculator.ExpressionParameter.Value = new StringValue("PopulationSize 0 Elites PlusSelection if - 2 * toint");53 numberOfSelectedSubScopesCalculator.Successor = selector;54 55 // Use Elitism or Plus-Selection as replacement strategy56 var selectedProcessor = (SubScopesProcessor)selector.Successor;57 var elitismReplacement = selectedProcessor.Successor;58 selectedProcessor.Successor = replacementBranch;59 replacementBranch.ConditionParameter.ActualName = "PlusSelection";60 replacementBranch.FalseBranch = elitismReplacement;61 62 // Plus selection replacement63 134 var replacementMergingReducer = new MergingReducer(); 64 135 var replacementBestSelector = new BestSelector(); 65 136 var replacementRightReducer = new RightReducer(); 137 var subScopesProcessor2 = new SubScopesProcessor(); 138 var bestSelector = new BestSelector(); 139 var rightReducer = new RightReducer(); 140 var mergingReducer = new MergingReducer(); 141 var reevaluateElitesBranch = new ConditionalBranch() { Name = "Reevaluate elites ?" }; 142 var incrementAgeProcessor = new UniformSubScopesProcessor(); 143 var ageIncrementor = new DoubleCounter() { Name = "Increment Age" }; 144 145 OperatorGraph.InitialOperator = numberOfSelectedParentsCalculator; 146 147 numberOfSelectedParentsCalculator.CollectedValues.Add(new LookupParameter<IntValue>(PopulationSizeParameter.Name)); 148 numberOfSelectedParentsCalculator.CollectedValues.Add(new LookupParameter<IntValue>(ElitesParameter.Name)); 149 numberOfSelectedParentsCalculator.CollectedValues.Add(new LookupParameter<BoolValue>(PlusSelectionParameter.Name)); 150 numberOfSelectedParentsCalculator.ExpressionResultParameter.ActualName = "NumberOfSelectedSubScopes"; 151 numberOfSelectedParentsCalculator.ExpressionParameter.Value = new StringValue("PopulationSize 0 Elites PlusSelection if - 2 * toint"); 152 numberOfSelectedParentsCalculator.Successor = selector; 153 154 selector.OperatorParameter.ActualName = SelectorParameter.Name; 155 selector.Successor = subScopesProcessor1; 156 157 subScopesProcessor1.Operators.Add(new EmptyOperator()); 158 subScopesProcessor1.Operators.Add(childrenCreator); 159 subScopesProcessor1.Successor = replacementBranch; 160 161 childrenCreator.ParentsPerChild = new IntValue(2); 162 childrenCreator.Successor = uniformSubScopesProcessor1; 163 164 uniformSubScopesProcessor1.Operator = crossover; 165 uniformSubScopesProcessor1.Successor = uniformSubScopesProcessor2; 166 167 crossover.OperatorParameter.ActualName = CrossoverParameter.Name; 168 crossover.Successor = stochasticBranch; 169 170 stochasticBranch.ProbabilityParameter.ActualName = MutationProbabilityParameter.Name; 171 stochasticBranch.RandomParameter.ActualName = RandomParameter.Name; 172 stochasticBranch.FirstBranch = mutator; 173 stochasticBranch.SecondBranch = null; 174 stochasticBranch.Successor = ageCalculator; 175 176 mutator.OperatorParameter.ActualName = MutatorParameter.Name; 177 mutator.Successor = null; 178 179 ageCalculator.ParameterToReduce.ActualName = AgeParameter.Name; 180 ageCalculator.TargetParameter.ActualName = AgeParameter.Name; 181 ageCalculator.WeightParameter.ActualName = AgeInheritanceParameter.Name; 182 ageCalculator.Successor = subScopesRemover; 183 184 subScopesRemover.RemoveAllSubScopes = true; 185 subScopesRemover.Successor = null; 186 187 uniformSubScopesProcessor2.Parallel.Value = true; 188 uniformSubScopesProcessor2.Operator = evaluator; 189 uniformSubScopesProcessor2.Successor = subScopesCounter; 190 191 evaluator.OperatorParameter.ActualName = EvaluatorParameter.Name; 192 evaluator.Successor = null; 193 194 subScopesCounter.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name; 195 subScopesCounter.AccumulateParameter.Value = new BoolValue(false); 196 subScopesCounter.Successor = null; 197 198 replacementBranch.ConditionParameter.ActualName = PlusSelectionParameter.Name; 66 199 replacementBranch.TrueBranch = replacementMergingReducer; 200 replacementBranch.FalseBranch = subScopesProcessor2; 201 replacementBranch.Successor = incrementAgeProcessor; 67 202 68 203 replacementMergingReducer.Successor = replacementBestSelector; 69 204 70 replacementBestSelector.NumberOfSelectedSubScopesParameter.ActualName = "PopulationSize";205 replacementBestSelector.NumberOfSelectedSubScopesParameter.ActualName = PopulationSizeParameter.Name; 71 206 replacementBestSelector.CopySelected = new BoolValue(false); 72 207 replacementBestSelector.Successor = replacementRightReducer; 73 208 74 replacementRightReducer.Successor = null; 75 76 // Increment ages of all individuals after replacement 77 var incrementAgeProcessor = new UniformSubScopesProcessor(); 78 var ageIncrementor = new DoubleCounter() { Name = "Increment Age" }; 79 replacementBranch.Successor = incrementAgeProcessor; 209 replacementRightReducer.Successor = reevaluateElitesBranch; 210 211 subScopesProcessor2.Operators.Add(bestSelector); 212 subScopesProcessor2.Operators.Add(new EmptyOperator()); 213 subScopesProcessor2.Successor = mergingReducer; 214 215 bestSelector.CopySelected = new BoolValue(false); 216 bestSelector.MaximizationParameter.ActualName = MaximizationParameter.Name; 217 bestSelector.NumberOfSelectedSubScopesParameter.ActualName = ElitesParameter.Name; 218 bestSelector.QualityParameter.ActualName = QualityParameter.Name; 219 bestSelector.Successor = rightReducer; 220 221 rightReducer.Successor = reevaluateElitesBranch; 222 223 mergingReducer.Successor = null; 224 225 reevaluateElitesBranch.ConditionParameter.ActualName = ReevaluateElitesParameter.Name; 226 reevaluateElitesBranch.TrueBranch = uniformSubScopesProcessor2; 227 reevaluateElitesBranch.FalseBranch = null; 228 reevaluateElitesBranch.Successor = null; 229 230 80 231 incrementAgeProcessor.Operator = ageIncrementor; 81 232 incrementAgeProcessor.Successor = null; 82 ageIncrementor.ValueParameter.ActualName = "Age"; 83 ageIncrementor.Increment = new DoubleValue(1.0); 84 85 // Insert AgeCalculator between crossover and its successor 86 var crossoverSuccessor = crossover.Successor; 87 var ageCalculator = new WeightingReducer() { Name = "Calculate Age" }; 88 crossover.Successor = ageCalculator; 89 90 ageCalculator.ParameterToReduce.ActualName = "Age"; 91 ageCalculator.TargetParameter.ActualName = "Age"; 92 ageCalculator.WeightParameter.ActualName = "AgeInheritance"; 93 ageCalculator.Successor = crossoverSuccessor; 94 95 // When counting the evaluated solutions, write in LayerEvaluatedSolutions 96 subScopesCounter.ValueParameter.ActualName = "LayerEvaluatedSolutions"; 97 subScopesCounter.AccumulateParameter.Value = new BoolValue(false); 98 99 // Instead of generational loop after merging of elites, stop 100 elitesMerger.Successor = null; 101 102 // Parameterize 103 foreach (var stochasticOperator in mainLoop.OperatorGraph.Iterate().OfType<IStochasticOperator>()) 104 stochasticOperator.RandomParameter.ActualName = "LocalRandom"; 105 foreach (var stochasticBranch in mainLoop.OperatorGraph.Iterate().OfType<StochasticBranch>()) 106 stochasticBranch.RandomParameter.ActualName = "LocalRandom"; 107 108 // Remove unused operators 109 var usedOperators = mainLoop.OperatorGraph.Iterate(); 110 var unusedOperators = mainLoop.OperatorGraph.Operators.Except(usedOperators); 111 foreach (var op in unusedOperators.ToList()) 112 mainLoop.OperatorGraph.Operators.Remove(op); 113 114 return mainLoop; 233 234 ageIncrementor.ValueParameter.ActualName = AgeParameter.Name; 235 ageIncrementor.IncrementParameter.Value = null; 236 ageIncrementor.IncrementParameter.ActualName = AgeIncrementParameter.Name; 237 ageIncrementor.Successor = null; 115 238 } 116 239 } -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/HeuristicLab.Algorithms.ALPS-3.3.csproj
r13111 r13124 80 80 </PropertyGroup> 81 81 <ItemGroup> 82 <Reference Include="HeuristicLab.Algorithms.GeneticAlgorithm-3.3">83 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Algorithms.GeneticAlgorithm-3.3.dll</HintPath>84 </Reference>85 82 <Reference Include="HeuristicLab.Analysis-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 86 83 <SpecificVersion>False</SpecificVersion> … … 134 131 <Compile Include="AlpsGeneticAlgorithmMainOperator.cs" /> 135 132 <Compile Include="ReseedingController.cs" /> 133 <Compile Include="ResultsHistoryWiper.cs" /> 136 134 <Compile Include="WeightingReducer.cs" /> 137 135 <Compile Include="Analyzers\OldestAverageYoungestAgeAnalyzer.cs" /> … … 142 140 <Compile Include="Analyzers\OldestAverageYoungestAgeCalculator.cs" /> 143 141 <Compile Include="EldersSelector.cs" /> 144 <Compile Include="La yerCreator.cs" />142 <Compile Include="LastScopeCloner.cs" /> 145 143 <Compile Include="MatingPoolCreator.cs" /> 146 144 <Compile Include="Plugin.cs" /> -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/LastScopeCloner.cs
r13123 r13124 22 22 using System; 23 23 using System.Linq; 24 using HeuristicLab.Analysis;25 24 using HeuristicLab.Common; 26 25 using HeuristicLab.Core; 27 using HeuristicLab.Data;28 26 using HeuristicLab.Operators; 29 using HeuristicLab.Optimization;30 27 using HeuristicLab.Parameters; 31 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 29 33 30 namespace HeuristicLab.Algorithms.ALPS { 34 [Item("La yerCreator", "An operator which creates a new layer by cloning the current oldest one.")]31 [Item("LastScopeCloner", "An operator that creates a new scope by cloning the current last one.")] 35 32 [StorableClass] 36 public sealed class LayerCreator : SingleSuccessorOperator { 37 private ILookupParameter<IntValue> OpenLayersParameter { 38 get { return (ILookupParameter<IntValue>)Parameters["OpenLayers"]; } 39 } 40 public OperatorParameter NewLayerOperatorParameter { 41 get { return (OperatorParameter)Parameters["NewLayerOperator"]; } 33 public sealed class LastScopeCloner : SingleSuccessorOperator { 34 public OperatorParameter NewScopeOperatorParameter { 35 get { return (OperatorParameter)Parameters["NewScopeOperator"]; } 42 36 } 43 37 44 public IOperator New LayerOperator {45 get { return New LayerOperatorParameter.Value; }46 set { New LayerOperatorParameter.Value = value; }38 public IOperator NewScopeOperator { 39 get { return NewScopeOperatorParameter.Value; } 40 set { NewScopeOperatorParameter.Value = value; } 47 41 } 48 42 49 43 [StorableConstructor] 50 private La yerCreator(bool deserializing) : base(deserializing) { }44 private LastScopeCloner(bool deserializing) : base(deserializing) { } 51 45 52 private La yerCreator(LayerCreator original, Cloner cloner)46 private LastScopeCloner(LastScopeCloner original, Cloner cloner) 53 47 : base(original, cloner) { 54 48 } 55 public LayerCreator() 56 : base() { 57 Parameters.Add(new LookupParameter<IntValue>("OpenLayers")); 58 Parameters.Add(new OperatorParameter("NewLayerOperator")); 49 public override IDeepCloneable Clone(Cloner cloner) { 50 return new LastScopeCloner(this, cloner); 59 51 } 60 52 61 public override IDeepCloneable Clone(Cloner cloner) { 62 return new LayerCreator(this, cloner); 53 public LastScopeCloner() 54 : base() { 55 Parameters.Add(new OperatorParameter("NewScopeOperator", "An Operator that is performed on the new scope.")); 63 56 } 64 57 65 58 public override IOperation Apply() { 66 var layersScope= ExecutionContext.Scope.SubScopes;67 if ( layersScope.Count < 1)59 var scopes = ExecutionContext.Scope.SubScopes; 60 if (scopes.Count < 1) 68 61 throw new ArgumentException("At least one layer must exist."); 69 62 70 var new Layer = (IScope)layersScope.Last().Clone();63 var newScope = (IScope)scopes.Last().Clone(); 71 64 72 int number;73 if (int.TryParse(new Layer.Name, out number))74 new Layer.Name = (number + 1).ToString();65 int scopeNumber; 66 if (int.TryParse(newScope.Name, out scopeNumber)) 67 newScope.Name = (scopeNumber + 1).ToString(); 75 68 76 layersScope.Add(newLayer);69 scopes.Add(newScope); 77 70 78 // Set new layer number79 newLayer.Variables["Layer"].Value = new IntValue(OpenLayersParameter.ActualValue.Value);80 81 // Decrement ages, because MainOperator is goint to increment it82 foreach (var solution in newLayer.SubScopes)83 ((DoubleValue)solution.Variables["Age"].Value).Value -= 1;84 85 // Reset existing values in the results to NaN to symbolize that no layer existed during that duration86 var results = (ResultCollection)newLayer.Variables["LayerResults"].Value;87 ResetResults(results);88 71 89 72 var next = new OperationCollection(base.Apply()); 90 next.Insert(0, ExecutionContext.CreateChildOperation(New LayerOperator, newLayer));73 next.Insert(0, ExecutionContext.CreateChildOperation(NewScopeOperator, newScope)); 91 74 return next; 92 }93 94 private void ResetResults(ResultCollection results) {95 var values = results.Select(r => r.Value);96 97 // Reset all values within results in results98 foreach (var resultsCollection in values.OfType<ResultCollection>())99 ResetResults(resultsCollection);100 101 // Reset values102 foreach (var dataTable in values.OfType<DataTable>()) {103 foreach (var row in dataTable.Rows)104 for (int i = 0; i < row.Values.Count; i++)105 row.Values[i] = double.NaN;106 }107 75 } 108 76 } -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/MatingPoolCreator.cs
r13031 r13124 32 32 public sealed class MatingPoolCreator : SingleSuccessorOperator { 33 33 34 public I LookupParameter<IntValue> MatingPoolRangeParameter {35 get { return (I LookupParameter<IntValue>)Parameters["MatingPoolRange"]; }34 public IValueLookupParameter<IntValue> MatingPoolRangeParameter { 35 get { return (IValueLookupParameter<IntValue>)Parameters["MatingPoolRange"]; } 36 36 } 37 37 … … 46 46 public MatingPoolCreator() 47 47 : base() { 48 Parameters.Add(new LookupParameter<IntValue>("MatingPoolRange"));48 Parameters.Add(new ValueLookupParameter<IntValue>("MatingPoolRange", "The range of sub-populations used for creating a mating pool. (1 = current + previous sub-population", new IntValue(1))); 49 49 } 50 50 51 /// <summary> 52 /// Copies the subscopes of the n previous scope into the current scope. (default n = 1) 53 /// <pre> 54 /// __ scope __ __ scope __ 55 /// / | \ / | \ 56 /// Pop1 Pop2 Pop3 => Pop1 Pop2 Pop3 57 /// /|\ /|\ /|\ /|\ /|\ /|\ 58 /// ABC DEF GHI ABC DEF GHI 59 /// ABC DEF 60 /// </pre> 61 /// </summary> 62 /// <returns>The next operation.</returns> 51 63 public override IOperation Apply() { 52 var layers = ExecutionContext.Scope.SubScopes;64 var subScopes = ExecutionContext.Scope.SubScopes; 53 65 int range = MatingPoolRangeParameter.ActualValue.Value; 54 66 55 for (int layer = layers.Count - 1; layer > 0; layer--) {56 var layerScope = layers[layer];57 for (int n = 1; (n <= range) && ( layer- n >= 0); n++) {58 var prev LayerScope = layers[layer- n];59 var individuals = prev LayerScope.SubScopes;67 for (int targetIndex = subScopes.Count - 1; targetIndex > 0; targetIndex--) { 68 var targetScope = subScopes[targetIndex]; 69 for (int n = 1; (n <= range) && (targetIndex - n >= 0); n++) { 70 var prevScope = subScopes[targetIndex - n]; 71 var individuals = prevScope.SubScopes; 60 72 foreach (var individual in individuals) { 61 layerScope.SubScopes.Add((IScope)individual.Clone(new Cloner()));73 targetScope.SubScopes.Add((IScope)individual.Clone(new Cloner())); 62 74 } 63 75 } -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/Plugin.cs.frame
r12994 r13124 40 40 [PluginDependency("HeuristicLab.Random", "3.3")] 41 41 [PluginDependency("HeuristicLab.Selection", "3.3")] 42 [PluginDependency("HeuristicLab.Algorithms.GeneticAlgorithm", "3.3")]43 42 public class HeuristicLabAlgorithmsALPSPlugin : PluginBase { 44 43 }
Note: See TracChangeset
for help on using the changeset viewer.