Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/MOTFAnalyzer.cs @ 13672

Last change on this file since 13672 was 13672, checked in by bwerth, 8 years ago

#1087 added Analyzers, reworked PFStore, added licence information, cleaned code

File size: 3.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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.Collections.Generic;
23using System.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Operators;
28using HeuristicLab.Optimization;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31
32
33namespace HeuristicLab.Problems.MultiObjectiveTestFunctions {
34
35  [StorableClass]
36  abstract class MOTFAnalyzer : SingleSuccessorOperator, IMultiObjectiveTestFunctionAnalyzer {
37
38    public ILookupParameter<IEncoding> EncodingParameter {
39      get { return (ILookupParameter<IEncoding>)Parameters["Encoding"]; }
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
50
51    private IMultiObjectiveTestFunction testFunction;
52    public IMultiObjectiveTestFunction TestFunction {
53      get { return testFunction; }
54      set { testFunction = value; }
55    }
56
57    protected MOTFAnalyzer(MOTFAnalyzer original, Cloner cloner) : base(original, cloner) {
58    }
59    [StorableConstructor]
60    protected MOTFAnalyzer(bool deserializing) : base(deserializing) { }
61    public MOTFAnalyzer() {
62      Parameters.Add(new LookupParameter<IEncoding>("Encoding", "An item that holds the problem's encoding."));
63      Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>("Qualities", "The qualities of the parameter vector."));
64      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The results collection to write to."));
65    }
66    [StorableHook(HookType.AfterDeserialization)]
67    private void AfterDeserialization() {
68    }
69
70    public bool EnabledByDefault {
71      get { return true; }
72    }
73
74    public override IOperation Apply() {
75      var encoding = EncodingParameter.ActualValue;
76      var results = ResultsParameter.ActualValue;
77
78      IEnumerable<IScope> scopes = new[] { ExecutionContext.Scope };
79      for (var i = 0; i < QualitiesParameter.Depth; i++)
80        scopes = scopes.Select(x => (IEnumerable<IScope>)x.SubScopes).Aggregate((a, b) => a.Concat(b));
81
82      var individuals = scopes.Select(encoding.GetIndividual).ToArray();
83      Analyze(individuals, QualitiesParameter.ActualValue.Select(x => x.ToArray()).ToArray(), results);
84      return base.Apply();
85    }
86
87    protected abstract void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results);
88  }
89}
Note: See TracBrowser for help on using the repository browser.