1#ifndef ZONOOPT_CONZONO_HPP_
2#define ZONOOPT_CONZONO_HPP_
20using namespace detail;
53 ConZono(
const Eigen::SparseMatrix<zono_float>&
G,
const Eigen::Vector<zono_float, -1>&
c,
54 const Eigen::SparseMatrix<zono_float>&
A,
const Eigen::Vector<zono_float, -1>&
b,
82 void set(
const Eigen::SparseMatrix<zono_float>&
G,
const Eigen::Vector<zono_float, -1>&
c,
83 const Eigen::SparseMatrix<zono_float>&
A,
const Eigen::Vector<zono_float, -1>&
b,
106 std::string
print()
const override;
110 OptSolution qp_opt(
const Eigen::SparseMatrix<zono_float>& P,
const Eigen::Vector<zono_float, -1>& q,
111 zono_float c,
const Eigen::SparseMatrix<zono_float>&
A,
const Eigen::Vector<zono_float, -1>&
b,
115 const Eigen::SparseMatrix<zono_float> &P,
const Eigen::Vector<zono_float, -1> &q,
zono_float c,
146std::unique_ptr<ConZono>
vrep_2_conzono(
const Eigen::Matrix<zono_float, -1, -1> &Vpoly);
150inline void ConZono::set(
const Eigen::SparseMatrix<zono_float>& G,
const Eigen::Vector<zono_float, -1>& c,
151 const Eigen::SparseMatrix<zono_float>& A,
const Eigen::Vector<zono_float, -1>& b,
152 const bool zero_one_form)
155 if (
G.rows() !=
c.size() ||
A.rows() !=
b.size() ||
G.cols() !=
A.cols())
157 throw std::invalid_argument(
"ConZono: inconsistent dimensions.");
165 this->
nG =
static_cast<int>(G.cols());
166 this->
nC =
static_cast<int>(A.rows());
167 this->
n =
static_cast<int>(G.rows());
171 this->
nGc = this->
nG;
174 this->
Gb.resize(this->
n, 0);
176 this->
Ab.resize(0, 0);
182 Eigen::SparseMatrix<zono_float>
G,
A;
186 c = this->c - this->G*Eigen::Vector<zono_float, -1>::Ones(this->
nG);
187 b = this->b + this->A*Eigen::Vector<zono_float, -1>::Ones(this->
nG);
195 c = this->c + 0.5*this->G*Eigen::Vector<zono_float, -1>::Ones(this->
nG);
196 b = this->b - 0.5*this->A*Eigen::Vector<zono_float, -1>::Ones(this->
nG);
206 std::stringstream
ss;
207 ss <<
"ConZono: " << std::endl;
208 ss <<
"n: " << this->
n << std::endl;
209 ss <<
"nG: " << this->
nG << std::endl;
210 ss <<
"nC: " << this->
nC << std::endl;
211 ss <<
"G: " << Eigen::Matrix<
zono_float, -1, -1>(this->
G) << std::endl;
212 ss <<
"c: " << this->
c << std::endl;
213 ss <<
"A: " << Eigen::Matrix<
zono_float, -1, -1>(this->
A) << std::endl;
214 ss <<
"b: " << this->
b << std::endl;
220 const Eigen::SparseMatrix<zono_float> &P,
const Eigen::Vector<zono_float, -1> &q,
const zono_float c,
224 if (P.rows() !=
this->n || P.cols() !=
this->n || q.size() !=
this->n)
226 throw std::invalid_argument(
"Optimize over: inconsistent dimensions.");
230 Eigen::SparseMatrix<zono_float>
P_fact = this->
G.transpose()*P*this->
G;
241 return this->G*
sol.z + this->
c;
248 if (this->
n != x.size())
250 throw std::invalid_argument(
"Point projection: inconsistent dimensions.");
254 Eigen::SparseMatrix<zono_float> P = this->
G.transpose()*this->
G;
255 Eigen::Vector<
zono_float, -1> q = this->
G.transpose()*(this->
c-x);
262 throw std::invalid_argument(
"Point projection: infeasible");
264 return this->
G*sol.
z + this->
c;
274 Eigen::SparseMatrix<zono_float> P (this->
nG, this->
nG);
276 Eigen::Vector<
zono_float, -1> q = Eigen::Vector<zono_float, -1>::Zero(this->
nG);
282 return sol.infeasible;
289 if (this->
n != d.size())
291 throw std::invalid_argument(
"Support: inconsistent dimensions.");
295 Eigen::SparseMatrix<zono_float> P (this->
nG, this->
nG);
296 Eigen::Vector<
zono_float, -1> q = -this->
G.transpose()*
d;
303 throw std::invalid_argument(
"Support: infeasible");
305 return d.dot(this->
G*sol.
z +
this->c);
312 if (this->
n != x.size())
314 throw std::invalid_argument(
"Contains point: inconsistent dimensions.");
318 Eigen::SparseMatrix<zono_float> P (this->
nG, this->
nG);
324 b.segment(0, this->
nC) = this->
b;
325 b.segment(this->
nC, this->
n) = x-this->
c;
330 return !(
sol.infeasible);
334 const zono_float c,
const Eigen::SparseMatrix<zono_float>& A,
const Eigen::Vector<zono_float, -1>& b,
342 xi_lb.setConstant(-1);
343 const Eigen::Vector<
zono_float, -1>
xi_ub = Eigen::Vector<zono_float, -1>::Ones(this->
nG);
345 const auto data = std::make_shared<ADMM_data>(P, q,
A,
b,
xi_lb,
xi_ub,
c, settings);
350 if (solution !=
nullptr)
361 throw std::invalid_argument(
"Bounding box: empty set");
374 const Eigen::SparseMatrix<zono_float> P (this->
nG, this->
nG);
375 Eigen::Vector<
zono_float, -1> q = -this->
G.transpose()*
d;
380 xi_lb = Eigen::Vector<zono_float, -1>::Zero(this->
nG);
382 xi_lb = -1.0*Eigen::Vector<zono_float, -1>::Ones(this->
nG);
384 xi_ub = Eigen::Vector<zono_float, -1>::Ones(this->
nG);
387 const auto data = std::make_shared<ADMM_data>(P, q, this->
A, this->
b, xi_lb,
xi_ub, zero, settings);
391 for (
int i=0;
i<this->
n;
i++)
398 data->q = -this->
G.transpose()*
d;
403 throw std::invalid_argument(
"Bounding box: Z is empty");
412 data->q = -this->
G.transpose()*
d;
417 throw std::invalid_argument(
"Bounding box: Z is empty");
Hybrid zonotope class for ZonoOpt library.
Box (i.e., interval vector) class.
Definition Intervals.hpp:718
Constrained zonotope class.
Definition ConZono.hpp:33
void set(const Eigen::SparseMatrix< zono_float > &G, const Eigen::Vector< zono_float, -1 > &c, const Eigen::SparseMatrix< zono_float > &A, const Eigen::Vector< zono_float, -1 > &b, bool zero_one_form=false)
Reset constrained zonotope object with the given parameters.
Definition ConZono.hpp:150
virtual void constraint_reduction()
Execute constraint reduction algorithm from Scott et. al. 2016.
Definition PolymorphicFunctions.hpp:1757
std::unique_ptr< HybZono > do_complement(zono_float delta_m, bool, const OptSettings &, OptSolution *, int, int) override
Definition PolymorphicFunctions.hpp:1021
HybZono * clone() const override
Clone method for polymorphic behavior.
Definition ConZono.hpp:67
ConZono()
Default constructor for ConZono class.
Definition ConZono.hpp:42
ConZono(const Eigen::SparseMatrix< zono_float > &G, const Eigen::Vector< zono_float, -1 > &c, const Eigen::SparseMatrix< zono_float > &A, const Eigen::Vector< zono_float, -1 > &b, const bool zero_one_form=false)
ConZono constructor.
Definition ConZono.hpp:53
void convert_form() override
Converts the set representation between -1-1 and 0-1 forms.
Definition ConZono.hpp:179
OptSolution qp_opt(const Eigen::SparseMatrix< zono_float > &P, const Eigen::Vector< zono_float, -1 > &q, zono_float c, const Eigen::SparseMatrix< zono_float > &A, const Eigen::Vector< zono_float, -1 > &b, const OptSettings &settings=OptSettings(), OptSolution *solution=nullptr) const
Definition ConZono.hpp:333
Box do_bounding_box(const OptSettings &settings, OptSolution *) override
Definition ConZono.hpp:356
bool do_contains_point(const Eigen::Vector< zono_float, -1 > &x, const OptSettings &settings, OptSolution *solution) const override
Definition ConZono.hpp:308
~ConZono() override=default
bool do_is_empty(const OptSettings &settings, OptSolution *solution) const override
Definition ConZono.hpp:267
std::string print() const override
Returns set information as a string.
Definition ConZono.hpp:204
virtual std::unique_ptr< Zono > to_zono_approx() const
Compute outer approximation of constrained zonotope as zonotope using SVD.
Definition PolymorphicFunctions.hpp:1957
Eigen::Vector< zono_float, -1 > do_optimize_over(const Eigen::SparseMatrix< zono_float > &P, const Eigen::Vector< zono_float, -1 > &q, zono_float c, const OptSettings &settings, OptSolution *solution) const override
Definition ConZono.hpp:219
zono_float do_support(const Eigen::Vector< zono_float, -1 > &d, const OptSettings &settings, OptSolution *solution) override
Definition ConZono.hpp:285
Eigen::Vector< zono_float, -1 > do_project_point(const Eigen::Vector< zono_float, -1 > &x, const OptSettings &settings, OptSolution *solution) const override
Definition ConZono.hpp:244
Hybrid zonotope class.
Definition HybZono.hpp:44
int nC
number of constraints
Definition HybZono.hpp:482
int n
set dimension
Definition HybZono.hpp:470
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
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
#define zono_float
Defines the floating-point type used in ZonoOpt.
Definition ZonoOpt.hpp:43
std::unique_ptr< ConZono > vrep_2_conzono(const Eigen::Matrix< zono_float, -1, -1 > &Vpoly)
Builds a constrained zonotope from a vertex representation polytope.
Definition PolymorphicFunctions.hpp:1547
Interval class.
Definition Intervals.hpp:372
Settings for optimization routines in ZonoOpt library.
Definition SolverDataStructures.hpp:26
Solution data structure for optimization routines in ZonoOpt library.
Definition SolverDataStructures.hpp:153
Eigen::Vector< zono_float, -1 > z
solution vector
Definition SolverDataStructures.hpp:157