Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/04/19 16:03:51 (5 years ago)
Author:
abeham
Message:

#2521: refactored multi-objective problems' maximization

  • Add ForceValue method to IValueParameter to perform changes even when it is read-only
  • Add MaximizationChanged event handler
Location:
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Problems
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Problems/MultiObjectiveHeuristicOptimizationProblem.cs

    r17226 r17317  
    2020#endregion
    2121
     22using System;
     23using HEAL.Attic;
    2224using HeuristicLab.Common;
    2325using HeuristicLab.Core;
    2426using HeuristicLab.Data;
    2527using HeuristicLab.Parameters;
    26 using HEAL.Attic;
    2728
    2829namespace HeuristicLab.Optimization {
     
    3637    [StorableConstructor]
    3738    protected MultiObjectiveHeuristicOptimizationProblem(StorableConstructorFlag _) : base(_) { }
    38     protected MultiObjectiveHeuristicOptimizationProblem(MultiObjectiveHeuristicOptimizationProblem<T, U> original, Cloner cloner) : base(original, cloner) { }
     39    protected MultiObjectiveHeuristicOptimizationProblem(MultiObjectiveHeuristicOptimizationProblem<T, U> original, Cloner cloner)
     40      : base(original, cloner) {
     41      RegisterEventHandlers();
     42    }
    3943    protected MultiObjectiveHeuristicOptimizationProblem()
    4044      : base() {
    4145      Parameters.Add(new ValueParameter<BoolArray>(MaximizationParameterName, "Determines for each objective whether it should be maximized or minimized."));
     46
     47      RegisterEventHandlers();
    4248    }
    4349
     
    4551      : base(evaluator, solutionCreator) {
    4652      Parameters.Add(new ValueParameter<BoolArray>(MaximizationParameterName, "Determines for each objective whether it should be maximized or minimized."));
     53
     54      RegisterEventHandlers();
     55    }
     56
     57    private void RegisterEventHandlers() {
     58      MaximizationParameter.ValueChanged += MaximizationParameterOnValueChanged;
     59    }
     60
     61    private void MaximizationParameterOnValueChanged(object sender, EventArgs e) {
     62      OnMaximizationChanged();
    4763    }
    4864
     
    6177      get { return Evaluator; }
    6278    }
     79
     80    public event EventHandler MaximizationChanged;
     81    protected void OnMaximizationChanged() {
     82      MaximizationChanged?.Invoke(this, EventArgs.Empty);
     83    }
    6384  }
    6485}
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.cs

    r17226 r17317  
    2020#endregion
    2121
     22using System;
     23using HEAL.Attic;
    2224using HeuristicLab.Common;
    2325using HeuristicLab.Core;
    2426using HeuristicLab.Data;
    2527using HeuristicLab.Parameters;
    26 using HEAL.Attic;
    2728
    2829namespace HeuristicLab.Optimization {
     
    3738    [StorableConstructor]
    3839    protected SingleObjectiveHeuristicOptimizationProblem(StorableConstructorFlag _) : base(_) { }
    39     protected SingleObjectiveHeuristicOptimizationProblem(SingleObjectiveHeuristicOptimizationProblem<T, U> original, Cloner cloner) : base(original, cloner) { }
     40    protected SingleObjectiveHeuristicOptimizationProblem(SingleObjectiveHeuristicOptimizationProblem<T, U> original, Cloner cloner)
     41      : base(original, cloner) {
     42      RegisterEventHandlers();
     43    }
    4044    protected SingleObjectiveHeuristicOptimizationProblem()
    4145      : base() {
    4246      Parameters.Add(new ValueParameter<BoolValue>(MaximizationParameterName, "Set to false if the problem should be minimized.", new BoolValue()));
    4347      Parameters.Add(new OptionalValueParameter<DoubleValue>(BestKnownQualityParameterName, "The quality of the best known solution of this problem."));
     48
     49      RegisterEventHandlers();
    4450    }
    4551
     
    4854      Parameters.Add(new ValueParameter<BoolValue>(MaximizationParameterName, "Set to false if the problem should be minimized.", new BoolValue()));
    4955      Parameters.Add(new OptionalValueParameter<DoubleValue>(BestKnownQualityParameterName, "The quality of the best known solution of this problem."));
     56
     57      RegisterEventHandlers();
     58    }
     59
     60    private void RegisterEventHandlers() {
     61      MaximizationParameter.ValueChanged += MaximizationParameterOnValueChanged;
     62    }
     63
     64    private void MaximizationParameterOnValueChanged(object sender, EventArgs e) {
     65      OnMaximizationChanged();
    5066    }
    5167
     
    5975      }
    6076      #endregion
     77      RegisterEventHandlers();
    6178    }
    6279    public ValueParameter<BoolValue> MaximizationParameter {
     
    6885    public BoolValue Maximization {
    6986      get { return MaximizationParameter.Value; }
    70       set { MaximizationParameter.Value = value; }
     87      set {
     88        if (Maximization == value) return;
     89        MaximizationParameter.Value = value;
     90      }
    7191    }
    7292
     
    85105      get { return Evaluator; }
    86106    }
     107
     108    public event EventHandler MaximizationChanged;
     109    protected void OnMaximizationChanged() {
     110      MaximizationChanged?.Invoke(this, EventArgs.Empty);
     111    }
    87112  }
    88113}
Note: See TracChangeset for help on using the changeset viewer.