[5580] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17180] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[5580] | 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 |
|
---|
[5618] | 22 | using System.Linq;
|
---|
[17832] | 23 | using HEAL.Attic;
|
---|
[5580] | 24 | using HeuristicLab.Common;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Data;
|
---|
[17832] | 27 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
[5580] | 28 | using HeuristicLab.Optimization;
|
---|
| 29 | using HeuristicLab.Parameters;
|
---|
| 30 |
|
---|
| 31 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
[16565] | 32 | [StorableType("E9876DF8-ACFA-41C8-93B7-FA40C57CE459")]
|
---|
[9049] | 33 | public abstract class SymbolicDataAnalysisMultiObjectiveProblem<T, U, V> : SymbolicDataAnalysisProblem<T, U, V>, ISymbolicDataAnalysisMultiObjectiveProblem
|
---|
[17832] | 34 | where T : class, IDataAnalysisProblemData
|
---|
[5618] | 35 | where U : class, ISymbolicDataAnalysisMultiObjectiveEvaluator<T>
|
---|
[5580] | 36 | where V : class, ISymbolicDataAnalysisSolutionCreator {
|
---|
| 37 | private const string MaximizationParameterName = "Maximization";
|
---|
| 38 | private const string BestKnownQualityParameterName = "BestKnownQuality";
|
---|
| 39 |
|
---|
| 40 | #region parameter properties
|
---|
[5618] | 41 | public IValueParameter<BoolArray> MaximizationParameter {
|
---|
| 42 | get { return (IValueParameter<BoolArray>)Parameters[MaximizationParameterName]; }
|
---|
[5580] | 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; }
|
---|
[5618] | 52 | set { MaximizationParameter.Value = value; }
|
---|
[5580] | 53 | }
|
---|
| 54 | IMultiObjectiveEvaluator IMultiObjectiveHeuristicOptimizationProblem.Evaluator {
|
---|
| 55 | get { return Evaluator; }
|
---|
| 56 | }
|
---|
| 57 | #endregion
|
---|
| 58 |
|
---|
| 59 | [StorableConstructor]
|
---|
[16565] | 60 | protected SymbolicDataAnalysisMultiObjectiveProblem(StorableConstructorFlag _) : base(_) { }
|
---|
[5685] | 61 | protected SymbolicDataAnalysisMultiObjectiveProblem(SymbolicDataAnalysisMultiObjectiveProblem<T, U, V> original, Cloner cloner)
|
---|
| 62 | : base(original, cloner) {
|
---|
| 63 | RegisterEventHandler();
|
---|
| 64 | }
|
---|
[5580] | 65 |
|
---|
[5618] | 66 | public SymbolicDataAnalysisMultiObjectiveProblem(T problemData, U evaluator, V solutionCreator)
|
---|
| 67 | : base(problemData, evaluator, solutionCreator) {
|
---|
[5580] | 68 | Parameters.Add(new ValueParameter<BoolArray>(MaximizationParameterName, "Set to false if the problem should be minimized."));
|
---|
[5685] | 69 |
|
---|
| 70 | ParameterizeOperators();
|
---|
| 71 | RegisterEventHandler();
|
---|
[5580] | 72 | }
|
---|
[5618] | 73 |
|
---|
[5685] | 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 |
|
---|
[5618] | 83 | protected override void OnEvaluatorChanged() {
|
---|
| 84 | base.OnEvaluatorChanged();
|
---|
[5685] | 85 | Evaluator.QualitiesParameter.ActualNameChanged += new System.EventHandler(QualitiesParameter_ActualNameChanged);
|
---|
[5618] | 86 | Maximization = new BoolArray(Evaluator.Maximization.ToArray());
|
---|
[5685] | 87 | ParameterizeOperators();
|
---|
[5618] | 88 | }
|
---|
[5685] | 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 | }
|
---|
[17832] | 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 | }
|
---|
[5685] | 115 | }
|
---|
[5580] | 116 | }
|
---|
| 117 | }
|
---|