1#ifndef ZONOOPT_ZONO_HPP_
2#define ZONOOPT_ZONO_HPP_
20using namespace detail;
50 Zono(
const Eigen::SparseMatrix<zono_float>&
G,
const Eigen::Vector<zono_float, -1>&
c,
68 void set(
const Eigen::SparseMatrix<zono_float>&
G,
const Eigen::Vector<zono_float, -1>&
c,
76 return new Zono(*
this);
91 std::string
print()
const override;
123std::unique_ptr<Zono>
make_regular_zono_2D(
zono_float radius,
int n_sides,
bool outer_approx=
false,
const Eigen::Vector<zono_float, 2>& c=Eigen::Vector<zono_float, 2>::Zero());
126inline void Zono::set(
const Eigen::SparseMatrix<zono_float>& G,
const Eigen::Vector<zono_float, -1>& c,
127 const bool zero_one_form)
130 if (
G.rows() !=
c.size())
132 throw std::invalid_argument(
"Zono: inconsistent dimensions.");
138 this->
nG =
static_cast<int>(this->G.cols());
139 this->
n =
static_cast<int>(this->G.rows());
143 this->
nGc = this->
nG;
147 this->
Gb.resize(this->
n, 0);
148 this->
A.resize(0, this->
nG);
150 this->
Ab.resize(0, 0);
157 Eigen::SparseMatrix<zono_float>
G;
161 c = this->c - this->G*Eigen::Vector<zono_float, -1>::Ones(this->
nG);
168 c = this->c + 0.5*this->G*Eigen::Vector<zono_float, -1>::Ones(this->
nG);
177 std::stringstream
ss;
178 ss <<
"Zono: " << std::endl;
179 ss <<
"n: " << this->
n << std::endl;
180 ss <<
"nG: " << this->
nG << std::endl;
181 ss <<
"G: " << Eigen::Matrix<
zono_float, -1, -1>(this->
G) << std::endl;
182 ss <<
"c: " << this->
c << std::endl;
205 for (
int i=0;
i<this->
nG; ++
i)
207 l -= this->
G.col(
i).cwiseAbs();
208 u += this->
G.col(
i).cwiseAbs();
219 throw std::invalid_argument(
"Zono reduce_order: desired order is less than dimension of set");
223 return std::make_unique<Zono>(*
this);
231 std::vector<std::pair<int, zono_float>>
sort_vec;
232 for (
int i=0;
i<this->
nG; ++
i)
234 sort_vec.emplace_back(
i, this->
G.col(
i).norm());
238 auto comp = [](
const std::pair<int, zono_float>&
a,
const std::pair<int, zono_float>&
b) ->
bool
240 return a.second >
b.second;
246 Eigen::SparseMatrix<zono_float>
G_K (this->n,
n_K);
247 std::vector<Eigen::Triplet<zono_float>>
triplets;
248 for (
int i=0;
i <
n_K; ++
i)
251 for (Eigen::SparseMatrix<zono_float>::InnerIterator
it(this->
G, k);
it; ++
it)
260 Eigen::SparseMatrix<zono_float>
G_L (this->n, this->nG -
n_K);
264 const int k = sort_vec[
i].first;
265 for (Eigen::SparseMatrix<zono_float>::InnerIterator
it(this->
G, k);
it; ++
it)
271 Zono L (
G_L, Eigen::Vector<zono_float, -1>::Zero(this->n));
281 throw std::runtime_error(
"In Zono::ReduceOrder, return type is not a zonotope?");
284 return std::unique_ptr<Zono>(
dynamic_cast<Zono*
>(
Z.release()));
292 const Eigen::Matrix<
zono_float, -1, -1>
Gd = this->
G.toDense();
293 for (
int i=0;
i<this->
nG; ++
i)
295 h += std::abs(
d.dot(
Gd.col(
i)));
Constrained zonotope class for ZonoOpt library.
Box (i.e., interval vector) class.
Definition Intervals.hpp:720
Constrained zonotope class.
Definition ConZono.hpp:33
Hybrid zonotope class.
Definition HybZono.hpp:44
int nC
number of constraints
Definition HybZono.hpp:482
int n
set dimension
Definition HybZono.hpp:470
friend std::unique_ptr< HybZono > minkowski_sum(const HybZono &Z1, HybZono &Z2)
Computes Minkowski sum of two sets Z1 and Z2.
Definition PolymorphicFunctions.hpp:133
bool zero_one_form
flag to indicate whether the set is in 0-1 or -1-1 form
Definition HybZono.hpp:485
Eigen::SparseMatrix< zono_float > Gc
continuous generator matrix
Definition HybZono.hpp:449
Eigen::SparseMatrix< zono_float > Gb
binary generator matrix
Definition HybZono.hpp:452
int nG
total number of factors. nG = nGc + nGb
Definition HybZono.hpp:473
bool sharp
flag to indicate whether the set is known to be sharp (i.e., convex relaxation = convex hull)
Definition HybZono.hpp:488
Eigen::Vector< zono_float, -1 > c
center vector
Definition HybZono.hpp:464
int nGb
number of binary factors
Definition HybZono.hpp:479
Box bounding_box(const OptSettings &settings=OptSettings(), OptSolution *solution=nullptr)
Computes a bounding box of the set object as a Box object.
Definition HybZono.hpp:398
Eigen::SparseMatrix< zono_float > A
constraint matrix A = [Ac, Ab]
Definition HybZono.hpp:455
Eigen::Vector< zono_float, -1 > b
constraint vector
Definition HybZono.hpp:467
Eigen::SparseMatrix< zono_float > Ab
binary constraint matrix
Definition HybZono.hpp:461
Eigen::SparseMatrix< zono_float > Ac
continuous constraint matrix
Definition HybZono.hpp:458
Eigen::SparseMatrix< zono_float > G
generator matrix G = [Gc, Gb]
Definition HybZono.hpp:446
int nGc
number of continuous factors
Definition HybZono.hpp:476
Zonotope class.
Definition Zono.hpp:33
bool do_is_empty(const OptSettings &settings, OptSolution *solution) const override
Definition Zono.hpp:187
std::string print() const override
Returns set information as a string.
Definition Zono.hpp:175
HybZono * clone() const override
Clone method for polymorphic behavior.
Definition Zono.hpp:74
std::unique_ptr< Zono > reduce_order(int n_o)
Perform zonotope order reduction.
Definition Zono.hpp:215
void set(const Eigen::SparseMatrix< zono_float > &G, const Eigen::Vector< zono_float, -1 > &c, bool zero_one_form=false)
Reset zonotope object with the given parameters.
Definition Zono.hpp:126
Zono(const Eigen::SparseMatrix< zono_float > &G, const Eigen::Vector< zono_float, -1 > &c, const bool zero_one_form=false)
Zono constructor.
Definition Zono.hpp:50
zono_float do_support(const Eigen::Vector< zono_float, -1 > &d, const OptSettings &settings, OptSolution *solution) override
Definition Zono.hpp:287
Zono()
Default constructor for Zono class.
Definition Zono.hpp:41
void convert_form() override
Converts the set representation between -1-1 and 0-1 forms.
Definition Zono.hpp:154
Box do_bounding_box(const OptSettings &settings, OptSolution *solution) override
Definition Zono.hpp:195
#define zono_float
Defines the floating-point type used in ZonoOpt.
Definition ZonoOpt.hpp:43
std::unique_ptr< Zono > interval_2_zono(const Box &box)
Builds a zonotope from a Box object.
Definition PolymorphicFunctions.hpp:1566
std::unique_ptr< Zono > make_regular_zono_2D(const zono_float radius, const int n_sides, const bool outer_approx, const Eigen::Vector< zono_float, 2 > &c)
Builds a 2D regular zonotope with a given radius and number of sides.
Definition PolymorphicFunctions.hpp:1585
Settings for optimization routines in ZonoOpt library.
Definition SolverDataStructures.hpp:26
Solution data structure for optimization routines in ZonoOpt library.
Definition SolverDataStructures.hpp:153