Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2521:

  • Moving solution creator parameter from problems to algorithms (breaking wiring in some HeuristicOptimizationProblems)
  • Disallowing evaluator or encoding changes in encoding-specific base problems (to avoid confusion in derived problems whether this needs to be handled or not)
  • Added private set to ReferenceParameter property (serialization)
  • 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.7 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> : HeuristicOptimizationProblem<T>, ISingleObjectiveHeuristicOptimizationProblem
33    where T : class, ISingleObjectiveEvaluator {
34    private const string MaximizationParameterName = "Maximization";
35    private const string BestKnownQualityParameterName = "BestKnownQuality";
36
37    [StorableConstructor]
38    protected SingleObjectiveHeuristicOptimizationProblem(StorableConstructorFlag _) : base(_) { }
39    protected SingleObjectiveHeuristicOptimizationProblem(SingleObjectiveHeuristicOptimizationProblem<T> original, Cloner cloner)
40      : base(original, cloner) {
41      RegisterEventHandlers();
42    }
43    protected SingleObjectiveHeuristicOptimizationProblem()
44      : base() {
45      Parameters.Add(new ValueParameter<BoolValue>(MaximizationParameterName, "Set to false if the problem should be minimized.", new BoolValue()));
46      Parameters.Add(new OptionalValueParameter<DoubleValue>(BestKnownQualityParameterName, "The quality of the best known solution of this problem."));
47
48      RegisterEventHandlers();
49    }
50
51    protected SingleObjectiveHeuristicOptimizationProblem(T evaluator)
52      : base(evaluator) {
53      Parameters.Add(new ValueParameter<BoolValue>(MaximizationParameterName, "Set to false if the problem should be minimized.", new BoolValue()));
54      Parameters.Add(new OptionalValueParameter<DoubleValue>(BestKnownQualityParameterName, "The quality of the best known solution of this problem."));
55
56      RegisterEventHandlers();
57    }
58
59    private void RegisterEventHandlers() {
60      MaximizationParameter.ValueChanged += MaximizationParameterOnValueChanged;
61    }
62
63    private void MaximizationParameterOnValueChanged(object sender, EventArgs e) {
64      OnMaximizationChanged();
65    }
66
67    [StorableHook(HookType.AfterDeserialization)]
68    private void AfterDeserialization() {
69      // BackwardsCompatibility3.3
70      #region Backwards compatible code (remove with 3.4)
71      if (BestKnownQualityParameter is ValueParameter<DoubleValue>) {
72        Parameters.Remove(BestKnownQualityParameterName);
73        Parameters.Add(new OptionalValueParameter<DoubleValue>(BestKnownQualityParameterName, "The quality of the best known solution of this problem."));
74      }
75      #endregion
76      RegisterEventHandlers();
77    }
78    public ValueParameter<BoolValue> MaximizationParameter {
79      get { return (ValueParameter<BoolValue>)Parameters[MaximizationParameterName]; }
80    }
81    IParameter ISingleObjectiveHeuristicOptimizationProblem.MaximizationParameter {
82      get { return MaximizationParameter; }
83    }
84    public BoolValue Maximization {
85      get { return MaximizationParameter.Value; }
86      set {
87        if (Maximization == value) return;
88        MaximizationParameter.Value = value;
89      }
90    }
91
92    public IValueParameter<DoubleValue> BestKnownQualityParameter {
93      get { return (IValueParameter<DoubleValue>)Parameters[BestKnownQualityParameterName]; }
94    }
95    IParameter ISingleObjectiveHeuristicOptimizationProblem.BestKnownQualityParameter {
96      get { return BestKnownQualityParameter; }
97    }
98    public DoubleValue BestKnownQuality {
99      get { return BestKnownQualityParameter.Value; }
100      set { BestKnownQualityParameter.Value = value; }
101    }
102
103    ISingleObjectiveEvaluator ISingleObjectiveHeuristicOptimizationProblem.Evaluator {
104      get { return Evaluator; }
105    }
106
107    public event EventHandler MaximizationChanged;
108    protected void OnMaximizationChanged() {
109      MaximizationChanged?.Invoke(this, EventArgs.Empty);
110    }
111  }
112}
Note: See TracBrowser for help on using the repository browser.