Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.cs @ 17317

Last change on this file since 17317 was 17317, checked in by abeham, 4 years ago

#2521: refactored multi-objective problems' maximization

  • Add ForceValue method to IValueParameter to perform changes even when it is read-only
  • Add MaximizationChanged event handler
  • Property svn:mergeinfo set to (toggle deleted branches)
    /branches/2839_HiveProjectManagement/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.csmergedeligible
    /stable/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.csmergedeligible
    /trunk/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.csmergedeligible
    /branches/2520_PersistenceReintegration/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.cs16451-16564
    /branches/2892_LR-prediction-intervals/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.cs15743-16388
    /branches/2915-AbsoluteSymbol/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.cs15943-16355
    /branches/2947_ConfigurableIndexedDataTable/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.cs16148-16526
    /branches/2965_CancelablePersistence/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.cs16321-16439
    /branches/Async/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.cs13329-15286
    /branches/CloningRefactoring/HeuristicLab.Optimization/3.3/SingleObjectiveHeuristicOptimizationProblem.cs4656-4721
    /branches/DataAnalysis Refactoring/HeuristicLab.Optimization/3.3/SingleObjectiveHeuristicOptimizationProblem.cs5471-5577
    /branches/DataAnalysis/HeuristicLab.Optimization/3.3/SingleObjectiveHeuristicOptimizationProblem.cs4458-4459,​4462,​4464
    /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Optimization/3.3/SingleObjectiveHeuristicOptimizationProblem.cs5060
    /branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.cs11570-12508
    /branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.cs11130-12721
    /branches/NET40/sources/HeuristicLab.Optimization/3.3/SingleObjectiveHeuristicOptimizationProblem.cs5138-5162
    /branches/ParallelEngine/HeuristicLab.Optimization/3.3/SingleObjectiveHeuristicOptimizationProblem.cs5175-5192
    /branches/QAP/HeuristicLab.Optimization/3.3/SingleObjectiveHeuristicOptimizationProblem.cs5810-5871
    /branches/QAPAlgorithms/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.cs6350-6627
    /branches/Restructure trunk solution/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.cs6828
    /branches/SuccessProgressAnalysis/HeuristicLab.Optimization/3.3/SingleObjectiveHeuristicOptimizationProblem.cs5370-5682
    /branches/TerminationCriteria/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.cs12526-12974
    /branches/TimeLimitRunOptimizer/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.cs9438-12626
    /branches/Trunk/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.cs6829-6865
    /branches/VNS/HeuristicLab.Optimization/3.3/SingleObjectiveHeuristicOptimizationProblem.cs5594-5752
    /branches/histogram/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.cs5959-6341
    /branches/symbreg-factors-2650/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.cs14232-14825
    /trunk/sources/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.cs13331-15681
File size: 4.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using HEAL.Attic;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Parameters;
28
29namespace HeuristicLab.Optimization {
30  [Item("Single-Objective Heuristic OptimizationProblem", "A base class for single-objective heuristic optimization problems.")]
31  [StorableType("DFD5588E-6AB2-4712-9083-A405EF21226F")]
32  public abstract class SingleObjectiveHeuristicOptimizationProblem<T, U> : HeuristicOptimizationProblem<T, U>, ISingleObjectiveHeuristicOptimizationProblem
33    where T : class, ISingleObjectiveEvaluator
34    where U : class, ISolutionCreator {
35    private const string MaximizationParameterName = "Maximization";
36    private const string BestKnownQualityParameterName = "BestKnownQuality";
37
38    [StorableConstructor]
39    protected SingleObjectiveHeuristicOptimizationProblem(StorableConstructorFlag _) : base(_) { }
40    protected SingleObjectiveHeuristicOptimizationProblem(SingleObjectiveHeuristicOptimizationProblem<T, U> original, Cloner cloner)
41      : base(original, cloner) {
42      RegisterEventHandlers();
43    }
44    protected SingleObjectiveHeuristicOptimizationProblem()
45      : base() {
46      Parameters.Add(new ValueParameter<BoolValue>(MaximizationParameterName, "Set to false if the problem should be minimized.", new BoolValue()));
47      Parameters.Add(new OptionalValueParameter<DoubleValue>(BestKnownQualityParameterName, "The quality of the best known solution of this problem."));
48
49      RegisterEventHandlers();
50    }
51
52    protected SingleObjectiveHeuristicOptimizationProblem(T evaluator, U solutionCreator)
53      : base(evaluator, solutionCreator) {
54      Parameters.Add(new ValueParameter<BoolValue>(MaximizationParameterName, "Set to false if the problem should be minimized.", new BoolValue()));
55      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();
66    }
67
68    [StorableHook(HookType.AfterDeserialization)]
69    private void AfterDeserialization() {
70      // BackwardsCompatibility3.3
71      #region Backwards compatible code (remove with 3.4)
72      if (BestKnownQualityParameter is ValueParameter<DoubleValue>) {
73        Parameters.Remove(BestKnownQualityParameterName);
74        Parameters.Add(new OptionalValueParameter<DoubleValue>(BestKnownQualityParameterName, "The quality of the best known solution of this problem."));
75      }
76      #endregion
77      RegisterEventHandlers();
78    }
79    public ValueParameter<BoolValue> MaximizationParameter {
80      get { return (ValueParameter<BoolValue>)Parameters[MaximizationParameterName]; }
81    }
82    IParameter ISingleObjectiveHeuristicOptimizationProblem.MaximizationParameter {
83      get { return MaximizationParameter; }
84    }
85    public BoolValue Maximization {
86      get { return MaximizationParameter.Value; }
87      set {
88        if (Maximization == value) return;
89        MaximizationParameter.Value = value;
90      }
91    }
92
93    public IValueParameter<DoubleValue> BestKnownQualityParameter {
94      get { return (IValueParameter<DoubleValue>)Parameters[BestKnownQualityParameterName]; }
95    }
96    IParameter ISingleObjectiveHeuristicOptimizationProblem.BestKnownQualityParameter {
97      get { return BestKnownQualityParameter; }
98    }
99    public DoubleValue BestKnownQuality {
100      get { return BestKnownQualityParameter.Value; }
101      set { BestKnownQualityParameter.Value = value; }
102    }
103
104    ISingleObjectiveEvaluator ISingleObjectiveHeuristicOptimizationProblem.Evaluator {
105      get { return Evaluator; }
106    }
107
108    public event EventHandler MaximizationChanged;
109    protected void OnMaximizationChanged() {
110      MaximizationChanged?.Invoke(this, EventArgs.Empty);
111    }
112  }
113}
Note: See TracBrowser for help on using the repository browser.