10 #ifndef ROL_NEW_CONSTRAINT_MANAGER_DEF_H
11 #define ROL_NEW_CONSTRAINT_MANAGER_DEF_H
15 template<
typename Real>
21 Real tol = std::sqrt(ROL_EPSILON<Real>());
22 con->value(*s,*x,tol);
26 template<
typename Real>
32 Ptr<BoundConstraint<Real>> bnd0;
33 if ( bnd == nullPtr ) {
34 bnd0 = makePtr<BoundConstraint<Real>>(*xprim);
41 psvec_.clear(); psvec_.push_back(xprim);
42 dsvec_.clear(); dsvec_.push_back(xdual);
43 sbnd_.clear(); sbnd_.push_back(bnd0);
44 cvec_.clear(); lvec_.clear(); rvec_.clear();
45 isInequality_.clear();
46 int cnt = 1, cnt_con = 0;
48 hasInequality_ =
false;
49 for (
auto it = input_con.begin(); it != input_con.end(); ++it) {
50 Ptr<Constraint<Real>> con = it->second.constraint;
51 Ptr<Vector<Real>> l = it->second.multiplier;
52 Ptr<Vector<Real>> r = it->second.residual;
53 Ptr<BoundConstraint<Real>> cbnd = it->second.bounds;
55 if ( con->isActivated() ) {
57 isInequality_.push_back(
false);
62 if (cbnd != nullPtr) {
63 if ( cbnd->isActivated() ) {
65 isInequality_.back() =
true;
67 psvec_.push_back(r->clone());
68 dsvec_.push_back(l->clone());
69 initializeSlackVariable(con,cbnd,psvec_[cnt],xprim);
71 sbnd_.push_back(cbnd);
74 hasInequality_ =
true;
84 if ( cnt_con > 1 || hasInequality_ ) {
85 con_ = makePtr<Constraint_Partitioned<Real>>(cvec_,isInequality_);
86 mul_ = makePtr<PartitionedVector<Real>>(lvec_);
87 res_ = makePtr<PartitionedVector<Real>>(rvec_);
101 if ( hasInequality_ ) {
102 xprim_ = makePtr<PartitionedVector<Real>>(psvec_);
103 xdual_ = makePtr<PartitionedVector<Real>>(dsvec_);
104 bnd_ = makePtr<BoundConstraint_Partitioned<Real>>(sbnd_,psvec_);
113 template<
typename Real>
120 Ptr<BoundConstraint<Real>> bnd0;
121 if ( bnd == nullPtr ) {
122 bnd0 = makePtr<BoundConstraint<Real>>(*xprim);
129 psvec_.clear(); psvec_.push_back(xprim);
130 dsvec_.clear(); dsvec_.push_back(xdual);
131 sbnd_.clear(); sbnd_.push_back(bnd0);
132 cvec_.clear(); lvec_.clear(); rvec_.clear();
133 lcvec_.clear(); llvec_.clear(); lrvec_.clear();
134 isInequality_.clear(); isLinearInequality_.clear();
135 int cnt = 1, cnt_con = 0, cnt_lcon = 0;
137 hasInequality_ =
false;
138 for (
auto it = input_con.begin(); it != input_con.end(); ++it) {
139 Ptr<Constraint<Real>> con = it->second.constraint;
140 Ptr<Vector<Real>> l = it->second.multiplier;
141 Ptr<Vector<Real>> r = it->second.residual;
142 Ptr<BoundConstraint<Real>> cbnd = it->second.bounds;
143 if (con != nullPtr) {
144 if ( con->isActivated() ) {
146 isInequality_.push_back(
false);
148 cvec_.push_back(con);
151 if (cbnd != nullPtr) {
152 if ( cbnd->isActivated() ) {
154 isInequality_.back() =
true;
156 psvec_.push_back(r->clone());
157 dsvec_.push_back(l->clone());
158 initializeSlackVariable(con,cbnd,psvec_[cnt],xprim);
160 sbnd_.push_back(cbnd);
163 hasInequality_ =
true;
171 for (
auto it = input_lcon.begin(); it != input_lcon.end(); ++it) {
172 Ptr<Constraint<Real>> con = it->second.constraint;
173 Ptr<Vector<Real>> l = it->second.multiplier;
174 Ptr<Vector<Real>> r = it->second.residual;
175 Ptr<BoundConstraint<Real>> cbnd = it->second.bounds;
176 if (con != nullPtr) {
177 if ( con->isActivated() ) {
179 isLinearInequality_.push_back(
false);
181 lcvec_.push_back(con);
184 if (cbnd != nullPtr) {
185 if ( cbnd->isActivated() ) {
187 isLinearInequality_.back() =
true;
189 psvec_.push_back(r->clone());
190 dsvec_.push_back(l->clone());
191 initializeSlackVariable(con,cbnd,psvec_[cnt],xprim);
193 sbnd_.push_back(cbnd);
196 hasInequality_ =
true;
206 if ( cnt_con > 1 || hasInequality_ ) {
207 con_ = makePtr<Constraint_Partitioned<Real>>(cvec_,isInequality_);
208 mul_ = makePtr<PartitionedVector<Real>>(lvec_);
209 res_ = makePtr<PartitionedVector<Real>>(rvec_);
216 if ( cnt_lcon > 1 || hasInequality_ ) {
217 linear_con_ = makePtr<Constraint_Partitioned<Real>>(lcvec_,isLinearInequality_,cnt_con);
218 linear_mul_ = makePtr<PartitionedVector<Real>>(llvec_);
219 linear_res_ = makePtr<PartitionedVector<Real>>(lrvec_);
222 linear_con_ = lcvec_[0];
223 linear_mul_ = llvec_[0];
224 linear_res_ = lrvec_[0];
231 linear_con_ = nullPtr;
232 linear_mul_ = nullPtr;
233 linear_res_ = nullPtr;
236 if ( hasInequality_ ) {
237 xprim_ = makePtr<PartitionedVector<Real>>(psvec_);
238 xdual_ = makePtr<PartitionedVector<Real>>(dsvec_);
239 bnd_ = makePtr<BoundConstraint_Partitioned<Real>>(sbnd_,psvec_);
248 template<
typename Real>
253 : isNull_(true), hasInequality_(false) {
257 template<
typename Real>
263 : isNull_(true), hasInequality_(false) {
267 template<
typename Real>
272 template<
typename Real>
277 template<
typename Real>
282 template<
typename Real>
287 template<
typename Real>
292 template<
typename Real>
297 template<
typename Real>
302 template<
typename Real>
307 template<
typename Real>
312 template<
typename Real>
317 template<
typename Real>
319 return hasInequality_;
322 template<
typename Real>
324 if (hasInequality_) {
325 int size =
static_cast<int>(cvec_.size());
327 for (
int i = 0; i < size; ++i) {
328 if (isInequality_[i]) {
330 initializeSlackVariable(cvec_[i],sbnd_[cnt],psvec_[cnt],psvec_[0]);
334 size =
static_cast<int>(lcvec_.size());
335 for (
int i = 0; i < size; ++i) {
336 if (isLinearInequality_[i]) {
338 initializeSlackVariable(lcvec_[i],sbnd_[cnt],psvec_[cnt],psvec_[0]);
void resetSlackVariables(void)
const Ptr< Constraint< Real > > getLinearConstraint(void) const
NewConstraintManager(const std::unordered_map< std::string, ConstraintData< Real >> &con, const Ptr< Vector< Real >> &xprim, const Ptr< Vector< Real >> &xdual, const Ptr< BoundConstraint< Real >> &bnd=nullPtr)
Defines the linear algebra or vector space interface.
void initializeSlackVariable(const Ptr< Constraint< Real >> &con, const Ptr< BoundConstraint< Real >> &cbnd, const Ptr< Vector< Real >> &s, const Ptr< Vector< Real >> &x) const
const Ptr< Vector< Real > > getMultiplier(void) const
const Ptr< Vector< Real > > getOptVector(void) const
const Ptr< Vector< Real > > getLinearMultiplier(void) const
bool hasInequality(void) const
void initialize(const std::unordered_map< std::string, ConstraintData< Real >> &input_con, const Ptr< Vector< Real >> &xprim, const Ptr< Vector< Real >> &xdual, const Ptr< BoundConstraint< Real >> &bnd)
const Ptr< Vector< Real > > getDualOptVector(void) const
const Ptr< Vector< Real > > getResidual(void) const
Provides the interface to apply upper and lower bound constraints.
const Ptr< Vector< Real > > getLinearResidual(void) const
const Ptr< Constraint< Real > > getConstraint(void) const
const Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Defines the general constraint operator interface.