Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/MultiObjectiveProgrammableProblem.cs @ 11780

Last change on this file since 11780 was 11780, checked in by mkommend, 9 years ago

#2174: Corrected maximization in programmable problem base classes.

File size: 3.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 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.Linq;
23using HeuristicLab.Analysis;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Problems.Programmable {
32  [StorableClass]
33  public abstract class MultiObjectiveProgrammableProblem<TEncoding> : ProgrammableProblem<TEncoding, MultiObjectiveEvaluator>, IMultiObjectiveHeuristicOptimizationProblem, IMultiObjectiveProblemDefinition
34  where TEncoding : class, IEncoding {
35    [StorableConstructor]
36    protected MultiObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { }
37
38    protected MultiObjectiveProgrammableProblem(MultiObjectiveProgrammableProblem<TEncoding> original, Cloner cloner)
39      : base(original, cloner) {
40      ParameterizeOperators();
41    }
42
43    protected MultiObjectiveProgrammableProblem()
44      : base() {
45        Parameters.Add(new ValueParameter<BoolArray>("Maximization", "Set to false if the problem should be minimized.", new BoolArray(Maximization)));
46
47      Operators.Add(Evaluator);
48      Operators.Add(new BestScopeSolutionAnalyzer());
49      Operators.Add(new MultiObjectiveAnalyzer());
50
51      ParameterizeOperators();
52    }
53
54    [StorableHook(HookType.AfterDeserialization)]
55    private void AfterDeserialization() {
56      ParameterizeOperators();
57    }
58
59    public abstract bool[] Maximization { get; }
60    public abstract double[] Evaluate(Individual individual, IRandom random);
61    public virtual void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) { }
62
63
64    protected override void OnEvaluatorChanged() {
65      base.OnEvaluatorChanged();
66      ParameterizeOperators();
67    }
68
69    protected override void ParameterizeOperators() {
70      base.ParameterizeOperators();
71      foreach (var op in Operators.OfType<IMultiObjectiveEvaluationOperator>())
72        op.EvaluateFunc = Evaluate;
73      foreach (var op in Operators.OfType<IMultiObjectiveAnalysisOperator>())
74        op.AnalyzeAction = Analyze;
75    }
76
77
78    #region IMultiObjectiveHeuristicOptimizationProblem Members
79    IParameter IMultiObjectiveHeuristicOptimizationProblem.MaximizationParameter {
80      get { return Parameters["Maximization"]; }
81    }
82    IMultiObjectiveEvaluator IMultiObjectiveHeuristicOptimizationProblem.Evaluator {
83      get { return Evaluator; }
84    }
85    #endregion
86  }
87}
Note: See TracBrowser for help on using the repository browser.