10 #ifndef ROL_RISK_BOUND_CONSTRAINT_H
11 #define ROL_RISK_BOUND_CONSTRAINT_H
22 Ptr<BoundConstraint<Real>>
bc_;
38 mutable Ptr<RiskVector<Real>>
lo_,
hi_;
42 std::vector<Real> &lower,
43 std::vector<Real> &upper,
46 lower.clear(); upper.clear();
48 std::string optType = parlist.sublist(
"SOL").get(
"Type",
"Risk Averse");
49 if ( optType ==
"Risk Averse" ||
50 optType ==
"Deviation" ||
51 optType ==
"Regret" ||
53 optType ==
"Probability" ) {
55 RandVarFunctionalInfo<Real>(parlist,name,nStat,lower,upper,activated);
56 augmented = (nStat > 0) ?
true :
false;
58 else if ( optType ==
"Risk Neutral" || optType ==
"Mean Value" ) {
64 ROL_TEST_FOR_EXCEPTION(
true,std::invalid_argument,
65 ">>> (ROL::RiskBoundConstraint): Invalid stochastic optimization type!" << optType);
71 if (parlist != nullPtr) {
95 int size = parlist.size();
101 bool activated =
false;
102 for (
int i = 0; i < size; ++i) {
103 if ( parlist[i] != nullPtr ) {
104 bool augmented =
false;
106 std::vector<Real> lo, up;
146 if ( !activatedObj ) {
147 if ( bc == nullPtr || (bc != nullPtr && !bc->isActivated()) ) {
163 if ( !activatedCon ) {
164 if ( bc == nullPtr || (bc != nullPtr && !bc->isActivated()) ) {
172 std::vector<Ptr<ParameterList>> &parlistCon,
182 if ( !activatedObj && !activatedCon ) {
183 if ( bc == nullPtr || (bc != nullPtr && !bc->isActivated()) ) {
204 Ptr<StdVector<Real>> xs =
dynamic_cast<RiskVector<Real>&
>(x).getStatisticVector(0);
209 for (
int i = 0; i < size; ++i) {
211 Ptr<StdVector<Real>> xs =
dynamic_cast<RiskVector<Real>&
>(x).getStatisticVector(1,i);
216 if (
bc_ != nullPtr &&
bc_->isActivated() ) {
224 Ptr<StdVector<Real>> xs =
dynamic_cast<RiskVector<Real>&
>(x).getStatisticVector(0);
229 for (
int i = 0; i < size; ++i) {
231 Ptr<StdVector<Real>> xs =
dynamic_cast<RiskVector<Real>&
>(x).getStatisticVector(1,i);
236 if (
bc_ != nullPtr &&
bc_->isActivated() ) {
238 bc_->projectInterior(*xvec);
244 Ptr<StdVector<Real>> vs =
dynamic_cast<RiskVector<Real>&
>(v).getStatisticVector(0);
245 Ptr<const StdVector<Real>> xs =
dynamic_cast<const RiskVector<Real>&
>(x).getStatisticVector(0);
250 for (
int i = 0; i < size; ++i) {
252 Ptr<StdVector<Real>> vs =
dynamic_cast<RiskVector<Real>&
>(v).getStatisticVector(1,i);
253 Ptr<const StdVector<Real>> xs =
dynamic_cast<const RiskVector<Real>&
>(x).getStatisticVector(1,i);
258 if (
bc_ != nullPtr &&
bc_->isActivated() ) {
260 Ptr<const Vector<Real>> xv =
dynamic_cast<const RiskVector<Real>&
>(x).getVector();
261 bc_->pruneUpperActive(*vv,*xv,eps);
267 Ptr<StdVector<Real>> vs =
dynamic_cast<RiskVector<Real>&
>(v).getStatisticVector(0);
268 Ptr<const StdVector<Real>> gs =
dynamic_cast<const RiskVector<Real>&
>(g).getStatisticVector(0);
269 Ptr<const StdVector<Real>> xs =
dynamic_cast<const RiskVector<Real>&
>(x).getStatisticVector(0);
270 statObj_bc_->pruneUpperActive(*vs,*gs,*xs,xeps,geps);
274 for (
int i = 0; i < size; ++i) {
276 Ptr<StdVector<Real>> vs =
dynamic_cast<RiskVector<Real>&
>(v).getStatisticVector(1,i);
277 Ptr<const StdVector<Real>> gs =
dynamic_cast<const RiskVector<Real>&
>(g).getStatisticVector(1,i);
278 Ptr<const StdVector<Real>> xs =
dynamic_cast<const RiskVector<Real>&
>(x).getStatisticVector(1,i);
279 statCon_bc_[i]->pruneUpperActive(*vs,*gs,*xs,xeps,geps);
283 if (
bc_ != nullPtr &&
bc_->isActivated() ) {
285 Ptr<const Vector<Real>> gv =
dynamic_cast<const RiskVector<Real>&
>(g).getVector();
286 Ptr<const Vector<Real>> xv =
dynamic_cast<const RiskVector<Real>&
>(x).getVector();
287 bc_->pruneUpperActive(*vv,*gv,*xv,xeps,geps);
293 Ptr<StdVector<Real>> vs =
dynamic_cast<RiskVector<Real>&
>(v).getStatisticVector(0);
294 Ptr<const StdVector<Real>> xs =
dynamic_cast<const RiskVector<Real>&
>(x).getStatisticVector(0);
299 for (
int i = 0; i < size; ++i) {
301 Ptr<StdVector<Real>> vs =
dynamic_cast<RiskVector<Real>&
>(v).getStatisticVector(1,i);
302 Ptr<const StdVector<Real>> xs =
dynamic_cast<const RiskVector<Real>&
>(x).getStatisticVector(1,i);
307 if (
bc_ != nullPtr &&
bc_->isActivated() ) {
309 Ptr<const Vector<Real>> xv =
dynamic_cast<const RiskVector<Real>&
>(x).getVector();
310 bc_->pruneLowerActive(*vv,*xv,eps);
316 Ptr<StdVector<Real>> vs =
dynamic_cast<RiskVector<Real>&
>(v).getStatisticVector(0);
317 Ptr<const StdVector<Real>> gs =
dynamic_cast<const RiskVector<Real>&
>(g).getStatisticVector(0);
318 Ptr<const StdVector<Real>> xs =
dynamic_cast<const RiskVector<Real>&
>(x).getStatisticVector(0);
319 statObj_bc_->pruneLowerActive(*vs,*gs,*xs,xeps,geps);
323 for (
int i = 0; i < size; ++i) {
325 Ptr<StdVector<Real>> vs =
dynamic_cast<RiskVector<Real>&
>(v).getStatisticVector(1,i);
326 Ptr<const StdVector<Real>> gs =
dynamic_cast<const RiskVector<Real>&
>(g).getStatisticVector(1,i);
327 Ptr<const StdVector<Real>> xs =
dynamic_cast<const RiskVector<Real>&
>(x).getStatisticVector(1,i);
328 statCon_bc_[i]->pruneLowerActive(*vs,*gs,*xs,xeps,geps);
332 if (
bc_ != nullPtr &&
bc_->isActivated() ) {
334 Ptr<const Vector<Real>> gv =
dynamic_cast<const RiskVector<Real>&
>(g).getVector();
335 Ptr<const Vector<Real>> xv =
dynamic_cast<const RiskVector<Real>&
>(x).getVector();
336 bc_->pruneLowerActive(*vv,*gv,*xv,xeps,geps);
342 const Ptr<const Vector<Real>> vlo =
bc_->getLowerBound();
343 Ptr<std::vector<Real>> lowerObj = makePtr<std::vector<Real>>(
lowerObj_);
345 std::vector<Ptr<std::vector<Real>>> lowerCon(size);
346 for (
int i = 0; i < size; ++i) {
347 lowerCon[i] = makePtr<std::vector<Real>>(
lowerCon_[i]);
349 lo_ = makePtr<RiskVector<Real>>(constPtrCast<Vector<Real>>(vlo),
358 const Ptr<const Vector<Real>> vhi =
bc_->getUpperBound();
359 Ptr<std::vector<Real>> upperObj = makePtr<std::vector<Real>>(
upperObj_);
361 std::vector<Ptr<std::vector<Real>>> upperCon(size);
362 for (
int i = 0; i < size; ++i) {
363 upperCon[i] = makePtr<std::vector<Real>>(
upperCon_[i]);
365 hi_ = makePtr<RiskVector<Real>>(constPtrCast<Vector<Real>>(vhi),
373 bool flagstat =
true, flagcon =
true, flagvec =
true;
375 Ptr<const StdVector<Real>> vs =
dynamic_cast<const RiskVector<Real>&
>(v).getStatisticVector(0);
380 for (
int i = 0; i < size; ++i) {
382 Ptr<const StdVector<Real>> vs =
dynamic_cast<const RiskVector<Real>&
>(v).getStatisticVector(1,i);
383 flagcon = (!
statCon_bc_[i]->isFeasible(*vs) ?
false : flagcon);
387 if (
bc_ != nullPtr &&
bc_->isActivated() ) {
388 Ptr<const Vector<Real>> vv =
dynamic_cast<const RiskVector<Real>&
>(v).getVector();
389 flagvec =
bc_->isFeasible(*vv);
391 return (flagstat && flagcon && flagvec);
396 Ptr<StdVector<Real>> dvs =
dynamic_cast<RiskVector<Real>&
>(dv).getStatisticVector(0);
397 Ptr<const StdVector<Real>> vs =
dynamic_cast<const RiskVector<Real>&
>(v).getStatisticVector(0);
398 Ptr<const StdVector<Real>> xs =
dynamic_cast<const RiskVector<Real>&
>(x).getStatisticVector(0);
399 Ptr<const StdVector<Real>> gs =
dynamic_cast<const RiskVector<Real>&
>(g).getStatisticVector(0);
400 statObj_bc_->applyInverseScalingFunction(*dvs,*vs,*xs,*gs);
404 for (
int i = 0; i < size; ++i) {
406 Ptr<StdVector<Real>> dvs =
dynamic_cast<RiskVector<Real>&
>(dv).getStatisticVector(1,i);
407 Ptr<const StdVector<Real>> vs =
dynamic_cast<const RiskVector<Real>&
>(v).getStatisticVector(1,i);
408 Ptr<const StdVector<Real>> xs =
dynamic_cast<const RiskVector<Real>&
>(x).getStatisticVector(1,i);
409 Ptr<const StdVector<Real>> gs =
dynamic_cast<const RiskVector<Real>&
>(g).getStatisticVector(1,i);
410 statCon_bc_[i]->applyInverseScalingFunction(*dvs,*vs,*xs,*gs);
414 if (
bc_ != nullPtr &&
bc_->isActivated() ) {
416 Ptr<const Vector<Real>> vs =
dynamic_cast<const RiskVector<Real>&
>(v).getVector();
417 Ptr<const Vector<Real>> xs =
dynamic_cast<const RiskVector<Real>&
>(x).getVector();
418 Ptr<const Vector<Real>> gs =
dynamic_cast<const RiskVector<Real>&
>(g).getVector();
419 bc_->applyInverseScalingFunction(*dvs,*vs,*xs,*gs);
425 Ptr<StdVector<Real>> dvs =
dynamic_cast<RiskVector<Real>&
>(dv).getStatisticVector(0);
426 Ptr<const StdVector<Real>> vs =
dynamic_cast<const RiskVector<Real>&
>(v).getStatisticVector(0);
427 Ptr<const StdVector<Real>> xs =
dynamic_cast<const RiskVector<Real>&
>(x).getStatisticVector(0);
428 Ptr<const StdVector<Real>> gs =
dynamic_cast<const RiskVector<Real>&
>(g).getStatisticVector(0);
429 statObj_bc_->applyScalingFunctionJacobian(*dvs,*vs,*xs,*gs);
433 for (
int i = 0; i < size; ++i) {
435 Ptr<StdVector<Real>> dvs =
dynamic_cast<RiskVector<Real>&
>(dv).getStatisticVector(1,i);
436 Ptr<const StdVector<Real>> vs =
dynamic_cast<const RiskVector<Real>&
>(v).getStatisticVector(1,i);
437 Ptr<const StdVector<Real>> xs =
dynamic_cast<const RiskVector<Real>&
>(x).getStatisticVector(1,i);
438 Ptr<const StdVector<Real>> gs =
dynamic_cast<const RiskVector<Real>&
>(g).getStatisticVector(1,i);
439 statCon_bc_[i]->applyScalingFunctionJacobian(*dvs,*vs,*xs,*gs);
443 if (
bc_ != nullPtr &&
bc_->isActivated() ) {
445 Ptr<const Vector<Real>> vs =
dynamic_cast<const RiskVector<Real>&
>(v).getVector();
446 Ptr<const Vector<Real>> xs =
dynamic_cast<const RiskVector<Real>&
>(x).getVector();
447 Ptr<const Vector<Real>> gs =
dynamic_cast<const RiskVector<Real>&
>(g).getVector();
448 bc_->applyScalingFunctionJacobian(*dvs,*vs,*xs,*gs);
Contains definitions for std::vector bound constraints.
std::vector< bool > activatedCon_
RiskBoundConstraint(const Ptr< BoundConstraint< Real >> &bc)
RiskBoundConstraint(Ptr< ParameterList > &parlistObj, std::vector< Ptr< ParameterList >> &parlistCon, const Ptr< BoundConstraint< Real >> &bc=nullPtr)
void activate(void)
Turn on bounds.
void pruneUpperActive(Vector< Real > &v, const Vector< Real > &g, const Vector< Real > &x, Real xeps=Real(0), Real geps=Real(0))
Set variables to zero if they correspond to the upper -binding set.
Contains definitions of custom data types in ROL.
std::vector< Real > lowerObj_
Defines the linear algebra or vector space interface.
bool buildObjStatBnd(Ptr< ParameterList > &parlist)
void pruneLowerActive(Vector< Real > &v, const Vector< Real > &g, const Vector< Real > &x, Real xeps=Real(0), Real geps=Real(0))
Set variables to zero if they correspond to the -binding set.
std::vector< std::vector< Real > > lowerCon_
Ptr< RiskVector< Real > > lo_
RiskBoundConstraint(std::vector< Ptr< ParameterList >> &parlist, const Ptr< BoundConstraint< Real >> &bc=nullPtr)
void pruneLowerActive(Vector< Real > &v, const Vector< Real > &x, Real eps=Real(0))
Set variables to zero if they correspond to the lower -active set.
void applyScalingFunctionJacobian(Vector< Real > &dv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g) const
Apply scaling function Jacobian.
void setBoundInfo(ParameterList &parlist, int &nStat, std::vector< Real > &lower, std::vector< Real > &upper, bool &augmented, bool &activated)
void pruneUpperActive(Vector< Real > &v, const Vector< Real > &x, Real eps=Real(0))
Set variables to zero if they correspond to the upper -active set.
RiskBoundConstraint(Ptr< ParameterList > &parlist, const Ptr< BoundConstraint< Real >> &bc=nullPtr)
std::vector< int > nStatCon_
const Ptr< const Vector< Real > > getLowerBound(void) const
Return the ref count pointer to the lower bound vector.
std::vector< std::vector< Real > > upperCon_
bool isFeasible(const Vector< Real > &v)
Check if the vector, v, is feasible.
const Ptr< const Vector< Real > > getUpperBound(void) const
Return the ref count pointer to the upper bound vector.
Ptr< StdBoundConstraint< Real > > statObj_bc_
Provides the interface to apply upper and lower bound constraints.
bool buildConStatBnd(std::vector< Ptr< ParameterList >> &parlist)
std::vector< Real > upperObj_
void projectInterior(Vector< Real > &x)
Project optimization variables into the interior of the feasible set.
void applyInverseScalingFunction(Vector< Real > &dv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g) const
Apply inverse scaling function.
void deactivate(void)
Turn off bounds.
void project(Vector< Real > &x)
Project optimization variables onto the bounds.
Ptr< BoundConstraint< Real > > bc_
Ptr< RiskVector< Real > > hi_
std::vector< Ptr< StdBoundConstraint< Real > > > statCon_bc_