Class Matrices.ConvexHyperpolyhedron

java.lang.Object
net.algart.arrays.Matrices.Region
net.algart.arrays.Matrices.ConvexHyperpolyhedron
Direct Known Subclasses:
Matrices.Simplex
Enclosing class:
Matrices

public static class Matrices.ConvexHyperpolyhedron extends Matrices.Region

Convex hyperpolyhedron: an intersection of several n-dimensional half-spaces and some hyperparallelepiped. While creating regions of this class, it is always necessary to specify some containing hyperparallelepiped. The coordinate ranges, returned by Matrices.Region.coordRanges() method of this class, are the corresponding ranges of the specified containing hyperparallelepiped.

More precisely, the region, specified by this class, consists of all such points (x0, x1, ..., xn−1), that:

a00x0 + a01x1 + ... + a0,n−1xn−1b0,
a10x0 + a11x1 + ... + a1,n−1xn−1b1,
...,
am−1,0x0 + am−1,1x1 + ... + am−1,n−1xn−1bm−1,
and also this point belongs to the specified containing hyperparallelepiped:
    coordRange(k).min()xkcoordRange(k).max() for all k=0,1,...,n−1.

The number of inequations m can be any non-negative integer 0,1,2,... (the degenerated case m=0 is equivalent to the hyperparallelepiped).

Convex hyperpolyhedrons can be created by the following methods:

In first method, you must directly specify the matrix A of coefficients aij, the vector b of coefficients bi and the containing hyperparallelepiped. (The containing hyperparallelepiped will be identical to the hyperparallelepiped, constructed by Matrices.Region.getHyperparallelepiped(IRange...coordRanges) method with the same coordRanges.)

Other 3 methods build a simplex — a particular case of the convex hyperpolyhedron. In these cases you need to specify its vertices only; necessary matrix A and vector b are calculated automatically.

This class is immutable and thread-safe: there are no ways to modify settings of the created instance.

  • Method Details

    • contains

      public boolean contains(long... coordinates)
      Description copied from class: Matrices.Region
      Returns true if and only if the point with the specified integer coordinates belongs to this region.

      The coordinates must contain at least Matrices.Region.n() elements. It can contain more than Matrices.Region.n() elements; then the extra elements will be ignored.

      Warning! Some inheritors of this class does not provide correct implementation of this method. In this case, Matrices.Region.isContainsSupported() method returns false and this method throws UnsupportedOperationException. So, you must always check the result of Matrices.Region.isContainsSupported() method before calling this one.

      However, this method must be correctly implemented, if this region is a 1-dimensional (Matrices.Region.n()==1) and Matrices.Region.isRectangular() method returns false.

      Note: even if the inheritor does not provide correct implementation of this method, it must always provide correct implementation of Matrices.Region.sectionAtLastCoordinate(long) method.

      Specified by:
      contains in class Matrices.Region
      Parameters:
      coordinates - the coordinates of the point: the first element is x, the second is y, ...
      Returns:
      true if and only if the point with the specified coordinates belongs to this region.
    • sectionAtLastCoordinate

      public Matrices.Region[] sectionAtLastCoordinate(long sectionCoordinateValue)
      Description copied from class: Matrices.Region
      Finds the intersection of this region with the hyperplane, described by the equation xn−1=sectionCoordinateValue, and returns this intersection as an array of (n−1)-dimensional regions. (Here xn−1 is the last coordinate of the points: y-coordinate in 2-dimensional case, z-coordinate in 3-dimensional case, etc.) If the intersection is empty, this method returns an empty array ("new Region[0]"). This method never returns null.

      This method must not be used if this region is 1-dimensional (Matrices.Region.n()==1). In this case, it throws IllegalStateException.

      This default implementation is based on Matrices.Region.contains(long...) method, which is supposed to be correctly implemented.

      Note: it is possible (in some rare exotic cases), that the regions, returned by this method, intersects with each other: some points will belong to 2 and more elements of the result. In particular, it is possible for Matrices.Polygon2D, if some sides of the polygon lie exactly at the horizontal y=sectionCoordinateValue.

      Implementations of this method in this packages, besides the implementation in Matrices.Polygon2D class, never return more than 1 region in the result.

      You must override this method if you prefer not to implement Matrices.Region.contains(long...) method (Matrices.Region.isContainsSupported() returns false). In this case, your implementation must not call Matrices.Region.contains(long...) method or super.Matrices.Region.sectionAtLastCoordinate(long).

      Overrides:
      sectionAtLastCoordinate in class Matrices.Region
      Parameters:
      sectionCoordinateValue - the value of the last coordinate.
      Returns:
      the intersection of this region and the (n−1)-dimensional hyperplane, corresponding to the specified value of the last coordinate (0, 1 or more regions, every region is (n−1)-dimensional).
    • toString

      public String toString()
      Returns a brief string description of this object.

      The result of this method may depend on implementation.

      Overrides:
      toString in class Object
      Returns:
      a brief string description of this object.
    • a

      public double[] a()
      Returns the matrix A: coefficients of the left side of inequations, defining the half-spaces (see the comments to this class). The elements of the matrix A will be listed in the returned array row by row: aij=a[i*n+j], i is the index of the row (0..m-1), j is the index of the column (0..n-1), a is the result of this method with length a.length=nm.

      The returned array is a clone of the internal array stored in this object.

      Returns:
      the matrix A: coefficients of the left side of inequations, defining the half-spaces.
    • b

      public double[] b()
      Returns the vector b: right sides of inequations, defining the half-spaces (see the comments to this class). The elements of the vector b will be listed in the returned array. The length of the returned array is the number of half-spaces.

      The returned array is a clone of the internal array stored in this object.

      Returns:
      the vector b: right sides of inequations, defining the half-spaces.