Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/Analysis/Aggregators/BoundingBoxAggregator.cs @ 16591

Last change on this file since 16591 was 16573, checked in by gkronber, 6 years ago

#2520: changed HeuristicLab.FLA addon to compile with new HL.Persistence

File size: 2.8 KB
Line 
1using System;
2using System.Collections.Generic;
3using HeuristicLab.Common;
4using HeuristicLab.Core;
5using HeuristicLab.Data;
6using HeuristicLab.Optimization;
7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
8using HEAL.Attic;
9
10namespace HeuristicLab.Analysis.FitnessLandscape {
11
12  [Item("BoundingBox Aggregator", "Aggregates bounding boxes")]
13  [StorableType("E6E3FEEA-AEA5-4B6B-87CF-A0AFEF26D9FD")]
14  public class BoundingBoxAggregator : Aggregator<DoubleMatrix> {
15
16    [StorableConstructor]
17    protected BoundingBoxAggregator(StorableConstructorFlag _) : base(_) { }
18    protected BoundingBoxAggregator(BoundingBoxAggregator original, Cloner cloner) : base(original, cloner) { }
19    public BoundingBoxAggregator() { }
20    public override IDeepCloneable Clone(Cloner cloner) {
21      return new BoundingBoxAggregator(this, cloner);
22    }
23
24    public override IResult CreateResult() {
25      return new Result("BoundingBox Analysis", Aggregate(items));
26    }
27
28    public static DataTable Aggregate(List<DoubleMatrix> boundingBoxes) {
29      DataTable table = new DataTable("Bounding Box Analysis");
30      DataRow volumes = new DataRow("Volumes");
31      table.Rows.Add(volumes);
32      foreach (DoubleMatrix matrix in boundingBoxes) {
33        double volume = 1;
34        for (int i = 0; i < matrix.Rows; i++) {
35          volume *= matrix[i, 1] - matrix[i, 0];
36        }
37        volumes.Values.Add(Math.Pow(volume, 1.0 / matrix.Rows));
38      }
39      DataRow nrOfOverlapsRow = new DataRow("Nr of Overlaps");
40      nrOfOverlapsRow.VisualProperties.SecondYAxis = true;
41      table.Rows.Add(nrOfOverlapsRow);
42      DataRow minDistanceRow = new DataRow("MinDistance");
43      DataRow maxDistanceRow = new DataRow("MaxDistance");
44      table.Rows.Add(minDistanceRow);
45      table.Rows.Add(maxDistanceRow);
46      foreach (DoubleMatrix a in boundingBoxes) {
47        double minDistance = double.MaxValue;
48        double maxDistance = double.MinValue;
49        int nrOfOverlaps = 0;
50        foreach (DoubleMatrix b in boundingBoxes) {
51          if (a == b)
52            continue;
53          double distance = 0;
54          for (int i = 0; i < a.Rows; i++) {
55            if (a[i, 1] < b[i, 0])
56              distance += square(b[i, 0] - a[i, 1]);
57            else if (b[i, 1] < a[i, 0])
58              distance += square(a[i, 0] - b[i, 1]);
59          }
60          distance = Math.Sqrt(distance);
61          if (distance == 0)
62            nrOfOverlaps++;
63          minDistance = Math.Min(minDistance, distance);
64          maxDistance = Math.Max(maxDistance, distance);
65        }
66        minDistanceRow.Values.Add(minDistance);
67        maxDistanceRow.Values.Add(maxDistance);
68        nrOfOverlapsRow.Values.Add(nrOfOverlaps);
69      }
70      return table;
71    }
72
73    private static double square(double x) {
74      return x * x;
75    }
76  }
77}
Note: See TracBrowser for help on using the repository browser.