1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using HeuristicLab.Common;
|
---|
4 | using HeuristicLab.Core;
|
---|
5 | using HeuristicLab.Data;
|
---|
6 | using HeuristicLab.Optimization;
|
---|
7 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.Analysis.FitnessLandscape {
|
---|
10 |
|
---|
11 | [Item("BoundingBox Aggregator", "Aggregates bounding boxes")]
|
---|
12 | [StorableClass]
|
---|
13 | public class BoundingBoxAggregator : Aggregator<DoubleMatrix> {
|
---|
14 |
|
---|
15 | [StorableConstructor]
|
---|
16 | protected BoundingBoxAggregator(bool deserializing) : base(deserializing) { }
|
---|
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 | }
|
---|