Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 16995 was 16995, checked in by gkronber, 5 years ago

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