Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10286


Ignore:
Timestamp:
01/06/14 02:36:31 (11 years ago)
Author:
ascheibe
Message:

#1886 added support for calculating big volumes

Location:
branches/HeuristicLab.Analysis.AlgorithmBehavior
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/AlgorithmBehaviorUnitTests.csproj

    r10222 r10286  
    9898  </Choose>
    9999  <ItemGroup>
     100    <Compile Include="BigVolumeTest.cs" />
    100101    <Compile Include="LPConvexHullSortingTest.cs" />
    101102    <Compile Include="LPConvexHullTest.cs" />
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/ConvexHullMeasures.cs

    r10279 r10286  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using Mehroz;
    2526using MIConvexHull;
    2627
     
    4445    }
    4546
     47    public static Fraction CalculateSimplexVolumeBig(List<double[]> simplex) {
     48      int dim = simplex.First().Length;
     49      double[,] diffs = new double[dim, dim];
     50
     51      for (int i = 1; i < simplex.Count; i++) {
     52        for (int j = 0; j < dim; j++) {
     53          diffs[j, i - 1] = simplex[i][j] - simplex[0][j];
     54        }
     55      }
     56
     57      //calculate determinante from lu decomposition
     58      int[] pivots = null;
     59      alglib.rmatrixlu(ref diffs, dim, dim, out pivots);
     60
     61      Fraction det = 1;
     62      for (int i = 0; i < dim; i++) {
     63        det = det * diffs[i, i];
     64      }
     65
     66      if (det < 0)
     67        det = -1 * det;
     68
     69      Fraction result = det / dim.Fact();
     70      return result;
     71    }
     72
    4673    //calculates the volume of a convex d-polytope
    4774    //decomposition based on delaunay triangulation
     
    6491      foreach (var simplex in simplices) {
    6592        volume += CalculateSimplexVolume(simplex.ToList());
     93      }
     94
     95      return volume;
     96    }
     97
     98    public static Fraction CalculateVolumeBig(List<double[]> convexHull) {
     99      Fraction volume = new Fraction(0.0);
     100
     101      int dim = convexHull.First().Length;
     102      if (dim > convexHull.Count)
     103        throw new ArgumentException("Nr. of points for volume calculation must be greater than dimension", "convexHull");
     104
     105      ITriangulation<DefaultVertex, DefaultTriangulationCell<DefaultVertex>> triangulation = null;
     106      try {
     107        //Under certain circumstances MIConvexHull is not able to calculate the triangulation
     108        triangulation = Triangulation.CreateDelaunay(ConvertToVertex(convexHull));
     109      }
     110      catch {
     111        return Fraction.NaN;
     112      }
     113      var simplices = ConvertFromTriangulation(triangulation);
     114      foreach (var simplex in simplices) {
     115        volume += CalculateSimplexVolumeBig(simplex.ToList());
    66116      }
    67117
     
    197247
    198248    public static double CalculateHypercubeVolume(double[] bounds, int dim) {
     249      //this is not very smart...
    199250      return CalculateVolume(GenerateHyperCube(bounds, dim));
     251    }
     252
     253    public static Fraction CalculateHypercubeVolumeBig(double[] bounds, int dim) {
     254      double diff = bounds[1] - bounds[0];
     255
     256      Fraction volume = diff;
     257      for (int i = 0; i < dim; i++) {
     258        volume *= diff;
     259      }
     260      return volume;
    200261    }
    201262  }
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers-3.3.csproj

    r10275 r10286  
    106106    <Reference Include="System.Core" />
    107107    <Reference Include="System.Drawing" />
     108    <Reference Include="System.Numerics" />
    108109    <Reference Include="System.Xml.Linq" />
    109110    <Reference Include="System.Data.DataSetExtensions" />
     
    113114  </ItemGroup>
    114115  <ItemGroup>
     116    <Compile Include="FractionClass.cs" />
    115117    <Compile Include="QhullWrapper.cs" />
    116118    <Compile Include="DoubleArrayExtensions.cs" />
Note: See TracChangeset for help on using the changeset viewer.