[11740] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12012] | 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[11740] | 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 |
|
---|
| 22 | using System.Linq;
|
---|
| 23 | using HeuristicLab.Common;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
[11780] | 25 | using HeuristicLab.Data;
|
---|
| 26 | using HeuristicLab.Parameters;
|
---|
[11740] | 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 28 |
|
---|
[11949] | 29 | namespace HeuristicLab.Optimization {
|
---|
[11740] | 30 | [StorableClass]
|
---|
[13361] | 31 | public abstract class MultiObjectiveProblem<TEncoding, TSolution> :
|
---|
| 32 | Problem<TEncoding, TSolution, MultiObjectiveEvaluator<TSolution>>,
|
---|
| 33 | IMultiObjectiveProblem<TEncoding, TSolution>,
|
---|
| 34 | IMultiObjectiveProblemDefinition<TEncoding, TSolution>
|
---|
[13339] | 35 | where TEncoding : class, IEncoding<TSolution>
|
---|
| 36 | where TSolution : class, ISolution {
|
---|
[13361] | 37 |
|
---|
[11740] | 38 | [StorableConstructor]
|
---|
[13336] | 39 | protected MultiObjectiveProblem(bool deserializing) : base(deserializing) { }
|
---|
[11740] | 40 |
|
---|
[13339] | 41 | protected MultiObjectiveProblem(MultiObjectiveProblem<TEncoding, TSolution> original, Cloner cloner)
|
---|
[11740] | 42 | : base(original, cloner) {
|
---|
| 43 | ParameterizeOperators();
|
---|
| 44 | }
|
---|
| 45 |
|
---|
[13336] | 46 | protected MultiObjectiveProblem()
|
---|
[11740] | 47 | : base() {
|
---|
[11996] | 48 | Parameters.Add(new ValueParameter<BoolArray>("Maximization", "Set to false if the problem should be minimized.", (BoolArray)new BoolArray(Maximization).AsReadOnly()));
|
---|
[11740] | 49 |
|
---|
[11753] | 50 | Operators.Add(Evaluator);
|
---|
[13336] | 51 | Operators.Add(new MultiObjectiveAnalyzer<TSolution>());
|
---|
[11740] | 52 |
|
---|
| 53 | ParameterizeOperators();
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 57 | private void AfterDeserialization() {
|
---|
| 58 | ParameterizeOperators();
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | public abstract bool[] Maximization { get; }
|
---|
[13336] | 62 | public abstract double[] Evaluate(TSolution individual, IRandom random);
|
---|
| 63 | public virtual void Analyze(TSolution[] individuals, double[][] qualities, ResultCollection results, IRandom random) { }
|
---|
[11740] | 64 |
|
---|
[13336] | 65 | //TODO
|
---|
| 66 | //protected override void OnOperatorsChanged() {
|
---|
| 67 | // base.OnOperatorsChanged();
|
---|
| 68 | // if (Encoding != null) {
|
---|
| 69 | // PruneSingleObjectiveOperators(Encoding);
|
---|
| 70 | // var multiEncoding = Encoding as MultiEncoding;
|
---|
| 71 | // if (multiEncoding != null) {
|
---|
| 72 | // foreach (var encoding in multiEncoding.Encodings.ToList()) {
|
---|
| 73 | // PruneSingleObjectiveOperators(encoding);
|
---|
| 74 | // }
|
---|
| 75 | // }
|
---|
| 76 | // }
|
---|
| 77 | //}
|
---|
[11970] | 78 |
|
---|
[13336] | 79 | //private void PruneSingleObjectiveOperators(IEncoding encoding) {
|
---|
| 80 | // if (encoding != null && encoding.Operators.Any(x => x is ISingleObjectiveOperator && !(x is IMultiObjectiveOperator)))
|
---|
| 81 | // encoding.Operators = encoding.Operators.Where(x => !(x is ISingleObjectiveOperator) || x is IMultiObjectiveOperator).ToList();
|
---|
| 82 | //}
|
---|
[11970] | 83 |
|
---|
[11740] | 84 | protected override void OnEvaluatorChanged() {
|
---|
| 85 | base.OnEvaluatorChanged();
|
---|
| 86 | ParameterizeOperators();
|
---|
| 87 | }
|
---|
| 88 |
|
---|
[11786] | 89 | private void ParameterizeOperators() {
|
---|
[13336] | 90 | foreach (var op in Operators.OfType<IMultiObjectiveEvaluationOperator<TSolution>>())
|
---|
[11740] | 91 | op.EvaluateFunc = Evaluate;
|
---|
[13336] | 92 | foreach (var op in Operators.OfType<IMultiObjectiveAnalysisOperator<TSolution>>())
|
---|
[11740] | 93 | op.AnalyzeAction = Analyze;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
[11780] | 96 |
|
---|
| 97 | #region IMultiObjectiveHeuristicOptimizationProblem Members
|
---|
| 98 | IParameter IMultiObjectiveHeuristicOptimizationProblem.MaximizationParameter {
|
---|
| 99 | get { return Parameters["Maximization"]; }
|
---|
| 100 | }
|
---|
| 101 | IMultiObjectiveEvaluator IMultiObjectiveHeuristicOptimizationProblem.Evaluator {
|
---|
| 102 | get { return Evaluator; }
|
---|
| 103 | }
|
---|
| 104 | #endregion
|
---|
[11740] | 105 | }
|
---|
| 106 | }
|
---|