- Timestamp:
- 11/25/15 17:50:52 (9 years ago)
- Location:
- trunk/sources/HeuristicLab.Algorithms.ALPS/3.3
- Files:
-
- 1 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.ALPS/3.3/AlpsOffspringSelectionGeneticAlgorithm.cs
r13326 r13402 38 38 39 39 namespace HeuristicLab.Algorithms.ALPS { 40 [Item("ALPS Genetic Algorithm", "A genetic algorithm within an age-layered population structure as described in Gregory S. Hornby. 2006. ALPS: the age-layered population structure for reducing the problem of premature convergence. In Proceedings of the 8th annual conference on Genetic and evolutionary computation (GECCO '06). 815-822.")]41 [Creatable(CreatableAttribute.Categories.PopulationBasedAlgorithms, Priority = 16 0)]40 [Item("ALPS OffspringSelection Genetic Algorithm", "An offspring selection genetic algorithm within an age-layered population structure.")] 41 [Creatable(CreatableAttribute.Categories.PopulationBasedAlgorithms, Priority = 162)] 42 42 [StorableClass] 43 public sealed class Alps GeneticAlgorithm : HeuristicOptimizationEngineAlgorithm, IStorableContent {43 public sealed class AlpsOffspringSelectionGeneticAlgorithm : HeuristicOptimizationEngineAlgorithm, IStorableContent { 44 44 public string Filename { get; set; } 45 45 … … 55 55 56 56 #region Parameter Properties 57 private I ValueParameter<IntValue> SeedParameter {58 get { return (I ValueParameter<IntValue>)Parameters["Seed"]; }59 } 60 private I ValueParameter<BoolValue> SetSeedRandomlyParameter {61 get { return (I ValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }57 private IFixedValueParameter<IntValue> SeedParameter { 58 get { return (IFixedValueParameter<IntValue>)Parameters["Seed"]; } 59 } 60 private IFixedValueParameter<BoolValue> SetSeedRandomlyParameter { 61 get { return (IFixedValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; } 62 62 } 63 63 … … 69 69 } 70 70 71 private I ValueParameter<IntValue> NumberOfLayersParameter {72 get { return (I ValueParameter<IntValue>)Parameters["NumberOfLayers"]; }73 } 74 private I ValueParameter<IntValue> PopulationSizeParameter {75 get { return (I ValueParameter<IntValue>)Parameters["PopulationSize"]; }71 private IFixedValueParameter<IntValue> NumberOfLayersParameter { 72 get { return (IFixedValueParameter<IntValue>)Parameters["NumberOfLayers"]; } 73 } 74 private IFixedValueParameter<IntValue> PopulationSizeParameter { 75 get { return (IFixedValueParameter<IntValue>)Parameters["PopulationSize"]; } 76 76 } 77 77 … … 85 85 get { return (IConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; } 86 86 } 87 private I ValueParameter<PercentValue> MutationProbabilityParameter {88 get { return (I ValueParameter<PercentValue>)Parameters["MutationProbability"]; }89 } 90 private I ValueParameter<IntValue> ElitesParameter {91 get { return (I ValueParameter<IntValue>)Parameters["Elites"]; }87 private IFixedValueParameter<PercentValue> MutationProbabilityParameter { 88 get { return (IFixedValueParameter<PercentValue>)Parameters["MutationProbability"]; } 89 } 90 private IFixedValueParameter<IntValue> ElitesParameter { 91 get { return (IFixedValueParameter<IntValue>)Parameters["Elites"]; } 92 92 } 93 93 private IFixedValueParameter<BoolValue> ReevaluateElitesParameter { 94 94 get { return (IFixedValueParameter<BoolValue>)Parameters["ReevaluateElites"]; } 95 95 } 96 private IValueParameter<BoolValue> PlusSelectionParameter { 97 get { return (IValueParameter<BoolValue>)Parameters["PlusSelection"]; } 98 } 99 100 private IValueParameter<EnumValue<AgingScheme>> AgingSchemeParameter { 101 get { return (IValueParameter<EnumValue<AgingScheme>>)Parameters["AgingScheme"]; } 102 } 103 private IValueParameter<IntValue> AgeGapParameter { 104 get { return (IValueParameter<IntValue>)Parameters["AgeGap"]; } 105 } 106 private IValueParameter<DoubleValue> AgeInheritanceParameter { 107 get { return (IValueParameter<DoubleValue>)Parameters["AgeInheritance"]; } 108 } 109 private IValueParameter<IntArray> AgeLimitsParameter { 110 get { return (IValueParameter<IntArray>)Parameters["AgeLimits"]; } 111 } 112 113 private IValueParameter<IntValue> MatingPoolRangeParameter { 114 get { return (IValueParameter<IntValue>)Parameters["MatingPoolRange"]; } 115 } 116 private IValueParameter<BoolValue> ReduceToPopulationSizeParameter { 117 get { return (IValueParameter<BoolValue>)Parameters["ReduceToPopulationSize"]; } 118 } 119 120 private IValueParameter<MultiTerminator> TerminatorParameter { 121 get { return (IValueParameter<MultiTerminator>)Parameters["Terminator"]; } 96 97 private IFixedValueParameter<DoubleValue> SuccessRatioParameter { 98 get { return (IFixedValueParameter<DoubleValue>)Parameters["SuccessRatio"]; } 99 } 100 private IFixedValueParameter<DoubleValue> ComparisonFactorParameter { 101 get { return (IFixedValueParameter<DoubleValue>)Parameters["ComparisonFactor"]; } 102 } 103 private IFixedValueParameter<DoubleValue> MaximumSelectionPressureParameter { 104 get { return (IFixedValueParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; } 105 } 106 private IFixedValueParameter<BoolValue> OffspringSelectionBeforeMutationParameter { 107 get { return (IFixedValueParameter<BoolValue>)Parameters["OffspringSelectionBeforeMutation"]; } 108 } 109 private IFixedValueParameter<IntValue> SelectedParentsParameter { 110 get { return (IFixedValueParameter<IntValue>)Parameters["SelectedParents"]; } 111 } 112 private IFixedValueParameter<BoolValue> FillPopulationWithParentsParameter { 113 get { return (IFixedValueParameter<BoolValue>)Parameters["FillPopulationWithParents"]; } 114 } 115 116 private IFixedValueParameter<EnumValue<AgingScheme>> AgingSchemeParameter { 117 get { return (IFixedValueParameter<EnumValue<AgingScheme>>)Parameters["AgingScheme"]; } 118 } 119 private IFixedValueParameter<IntValue> AgeGapParameter { 120 get { return (IFixedValueParameter<IntValue>)Parameters["AgeGap"]; } 121 } 122 private IFixedValueParameter<DoubleValue> AgeInheritanceParameter { 123 get { return (IFixedValueParameter<DoubleValue>)Parameters["AgeInheritance"]; } 124 } 125 private IFixedValueParameter<IntArray> AgeLimitsParameter { 126 get { return (IFixedValueParameter<IntArray>)Parameters["AgeLimits"]; } 127 } 128 129 private IFixedValueParameter<IntValue> MatingPoolRangeParameter { 130 get { return (IFixedValueParameter<IntValue>)Parameters["MatingPoolRange"]; } 131 } 132 private IFixedValueParameter<BoolValue> ReduceToPopulationSizeParameter { 133 get { return (IFixedValueParameter<BoolValue>)Parameters["ReduceToPopulationSize"]; } 134 } 135 136 private IFixedValueParameter<MultiTerminator> TerminatorParameter { 137 get { return (IFixedValueParameter<MultiTerminator>)Parameters["Terminator"]; } 122 138 } 123 139 #endregion 124 140 125 141 #region Properties 126 public IntValueSeed {127 get { return SeedParameter.Value ; }128 set { SeedParameter.Value = value; }129 } 130 public BoolValueSetSeedRandomly {131 get { return SetSeedRandomlyParameter.Value ; }132 set { SetSeedRandomlyParameter.Value = value; }142 public int Seed { 143 get { return SeedParameter.Value.Value; } 144 set { SeedParameter.Value.Value = value; } 145 } 146 public bool SetSeedRandomly { 147 get { return SetSeedRandomlyParameter.Value.Value; } 148 set { SetSeedRandomlyParameter.Value.Value = value; } 133 149 } 134 150 … … 140 156 } 141 157 142 public IntValueNumberOfLayers {143 get { return NumberOfLayersParameter.Value ; }144 set { NumberOfLayersParameter.Value = value; }145 } 146 public IntValuePopulationSize {147 get { return PopulationSizeParameter.Value ; }148 set { PopulationSizeParameter.Value = value; }158 public int NumberOfLayers { 159 get { return NumberOfLayersParameter.Value.Value; } 160 set { NumberOfLayersParameter.Value.Value = value; } 161 } 162 public int PopulationSize { 163 get { return PopulationSizeParameter.Value.Value; } 164 set { PopulationSizeParameter.Value.Value = value; } 149 165 } 150 166 … … 161 177 set { MutatorParameter.Value = value; } 162 178 } 163 public PercentValue MutationProbability {164 get { return MutationProbabilityParameter.Value ; }165 set { MutationProbabilityParameter.Value = value; }166 } 167 public IntValueElites {168 get { return ElitesParameter.Value ; }169 set { ElitesParameter.Value = value; }179 public double MutationProbability { 180 get { return MutationProbabilityParameter.Value.Value; } 181 set { MutationProbabilityParameter.Value.Value = value; } 182 } 183 public int Elites { 184 get { return ElitesParameter.Value.Value; } 185 set { ElitesParameter.Value.Value = value; } 170 186 } 171 187 public bool ReevaluteElites { … … 173 189 set { ReevaluateElitesParameter.Value.Value = value; } 174 190 } 175 public bool PlusSelection { 176 get { return PlusSelectionParameter.Value.Value; } 177 set { PlusSelectionParameter.Value.Value = value; } 178 } 179 180 public EnumValue<AgingScheme> AgingScheme { 181 get { return AgingSchemeParameter.Value; } 182 set { AgingSchemeParameter.Value = value; } 183 } 184 public IntValue AgeGap { 185 get { return AgeGapParameter.Value; } 186 set { AgeGapParameter.Value = value; } 187 } 188 public DoubleValue AgeInheritance { 189 get { return AgeInheritanceParameter.Value; } 190 set { AgeInheritanceParameter.Value = value; } 191 192 public double SuccessRatio { 193 get { return SuccessRatioParameter.Value.Value; } 194 set { SuccessRatioParameter.Value.Value = value; } 195 } 196 public double ComparisonFactor { 197 get { return ComparisonFactorParameter.Value.Value; } 198 set { ComparisonFactorParameter.Value.Value = value; } 199 } 200 public double MaximumSelectionPressure { 201 get { return MaximumSelectionPressureParameter.Value.Value; } 202 set { MaximumSelectionPressureParameter.Value.Value = value; } 203 } 204 public bool OffspringSelectionBeforeMutation { 205 get { return OffspringSelectionBeforeMutationParameter.Value.Value; } 206 set { OffspringSelectionBeforeMutationParameter.Value.Value = value; } 207 } 208 public int SelectedParents { 209 get { return SelectedParentsParameter.Value.Value; } 210 set { SelectedParentsParameter.Value.Value = value; } 211 } 212 public bool FillPopulationWithParents { 213 get { return FillPopulationWithParentsParameter.Value.Value; } 214 set { FillPopulationWithParentsParameter.Value.Value = value; } 215 } 216 217 public AgingScheme AgingScheme { 218 get { return AgingSchemeParameter.Value.Value; } 219 set { AgingSchemeParameter.Value.Value = value; } 220 } 221 public int AgeGap { 222 get { return AgeGapParameter.Value.Value; } 223 set { AgeGapParameter.Value.Value = value; } 224 } 225 public double AgeInheritance { 226 get { return AgeInheritanceParameter.Value.Value; } 227 set { AgeInheritanceParameter.Value.Value = value; } 191 228 } 192 229 public IntArray AgeLimits { 193 230 get { return AgeLimitsParameter.Value; } 194 set { AgeLimitsParameter.Value = value; } 195 } 196 197 public IntValue MatingPoolRange { 198 get { return MatingPoolRangeParameter.Value; } 199 set { MatingPoolRangeParameter.Value = value; } 231 set { 232 AgeLimits.Length = value.Length; 233 for (int i = 0; i < value.Length; i++) 234 AgeLimits[i] = value[i]; 235 } 236 } 237 238 public int MatingPoolRange { 239 get { return MatingPoolRangeParameter.Value.Value; } 240 set { MatingPoolRangeParameter.Value.Value = value; } 200 241 } 201 242 … … 214 255 get { return OperatorGraph.Iterate().OfType<SolutionsCreator>().First(); } 215 256 } 216 private Alps GeneticAlgorithmMainLoop MainLoop {217 get { return OperatorGraph.Iterate().OfType<Alps GeneticAlgorithmMainLoop>().First(); }257 private AlpsOffspringSelectionGeneticAlgorithmMainLoop MainLoop { 258 get { return OperatorGraph.Iterate().OfType<AlpsOffspringSelectionGeneticAlgorithmMainLoop>().First(); } 218 259 } 219 260 #endregion … … 232 273 [Storable] 233 274 private AgeDistributionAnalyzer layerAgeDistributionAnalyzer; 275 [Storable] 276 private ValueAnalyzer selectionPressureAnalyzer; 277 [Storable] 278 private ValueAnalyzer layerSelectionPressureAnalyzer; 279 [Storable] 280 private ValueAnalyzer currentSuccessRatioAnalyzer; 234 281 #endregion 235 282 … … 237 284 [Storable] 238 285 private ComparisonTerminator<IntValue> generationsTerminator; 286 //[Storable] 287 //private ComparisonTerminator<DoubleValue> selectionPressureTerminator; 239 288 [Storable] 240 289 private ComparisonTerminator<IntValue> evaluationsTerminator; … … 247 296 #region Constructors 248 297 [StorableConstructor] 249 private Alps GeneticAlgorithm(bool deserializing)298 private AlpsOffspringSelectionGeneticAlgorithm(bool deserializing) 250 299 : base(deserializing) { } 251 300 [StorableHook(HookType.AfterDeserialization)] … … 253 302 Initialize(); 254 303 } 255 private Alps GeneticAlgorithm(AlpsGeneticAlgorithm original, Cloner cloner)304 private AlpsOffspringSelectionGeneticAlgorithm(AlpsOffspringSelectionGeneticAlgorithm original, Cloner cloner) 256 305 : base(original, cloner) { 257 306 qualityAnalyzer = cloner.Clone(original.qualityAnalyzer); … … 261 310 ageDistributionAnalyzer = cloner.Clone(original.ageDistributionAnalyzer); 262 311 layerAgeDistributionAnalyzer = cloner.Clone(original.layerAgeDistributionAnalyzer); 312 selectionPressureAnalyzer = cloner.Clone(original.selectionPressureAnalyzer); 313 layerSelectionPressureAnalyzer = cloner.Clone(original.layerSelectionPressureAnalyzer); 314 currentSuccessRatioAnalyzer = cloner.Clone(original.currentSuccessRatioAnalyzer); 263 315 generationsTerminator = cloner.Clone(original.generationsTerminator); 316 //selectionPressureTerminator = cloner.Clone(original.selectionPressureTerminator); 264 317 evaluationsTerminator = cloner.Clone(original.evaluationsTerminator); 265 318 qualityTerminator = cloner.Clone(original.qualityTerminator); … … 268 321 } 269 322 public override IDeepCloneable Clone(Cloner cloner) { 270 return new Alps GeneticAlgorithm(this, cloner);271 } 272 public Alps GeneticAlgorithm()323 return new AlpsOffspringSelectionGeneticAlgorithm(this, cloner); 324 } 325 public AlpsOffspringSelectionGeneticAlgorithm() 273 326 : base() { 274 327 #region Add parameters 275 Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));276 Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));328 Parameters.Add(new FixedValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0))); 329 Parameters.Add(new FixedValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true))); 277 330 278 331 Parameters.Add(new FixedValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze all individuals from all layers combined.", new MultiAnalyzer())); 279 332 Parameters.Add(new FixedValueParameter<MultiAnalyzer>("LayerAnalyzer", "The operator used to analyze each layer.", new MultiAnalyzer())); 280 333 281 Parameters.Add(new ValueParameter<IntValue>("NumberOfLayers", "The number of layers.", new IntValue(10)));282 Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions in each layer.", new IntValue(100)));334 Parameters.Add(new FixedValueParameter<IntValue>("NumberOfLayers", "The number of layers.", new IntValue(10))); 335 Parameters.Add(new FixedValueParameter<IntValue>("PopulationSize", "The size of the population of solutions in each layer.", new IntValue(100))); 283 336 284 337 Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction.")); 285 338 Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions.")); 286 339 Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions.")); 287 Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));288 Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));340 Parameters.Add(new FixedValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05))); 341 Parameters.Add(new FixedValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1))); 289 342 Parameters.Add(new FixedValueParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)", new BoolValue(false)) { Hidden = true }); 290 Parameters.Add(new ValueParameter<BoolValue>("PlusSelection", "Include the parents in the selection of the invividuals for the next generation.", new BoolValue(false))); 291 292 Parameters.Add(new ValueParameter<EnumValue<AgingScheme>>("AgingScheme", "The aging scheme for setting the age-limits for the layers.", new EnumValue<AgingScheme>(ALPS.AgingScheme.Polynomial))); 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))); 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 }); 295 Parameters.Add(new ValueParameter<IntArray>("AgeLimits", "The maximum age an individual is allowed to reach in a certain layer.", new IntArray(new int[0])) { Hidden = true }); 296 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 }); 298 Parameters.Add(new ValueParameter<BoolValue>("ReduceToPopulationSize", "Reduce the CurrentPopulationSize after elder migration to PopulationSize", new BoolValue(true)) { Hidden = true }); 299 300 Parameters.Add(new ValueParameter<MultiTerminator>("Terminator", "The termination criteria that defines if the algorithm should continue or stop.", new MultiTerminator())); 343 344 Parameters.Add(new FixedValueParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved.", new DoubleValue(1))); 345 Parameters.Add(new FixedValueParameter<DoubleValue>("ComparisonFactor", "The comparison factor is used to determine whether the offspring should be compared to the better parent, the worse parent or a quality value linearly interpolated between them. It is in the range [0;1].", new DoubleValue(1))); 346 Parameters.Add(new FixedValueParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm.", new DoubleValue(100))); 347 Parameters.Add(new FixedValueParameter<BoolValue>("OffspringSelectionBeforeMutation", "True if the offspring selection step should be applied before mutation, false if it should be applied after mutation.", new BoolValue(false))); 348 Parameters.Add(new FixedValueParameter<IntValue>("SelectedParents", "How much parents should be selected each time the offspring selection step is performed until the population is filled. This parameter should be about the same or twice the size of PopulationSize for smaller problems, and less for large problems.", new IntValue(200))); 349 Parameters.Add(new FixedValueParameter<BoolValue>("FillPopulationWithParents", "True if the population should be filled with parent individual or false if worse children should be used when the maximum selection pressure is exceeded.", new BoolValue(false)) { Hidden = true }); 350 351 Parameters.Add(new FixedValueParameter<EnumValue<AgingScheme>>("AgingScheme", "The aging scheme for setting the age-limits for the layers.", new EnumValue<AgingScheme>(ALPS.AgingScheme.Polynomial))); 352 Parameters.Add(new FixedValueParameter<IntValue>("AgeGap", "The frequency of reseeding the lowest layer and scaling factor for the age-limits for the layers.", new IntValue(20))); 353 Parameters.Add(new FixedValueParameter<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 }); 354 Parameters.Add(new FixedValueParameter<IntArray>("AgeLimits", "The maximum age an individual is allowed to reach in a certain layer.", new IntArray(new int[0])) { Hidden = true }); 355 356 Parameters.Add(new FixedValueParameter<IntValue>("MatingPoolRange", "The range of layers used for creating a mating pool. (1 = current + previous layer)", new IntValue(1)) { Hidden = true }); 357 Parameters.Add(new FixedValueParameter<BoolValue>("ReduceToPopulationSize", "Reduce the CurrentPopulationSize after elder migration to PopulationSize", new BoolValue(true)) { Hidden = true }); 358 359 Parameters.Add(new FixedValueParameter<MultiTerminator>("Terminator", "The termination criteria that defines if the algorithm should continue or stop.", new MultiTerminator())); 301 360 #endregion 302 361 … … 313 372 var initializeGlobalEvaluatedSolutions = new DataReducer() { Name = "Initialize EvaluatedSolutions" }; 314 373 var resultsCollector = new ResultsCollector(); 315 var mainLoop = new Alps GeneticAlgorithmMainLoop();374 var mainLoop = new AlpsOffspringSelectionGeneticAlgorithmMainLoop(); 316 375 #endregion 317 376 … … 373 432 mainLoop.ElitesParameter.ActualName = ElitesParameter.Name; 374 433 mainLoop.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name; 375 mainLoop.PlusSelectionParameter.ActualName = PlusSelectionParameter.Name; 434 mainLoop.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name; 435 mainLoop.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name; 436 mainLoop.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name; 437 mainLoop.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name; 438 mainLoop.FillPopulationWithParentsParameter.ActualName = FillPopulationWithParentsParameter.Name; 376 439 mainLoop.AgeParameter.ActualName = "Age"; 377 440 mainLoop.AgeGapParameter.ActualName = AgeGapParameter.Name; … … 383 446 #endregion 384 447 385 #region Set selectors448 #region Set operators 386 449 foreach (var selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(s => !(s is IMultiObjectiveSelector)).OrderBy(s => Name)) 387 450 SelectorParameter.ValidValues.Add(selector); … … 400 463 ageDistributionAnalyzer = new AgeDistributionAnalyzer(); 401 464 layerAgeDistributionAnalyzer = new AgeDistributionAnalyzer(); 465 selectionPressureAnalyzer = new ValueAnalyzer(); 466 layerSelectionPressureAnalyzer = new ValueAnalyzer(); 467 currentSuccessRatioAnalyzer = new ValueAnalyzer(); 402 468 #endregion 403 469 404 470 #region Create terminators 405 471 generationsTerminator = new ComparisonTerminator<IntValue>("Generations", ComparisonType.Less, new IntValue(1000)) { Name = "Generations" }; 472 //selectionPressureTerminator = new ComparisonTerminator<DoubleValue>("SelectionPressure", ComparisonType.Less, MaximumSelectionPressureParameter); 406 473 evaluationsTerminator = new ComparisonTerminator<IntValue>("EvaluatedSolutions", ComparisonType.Less, new IntValue(int.MaxValue)) { Name = "Evaluations" }; 407 474 qualityTerminator = new SingleObjectiveQualityTerminator() { Name = "Quality" }; … … 503 570 } 504 571 505 private void AgeGapParameter_ValueChanged(object sender, EventArgs e) {506 AgeGap.ValueChanged += AgeGap_ValueChanged;507 ParameterizeAgeLimits();508 }509 572 private void AgeGap_ValueChanged(object sender, EventArgs e) { 510 573 ParameterizeAgeLimits(); 511 574 } 512 private void AgingSchemeParameter_ValueChanged(object sender, EventArgs e) {513 AgingScheme.ValueChanged += AgingScheme_ValueChanged;514 ParameterizeAgeLimits();515 }516 575 private void AgingScheme_ValueChanged(object sender, EventArgs e) { 517 ParameterizeAgeLimits();518 }519 private void NumberOfLayersParameter_ValueChanged(object sender, EventArgs e) {520 NumberOfLayers.ValueChanged += NumberOfLayers_ValueChanged;521 576 ParameterizeAgeLimits(); 522 577 } … … 552 607 Problem.Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged; 553 608 554 NumberOfLayersParameter.ValueChanged += NumberOfLayersParameter_ValueChanged; 555 NumberOfLayers.ValueChanged += NumberOfLayers_ValueChanged; 609 NumberOfLayersParameter.Value.ValueChanged += NumberOfLayers_ValueChanged; 556 610 557 611 Analyzer.Operators.ItemsAdded += AnalyzerOperators_ItemsAdded; 558 612 LayerAnalyzer.Operators.ItemsAdded += LayerAnalyzerOperators_ItemsAdded; 559 613 560 AgeGapParameter.ValueChanged += AgeGapParameter_ValueChanged; 561 AgeGap.ValueChanged += AgeGap_ValueChanged; 562 AgingSchemeParameter.ValueChanged += AgingSchemeParameter_ValueChanged; 563 AgingScheme.ValueChanged += AgingScheme_ValueChanged; 564 565 qualityAnalyzer.CurrentBestQualityParameter.NameChanged += new EventHandler(QualityAnalyzer_CurrentBestQualityParameter_NameChanged); 614 AgeGapParameter.Value.ValueChanged += AgeGap_ValueChanged; 615 AgingSchemeParameter.Value.ValueChanged += AgingScheme_ValueChanged; 616 617 qualityAnalyzer.CurrentBestQualityParameter.NameChanged += QualityAnalyzer_CurrentBestQualityParameter_NameChanged; 566 618 } 567 619 private void ParameterizeSolutionsCreator() { … … 581 633 layerQualityAnalyzer.ResultsParameter.Hidden = true; 582 634 layerQualityAnalyzer.QualityParameter.Depth = 1; 635 selectionPressureAnalyzer.Name = "SelectionPressure Analyzer"; 636 selectionPressureAnalyzer.ResultsParameter.ActualName = "Results"; 637 selectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure"; 638 selectionPressureAnalyzer.ValueParameter.Depth = 1; 639 selectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History"; 640 layerSelectionPressureAnalyzer.Name = "SelectionPressure Analyzer"; 641 layerSelectionPressureAnalyzer.ResultsParameter.ActualName = "LayerResults"; 642 layerSelectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure"; 643 layerSelectionPressureAnalyzer.ValueParameter.Depth = 0; 644 layerSelectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History"; 645 currentSuccessRatioAnalyzer.Name = "CurrentSuccessRatio Analyzer"; 646 currentSuccessRatioAnalyzer.ResultsParameter.ActualName = "Results"; 647 currentSuccessRatioAnalyzer.ValueParameter.ActualName = "CurrentSuccessRatio"; 648 currentSuccessRatioAnalyzer.ValueParameter.Depth = 1; 649 currentSuccessRatioAnalyzer.ValuesParameter.ActualName = "Success Ratio History"; 583 650 if (Problem != null) { 584 651 qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; … … 600 667 selector.CopySelected = new BoolValue(true); 601 668 selector.NumberOfSelectedSubScopesParameter.Hidden = true; 669 selector.NumberOfSelectedSubScopesParameter.ActualName = SelectedParentsParameter.Name; 602 670 ParameterizeStochasticOperatorForLayer(selector); 603 671 } … … 625 693 } 626 694 private void ParameterizeAgeLimits() { 627 var scheme = AgingScheme.Value; 628 int ageGap = AgeGap.Value; 629 int numberOfLayers = NumberOfLayers.Value; 630 AgeLimits = scheme.CalculateAgeLimits(ageGap, numberOfLayers); 695 AgeLimits = AgingScheme.CalculateAgeLimits(AgeGap, NumberOfLayers); 631 696 } 632 697 … … 657 722 Analyzer.Operators.Add(ageAnalyzer, ageAnalyzer.EnabledByDefault); 658 723 Analyzer.Operators.Add(ageDistributionAnalyzer, ageDistributionAnalyzer.EnabledByDefault); 724 Analyzer.Operators.Add(selectionPressureAnalyzer, false); // find way to make history "pretty" 725 selectionPressureAnalyzer.ValueParameter.Depth = 1; // Adding analyzer sets depth to 2 726 Analyzer.Operators.Add(currentSuccessRatioAnalyzer, false); 727 currentSuccessRatioAnalyzer.ValueParameter.Depth = 1; // Adding analyzer sets depth to 2 659 728 LayerAnalyzer.Operators.Add(layerQualityAnalyzer, false); 660 729 LayerAnalyzer.Operators.Add(layerAgeAnalyzer, false); 661 730 LayerAnalyzer.Operators.Add(layerAgeDistributionAnalyzer, false); 731 LayerAnalyzer.Operators.Add(layerSelectionPressureAnalyzer, false); 732 layerSelectionPressureAnalyzer.ValueParameter.Depth = 0; // Adding layer-analyzer sets depth to 1 733 662 734 663 735 if (Problem != null) { … … 702 774 var newTerminators = new Dictionary<ITerminator, bool> { 703 775 {generationsTerminator, !Terminators.Operators.Contains(generationsTerminator) || Terminators.Operators.ItemChecked(generationsTerminator)}, 776 //{selectionPressureTerminator, !Terminators.Operators.Contains(selectionPressureTerminator) || Terminators.Operators.ItemChecked(selectionPressureTerminator)}, 704 777 {evaluationsTerminator, Terminators.Operators.Contains(evaluationsTerminator) && Terminators.Operators.ItemChecked(evaluationsTerminator)}, 705 778 {qualityTerminator, Terminators.Operators.Contains(qualityTerminator) && Terminators.Operators.ItemChecked(qualityTerminator) }, -
trunk/sources/HeuristicLab.Algorithms.ALPS/3.3/AlpsOffspringSelectionGeneticAlgorithmMainLoop.cs
r13326 r13402 32 32 namespace HeuristicLab.Algorithms.ALPS { 33 33 34 [Item("Alps GeneticAlgorithmMainLoop", "An ALPSgenetic algorithm main loop operator.")]34 [Item("AlpsOffspringSelectionGeneticAlgorithmMainLoop", "An ALPS offspring selection genetic algorithm main loop operator.")] 35 35 [StorableClass] 36 public sealed class Alps GeneticAlgorithmMainLoop : AlgorithmOperator {36 public sealed class AlpsOffspringSelectionGeneticAlgorithmMainLoop : AlgorithmOperator { 37 37 #region Parameter Properties 38 38 public IValueLookupParameter<IRandom> GlobalRandomParameter { … … 91 91 get { return (IValueLookupParameter<BoolValue>)Parameters["ReevaluateElites"]; } 92 92 } 93 public IValueLookupParameter<BoolValue> PlusSelectionParameter { 94 get { return (IValueLookupParameter<BoolValue>)Parameters["PlusSelection"]; } 93 94 public IValueLookupParameter<DoubleValue> SuccessRatioParameter { 95 get { return (IValueLookupParameter<DoubleValue>)Parameters["SuccessRatio"]; } 96 } 97 public ILookupParameter<DoubleValue> ComparisonFactorParameter { 98 get { return (ILookupParameter<DoubleValue>)Parameters["ComparisonFactor"]; } 99 } 100 public IValueLookupParameter<DoubleValue> MaximumSelectionPressureParameter { 101 get { return (IValueLookupParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; } 102 } 103 public IValueLookupParameter<BoolValue> OffspringSelectionBeforeMutationParameter { 104 get { return (IValueLookupParameter<BoolValue>)Parameters["OffspringSelectionBeforeMutation"]; } 105 } 106 public IValueLookupParameter<BoolValue> FillPopulationWithParentsParameter { 107 get { return (IValueLookupParameter<BoolValue>)Parameters["FillPopulationWithParents"]; } 95 108 } 96 109 … … 121 134 122 135 [StorableConstructor] 123 private Alps GeneticAlgorithmMainLoop(bool deserializing)136 private AlpsOffspringSelectionGeneticAlgorithmMainLoop(bool deserializing) 124 137 : base(deserializing) { } 125 private Alps GeneticAlgorithmMainLoop(AlpsGeneticAlgorithmMainLoop original, Cloner cloner)138 private AlpsOffspringSelectionGeneticAlgorithmMainLoop(AlpsOffspringSelectionGeneticAlgorithmMainLoop original, Cloner cloner) 126 139 : base(original, cloner) { } 127 140 public override IDeepCloneable Clone(Cloner cloner) { 128 return new Alps GeneticAlgorithmMainLoop(this, cloner);129 } 130 public Alps GeneticAlgorithmMainLoop()141 return new AlpsOffspringSelectionGeneticAlgorithmMainLoop(this, cloner); 142 } 143 public AlpsOffspringSelectionGeneticAlgorithmMainLoop() 131 144 : base() { 132 145 Parameters.Add(new ValueLookupParameter<IRandom>("GlobalRandom", "A pseudo random number generator.")); … … 151 164 Parameters.Add(new ValueLookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.")); 152 165 Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)")); 153 Parameters.Add(new ValueLookupParameter<BoolValue>("PlusSelection", "Include the parents in the selection of the invividuals for the next generation.")); 166 167 Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved.")); 168 Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactor", "The comparison factor is used to determine whether the offspring should be compared to the better parent, the worse parent or a quality value linearly interpolated between them. It is in the range [0;1].")); 169 Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm.")); 170 Parameters.Add(new ValueLookupParameter<BoolValue>("OffspringSelectionBeforeMutation", "True if the offspring selection step should be applied before mutation, false if it should be applied after mutation.")); 171 Parameters.Add(new ValueLookupParameter<BoolValue>("FillPopulationWithParents", "True if the population should be filled with parent individual or false if worse children should be used when the maximum selection pressure is exceeded.")); 154 172 155 173 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Age", "The age of individuals.")); … … 168 186 var layerVariableCreator = new VariableCreator() { Name = "Initialize Layer" }; 169 187 var initLayerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" }; 188 var layerResultCollector = new ResultsCollector() { Name = "Collect layer results" }; 170 189 var initAnalyzerPlaceholder = new Placeholder() { Name = "Analyzer (Placeholder)" }; 171 190 var resultsCollector = new ResultsCollector(); … … 173 192 var matingPoolProcessor = new UniformSubScopesProcessor() { Name = "Process Mating Pools" }; 174 193 var initializeLayer = new Assigner() { Name = "Reset LayerEvaluatedSolutions" }; 175 var mainOperator = new Alps GeneticAlgorithmMainOperator();194 var mainOperator = new AlpsOffspringSelectionGeneticAlgorithmMainOperator(); 176 195 var generationsIcrementor = new IntCounter() { Name = "Increment Generations" }; 177 196 var evaluatedSolutionsReducer = new DataReducer() { Name = "Increment EvaluatedSolutions" }; … … 195 214 layerVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Layer", new IntValue(0))); 196 215 layerVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>("LayerResults")); 216 layerVariableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("SelectionPressure", new DoubleValue(0))); 217 layerVariableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("CurrentSuccessRatio", new DoubleValue(0))); 197 218 layerVariableCreator.Successor = initLayerAnalyzerPlaceholder; 198 219 199 220 initLayerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name; 200 initLayerAnalyzerPlaceholder.Successor = null; 221 initLayerAnalyzerPlaceholder.Successor = layerResultCollector; 222 223 layerResultCollector.ResultsParameter.ActualName = "LayerResults"; 224 layerResultCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Selection Pressure", "Displays the rising selection pressure during a generation.", "SelectionPressure")); 225 layerResultCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Success Ratio", "Indicates how many successful children were already found during a generation (relative to the population size).", "CurrentSuccessRatio")); 226 layerResultCollector.Successor = null; 201 227 202 228 initAnalyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameter.Name; … … 233 259 mainOperator.ElitesParameter.ActualName = ElitesParameter.Name; 234 260 mainOperator.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name; 235 mainOperator.PlusSelectionParameter.ActualName = PlusSelectionParameter.Name; 261 mainOperator.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name; 262 mainOperator.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name; 263 mainOperator.CurrentSuccessRatioParameter.ActualName = "CurrentSuccessRatio"; 264 mainOperator.SelectionPressureParameter.ActualName = "SelectionPressure"; 265 mainOperator.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name; 266 mainOperator.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name; 267 mainOperator.FillPopulationWithParentsParameter.ActualName = FillPopulationWithParentsParameter.Name; 236 268 mainOperator.AgeParameter.ActualName = AgeParameter.Name; 237 269 mainOperator.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name; … … 327 359 var updateLayerNumber = new Assigner() { Name = "Layer = OpenLayers" }; 328 360 var historyWiper = new ResultsHistoryWiper() { Name = "Clear History in Results" }; 329 var createChildrenViaCrossover = new Alps GeneticAlgorithmMainOperator();361 var createChildrenViaCrossover = new AlpsOffspringSelectionGeneticAlgorithmMainOperator(); 330 362 var incrEvaluatedSolutionsForNewLayer = new SubScopesCounter() { Name = "Update EvaluatedSolutions" }; 331 363 var incrOpenLayers = new IntCounter() { Name = "Incr. OpenLayers" }; … … 373 405 createChildrenViaCrossover.SelectorParameter.ActualName = SelectorParameter.Name; 374 406 createChildrenViaCrossover.CrossoverParameter.ActualName = CrossoverParameter.Name; 375 createChildrenViaCrossover.MutatorParameter.ActualName = MutatorParameter. Name;407 createChildrenViaCrossover.MutatorParameter.ActualName = MutatorParameter.ActualName; 376 408 createChildrenViaCrossover.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name; 377 409 createChildrenViaCrossover.ElitesParameter.ActualName = ElitesParameter.Name; 378 410 createChildrenViaCrossover.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name; 379 createChildrenViaCrossover.PlusSelectionParameter.ActualName = PlusSelectionParameter.Name; 411 createChildrenViaCrossover.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name; 412 createChildrenViaCrossover.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name; 413 createChildrenViaCrossover.CurrentSuccessRatioParameter.ActualName = "CurrentSuccessRatio"; 414 createChildrenViaCrossover.SelectionPressureParameter.ActualName = "SelectionPressure"; 415 createChildrenViaCrossover.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name; 416 createChildrenViaCrossover.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name; 417 createChildrenViaCrossover.FillPopulationWithParentsParameter.ActualName = FillPopulationWithParentsParameter.Name; 380 418 createChildrenViaCrossover.AgeParameter.ActualName = AgeParameter.Name; 381 419 createChildrenViaCrossover.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name; -
trunk/sources/HeuristicLab.Algorithms.ALPS/3.3/AlpsOffspringSelectionGeneticAlgorithmMainOperator.cs
r13326 r13402 29 29 using HeuristicLab.Selection; 30 30 31 namespace HeuristicLab.Algorithms. OffspringSelectionGeneticAlgorithm{31 namespace HeuristicLab.Algorithms.ALPS { 32 32 /// <summary> 33 33 /// An operator which represents the main loop of an offspring selection genetic algorithm. 34 34 /// </summary> 35 [Item(" OffspringSelectionGeneticAlgorithmMainOperator", "An operator that represents the core of anoffspring selection genetic algorithm.")]35 [Item("AlpsOffspringSelectionGeneticAlgorithmMainOperator", "An operator that represents the core of an alps offspring selection genetic algorithm.")] 36 36 [StorableClass] 37 public sealed class OffspringSelectionGeneticAlgorithmMainOperator : AlgorithmOperator {37 public sealed class AlpsOffspringSelectionGeneticAlgorithmMainOperator : AlgorithmOperator { 38 38 #region Parameter properties 39 public ValueLookupParameter<IRandom> RandomParameter { 40 get { return (ValueLookupParameter<IRandom>)Parameters["Random"]; } 41 } 42 public ValueLookupParameter<BoolValue> MaximizationParameter { 43 get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; } 44 } 45 public ScopeTreeLookupParameter<DoubleValue> QualityParameter { 46 get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 47 } 48 public ValueLookupParameter<IOperator> SelectorParameter { 49 get { return (ValueLookupParameter<IOperator>)Parameters["Selector"]; } 50 } 51 public ValueLookupParameter<IOperator> CrossoverParameter { 52 get { return (ValueLookupParameter<IOperator>)Parameters["Crossover"]; } 53 } 54 public ValueLookupParameter<PercentValue> MutationProbabilityParameter { 55 get { return (ValueLookupParameter<PercentValue>)Parameters["MutationProbability"]; } 56 } 57 public ValueLookupParameter<IOperator> MutatorParameter { 58 get { return (ValueLookupParameter<IOperator>)Parameters["Mutator"]; } 59 } 60 public ValueLookupParameter<IOperator> EvaluatorParameter { 61 get { return (ValueLookupParameter<IOperator>)Parameters["Evaluator"]; } 62 } 63 public LookupParameter<IntValue> EvaluatedSolutionsParameter { 64 get { return (LookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; } 65 } 66 public ValueLookupParameter<IntValue> ElitesParameter { 67 get { return (ValueLookupParameter<IntValue>)Parameters["Elites"]; } 39 public IValueLookupParameter<IRandom> RandomParameter { 40 get { return (IValueLookupParameter<IRandom>)Parameters["Random"]; } 41 } 42 public IValueLookupParameter<IOperator> EvaluatorParameter { 43 get { return (IValueLookupParameter<IOperator>)Parameters["Evaluator"]; } 44 } 45 public ILookupParameter<IntValue> EvaluatedSolutionsParameter { 46 get { return (ILookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; } 47 } 48 public IScopeTreeLookupParameter<DoubleValue> QualityParameter { 49 get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 50 } 51 public IValueLookupParameter<BoolValue> MaximizationParameter { 52 get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; } 53 } 54 55 public ILookupParameter<IntValue> PopulationSizeParameter { 56 get { return (ILookupParameter<IntValue>)Parameters["PopulationSize"]; } 57 } 58 59 public IValueLookupParameter<IOperator> SelectorParameter { 60 get { return (IValueLookupParameter<IOperator>)Parameters["Selector"]; } 61 } 62 public IValueLookupParameter<IOperator> CrossoverParameter { 63 get { return (IValueLookupParameter<IOperator>)Parameters["Crossover"]; } 64 } 65 public IValueLookupParameter<IOperator> MutatorParameter { 66 get { return (IValueLookupParameter<IOperator>)Parameters["Mutator"]; } 67 } 68 public IValueLookupParameter<PercentValue> MutationProbabilityParameter { 69 get { return (IValueLookupParameter<PercentValue>)Parameters["MutationProbability"]; } 70 } 71 public IValueLookupParameter<IntValue> ElitesParameter { 72 get { return (IValueLookupParameter<IntValue>)Parameters["Elites"]; } 68 73 } 69 74 public IValueLookupParameter<BoolValue> ReevaluateElitesParameter { 70 75 get { return (IValueLookupParameter<BoolValue>)Parameters["ReevaluateElites"]; } 71 76 } 72 public LookupParameter<DoubleValue> ComparisonFactorParameter { 73 get { return (LookupParameter<DoubleValue>)Parameters["ComparisonFactor"]; } 74 } 75 public LookupParameter<DoubleValue> CurrentSuccessRatioParameter { 76 get { return (LookupParameter<DoubleValue>)Parameters["CurrentSuccessRatio"]; } 77 } 78 public ValueLookupParameter<DoubleValue> SuccessRatioParameter { 79 get { return (ValueLookupParameter<DoubleValue>)Parameters["SuccessRatio"]; } 80 } 81 public LookupParameter<DoubleValue> SelectionPressureParameter { 82 get { return (LookupParameter<DoubleValue>)Parameters["SelectionPressure"]; } 83 } 84 public ValueLookupParameter<DoubleValue> MaximumSelectionPressureParameter { 85 get { return (ValueLookupParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; } 86 } 87 public ValueLookupParameter<BoolValue> OffspringSelectionBeforeMutationParameter { 88 get { return (ValueLookupParameter<BoolValue>)Parameters["OffspringSelectionBeforeMutation"]; } 77 78 public ILookupParameter<DoubleValue> ComparisonFactorParameter { 79 get { return (ILookupParameter<DoubleValue>)Parameters["ComparisonFactor"]; } 80 } 81 public ILookupParameter<DoubleValue> CurrentSuccessRatioParameter { 82 get { return (ILookupParameter<DoubleValue>)Parameters["CurrentSuccessRatio"]; } 83 } 84 public IValueLookupParameter<DoubleValue> SuccessRatioParameter { 85 get { return (IValueLookupParameter<DoubleValue>)Parameters["SuccessRatio"]; } 86 } 87 public ILookupParameter<DoubleValue> SelectionPressureParameter { 88 get { return (ILookupParameter<DoubleValue>)Parameters["SelectionPressure"]; } 89 } 90 public IValueLookupParameter<DoubleValue> MaximumSelectionPressureParameter { 91 get { return (IValueLookupParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; } 92 } 93 public IValueLookupParameter<BoolValue> OffspringSelectionBeforeMutationParameter { 94 get { return (IValueLookupParameter<BoolValue>)Parameters["OffspringSelectionBeforeMutation"]; } 89 95 } 90 96 public IValueLookupParameter<BoolValue> FillPopulationWithParentsParameter { 91 97 get { return (IValueLookupParameter<BoolValue>)Parameters["FillPopulationWithParents"]; } 92 98 } 99 100 public IScopeTreeLookupParameter<DoubleValue> AgeParameter { 101 get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Age"]; } 102 } 103 public IValueLookupParameter<DoubleValue> AgeInheritanceParameter { 104 get { return (IValueLookupParameter<DoubleValue>)Parameters["AgeInheritance"]; } 105 } 106 public IValueLookupParameter<DoubleValue> AgeIncrementParameter { 107 get { return (IValueLookupParameter<DoubleValue>)Parameters["AgeIncrement"]; } 108 } 93 109 #endregion 94 110 95 111 [StorableConstructor] 96 private OffspringSelectionGeneticAlgorithmMainOperator(bool deserializing) : base(deserializing) { }97 private OffspringSelectionGeneticAlgorithmMainOperator(OffspringSelectionGeneticAlgorithmMainOperator original, Cloner cloner)112 private AlpsOffspringSelectionGeneticAlgorithmMainOperator(bool deserializing) : base(deserializing) { } 113 private AlpsOffspringSelectionGeneticAlgorithmMainOperator(AlpsOffspringSelectionGeneticAlgorithmMainOperator original, Cloner cloner) 98 114 : base(original, cloner) { 99 115 } 100 116 public override IDeepCloneable Clone(Cloner cloner) { 101 return new OffspringSelectionGeneticAlgorithmMainOperator(this, cloner);102 } 103 public OffspringSelectionGeneticAlgorithmMainOperator()117 return new AlpsOffspringSelectionGeneticAlgorithmMainOperator(this, cloner); 118 } 119 public AlpsOffspringSelectionGeneticAlgorithmMainOperator() 104 120 : base() { 105 121 Initialize(); 106 122 } 107 123 108 [StorableHook(HookType.AfterDeserialization)]109 private void AfterDeserialization() {110 // BackwardsCompatibility3.3111 #region Backwards compatible code, remove with 3.4112 if (!Parameters.ContainsKey("ReevaluateElites")) {113 Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));114 }115 if (!Parameters.ContainsKey("FillPopulationWithParents"))116 Parameters.Add(new ValueLookupParameter<BoolValue>("FillPopulationWithParents", "True if the population should be filled with parent individual or false if worse children should be used when the maximum selection pressure is exceeded."));117 #endregion118 }119 120 124 private void Initialize() { 121 #region Create parameters122 125 Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator.")); 126 127 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.")); 128 Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of evaluated solutions.")); 129 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution.")); 123 130 Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false.")); 124 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution.")); 131 132 Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population of solutions in each layer.")); 125 133 Parameters.Add(new ValueLookupParameter<IOperator>("Selector", "The operator used to select solutions for reproduction.")); 126 134 Parameters.Add(new ValueLookupParameter<IOperator>("Crossover", "The operator used to cross solutions.")); 135 Parameters.Add(new ValueLookupParameter<IOperator>("Mutator", "The operator used to mutate solutions.")); 127 136 Parameters.Add(new ValueLookupParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.")); 128 Parameters.Add(new ValueLookupParameter<IOperator>("Mutator", "The operator used to mutate solutions."));129 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."));130 Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of evaluated solutions."));131 137 Parameters.Add(new ValueLookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.")); 132 138 Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)")); 139 133 140 Parameters.Add(new LookupParameter<DoubleValue>("ComparisonFactor", "The comparison factor is used to determine whether the offspring should be compared to the better parent, the worse parent or a quality value linearly interpolated between them. It is in the range [0;1].")); 134 141 Parameters.Add(new LookupParameter<DoubleValue>("CurrentSuccessRatio", "The current success ratio.")); … … 138 145 Parameters.Add(new ValueLookupParameter<BoolValue>("OffspringSelectionBeforeMutation", "True if the offspring selection step should be applied before mutation, false if it should be applied after mutation.")); 139 146 Parameters.Add(new ValueLookupParameter<BoolValue>("FillPopulationWithParents", "True if the population should be filled with parent individual or false if worse children should be used when the maximum selection pressure is exceeded.")); 140 #endregion 141 142 #region Create operators 143 Placeholder selector = new Placeholder(); 144 SubScopesProcessor subScopesProcessor1 = new SubScopesProcessor(); 145 ChildrenCreator childrenCreator = new ChildrenCreator(); 146 ConditionalBranch osBeforeMutationBranch = new ConditionalBranch(); 147 UniformSubScopesProcessor uniformSubScopesProcessor1 = new UniformSubScopesProcessor(); 148 Placeholder crossover1 = new Placeholder(); 149 UniformSubScopesProcessor uniformSubScopesProcessor2 = new UniformSubScopesProcessor(); 150 Placeholder evaluator1 = new Placeholder(); 151 SubScopesCounter subScopesCounter1 = new SubScopesCounter(); 152 WeightedParentsQualityComparator qualityComparer1 = new WeightedParentsQualityComparator(); 153 SubScopesRemover subScopesRemover1 = new SubScopesRemover(); 154 UniformSubScopesProcessor uniformSubScopesProcessor3 = new UniformSubScopesProcessor(); 155 StochasticBranch mutationBranch1 = new StochasticBranch(); 156 Placeholder mutator1 = new Placeholder(); 157 VariableCreator variableCreator1 = new VariableCreator(); 158 VariableCreator variableCreator2 = new VariableCreator(); 159 ConditionalSelector conditionalSelector = new ConditionalSelector(); 160 SubScopesProcessor subScopesProcessor2 = new SubScopesProcessor(); 161 UniformSubScopesProcessor uniformSubScopesProcessor4 = new UniformSubScopesProcessor(); 162 Placeholder evaluator2 = new Placeholder(); 163 SubScopesCounter subScopesCounter2 = new SubScopesCounter(); 164 MergingReducer mergingReducer1 = new MergingReducer(); 165 UniformSubScopesProcessor uniformSubScopesProcessor5 = new UniformSubScopesProcessor(); 166 Placeholder crossover2 = new Placeholder(); 167 StochasticBranch mutationBranch2 = new StochasticBranch(); 168 Placeholder mutator2 = new Placeholder(); 169 UniformSubScopesProcessor uniformSubScopesProcessor6 = new UniformSubScopesProcessor(); 170 Placeholder evaluator3 = new Placeholder(); 171 SubScopesCounter subScopesCounter3 = new SubScopesCounter(); 172 WeightedParentsQualityComparator qualityComparer2 = new WeightedParentsQualityComparator(); 173 SubScopesRemover subScopesRemover2 = new SubScopesRemover(); 174 OffspringSelector offspringSelector = new OffspringSelector(); 175 SubScopesProcessor subScopesProcessor3 = new SubScopesProcessor(); 176 BestSelector bestSelector = new BestSelector(); 177 WorstSelector worstSelector = new WorstSelector(); 178 RightReducer rightReducer = new RightReducer(); 179 LeftReducer leftReducer = new LeftReducer(); 180 MergingReducer mergingReducer2 = new MergingReducer(); 181 ConditionalBranch reevaluateElitesBranch = new ConditionalBranch(); 182 UniformSubScopesProcessor uniformSubScopesProcessor7 = new UniformSubScopesProcessor(); 183 Placeholder evaluator4 = new Placeholder(); 184 SubScopesCounter subScopesCounter4 = new SubScopesCounter(); 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<DoubleValue>("AgeIncrement", "The value the age the individuals is incremented if they survives a generation.")); 151 152 153 var selector = new Placeholder(); 154 var subScopesProcessor1 = new SubScopesProcessor(); 155 var childrenCreator = new ChildrenCreator(); 156 var osBeforeMutationBranch = new ConditionalBranch(); 157 var uniformSubScopesProcessor1 = new UniformSubScopesProcessor(); 158 var crossover1 = new Placeholder(); 159 var uniformSubScopesProcessor2 = new UniformSubScopesProcessor(); 160 var evaluator1 = new Placeholder(); 161 var subScopesCounter1 = new SubScopesCounter(); 162 var qualityComparer1 = new WeightedParentsQualityComparator(); 163 var ageCalculator1 = new WeightingReducer() { Name = "Calculate Age" }; 164 var subScopesRemover1 = new SubScopesRemover(); 165 var uniformSubScopesProcessor3 = new UniformSubScopesProcessor(); 166 var mutationBranch1 = new StochasticBranch(); 167 var mutator1 = new Placeholder(); 168 var variableCreator1 = new VariableCreator(); 169 var variableCreator2 = new VariableCreator(); 170 var conditionalSelector = new ConditionalSelector(); 171 var subScopesProcessor2 = new SubScopesProcessor(); 172 var uniformSubScopesProcessor4 = new UniformSubScopesProcessor(); 173 var evaluator2 = new Placeholder(); 174 var subScopesCounter2 = new SubScopesCounter(); 175 var mergingReducer1 = new MergingReducer(); 176 var uniformSubScopesProcessor5 = new UniformSubScopesProcessor(); 177 var crossover2 = new Placeholder(); 178 var mutationBranch2 = new StochasticBranch(); 179 var mutator2 = new Placeholder(); 180 var uniformSubScopesProcessor6 = new UniformSubScopesProcessor(); 181 var evaluator3 = new Placeholder(); 182 var subScopesCounter3 = new SubScopesCounter(); 183 var qualityComparer2 = new WeightedParentsQualityComparator(); 184 var ageCalculator2 = new WeightingReducer() { Name = "Calculate Age" }; 185 var subScopesRemover2 = new SubScopesRemover(); 186 var offspringSelector = new AlpsOffspringSelector(); 187 var subScopesProcessor3 = new SubScopesProcessor(); 188 var bestSelector = new BestSelector(); 189 var worstSelector = new WorstSelector(); 190 var rightReducer = new RightReducer(); 191 var leftReducer = new LeftReducer(); 192 var mergingReducer2 = new MergingReducer(); 193 var reevaluateElitesBranch = new ConditionalBranch(); 194 var uniformSubScopesProcessor7 = new UniformSubScopesProcessor(); 195 var evaluator4 = new Placeholder(); 196 var subScopesCounter4 = new SubScopesCounter(); 197 var incrementAgeProcessor = new UniformSubScopesProcessor(); 198 var ageIncrementor = new DoubleCounter() { Name = "Increment Age" }; 199 200 201 OperatorGraph.InitialOperator = selector; 185 202 186 203 selector.Name = "Selector (placeholder)"; 187 204 selector.OperatorParameter.ActualName = SelectorParameter.Name; 205 selector.Successor = subScopesProcessor1; 206 207 subScopesProcessor1.Operators.Add(new EmptyOperator()); 208 subScopesProcessor1.Operators.Add(childrenCreator); 209 subScopesProcessor1.Successor = offspringSelector; 188 210 189 211 childrenCreator.ParentsPerChild = new IntValue(2); 212 childrenCreator.Successor = osBeforeMutationBranch; 190 213 191 214 osBeforeMutationBranch.Name = "Apply OS before mutation?"; 192 215 osBeforeMutationBranch.ConditionParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name; 216 osBeforeMutationBranch.TrueBranch = uniformSubScopesProcessor1; 217 osBeforeMutationBranch.FalseBranch = uniformSubScopesProcessor5; 218 osBeforeMutationBranch.Successor = null; 219 220 uniformSubScopesProcessor1.Operator = crossover1; 221 uniformSubScopesProcessor1.Successor = uniformSubScopesProcessor2; 193 222 194 223 crossover1.Name = "Crossover (placeholder)"; 195 224 crossover1.OperatorParameter.ActualName = CrossoverParameter.Name; 225 crossover1.Successor = null; 196 226 197 227 uniformSubScopesProcessor2.Parallel.Value = true; 228 uniformSubScopesProcessor2.Operator = evaluator1; 229 uniformSubScopesProcessor2.Successor = subScopesCounter1; 198 230 199 231 evaluator1.Name = "Evaluator (placeholder)"; 200 232 evaluator1.OperatorParameter.ActualName = EvaluatorParameter.Name; 233 evaluator1.Successor = qualityComparer1; 201 234 202 235 subScopesCounter1.Name = "Increment EvaluatedSolutions"; 203 236 subScopesCounter1.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name; 237 subScopesCounter1.Successor = uniformSubScopesProcessor3; 238 239 uniformSubScopesProcessor3.Operator = mutationBranch1; 240 uniformSubScopesProcessor3.Successor = conditionalSelector; 204 241 205 242 qualityComparer1.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name; … … 208 245 qualityComparer1.RightSideParameter.ActualName = QualityParameter.Name; 209 246 qualityComparer1.ResultParameter.ActualName = "SuccessfulOffspring"; 247 qualityComparer1.Successor = ageCalculator1; 248 249 ageCalculator1.ParameterToReduce.ActualName = AgeParameter.Name; 250 ageCalculator1.TargetParameter.ActualName = AgeParameter.Name; 251 ageCalculator1.WeightParameter.ActualName = AgeInheritanceParameter.Name; 252 ageCalculator1.Successor = subScopesRemover1; 210 253 211 254 subScopesRemover1.RemoveAllSubScopes = true; 255 subScopesRemover1.Successor = null; 212 256 213 257 mutationBranch1.ProbabilityParameter.ActualName = MutationProbabilityParameter.Name; 214 258 mutationBranch1.RandomParameter.ActualName = RandomParameter.Name; 259 mutationBranch1.FirstBranch = mutator1; 260 mutationBranch1.SecondBranch = variableCreator2; 261 mutationBranch1.Successor = null; 215 262 216 263 mutator1.Name = "Mutator (placeholder)"; 217 264 mutator1.OperatorParameter.ActualName = MutatorParameter.Name; 265 mutator1.Successor = variableCreator1; 218 266 219 267 variableCreator1.Name = "MutatedOffspring = true"; 220 268 variableCreator1.CollectedValues.Add(new ValueParameter<BoolValue>("MutatedOffspring", null, new BoolValue(true), false)); 269 variableCreator1.Successor = null; 221 270 222 271 variableCreator2.Name = "MutatedOffspring = false"; 223 272 variableCreator2.CollectedValues.Add(new ValueParameter<BoolValue>("MutatedOffspring", null, new BoolValue(false), false)); 273 variableCreator2.Successor = null; 224 274 225 275 conditionalSelector.ConditionParameter.ActualName = "MutatedOffspring"; 226 276 conditionalSelector.ConditionParameter.Depth = 1; 227 277 conditionalSelector.CopySelected.Value = false; 278 conditionalSelector.Successor = subScopesProcessor2; 279 280 subScopesProcessor2.Operators.Add(new EmptyOperator()); 281 subScopesProcessor2.Operators.Add(uniformSubScopesProcessor4); 282 subScopesProcessor2.Successor = mergingReducer1; 283 284 mergingReducer1.Successor = null; 228 285 229 286 uniformSubScopesProcessor4.Parallel.Value = true; 287 uniformSubScopesProcessor4.Operator = evaluator2; 288 uniformSubScopesProcessor4.Successor = subScopesCounter2; 230 289 231 290 evaluator2.Name = "Evaluator (placeholder)"; 232 291 evaluator2.OperatorParameter.ActualName = EvaluatorParameter.Name; 292 evaluator2.Successor = null; 233 293 234 294 subScopesCounter2.Name = "Increment EvaluatedSolutions"; 235 295 subScopesCounter2.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name; 296 subScopesCounter2.Successor = null; 297 298 uniformSubScopesProcessor5.Operator = crossover2; 299 uniformSubScopesProcessor5.Successor = uniformSubScopesProcessor6; 236 300 237 301 crossover2.Name = "Crossover (placeholder)"; 238 302 crossover2.OperatorParameter.ActualName = CrossoverParameter.Name; 303 crossover2.Successor = mutationBranch2; 239 304 240 305 mutationBranch2.ProbabilityParameter.ActualName = MutationProbabilityParameter.Name; 241 306 mutationBranch2.RandomParameter.ActualName = RandomParameter.Name; 307 mutationBranch2.FirstBranch = mutator2; 308 mutationBranch2.SecondBranch = null; 309 mutationBranch2.Successor = null; 242 310 243 311 mutator2.Name = "Mutator (placeholder)"; 244 312 mutator2.OperatorParameter.ActualName = MutatorParameter.Name; 313 mutator2.Successor = null; 245 314 246 315 uniformSubScopesProcessor6.Parallel.Value = true; 316 uniformSubScopesProcessor6.Operator = evaluator3; 317 uniformSubScopesProcessor6.Successor = subScopesCounter3; 247 318 248 319 evaluator3.Name = "Evaluator (placeholder)"; 249 320 evaluator3.OperatorParameter.ActualName = EvaluatorParameter.Name; 321 evaluator3.Successor = qualityComparer2; 250 322 251 323 subScopesCounter3.Name = "Increment EvaluatedSolutions"; … … 257 329 qualityComparer2.RightSideParameter.ActualName = QualityParameter.Name; 258 330 qualityComparer2.ResultParameter.ActualName = "SuccessfulOffspring"; 331 qualityComparer2.Successor = ageCalculator2; 332 333 ageCalculator2.ParameterToReduce.ActualName = AgeParameter.Name; 334 ageCalculator2.TargetParameter.ActualName = AgeParameter.Name; 335 ageCalculator2.WeightParameter.ActualName = AgeInheritanceParameter.Name; 336 ageCalculator2.Successor = subScopesRemover2; 259 337 260 338 subScopesRemover2.RemoveAllSubScopes = true; 339 subScopesRemover2.Successor = null; 340 341 subScopesCounter3.Successor = null; 261 342 262 343 offspringSelector.CurrentSuccessRatioParameter.ActualName = CurrentSuccessRatioParameter.Name; … … 268 349 offspringSelector.SuccessfulOffspringParameter.ActualName = "SuccessfulOffspring"; 269 350 offspringSelector.FillPopulationWithParentsParameter.ActualName = FillPopulationWithParentsParameter.Name; 351 offspringSelector.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name; 352 offspringSelector.OffspringCreator = selector; 353 offspringSelector.Successor = subScopesProcessor3; 354 355 subScopesProcessor3.Operators.Add(bestSelector); 356 subScopesProcessor3.Operators.Add(worstSelector); 357 subScopesProcessor3.Successor = mergingReducer2; 270 358 271 359 bestSelector.CopySelected = new BoolValue(false); … … 273 361 bestSelector.NumberOfSelectedSubScopesParameter.ActualName = ElitesParameter.Name; 274 362 bestSelector.QualityParameter.ActualName = QualityParameter.Name; 363 bestSelector.Successor = rightReducer; 364 365 rightReducer.Successor = reevaluateElitesBranch; 366 367 reevaluateElitesBranch.ConditionParameter.ActualName = "ReevaluateElites"; 368 reevaluateElitesBranch.Name = "Reevaluate elites ?"; 369 reevaluateElitesBranch.TrueBranch = uniformSubScopesProcessor7; 370 reevaluateElitesBranch.FalseBranch = null; 371 reevaluateElitesBranch.Successor = null; 372 373 uniformSubScopesProcessor7.Parallel.Value = true; 374 uniformSubScopesProcessor7.Operator = evaluator4; 375 uniformSubScopesProcessor7.Successor = subScopesCounter4; 376 377 evaluator4.Name = "Evaluator (placeholder)"; 378 evaluator4.OperatorParameter.ActualName = EvaluatorParameter.Name; 379 380 subScopesCounter4.Name = "Increment EvaluatedSolutions"; 381 subScopesCounter4.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name; 382 subScopesCounter4.Successor = null; 275 383 276 384 worstSelector.CopySelected = new BoolValue(false); … … 278 386 worstSelector.NumberOfSelectedSubScopesParameter.ActualName = ElitesParameter.Name; 279 387 worstSelector.QualityParameter.ActualName = QualityParameter.Name; 280 281 reevaluateElitesBranch.ConditionParameter.ActualName = "ReevaluateElites";282 reevaluateElitesBranch.Name = "Reevaluate elites ?";283 284 uniformSubScopesProcessor7.Parallel.Value = true;285 286 evaluator4.Name = "Evaluator (placeholder)";287 evaluator4.OperatorParameter.ActualName = EvaluatorParameter.Name;288 289 subScopesCounter4.Name = "Increment EvaluatedSolutions";290 subScopesCounter4.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;291 #endregion292 293 #region Create operator graph294 OperatorGraph.InitialOperator = selector;295 selector.Successor = subScopesProcessor1;296 subScopesProcessor1.Operators.Add(new EmptyOperator());297 subScopesProcessor1.Operators.Add(childrenCreator);298 subScopesProcessor1.Successor = offspringSelector;299 childrenCreator.Successor = osBeforeMutationBranch;300 osBeforeMutationBranch.TrueBranch = uniformSubScopesProcessor1;301 osBeforeMutationBranch.FalseBranch = uniformSubScopesProcessor5;302 osBeforeMutationBranch.Successor = null;303 uniformSubScopesProcessor1.Operator = crossover1;304 uniformSubScopesProcessor1.Successor = uniformSubScopesProcessor2;305 crossover1.Successor = null;306 uniformSubScopesProcessor2.Operator = evaluator1;307 uniformSubScopesProcessor2.Successor = subScopesCounter1;308 evaluator1.Successor = qualityComparer1;309 qualityComparer1.Successor = subScopesRemover1;310 subScopesRemover1.Successor = null;311 subScopesCounter1.Successor = uniformSubScopesProcessor3;312 uniformSubScopesProcessor3.Operator = mutationBranch1;313 uniformSubScopesProcessor3.Successor = conditionalSelector;314 mutationBranch1.FirstBranch = mutator1;315 mutationBranch1.SecondBranch = variableCreator2;316 mutationBranch1.Successor = null;317 mutator1.Successor = variableCreator1;318 variableCreator1.Successor = null;319 variableCreator2.Successor = null;320 conditionalSelector.Successor = subScopesProcessor2;321 subScopesProcessor2.Operators.Add(new EmptyOperator());322 subScopesProcessor2.Operators.Add(uniformSubScopesProcessor4);323 subScopesProcessor2.Successor = mergingReducer1;324 uniformSubScopesProcessor4.Operator = evaluator2;325 uniformSubScopesProcessor4.Successor = subScopesCounter2;326 evaluator2.Successor = null;327 subScopesCounter2.Successor = null;328 mergingReducer1.Successor = null;329 uniformSubScopesProcessor5.Operator = crossover2;330 uniformSubScopesProcessor5.Successor = uniformSubScopesProcessor6;331 crossover2.Successor = mutationBranch2;332 mutationBranch2.FirstBranch = mutator2;333 mutationBranch2.SecondBranch = null;334 mutationBranch2.Successor = null;335 mutator2.Successor = null;336 uniformSubScopesProcessor6.Operator = evaluator3;337 uniformSubScopesProcessor6.Successor = subScopesCounter3;338 evaluator3.Successor = qualityComparer2;339 qualityComparer2.Successor = subScopesRemover2;340 subScopesRemover2.Successor = null;341 subScopesCounter3.Successor = null;342 offspringSelector.OffspringCreator = selector;343 offspringSelector.Successor = subScopesProcessor3;344 subScopesProcessor3.Operators.Add(bestSelector);345 subScopesProcessor3.Operators.Add(worstSelector);346 subScopesProcessor3.Successor = mergingReducer2;347 bestSelector.Successor = rightReducer;348 rightReducer.Successor = reevaluateElitesBranch;349 reevaluateElitesBranch.TrueBranch = uniformSubScopesProcessor7;350 uniformSubScopesProcessor7.Operator = evaluator4;351 uniformSubScopesProcessor7.Successor = subScopesCounter4;352 subScopesCounter4.Successor = null;353 reevaluateElitesBranch.FalseBranch = null;354 reevaluateElitesBranch.Successor = null;355 388 worstSelector.Successor = leftReducer; 389 356 390 leftReducer.Successor = null; 357 mergingReducer2.Successor = null; 358 #endregion 391 392 mergingReducer2.Successor = incrementAgeProcessor; 393 394 incrementAgeProcessor.Operator = ageIncrementor; 395 incrementAgeProcessor.Successor = null; 396 397 ageIncrementor.ValueParameter.ActualName = AgeParameter.Name; 398 ageIncrementor.IncrementParameter.Value = null; 399 ageIncrementor.IncrementParameter.ActualName = AgeIncrementParameter.Name; 400 ageIncrementor.Successor = null; 359 401 } 360 402 -
trunk/sources/HeuristicLab.Algorithms.ALPS/3.3/AlpsOffspringSelector.cs
r13391 r13402 28 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 29 30 namespace HeuristicLab. Selection{31 [Item(" OffspringSelector", "Selects among the offspring population those that are designated successful and discards the unsuccessful offspring, except for some lucky losers. It expects the parent scopes to be below the first sub-scope, and offspring scopes to be below the second sub-scope separated again in two sub-scopes, the first with the failed offspring and the second with successful offspring.")]30 namespace HeuristicLab.Algorithms.ALPS { 31 [Item("AlpsOffspringSelector", "Selects among the offspring population those that are designated successful and discards the unsuccessful offspring, except for some lucky losers. It expects the parent scopes to be below the first sub-scope, and offspring scopes to be below the second sub-scope separated again in two sub-scopes, the first with the failed offspring and the second with successful offspring.")] 32 32 [StorableClass] 33 public class OffspringSelector : SingleSuccessorOperator {34 public ValueLookupParameter<DoubleValue> MaximumSelectionPressureParameter {35 get { return ( ValueLookupParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; }33 public class AlpsOffspringSelector : SingleSuccessorOperator { 34 public IValueLookupParameter<DoubleValue> MaximumSelectionPressureParameter { 35 get { return (IValueLookupParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; } 36 36 } 37 public ValueLookupParameter<DoubleValue> SuccessRatioParameter {38 get { return ( ValueLookupParameter<DoubleValue>)Parameters["SuccessRatio"]; }37 public IValueLookupParameter<DoubleValue> SuccessRatioParameter { 38 get { return (IValueLookupParameter<DoubleValue>)Parameters["SuccessRatio"]; } 39 39 } 40 public LookupParameter<DoubleValue> SelectionPressureParameter {41 get { return ( ValueLookupParameter<DoubleValue>)Parameters["SelectionPressure"]; }40 public ILookupParameter<DoubleValue> SelectionPressureParameter { 41 get { return (IValueLookupParameter<DoubleValue>)Parameters["SelectionPressure"]; } 42 42 } 43 public LookupParameter<DoubleValue> CurrentSuccessRatioParameter {44 get { return ( LookupParameter<DoubleValue>)Parameters["CurrentSuccessRatio"]; }43 public ILookupParameter<DoubleValue> CurrentSuccessRatioParameter { 44 get { return (ILookupParameter<DoubleValue>)Parameters["CurrentSuccessRatio"]; } 45 45 } 46 public LookupParameter<ItemList<IScope>> OffspringPopulationParameter {47 get { return ( LookupParameter<ItemList<IScope>>)Parameters["OffspringPopulation"]; }46 public ILookupParameter<ItemList<IScope>> OffspringPopulationParameter { 47 get { return (ILookupParameter<ItemList<IScope>>)Parameters["OffspringPopulation"]; } 48 48 } 49 public LookupParameter<IntValue> OffspringPopulationWinnersParameter {50 get { return ( LookupParameter<IntValue>)Parameters["OffspringPopulationWinners"]; }49 public ILookupParameter<IntValue> OffspringPopulationWinnersParameter { 50 get { return (ILookupParameter<IntValue>)Parameters["OffspringPopulationWinners"]; } 51 51 } 52 public ScopeTreeLookupParameter<BoolValue> SuccessfulOffspringParameter {53 get { return ( ScopeTreeLookupParameter<BoolValue>)Parameters["SuccessfulOffspring"]; }52 public IScopeTreeLookupParameter<BoolValue> SuccessfulOffspringParameter { 53 get { return (IScopeTreeLookupParameter<BoolValue>)Parameters["SuccessfulOffspring"]; } 54 54 } 55 55 public OperatorParameter OffspringCreatorParameter { 56 56 get { return (OperatorParameter)Parameters["OffspringCreator"]; } 57 57 } 58 59 58 public IValueLookupParameter<BoolValue> FillPopulationWithParentsParameter { 60 59 get { return (IValueLookupParameter<BoolValue>)Parameters["FillPopulationWithParents"]; } 60 } 61 public ILookupParameter<IntValue> PopulationSizeParameter { 62 get { return (ILookupParameter<IntValue>)Parameters["PopulationSize"]; } 61 63 } 62 64 … … 67 69 68 70 [StorableConstructor] 69 protected OffspringSelector(bool deserializing) : base(deserializing) { } 70 [StorableHook(HookType.AfterDeserialization)] 71 private void AfterDeserialization() { 72 // BackwardsCompatibility3.3 73 #region Backwards compatible code, remove with 3.4 74 if (Parameters.ContainsKey("FillPopulationWithParents") && Parameters["FillPopulationWithParents"] is FixedValueParameter<BoolValue>) 75 Parameters.Remove("FillPopulationWithParents"); 76 if (!Parameters.ContainsKey("FillPopulationWithParents")) 77 Parameters.Add(new ValueLookupParameter<BoolValue>("FillPopulationWithParents", "True if the population should be filled with parent individuals instead of lucky losers.")); 78 #endregion 71 protected AlpsOffspringSelector(bool deserializing) : base(deserializing) { } 72 protected AlpsOffspringSelector(AlpsOffspringSelector original, Cloner cloner) : base(original, cloner) { } 73 public override IDeepCloneable Clone(Cloner cloner) { 74 return new AlpsOffspringSelector(this, cloner); 79 75 } 80 81 protected OffspringSelector(OffspringSelector original, Cloner cloner) : base(original, cloner) { } 82 public override IDeepCloneable Clone(Cloner cloner) { 83 return new OffspringSelector(this, cloner); 84 } 85 public OffspringSelector() 76 public AlpsOffspringSelector() 86 77 : base() { 87 78 Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure which prematurely terminates the offspring selection step.")); … … 94 85 Parameters.Add(new OperatorParameter("OffspringCreator", "The operator used to create new offspring.")); 95 86 Parameters.Add(new ValueLookupParameter<BoolValue>("FillPopulationWithParents", "True if the population should be filled with parent individual or false if worse children should be used when the maximum selection pressure is exceeded.")); 87 Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population of solutions in each layer.")); 96 88 } 97 89 … … 105 97 IScope parents = scope.SubScopes[0]; 106 98 IScope offspring = scope.SubScopes[1]; 107 int populationSize = parents.SubScopes.Count;99 int populationSize = PopulationSizeParameter.ActualValue.Value; 108 100 109 101 // retrieve actual selection pressure and success ratio -
trunk/sources/HeuristicLab.Algorithms.ALPS/3.3/HeuristicLab.Algorithms.ALPS-3.3.csproj
r13231 r13402 85 85 </ItemGroup> 86 86 <ItemGroup> 87 <Compile Include="AlpsOffspringSelectionGeneticAlgorithmMainLoop.cs" /> 88 <Compile Include="AlpsOffspringSelectionGeneticAlgorithm.cs" /> 87 89 <Compile Include="AlpsGeneticAlgorithmMainOperator.cs" /> 90 <Compile Include="AlpsOffspringSelectionGeneticAlgorithmMainOperator.cs" /> 91 <Compile Include="AlpsOffspringSelector.cs" /> 88 92 <Compile Include="ReseedingController.cs" /> 89 93 <Compile Include="ResultsHistoryWiper.cs" />
Note: See TracChangeset
for help on using the changeset viewer.