Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/RealVectorConvexHullSolutionCacheAnalyzer.cs @ 10429

Last change on this file since 10429 was 10116, checked in by ascheibe, 11 years ago

#1886 added convex hull RunCollectionModifiers

File size: 3.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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.Linq;
23using HeuristicLab.Analysis.SolutionCaching;
24using HeuristicLab.Analysis.SolutionCaching.RealVectorEncoding;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Encodings.RealVectorEncoding;
28using HeuristicLab.Optimization;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers {
32  [StorableClass]
33  [Item("RealVectorConvexHullSolutionCacheAnalyzer", "Calculates convex hull-based measures from real vector solution caches.")]
34  public class RealVectorConvexHullSolutionCacheAnalyzer : SolutionCacheAnalyzer<RealVector, RealVectorSolutionInformation> {
35    [StorableConstructor]
36    private RealVectorConvexHullSolutionCacheAnalyzer(bool deserializing) : base(deserializing) { }
37    private RealVectorConvexHullSolutionCacheAnalyzer(RealVectorConvexHullSolutionCacheAnalyzer original, Cloner cloner)
38      : base(original, cloner) {
39    }
40    public override IDeepCloneable Clone(Cloner cloner) {
41      return new RealVectorConvexHullSolutionCacheAnalyzer(this, cloner);
42    }
43
44    public RealVectorConvexHullSolutionCacheAnalyzer() : base() { }
45
46    public override void ExecuteAnalysis(ResultCollection results, SolutionCache<RealVector, RealVectorSolutionInformation> solutionCache) {
47      int i = 0;
48      var sols = solutionCache.GetSolutionsFromGeneration(i);
49      DataTable dt = new DataTable("Convex Hull Volume over Generations");
50      DataRow dtVolumeRow = new DataRow("Volume");
51      DataRow dtNrPointsRow = new DataRow("Nr. of Points");
52      dt.Rows.Add(dtVolumeRow);
53      dt.Rows.Add(dtNrPointsRow);
54
55      while (sols.Count != 0) {
56        var input = sols.Select(x => ConvertRealVectorToArray(x)).ToArray();
57        var convexHull = LPHull.Calculate(input);
58        var volume = ConvexHullMeasures.CalculateVolume(convexHull);
59        dtVolumeRow.Values.Add(volume);
60        dtNrPointsRow.Values.Add(convexHull.Count);
61
62        sols = solutionCache.GetSolutionsFromGeneration(++i);
63      }
64
65      results.Add(new Result("Convex Hull Measures", dt));
66    }
67
68    private double[] ConvertRealVectorToArray(RealVector p) {
69      double[] vertex = p.Select(x => (double)x).ToArray();
70      return vertex;
71    }
72  }
73}
Note: See TracBrowser for help on using the repository browser.