Changeset 12328
- Timestamp:
- 04/20/15 11:28:32 (10 years ago)
- Location:
- branches/TerminationCriteria
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/TerminationCriteria/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/OffspringSelectionGeneticAlgorithm.cs
r12312 r12328 194 194 set { AnalyzerParameter.Value = value; } 195 195 } 196 196 197 public IntValue MaximumEvaluatedSolutions { 197 198 get { return MaximumEvaluatedSolutionsParameter.Value; } … … 202 203 set { FillPopulationWithParentsParameter.Value.Value = value; } 203 204 } 205 private MultiTerminationCriterion TerminationCriteria { 206 get { return TerminationCriteriaParameter.Value; } 207 } 204 208 private RandomCreator RandomCreator { 205 209 get { return (RandomCreator)OperatorGraph.InitialOperator; } … … 217 221 [Storable] 218 222 private SuccessfulOffspringAnalyzer successfulOffspringAnalyzer; 223 [Storable] 224 private ComparisonTerminationCriterion<IntValue> maximumGenerationsTerminationCriterion; 225 [Storable] 226 private ComparisonTerminationCriterion<IntValue> maximumEvaluatedSolutionsTerminationCriterion; 227 [Storable] 228 private ComparisonTerminationCriterion<DoubleValue> maximumSelectionPressureTerminationCriterion; 229 [Storable] 230 private ComparisonTerminationCriterion<DoubleValue> qualityTerminationCriterion; 231 [Storable] 232 private ExecutionTimeTimeTerminationCriterion executionTimeTerminationCriterion; 219 233 #endregion 220 234 … … 241 255 selectionPressureAnalyzer = cloner.Clone(original.selectionPressureAnalyzer); 242 256 successfulOffspringAnalyzer = cloner.Clone(original.successfulOffspringAnalyzer); 257 maximumGenerationsTerminationCriterion = cloner.Clone(original.maximumGenerationsTerminationCriterion); 258 maximumEvaluatedSolutionsTerminationCriterion = cloner.Clone(original.maximumEvaluatedSolutionsTerminationCriterion); 259 maximumSelectionPressureTerminationCriterion = cloner.Clone(original.maximumSelectionPressureTerminationCriterion); 260 qualityTerminationCriterion = cloner.Clone(original.qualityTerminationCriterion); 261 executionTimeTerminationCriterion = cloner.Clone(original.executionTimeTerminationCriterion); 243 262 Initialize(); 244 263 } … … 331 350 ParameterizeAnalyzers(); 332 351 UpdateAnalyzers(); 333 AddTerminationCriteria(); 352 353 maximumGenerationsTerminationCriterion = new ComparisonTerminationCriterion<IntValue>("Generations", "MaximumGenerations", ComparisonType.GreaterOrEqual) { Name = "Maximum Generations" }; 354 maximumEvaluatedSolutionsTerminationCriterion = new ComparisonTerminationCriterion<IntValue>("EvaluatedSolutions", "MaximumEvaluatedSolutions", ComparisonType.GreaterOrEqual) { Name = "Maximum Evaluations" }; 355 maximumSelectionPressureTerminationCriterion = new ComparisonTerminationCriterion<DoubleValue>("SelectionPressure", "MaximumSelectionPressure", ComparisonType.GreaterOrEqual) { Name = "Maximum Selection" }; 356 qualityTerminationCriterion = new ComparisonTerminationCriterion<DoubleValue>() { Name = "Maximum/Minimum Quality" }; 357 executionTimeTerminationCriterion = new ExecutionTimeTimeTerminationCriterion(this, TimeSpan.FromMinutes(5)) { Name = "Maximum Execution Time" }; 358 UpdateTerminationCriteria(); 334 359 335 360 Initialize(); … … 355 380 UpdateMutators(); 356 381 UpdateAnalyzers(); 382 UpdateTerminationCriteria(); 357 383 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 358 384 base.OnProblemChanged(); … … 513 539 Analyzer.Operators.Add(successfulOffspringAnalyzer, successfulOffspringAnalyzer.EnabledByDefault); 514 540 } 515 private void AddTerminationCriteria() { 516 TerminationCriteriaParameter.Value.Operators.Add( 517 new ComparisonTerminationCriterion<IntValue>("Generations", "MaximumGenerations", ComparisonType.GreaterOrEqual) { Name = "Maximum Generations" }); 518 TerminationCriteriaParameter.Value.Operators.Add( 519 new ComparisonTerminationCriterion<IntValue>("EvaluatedSolutions", "MaximumEvaluatedSolutions", ComparisonType.GreaterOrEqual) { Name = "Maximum Evaluations" }); 520 TerminationCriteriaParameter.Value.Operators.Add( 521 new ComparisonTerminationCriterion<DoubleValue>("SelectionPressure", "MaximumSelectionPressure", ComparisonType.GreaterOrEqual) { Name = "Maximum Selection Pressure" }); 541 private void UpdateTerminationCriteria() { 542 TerminationCriteria.Operators.Clear(); 543 544 if (Problem != null) { 545 foreach (var terminationCriterion in Problem.Operators.OfType<ITerminationCriterion>()) 546 TerminationCriteria.Operators.Add(terminationCriterion); 547 bool maximization = ((BoolValue)Problem.MaximizationParameter.ActualValue).Value; 548 qualityTerminationCriterion.Name = maximization ? "Maximum Quality" : "Minimum Quality"; 549 qualityTerminationCriterion.Comparison = new Comparison(maximization ? ComparisonType.GreaterOrEqual : ComparisonType.LessOrEqual); 550 qualityTerminationCriterion.LeftSideParameter.ActualName = qualityAnalyzer.CurrentBestQualityParameter.Name; 551 qualityTerminationCriterion.RightSideParameter.Value = new DoubleValue(maximization ? double.MaxValue : double.MinValue); 552 } 553 TerminationCriteria.Operators.Add(maximumGenerationsTerminationCriterion); 554 TerminationCriteria.Operators.Add(maximumEvaluatedSolutionsTerminationCriterion); 555 TerminationCriteria.Operators.Add(maximumSelectionPressureTerminationCriterion); 556 TerminationCriteria.Operators.Add(qualityTerminationCriterion, checkedState: false); 557 TerminationCriteria.Operators.Add(executionTimeTerminationCriterion, checkedState: false); 522 558 } 523 559 private OffspringSelectionGeneticAlgorithmMainLoop FindMainLoop(IOperator start) { -
branches/TerminationCriteria/HeuristicLab.Termination/3.3/ComparisonTerminationCriterion.cs
r12310 r12328 28 28 29 29 namespace HeuristicLab.Termination { 30 [Item("ComparisonTerminationCriterion", " ")]30 [Item("ComparisonTerminationCriterion", "An termination criterion which compares to values.")] 31 31 [StorableClass] 32 public sealedclass ComparisonTerminationCriterion<T> : TerminationCriterion where T : class, IItem, IComparable {32 public class ComparisonTerminationCriterion<T> : TerminationCriterion where T : class, IItem, IComparable { 33 33 public ILookupParameter<T> LeftSideParameter { 34 34 get { return (ILookupParameter<T>)Parameters["LeftSide"]; } … … 47 47 48 48 [StorableConstructor] 49 pr ivateComparisonTerminationCriterion(bool deserializing) : base(deserializing) { }50 pr ivateComparisonTerminationCriterion(ComparisonTerminationCriterion<T> original, Cloner cloner)49 protected ComparisonTerminationCriterion(bool deserializing) : base(deserializing) { } 50 protected ComparisonTerminationCriterion(ComparisonTerminationCriterion<T> original, Cloner cloner) 51 51 : base(original, cloner) { 52 52 } … … 58 58 Parameters.Add(new LookupParameter<T>("LeftSide", "The left side of the comparison.")); 59 59 Parameters.Add(new ValueLookupParameter<T>("RightSide", "The right side of the comparison.")); 60 Parameters.Add(new ValueParameter<Comparison>("Comparison", "The type of comparison.", new Comparison(ComparisonType. Equal)) { Hidden = true });60 Parameters.Add(new ValueParameter<Comparison>("Comparison", "The type of comparison.", new Comparison(ComparisonType.GreaterOrEqual)) { Hidden = true }); 61 61 } 62 62 public ComparisonTerminationCriterion(string leftSideActualName, string rightSideActualName, ComparisonType comparison = ComparisonType.GreaterOrEqual) -
branches/TerminationCriteria/HeuristicLab.Termination/3.3/HeuristicLab.Termination-3.3.csproj
r12310 r12328 121 121 <Compile Include="ComparisonTerminationCriterion.cs" /> 122 122 <Compile Include="MultiTerminationCriterion.cs" /> 123 <Compile Include="ExecutionTimeTimeTerminationCriterion.cs" /> 123 124 <Compile Include="TerminationCriterion.cs" /> 124 125 <Compile Include="TerminationOperator.cs" />
Note: See TracChangeset
for help on using the changeset viewer.