Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/MultiObjectiveBasicProblem.cs @ 11814

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

#2174: Renamed scriptable to programmable problem.

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