[13368] | 1 | #region License Information
|
---|
[11961] | 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 |
|
---|
| 22 | using System;
|
---|
[11400] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using HeuristicLab.Common;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Data;
|
---|
| 28 | using HeuristicLab.Operators;
|
---|
| 29 | using HeuristicLab.Parameters;
|
---|
| 30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 31 |
|
---|
[11949] | 32 | namespace HeuristicLab.Optimization {
|
---|
[11484] | 33 | [Item("Multi-objective Analyzer", "Calls the Analyze method of the problem definition.")]
|
---|
[14711] | 34 | [StorableType("01475E97-13B0-446C-8A86-DE26817E2E44")]
|
---|
[11880] | 35 | public class MultiObjectiveAnalyzer : SingleSuccessorOperator, IMultiObjectiveAnalysisOperator, IStochasticOperator {
|
---|
[11400] | 36 | public bool EnabledByDefault { get { return true; } }
|
---|
| 37 |
|
---|
[11559] | 38 | public ILookupParameter<IEncoding> EncodingParameter {
|
---|
| 39 | get { return (ILookupParameter<IEncoding>)Parameters["Encoding"]; }
|
---|
[11400] | 40 | }
|
---|
| 41 |
|
---|
| 42 | public IScopeTreeLookupParameter<DoubleArray> QualitiesParameter {
|
---|
| 43 | get { return (IScopeTreeLookupParameter<DoubleArray>)Parameters["Qualities"]; }
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | public ILookupParameter<ResultCollection> ResultsParameter {
|
---|
| 47 | get { return (ILookupParameter<ResultCollection>)Parameters["Results"]; }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
[11880] | 50 | public ILookupParameter<IRandom> RandomParameter {
|
---|
| 51 | get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
|
---|
| 52 | }
|
---|
[11739] | 53 |
|
---|
[11880] | 54 | public Action<Individual[], double[][], ResultCollection, IRandom> AnalyzeAction { get; set; }
|
---|
| 55 |
|
---|
[11400] | 56 | [StorableConstructor]
|
---|
| 57 | protected MultiObjectiveAnalyzer(bool deserializing) : base(deserializing) { }
|
---|
| 58 | protected MultiObjectiveAnalyzer(MultiObjectiveAnalyzer original, Cloner cloner) : base(original, cloner) { }
|
---|
| 59 | public MultiObjectiveAnalyzer() {
|
---|
| 60 | Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use."));
|
---|
[11559] | 61 | Parameters.Add(new LookupParameter<IEncoding>("Encoding", "An item that holds the problem's encoding."));
|
---|
[11400] | 62 | Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>("Qualities", "The qualities of the parameter vector."));
|
---|
| 63 | Parameters.Add(new LookupParameter<ResultCollection>("Results", "The results collection to write to."));
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 67 | return new MultiObjectiveAnalyzer(this, cloner);
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | public override IOperation Apply() {
|
---|
[11598] | 71 | var encoding = EncodingParameter.ActualValue;
|
---|
[11400] | 72 | var results = ResultsParameter.ActualValue;
|
---|
[11880] | 73 | var random = RandomParameter.ActualValue;
|
---|
[11400] | 74 |
|
---|
| 75 | IEnumerable<IScope> scopes = new[] { ExecutionContext.Scope };
|
---|
| 76 | for (var i = 0; i < QualitiesParameter.Depth; i++)
|
---|
| 77 | scopes = scopes.Select(x => (IEnumerable<IScope>)x.SubScopes).Aggregate((a, b) => a.Concat(b));
|
---|
| 78 |
|
---|
[11619] | 79 | var individuals = scopes.Select(encoding.GetIndividual).ToArray();
|
---|
[11880] | 80 | AnalyzeAction(individuals, QualitiesParameter.ActualValue.Select(x => x.ToArray()).ToArray(), results, random);
|
---|
[11400] | 81 | return base.Apply();
|
---|
| 82 | }
|
---|
| 83 | }
|
---|
| 84 | }
|
---|