Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/20/15 11:28:32 (10 years ago)
Author:
pfleck
Message:

#2027
Added execution-time based termination criterion.
Restructured configuring termination criteria.

Location:
branches/TerminationCriteria
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/TerminationCriteria/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/OffspringSelectionGeneticAlgorithm.cs

    r12312 r12328  
    194194      set { AnalyzerParameter.Value = value; }
    195195    }
     196
    196197    public IntValue MaximumEvaluatedSolutions {
    197198      get { return MaximumEvaluatedSolutionsParameter.Value; }
     
    202203      set { FillPopulationWithParentsParameter.Value.Value = value; }
    203204    }
     205    private MultiTerminationCriterion TerminationCriteria {
     206      get { return TerminationCriteriaParameter.Value; }
     207    }
    204208    private RandomCreator RandomCreator {
    205209      get { return (RandomCreator)OperatorGraph.InitialOperator; }
     
    217221    [Storable]
    218222    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;
    219233    #endregion
    220234
     
    241255      selectionPressureAnalyzer = cloner.Clone(original.selectionPressureAnalyzer);
    242256      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);
    243262      Initialize();
    244263    }
     
    331350      ParameterizeAnalyzers();
    332351      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();
    334359
    335360      Initialize();
     
    355380      UpdateMutators();
    356381      UpdateAnalyzers();
     382      UpdateTerminationCriteria();
    357383      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    358384      base.OnProblemChanged();
     
    513539      Analyzer.Operators.Add(successfulOffspringAnalyzer, successfulOffspringAnalyzer.EnabledByDefault);
    514540    }
    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);
    522558    }
    523559    private OffspringSelectionGeneticAlgorithmMainLoop FindMainLoop(IOperator start) {
  • branches/TerminationCriteria/HeuristicLab.Termination/3.3/ComparisonTerminationCriterion.cs

    r12310 r12328  
    2828
    2929namespace HeuristicLab.Termination {
    30   [Item("ComparisonTerminationCriterion", "")]
     30  [Item("ComparisonTerminationCriterion", "An termination criterion which compares to values.")]
    3131  [StorableClass]
    32   public sealed class ComparisonTerminationCriterion<T> : TerminationCriterion where T : class, IItem, IComparable {
     32  public class ComparisonTerminationCriterion<T> : TerminationCriterion where T : class, IItem, IComparable {
    3333    public ILookupParameter<T> LeftSideParameter {
    3434      get { return (ILookupParameter<T>)Parameters["LeftSide"]; }
     
    4747
    4848    [StorableConstructor]
    49     private ComparisonTerminationCriterion(bool deserializing) : base(deserializing) { }
    50     private ComparisonTerminationCriterion(ComparisonTerminationCriterion<T> original, Cloner cloner)
     49    protected ComparisonTerminationCriterion(bool deserializing) : base(deserializing) { }
     50    protected ComparisonTerminationCriterion(ComparisonTerminationCriterion<T> original, Cloner cloner)
    5151      : base(original, cloner) {
    5252    }
     
    5858      Parameters.Add(new LookupParameter<T>("LeftSide", "The left side of the comparison."));
    5959      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 });
    6161    }
    6262    public ComparisonTerminationCriterion(string leftSideActualName, string rightSideActualName, ComparisonType comparison = ComparisonType.GreaterOrEqual)
  • branches/TerminationCriteria/HeuristicLab.Termination/3.3/HeuristicLab.Termination-3.3.csproj

    r12310 r12328  
    121121    <Compile Include="ComparisonTerminationCriterion.cs" />
    122122    <Compile Include="MultiTerminationCriterion.cs" />
     123    <Compile Include="ExecutionTimeTimeTerminationCriterion.cs" />
    123124    <Compile Include="TerminationCriterion.cs" />
    124125    <Compile Include="TerminationOperator.cs" />
Note: See TracChangeset for help on using the changeset viewer.