Changeset 12411 for branches/TerminationCriteria/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm
- Timestamp:
- 06/01/15 16:47:32 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/TerminationCriteria/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/OffspringSelectionGeneticAlgorithm.cs
r12410 r12411 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Linq; 24 25 using HeuristicLab.Analysis; … … 110 111 get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; } 111 112 } 112 private ValueParameter<IntValue> MaximumEvaluatedSolutionsParameter {113 get { return ( ValueParameter<IntValue>)Parameters["MaximumEvaluatedSolutions"]; }113 private IFixedValueParameter<IntValue> MaximumEvaluatedSolutionsParameter { 114 get { return (IFixedValueParameter<IntValue>)Parameters["MaximumEvaluatedSolutions"]; } 114 115 } 115 116 private IFixedValueParameter<BoolValue> FillPopulationWithParentsParameter { … … 194 195 set { AnalyzerParameter.Value = value; } 195 196 } 196 public IntValueMaximumEvaluatedSolutions {197 get { return MaximumEvaluatedSolutionsParameter.Value ; }198 set { MaximumEvaluatedSolutionsParameter.Value = value; }197 public int MaximumEvaluatedSolutions { 198 get { return MaximumEvaluatedSolutionsParameter.Value.Value; } 199 set { MaximumEvaluatedSolutionsParameter.Value.Value = value; } 199 200 } 200 201 public bool FillPopulationWithParents { … … 221 222 private SuccessfulOffspringAnalyzer successfulOffspringAnalyzer; 222 223 [Storable] 223 private MaximumIterationsTerminatorgenerationsTerminator;224 [Storable] 225 private ComparisonTerminator<IntValue> evaluat edSolutionsTerminator;224 private ComparisonTerminator<IntValue> generationsTerminator; 225 [Storable] 226 private ComparisonTerminator<IntValue> evaluationsTerminator; 226 227 [Storable] 227 228 private ComparisonTerminator<DoubleValue> selectionPressureTerminator; … … 255 256 successfulOffspringAnalyzer = cloner.Clone(original.successfulOffspringAnalyzer); 256 257 generationsTerminator = cloner.Clone(original.generationsTerminator); 257 evaluat edSolutionsTerminator = cloner.Clone(original.evaluatedSolutionsTerminator);258 evaluationsTerminator = cloner.Clone(original.evaluationsTerminator); 258 259 selectionPressureTerminator = cloner.Clone(original.selectionPressureTerminator); 259 260 qualityTerminator = cloner.Clone(original.qualityTerminator); … … 284 285 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))); 285 286 Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer())); 286 Parameters.Add(new ValueParameter<IntValue>("MaximumEvaluatedSolutions", "The maximum number of evaluated solutions (approximately).", new IntValue(int.MaxValue)));287 Parameters.Add(new FixedValueParameter<IntValue>("MaximumEvaluatedSolutions", "The maximum number of evaluated solutions (approximately).", new IntValue(int.MaxValue))); 287 288 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 }); 288 289 Parameters.Add(new ValueParameter<MultiTerminator>("Termination", "The termination criteria which sould be checked.", new MultiTerminator())); … … 344 345 UpdateAnalyzers(); 345 346 346 generationsTerminator = new MaximumIterationsTerminator();347 evaluatedSolutionsTerminator = new ComparisonTerminator<IntValue>("EvaluatedSolutions", ComparisonType.Less, new IntValue(int.MaxValue)) { Name = "Evaluations" };348 selectionPressureTerminator = new ComparisonTerminator<DoubleValue>("SelectionPressure", ComparisonType.Less, new DoubleValue(200)) { Name = "Selection Pressure" };349 qualityTerminator = new SingleObjectiveQualityTerminator();350 executionTimeTerminator = new ExecutionTimeTerminator(this, new TimeSpanValue(TimeSpan.FromMinutes(5))) { Name = "Execution Time" };351 ParameterizeTerminators();352 UpdateTerminators();353 354 347 foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name)) 355 348 ComparisonFactorModifierParameter.ValidValues.Add(modifier); … … 357 350 if (linearModifier != null) ComparisonFactorModifierParameter.Value = linearModifier; 358 351 ParameterizeComparisonFactorModifiers(); 352 353 generationsTerminator = new ComparisonTerminator<IntValue>("Generations", ComparisonType.Less, MaximumGenerationsParameter) { Name = "Generations" }; 354 evaluationsTerminator = new ComparisonTerminator<IntValue>("EvaluatedSolutions", ComparisonType.Less, MaximumEvaluatedSolutionsParameter) { Name = "Evaluations" }; 355 selectionPressureTerminator = new ComparisonTerminator<DoubleValue>("SelectionPressure", ComparisonType.Less, MaximumSelectionPressure) { Name = "Selection Pressure" }; 356 qualityTerminator = new SingleObjectiveQualityTerminator() { Name = "Quality" }; 357 executionTimeTerminator = new ExecutionTimeTerminator(this, new TimeSpanValue(TimeSpan.FromMinutes(5))); 358 ParameterizeTerminators(); 359 UpdateTerminators(); 359 360 360 361 Initialize(); … … 503 504 } 504 505 private void ParameterizeTerminators() { 505 generationsTerminator.IterationsParameter.ActualName = "Generations";506 generationsTerminator.MaximumIterationsParameter = MaximumGenerationsParameter;507 508 506 qualityTerminator.Parameterize(qualityAnalyzer.CurrentBestQualityParameter, Problem); 509 507 } … … 566 564 } 567 565 private void UpdateTerminators() { 568 // ToDo restore checked state 569 Terminators.Operators.Clear(); 566 var newTerminators = new Dictionary<ITerminator, bool> { 567 {generationsTerminator, !Terminators.Operators.Contains(generationsTerminator) || Terminators.Operators.ItemChecked(generationsTerminator)}, 568 {selectionPressureTerminator, !Terminators.Operators.Contains(selectionPressureTerminator) || Terminators.Operators.ItemChecked(selectionPressureTerminator) }, 569 {evaluationsTerminator, Terminators.Operators.Contains(evaluationsTerminator) && Terminators.Operators.ItemChecked(evaluationsTerminator)}, 570 {qualityTerminator, Terminators.Operators.Contains(qualityTerminator) && Terminators.Operators.ItemChecked(qualityTerminator) }, 571 {executionTimeTerminator, Terminators.Operators.Contains(executionTimeTerminator) && Terminators.Operators.ItemChecked(executionTimeTerminator)} 572 }; 570 573 if (Problem != null) { 571 574 foreach (var terminator in Problem.Operators.OfType<ITerminator>()) 572 Terminators.Operators.Add(terminator); 573 } 574 Terminators.Operators.Add(generationsTerminator); 575 Terminators.Operators.Add(evaluatedSolutionsTerminator); 576 Terminators.Operators.Add(selectionPressureTerminator); 577 Terminators.Operators.Add(qualityTerminator, checkedState: false); 578 Terminators.Operators.Add(executionTimeTerminator, checkedState: false); 575 newTerminators.Add(terminator, !Terminators.Operators.Contains(terminator) || Terminators.Operators.ItemChecked(terminator)); 576 } 577 578 Terminators.Operators.Clear(); 579 foreach (var newTerminator in newTerminators) 580 Terminators.Operators.Add(newTerminator.Key, newTerminator.Value); 579 581 } 580 582 private OffspringSelectionGeneticAlgorithmMainLoop FindMainLoop(IOperator start) {
Note: See TracChangeset
for help on using the changeset viewer.