source: trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisMultiObjectiveProblem.cs @ 17832

Last change on this file since 17832 was 17832, checked in by bburlacu, 16 months ago

#3048: Disable the ContextAware and DeterministicBest crossovers in the SymbolicDataAnalysisMultiObjectiveProblem.

File size: 4.9 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.Linq;
23using HEAL.Attic;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
28using HeuristicLab.Optimization;
29using HeuristicLab.Parameters;
30
31namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
32  [StorableType("E9876DF8-ACFA-41C8-93B7-FA40C57CE459")]
33  public abstract class SymbolicDataAnalysisMultiObjectiveProblem<T, U, V> : SymbolicDataAnalysisProblem<T, U, V>, ISymbolicDataAnalysisMultiObjectiveProblem
34    where T : class, IDataAnalysisProblemData
35    where U : class, ISymbolicDataAnalysisMultiObjectiveEvaluator<T>
36    where V : class, ISymbolicDataAnalysisSolutionCreator {
37    private const string MaximizationParameterName = "Maximization";
38    private const string BestKnownQualityParameterName = "BestKnownQuality";
39
40    #region parameter properties
41    public IValueParameter<BoolArray> MaximizationParameter {
42      get { return (IValueParameter<BoolArray>)Parameters[MaximizationParameterName]; }
43    }
44    IParameter IMultiObjectiveHeuristicOptimizationProblem.MaximizationParameter {
45      get { return MaximizationParameter; }
46    }
47    #endregion
48
49    #region properties
50    public BoolArray Maximization {
51      get { return MaximizationParameter.Value; }
52      set { MaximizationParameter.Value = value; }
53    }
54    IMultiObjectiveEvaluator IMultiObjectiveHeuristicOptimizationProblem.Evaluator {
55      get { return Evaluator; }
56    }
57    #endregion
58
59    [StorableConstructor]
60    protected SymbolicDataAnalysisMultiObjectiveProblem(StorableConstructorFlag _) : base(_) { }
61    protected SymbolicDataAnalysisMultiObjectiveProblem(SymbolicDataAnalysisMultiObjectiveProblem<T, U, V> original, Cloner cloner)
62      : base(original, cloner) {
63      RegisterEventHandler();
64    }
65
66    public SymbolicDataAnalysisMultiObjectiveProblem(T problemData, U evaluator, V solutionCreator)
67      : base(problemData, evaluator, solutionCreator) {
68      Parameters.Add(new ValueParameter<BoolArray>(MaximizationParameterName, "Set to false if the problem should be minimized."));
69
70      ParameterizeOperators();
71      RegisterEventHandler();
72    }
73
74    [StorableHook(HookType.AfterDeserialization)]
75    private void AfterDeserialization() {
76      RegisterEventHandler();
77    }
78
79    private void RegisterEventHandler() {
80      Evaluator.QualitiesParameter.ActualNameChanged += new System.EventHandler(QualitiesParameter_ActualNameChanged);
81    }
82
83    protected override void OnEvaluatorChanged() {
84      base.OnEvaluatorChanged();
85      Evaluator.QualitiesParameter.ActualNameChanged += new System.EventHandler(QualitiesParameter_ActualNameChanged);
86      Maximization = new BoolArray(Evaluator.Maximization.ToArray());
87      ParameterizeOperators();
88    }
89
90    private void QualitiesParameter_ActualNameChanged(object sender, System.EventArgs e) {
91      ParameterizeOperators();
92    }
93
94    protected override void ParameterizeOperators() {
95      base.ParameterizeOperators();
96      foreach (var op in Operators.OfType<ISymbolicDataAnalysisMultiObjectiveAnalyzer>()) {
97        op.QualitiesParameter.ActualName = Evaluator.QualitiesParameter.ActualName;
98        op.MaximizationParameter.ActualName = MaximizationParameterName;
99      }
100
101      // these two crossover operators are compatible with single-objective problems only so we remove them from the operators collection
102      bool pred(IItem x) {
103        return x is SymbolicDataAnalysisExpressionDeterministicBestCrossover<T> || x is SymbolicDataAnalysisExpressionContextAwareCrossover<T>;
104      };
105      Operators.RemoveAll(pred);
106      // if a multi crossover is present, remove them from its operator collection
107      var cx = Operators.FirstOrDefault(x => x is MultiSymbolicDataAnalysisExpressionCrossover<T>);
108      if (cx != null) {
109        var multiCrossover = (MultiSymbolicDataAnalysisExpressionCrossover<T>)cx;
110        var items = multiCrossover.Operators.Where(pred).Cast<ISymbolicExpressionTreeCrossover>().ToList();
111        foreach (var item in items) {
112          multiCrossover.Operators.Remove(item);
113        }
114      }
115    }
116  }
117}
Note: See TracBrowser for help on using the repository browser.