lucid  0.0.1
Lifting-based Uncertain Control Invariant Dynamics
Loading...
Searching...
No Matches
lucid::PolytopeSet Class Referencefinal

A convex polytope set in half-space representation. More...

#include <PolytopeSet.h>

Inheritance diagram for lucid::PolytopeSet:
lucid::Set

Public Member Functions

 PolytopeSet (Matrix A, Vector b)
 Construct a polytope from hyperplane normals and offsets.
 
 PolytopeSet (std::initializer_list< std::initializer_list< Scalar > > A, std::initializer_list< Scalar > b)
 Construct a polytope from hyperplane normals and offsets.
 
Dimension dimension () const override
 Get read-only access to the dimension of the set \( \texttip{\mathcal{X}}{Polish sample vector space} \).
 
Matrix sample (Index num_samples) const override
 Extract \( N \) elements from \( \texttip{\mathcal{X}}{Polish sample vector space} \) using some kind of random distribution.
 
bool operator() (ConstVectorRef x) const override
 Check if a vector is in \( \texttip{\mathcal{X}}{Polish sample vector space} \).
 
Matrix lattice (const VectorI &points_per_dim, bool endpoint) const override
 Generate a lattice of points in the set.
 
void scale (Scalar factor)
 Scale the polytope by a factor.
 
const Matrix & A () const
 Get read-only access to the hyperplane normals matrix of the polytope.
 
const Vector & b () const
 Get read-only access to the hyperplane offsets vector of the polytope.
 
std::string to_string () const override
 Obtain the string representation of this object.
 
std::unique_ptr< Setclone () const override
 Clone the set.
 
Matrix lattice (Index points_per_dim, bool endpoint=false) const
 Generate a lattice of points in the set.
 
- Public Member Functions inherited from lucid::Set
Vector sample () const
 Extract an element from \( \texttip{\mathcal{X}}{Polish sample vector space} \) using some kind of random distribution.
 
bool contains (ConstVectorRef x) const
 Check if a vector is in \( \texttip{\mathcal{X}}{Polish sample vector space} \).
 
bool contains_wrapped (ConstVectorRef x, ConstVectorRef period, Dimension num_periods) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool contains_wrapped (ConstVectorRef x, ConstVectorRef period, const std::vector< Dimension > &num_periods) const
 Check if a vector is in \( \texttip{\mathcal{X}}{Polish sample vector space} \), having the vector wrapped around a given period.
 
bool contains_wrapped (ConstVectorRef x, ConstVectorRef period, Dimension num_periods_below, Dimension num_periods_above) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool contains_wrapped (ConstVectorRef x, ConstVectorRef period, const std::vector< Dimension > &num_periods_below, const std::vector< Dimension > &num_periods_above) const
 Check if a vector is in \( \texttip{\mathcal{X}}{Polish sample vector space} \), having the vector wrapped around a given period.
 
bool contains_wrapped (ConstVectorRef x, ConstVectorRef period) const
 Check if a vector is in \( \texttip{\mathcal{X}}{Polish sample vector space} \), having the vector wrapped around a given period.
 
Matrix include (ConstMatrixRef xs) const
 Filter a set xs, returning only the row vectors that are in \( \texttip{\mathcal{X}}{Polish sample vector space} \).
 
std::vector< Index > include_mask (ConstMatrixRef xs) const
 Filter a set xs, returning a mask containing the indices corresponding to the row vectors that are in \( \texttip{\mathcal{X}}{Polish sample vector space} \).
 
std::vector< Index > include_mask_wrapped (ConstMatrixRef xs, ConstVectorRef period) const
 Filter a set xs, returning a mask containing the indices corresponding to the row vectors that are in \( \texttip{\mathcal{X}}{Polish sample vector space} \), accounting for wrapping around a given period.
 
Matrix exclude (ConstMatrixRef xs) const
 Filter xs, return only the row vectors that are NOT in \( \texttip{\mathcal{X}}{Polish sample vector space} \).
 
std::vector< Index > exclude_mask (ConstMatrixRef xs) const
 Filter a set xs, returning a mask containing the indices corresponding to the row vectors that are NOT in \( \texttip{\mathcal{X}}{Polish sample vector space} \).
 
std::vector< Index > exclude_mask_wrapped (ConstMatrixRef xs, ConstVectorRef period) const
 Filter a set xs, returning a mask containing the indices corresponding to the row vectors that are NOT in \( \texttip{\mathcal{X}}{Polish sample vector space} \), accounting for wrapping around a given period.
 
std::pair< std::vector< Index >, std::vector< Index > > include_exclude_masks (ConstMatrixRef xs) const
 Filter a set xs, returning masks containing the indices corresponding to the row vectors that are in \( \texttip{\mathcal{X}}{Polish sample vector space} \) and NOT in \( \texttip{\mathcal{X}}{Polish sample vector space} \).
 
std::pair< std::vector< Index >, std::vector< Index > > include_exclude_masks_wrapped (ConstMatrixRef xs, ConstVectorRef period) const
 Filter a set xs, returning masks containing the indices corresponding to the row vectors that are in \( \texttip{\mathcal{X}}{Polish sample vector space} \) and NOT in \( \texttip{\mathcal{X}}{Polish sample vector space} \), accounting for wrapping around a given period.
 
std::pair< std::vector< Index >, std::vector< Index > > include_exclude_masks_wrapped (ConstMatrixRef xs, const RectSet &period) const
 Filter a set xs, returning masks containing the indices corresponding to the row vectors that are in \( \texttip{\mathcal{X}}{Polish sample vector space} \) and NOT in \( \texttip{\mathcal{X}}{Polish sample vector space} \), accounting for wrapping around a given period.
 
std::unique_ptr< Setscale_wrapped (double scale, const RectSet &bounds, bool relative_to_bounds=false) const
 Scale the set by the given factor while keeping it inside the given bounds.
 
std::unique_ptr< Setscale_wrapped (ConstVectorRef scale, const RectSet &bounds, bool relative_to_bounds=false) const
 Scale the set by the given factor while keeping it inside the given bounds.
 
template<bool Inplace = false>
requires (!Inplace)
std::unique_ptr< Setincrease_size (ConstVectorRef size_increase) const
 Increase the size of the set.
 
template<bool Inplace = false>
requires (Inplace)
void increase_size (ConstVectorRef size_increase)
 Increase the size of the set.
 
void change_size (double delta_size)
 Change the size of the set.
 
virtual void change_size (ConstVectorRef delta_size)
 Change the size of the set.
 
Matrix lattice (Index points_per_dim, bool endpoint=false) const
 Generate a lattice of points in the set.
 
virtual std::unique_ptr< Setto_rect_set () const
 Convert the set to a rectangular set.
 
virtual std::unique_ptr< Setto_anisotropic () const
 Create a new anisotropic set.
 
virtual Vector general_lower_bound () const
 Get read-only access to the lower bound of the smallest rectangular set including the whole set.
 
virtual Vector general_upper_bound () const
 Get read-only access to the upper bound of the smallest rectangular set including the whole set.
 
template<class Derived>
Eigen::MatrixBase< Derived > & operator>> (Eigen::MatrixBase< Derived > &x) const
 Extract \( N \) elements element from \( \texttip{\mathcal{X}}{Polish sample vector space} \) using some kind of random distribution, where \( N \) is the number of rows in \( \texttip{x}{Element of the vector space} \).
 

Static Public Member Functions

static PolytopeSet from_box (const std::vector< std::pair< Scalar, Scalar > > &bounds)
 Create a polytope from a bounding box (hyperrectangle).
 

Private Member Functions

std::pair< Vector, Vector > compute_bounding_box () const
 Compute bounding box of the polytope using linear programming.
 

Private Attributes

Matrix A_
 Hyperplane normals matrix (m x n)
 
Vector b_
 Hyperplane offsets vector (m)
 
std::optional< std::pair< Vector, Vector > > bbox_
 Cached bounding box.
 

Additional Inherited Members

- Protected Member Functions inherited from lucid::Set
virtual std::unique_ptr< Setscale_wrapped_impl (ConstVectorRef scale, const RectSet &bounds, bool relative_to_bounds) const
 Scale the rectangular set by the given factor while keeping it inside the given bounds.
 
virtual void increase_size_impl (ConstVectorRef size_increase)
 Increase the size of the set.
 

Detailed Description

A convex polytope set in half-space representation.

A vector \( \texttip{x}{Element of the vector space} \) is in the set if \( A x \le b \), where \( A \) is a matrix of hyperplane normals and \( b \) is a vector of hyperplane offsets.

Constructor & Destructor Documentation

◆ PolytopeSet() [1/2]

lucid::PolytopeSet::PolytopeSet ( Matrix A,
Vector b )

Construct a polytope from hyperplane normals and offsets.

Parameters
Amatrix of hyperplane normals (each row is a normal vector)
bvector of hyperplane offsets

◆ PolytopeSet() [2/2]

lucid::PolytopeSet::PolytopeSet ( std::initializer_list< std::initializer_list< Scalar > > A,
std::initializer_list< Scalar > b )

Construct a polytope from hyperplane normals and offsets.

Parameters
Amatrix of hyperplane normals (each row is a normal vector)
bvector of hyperplane offsets

Member Function Documentation

◆ A()

const Matrix & lucid::PolytopeSet::A ( ) const
inlinenodiscard

Get read-only access to the hyperplane normals matrix of the polytope.

Returns
hyperplane normals matrix of the polytope

◆ b()

const Vector & lucid::PolytopeSet::b ( ) const
inlinenodiscard

Get read-only access to the hyperplane offsets vector of the polytope.

Returns
hyperplane offsets vector of the polytope

◆ clone()

std::unique_ptr< Set > lucid::PolytopeSet::clone ( ) const
nodiscardoverridevirtual

Clone the set.

Create a new instance of the set with the same properties as the current one.

Returns
new instance of the set

Implements lucid::Set.

◆ compute_bounding_box()

std::pair< Vector, Vector > lucid::PolytopeSet::compute_bounding_box ( ) const
private

Compute bounding box of the polytope using linear programming.

Returns
pair of lower and upper bounds

◆ dimension()

Dimension lucid::PolytopeSet::dimension ( ) const
inlinenodiscardoverridevirtual

Get read-only access to the dimension of the set \( \texttip{\mathcal{X}}{Polish sample vector space} \).

Returns
dimension of the set \( \texttip{\mathcal{X}}{Polish sample vector space} \)

Implements lucid::Set.

◆ from_box()

PolytopeSet lucid::PolytopeSet::from_box ( const std::vector< std::pair< Scalar, Scalar > > & bounds)
static

Create a polytope from a bounding box (hyperrectangle).

Parameters
boundsvector of pairs of lower and upper bounds
Returns
polytope representing the hyperrectangle

◆ lattice() [1/2]

Matrix lucid::PolytopeSet::lattice ( const VectorI & points_per_dim,
bool endpoint ) const
nodiscardoverridevirtual

Generate a lattice of points in the set.

Parameters
points_per_dimnumber of points per each dimension
endpointwhether to include the endpoints of the lattice
Returns
lattice of points in the set

Implements lucid::Set.

◆ lattice() [2/2]

Matrix lucid::Set::lattice ( Index points_per_dim,
bool endpoint = false ) const
nodiscard

Generate a lattice of points in the set.

Parameters
points_per_dimnumber of points per each dimension
endpointwhether to include the endpoints of the lattice
Returns
lattice of points in the set

◆ operator()()

bool lucid::PolytopeSet::operator() ( ConstVectorRef x) const
nodiscardoverridevirtual

Check if a vector is in \( \texttip{\mathcal{X}}{Polish sample vector space} \).

Precondition
\( \texttip{x}{Element of the vector space} \) must have the same dimension as the set
Parameters
xvector to test
Returns
true if \( \texttip{x}{Element of the vector space} \) is in the set
false if \( \texttip{x}{Element of the vector space} \) is not in the set

Implements lucid::Set.

◆ sample()

Matrix lucid::PolytopeSet::sample ( Index num_samples) const
nodiscardoverridevirtual

Extract \( N \) elements from \( \texttip{\mathcal{X}}{Polish sample vector space} \) using some kind of random distribution.

Note
The seed for the random number generator can be set using random::seed.
Precondition
num_samples must be greater than 0
Parameters
num_samplesnumber of samples to generate \( N \)
Returns
\( \texttip{n}{Number of samples} \times \texttip{d}{Dimension of the vector space} \) matrix of samples, where \( \texttip{d}{Dimension of the vector space} \) is the dimension of \( \texttip{\mathcal{X}}{Polish sample vector space} \). In other words, the samples are stored as rows vectors in the matrix

Implements lucid::Set.

◆ scale()

void lucid::PolytopeSet::scale ( Scalar factor)

Scale the polytope by a factor.

The constraints \( A x \le b \) are scaled to \( A x \le s b \).

Parameters
factorscaling factor \( s \)

◆ to_string()

std::string lucid::PolytopeSet::to_string ( ) const
nodiscardoverridevirtual

Obtain the string representation of this object.

Returns
string representation of this object

Reimplemented from lucid::Set.


The documentation for this class was generated from the following files: