Changeset 12550
- Timestamp:
- 06/30/15 12:43:44 (9 years ago)
- Location:
- branches/ALPS/HeuristicLab.Algorithms.ALPS.OffspringSelection/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ALPS/HeuristicLab.Algorithms.ALPS.OffspringSelection/3.3/AlpsOffspringSelectionGeneticAlgorithm.cs
r12331 r12550 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Linq; 24 25 using HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm; … … 63 64 get { return (IFixedValueParameter<BoolValue>)Parameters["ReevaluateElites"]; } 64 65 } 65 private I ValueParameter<IntValue> MaximumGenerationsParameter {66 get { return (I ValueParameter<IntValue>)Parameters["MaximumGenerations"]; }66 private IFixedValueParameter<IntValue> MaximumGenerationsParameter { 67 get { return (IFixedValueParameter<IntValue>)Parameters["MaximumGenerations"]; } 67 68 } 68 69 private ValueLookupParameter<DoubleValue> SuccessRatioParameter { … … 78 79 get { return (IConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["ComparisonFactorModifier"]; } 79 80 } 80 private ValueLookupParameter<DoubleValue> MaximumSelectionPressureParameter {81 get { return ( ValueLookupParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; }81 private IFixedValueParameter<DoubleValue> MaximumSelectionPressureParameter { 82 get { return (IFixedValueParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; } 82 83 } 83 84 private ValueLookupParameter<BoolValue> OffspringSelectionBeforeMutationParameter { … … 87 88 get { return (ValueLookupParameter<IntValue>)Parameters["SelectedParents"]; } 88 89 } 89 private ValueParameter<IntValue> MaximumEvaluatedSolutionsParameter {90 get { return ( ValueParameter<IntValue>)Parameters["MaximumEvaluatedSolutions"]; }90 private IValueParameter<IntValue> MaximumEvaluatedSolutionsParameter { 91 get { return (IValueParameter<IntValue>)Parameters["MaximumEvaluatedSolutions"]; } 91 92 } 92 93 private IFixedValueParameter<BoolValue> FillPopulationWithParentsParameter { … … 124 125 set { ReevaluateElitesParameter.Value.Value = value; } 125 126 } 126 public IntValueMaximumGenerations {127 get { return MaximumGenerationsParameter.Value ; }128 set { MaximumGenerationsParameter.Value = value; }127 public int MaximumGenerations { 128 get { return MaximumGenerationsParameter.Value.Value; } 129 set { MaximumGenerationsParameter.Value.Value = value; } 129 130 } 130 131 public DoubleValue SuccessRatio { … … 144 145 set { ComparisonFactorModifierParameter.Value = value; } 145 146 } 146 public DoubleValue MaximumSelectionPressure {147 get { return MaximumSelectionPressureParameter.Value ; }148 set { MaximumSelectionPressureParameter.Value = value; }147 public double MaximumSelectionPressure { 148 get { return MaximumSelectionPressureParameter.Value.Value; } 149 set { MaximumSelectionPressureParameter.Value.Value = value; } 149 150 } 150 151 public BoolValue OffspringSelectionBeforeMutation { … … 156 157 set { SelectedParentsParameter.Value = value; } 157 158 } 158 public IntValue MaximumEvaluatedSolutions {159 get { return MaximumEvaluatedSolutionsParameter.Value; }160 set { MaximumEvaluatedSolutionsParameter.Value = value; }161 }162 159 public bool FillPopulationWithParents { 163 160 get { return FillPopulationWithParentsParameter.Value.Value; } … … 171 168 172 169 [Storable] 173 private ValueAnalyzer selectionPressureAnalyzer;170 private ValueAnalyzer layerSelectionPressureAnalyzer; 174 171 [Storable] 175 172 private SuccessfulOffspringAnalyzer successfulOffspringAnalyzer; 173 174 [Storable] 175 private ComparisonTerminator<IntValue> generationsTerminator; 176 //[Storable]private ComparisonTerminator<DoubleValue> selectionPressureTerminator; 176 177 177 178 [StorableConstructor] … … 180 181 private AlpsOffspringSelectionGeneticAlgorithm(AlpsOffspringSelectionGeneticAlgorithm original, Cloner cloner) 181 182 : base(original, cloner) { 182 selectionPressureAnalyzer = cloner.Clone(original.selectionPressureAnalyzer);183 layerSelectionPressureAnalyzer = cloner.Clone(original.layerSelectionPressureAnalyzer); 183 184 successfulOffspringAnalyzer = cloner.Clone(original.successfulOffspringAnalyzer); 185 generationsTerminator = cloner.Clone(original.generationsTerminator); 186 //selectionPressureTerminator = cloner.Clone(original.selectionPressureTerminator); 184 187 Initialize(); 185 188 } … … 197 200 Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1))); 198 201 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 }); 199 Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000)));202 Parameters.Add(new FixedValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000))); 200 203 Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved.", new DoubleValue(1))); 201 204 Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorLowerBound", "The lower bound of the comparison factor (start).", new DoubleValue(0))); 202 205 Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorUpperBound", "The upper bound of the comparison factor (end).", new DoubleValue(1))); 203 206 Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("ComparisonFactorModifier", "The operator used to modify the comparison factor.", new ItemSet<IDiscreteDoubleValueModifier>(new IDiscreteDoubleValueModifier[] { new LinearDiscreteDoubleValueModifier() }), new LinearDiscreteDoubleValueModifier())); 204 Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm.", new DoubleValue(100)));207 Parameters.Add(new FixedValueParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm.", new DoubleValue(100))); 205 208 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.", new BoolValue(false))); 206 209 Parameters.Add(new ValueLookupParameter<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))); 207 Parameters.Add(new ValueParameter<IntValue>("MaximumEvaluatedSolutions", "The maximum number of evaluated solutions (approximately).", new IntValue(int.MaxValue)));208 210 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 }); 209 211 … … 285 287 ParameterizeComparisonFactorModifiers(); 286 288 287 selectionPressureAnalyzer = new ValueAnalyzer();289 layerSelectionPressureAnalyzer = new ValueAnalyzer(); 288 290 successfulOffspringAnalyzer = new SuccessfulOffspringAnalyzer(); 289 selectionPressureAnalyzer.Name = "SelectionPressure Analyzer";290 selectionPressureAnalyzer.ResultsParameter.ActualName = "Results";291 selectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure";292 selectionPressureAnalyzer.ValueParameter.Depth = 0;293 selectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History";294 successfulOffspringAnalyzer.ResultsParameter.ActualName = "Results";291 layerSelectionPressureAnalyzer.Name = "SelectionPressure Analyzer"; 292 //layerSelectionPressureAnalyzer.ResultsParameter.ActualName = "Results"; 293 layerSelectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure"; 294 layerSelectionPressureAnalyzer.ValueParameter.Depth = 0; 295 layerSelectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History"; 296 //successfulOffspringAnalyzer.ResultsParameter.ActualName = "Results"; 295 297 successfulOffspringAnalyzer.GenerationsParameter.ActualName = "Generations"; 296 298 successfulOffspringAnalyzer.SuccessfulOffspringFlagParameter.Value.Value = "SuccessfulOffspring"; 297 299 successfulOffspringAnalyzer.DepthParameter.Value = new IntValue(1); 300 301 generationsTerminator = new ComparisonTerminator<IntValue>("Generations", ComparisonType.Less, MaximumGenerationsParameter) { Name = "Generations" }; 302 //selectionPressureTerminator = new ComparisonTerminator<DoubleValue>("SelectionPressure", ComparisonType.Less, MaximumSelectionPressureParameter) { Name = "Selection Pressure" }; 303 304 UpdateAnalyzers(); 305 UpdateTerminators(); 298 306 299 307 Initialize(); … … 309 317 UpdateCrossovers(); 310 318 UpdateMutators(); 319 UpdateAnalyzers(); 320 UpdateTerminators(); 311 321 } 312 322 protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) { … … 325 335 UpdateCrossovers(); 326 336 UpdateMutators(); 337 UpdateAnalyzers(); 338 UpdateTerminators(); 327 339 } 328 340 protected override void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) { … … 396 408 397 409 #region Updates 410 private void UpdateTerminators() { 411 var newTerminators = new Dictionary<ITerminator, bool> { 412 {generationsTerminator, !Terminators.Operators.Contains(generationsTerminator) || Terminators.Operators.ItemChecked(generationsTerminator)}, 413 //{selectionPressureTerminator, !Terminators.Operators.Contains(generationsTerminator) || Terminators.Operators.ItemChecked(selectionPressureTerminator)}, 414 {evaluationsTerminator, Terminators.Operators.Contains(evaluationsTerminator) && Terminators.Operators.ItemChecked(evaluationsTerminator)}, 415 {qualityTerminator, Terminators.Operators.Contains(qualityTerminator) && Terminators.Operators.ItemChecked(qualityTerminator) }, 416 {executionTimeTerminator, Terminators.Operators.Contains(executionTimeTerminator) && Terminators.Operators.ItemChecked(executionTimeTerminator)} 417 }; 418 if (Problem != null) { 419 foreach (var terminator in Problem.Operators.OfType<ITerminator>()) 420 newTerminators.Add(terminator, !Terminators.Operators.Contains(terminator) || Terminators.Operators.ItemChecked(terminator)); 421 } 422 423 Terminators.Operators.Clear(); 424 425 foreach (var newTerminator in newTerminators) 426 Terminators.Operators.Add(newTerminator.Key, newTerminator.Value); 427 } 398 428 private void UpdateCrossovers() { 399 429 var oldCrossover = CrossoverParameter.Value; … … 427 457 } 428 458 } 459 private void UpdateAnalyzers() { 460 LayerAnalyzer.Operators.Add(layerSelectionPressureAnalyzer, layerSelectionPressureAnalyzer.EnabledByDefault); 461 layerSelectionPressureAnalyzer.ValueParameter.Depth = 0; // Correct Depth because the depth of layer-analyzers is automatically set to 1 462 LayerAnalyzer.Operators.Add(successfulOffspringAnalyzer, successfulOffspringAnalyzer.EnabledByDefault); 463 } 429 464 #endregion 430 465 } -
branches/ALPS/HeuristicLab.Algorithms.ALPS.OffspringSelection/3.3/AlpsOffspringSelectionGeneticAlgorithmMainLoop.cs
r12348 r12550 113 113 var layerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" }; 114 114 var analyzerPlaceholder = new Placeholder() { Name = "Analyzer (Placeholder)" }; 115 var generationsComparator = new Comparator() { Name = "Generations >= MaximumGenerations" }; 116 var terminateBranch = new ConditionalBranch() { Name = "Terminate?" }; 115 var termination = new TerminationOperator(); 117 116 118 117 OperatorGraph.InitialOperator = variableCreator; … … 190 189 191 190 analyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameter.Name; 192 analyzerPlaceholder.Successor = generationsComparator; 193 194 generationsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual); 195 generationsComparator.LeftSideParameter.ActualName = "Generations"; 196 generationsComparator.RightSideParameter.ActualName = MaximumGenerationsParameter.Name; 197 generationsComparator.ResultParameter.ActualName = "TerminateGenerations"; 198 generationsComparator.Successor = terminateBranch; 199 200 terminateBranch.ConditionParameter.ActualName = "TerminateGenerations"; 201 terminateBranch.FalseBranch = matingPoolPreProcessor; 191 analyzerPlaceholder.Successor = termination; 192 193 termination.ContinueBranch = matingPoolPreProcessor; 202 194 } 203 195
Note: See TracChangeset
for help on using the changeset viewer.