Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2708_ScopedAlgorithms/HeuristicLab.Optimization/3.3/BasicProblems/MultiObjectiveProblem.cs @ 16796

Last change on this file since 16796 was 13388, checked in by abeham, 9 years ago

#2521:

  • Readded excluded views
  • Removed ProblemInstanceProviderView which was not referenced in the project file
  • Fixed plugin dependency
File size: 3.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Optimization {
30  [StorableClass]
31  public abstract class MultiObjectiveProblem<TEncoding, TSolution> :
32    Problem<TEncoding, TSolution, MultiObjectiveEvaluator<TSolution>>,
33    IMultiObjectiveProblem<TEncoding, TSolution>,
34    IMultiObjectiveProblemDefinition<TEncoding, TSolution>
35    where TEncoding : class, IEncoding<TSolution>
36    where TSolution : class, ISolution {
37
38    [StorableConstructor]
39    protected MultiObjectiveProblem(bool deserializing) : base(deserializing) { }
40
41    protected MultiObjectiveProblem(MultiObjectiveProblem<TEncoding, TSolution> original, Cloner cloner)
42      : base(original, cloner) {
43      ParameterizeOperators();
44    }
45
46    protected MultiObjectiveProblem()
47      : base() {
48      Parameters.Add(new ValueParameter<BoolArray>("Maximization", "Set to false if the problem should be minimized.", (BoolArray)new BoolArray(Maximization).AsReadOnly()));
49
50      Operators.Add(Evaluator);
51      Operators.Add(new MultiObjectiveAnalyzer<TSolution>());
52
53      ParameterizeOperators();
54    }
55
56    [StorableHook(HookType.AfterDeserialization)]
57    private void AfterDeserialization() {
58      ParameterizeOperators();
59    }
60
61    public abstract bool[] Maximization { get; }
62    public abstract double[] Evaluate(TSolution individual, IRandom random);
63    public virtual void Analyze(TSolution[] individuals, double[][] qualities, ResultCollection results, IRandom random) { }
64
65    protected override void OnEvaluatorChanged() {
66      base.OnEvaluatorChanged();
67      ParameterizeOperators();
68    }
69
70    private void ParameterizeOperators() {
71      foreach (var op in Operators.OfType<IMultiObjectiveEvaluationOperator<TSolution>>())
72        op.EvaluateFunc = Evaluate;
73      foreach (var op in Operators.OfType<IMultiObjectiveAnalysisOperator<TSolution>>())
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.