Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Algorithms.NSGA2/3.3/BasicMultiObjectiveQualityAnalyzer.cs @ 12440

Last change on this file since 12440 was 12012, checked in by ascheibe, 10 years ago

#2212 merged r12008, r12009, r12010 back into trunk

File size: 4.1 KB
RevLine 
[4086]1#region License Information
2/* HeuristicLab
[12012]3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[4086]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;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Operators;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28using HeuristicLab.Core;
29using HeuristicLab.Data;
30using HeuristicLab.Optimization;
31using HeuristicLab.Parameters;
[4902]32using HeuristicLab.Common;
[4086]33
34namespace HeuristicLab.Algorithms.NSGA2 {
35  [Item("BasicMultiObjectiveSolutionAnalyzer", "Basic analyzer for multiobjective problems that collects and presents the current pareto front as double matrix.")]
36  [StorableClass]
37  public class BasicMultiObjectiveQualityAnalyzer : SingleSuccessorOperator, IAnalyzer {
38    public IScopeTreeLookupParameter<IntValue> RankParameter {
39      get { return (IScopeTreeLookupParameter<IntValue>)Parameters["Rank"]; }
40    }
41    public IScopeTreeLookupParameter<DoubleArray> QualitiesParameter {
42      get { return (IScopeTreeLookupParameter<DoubleArray>)Parameters["Qualities"]; }
43    }
44    public ILookupParameter<ResultCollection> ResultsParameter {
45      get { return (ILookupParameter<ResultCollection>)Parameters["Results"]; }
46    }
47
[4902]48    [StorableConstructor]
49    protected BasicMultiObjectiveQualityAnalyzer(bool deserializing) : base(deserializing) { }
50    protected BasicMultiObjectiveQualityAnalyzer(BasicMultiObjectiveQualityAnalyzer original, Cloner cloner) : base(original, cloner) { }
[4086]51    public BasicMultiObjectiveQualityAnalyzer() {
52      Parameters.Add(new ScopeTreeLookupParameter<IntValue>("Rank", "The rank of solution describes to which front it belongs."));
53      Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>("Qualities", "The vector of qualities of each solution."));
54      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The result collection to store the front to."));
55    }
56
57    public override IOperation Apply() {
58      ItemArray<IntValue> ranks = RankParameter.ActualValue;
59      ItemArray<DoubleArray> qualities = QualitiesParameter.ActualValue;
60      ResultCollection results = ResultsParameter.ActualValue;
[4601]61     
62      bool populationLevel = RankParameter.Depth == 1;
[4086]63
64      int objectives = qualities[0].Length;
65      int frontSize = ranks.Count(x => x.Value == 0);
[4601]66      ItemArray<IScope> paretoArchive = null;
67      if (populationLevel) paretoArchive = new ItemArray<IScope>(frontSize);
[4086]68
69      DoubleMatrix front = new DoubleMatrix(frontSize, objectives);
70      int counter = 0;
71      for (int i = 0; i < ranks.Length; i++) {
72        if (ranks[i].Value == 0) {
73          for (int k = 0; k < objectives; k++)
74            front[counter, k] = qualities[i][k];
[4601]75          if (populationLevel) {
76            paretoArchive[counter] = (IScope)ExecutionContext.Scope.SubScopes[i].Clone();
77          }
[4086]78          counter++;
79        }
80      }
81
82      if (results.ContainsKey("Pareto Front"))
83        results["Pareto Front"].Value = front;
84      else results.Add(new Result("Pareto Front", front));
85
[4601]86      if (populationLevel) {
87        if (results.ContainsKey("Pareto Archive"))
88          results["Pareto Archive"].Value = paretoArchive;
89        else results.Add(new Result("Pareto Archive", paretoArchive));
90      }
[4086]91      return base.Apply();
92    }
[4902]93
94    public override IDeepCloneable Clone(Cloner cloner) {
95      return new BasicMultiObjectiveQualityAnalyzer(this, cloner);
96    }
[4086]97  }
98}
Note: See TracBrowser for help on using the repository browser.