1212
1313#include < iostream>
1414
15+ #include " ROL_AugmentedLagrangianObjective2.hpp"
16+ #include " ROL_AugmentedLagrangianPenalty.hpp"
17+ #include " ROL_IdentityOperator.hpp"
18+ #include " ROL_PartitionedVector.hpp"
19+ #include " ROL_PolyhedralProjection.hpp"
20+ #include " ROL_Projection_Partitioned.hpp"
21+ #include " ROL_ZeroProjection.hpp"
22+
1523namespace ROL {
1624
1725template <typename Real>
@@ -71,8 +79,8 @@ void Problem<Real>::addConstraint( std::string name,
7179 it = INPUT_linear_con_.find (name);
7280 ROL_TEST_FOR_EXCEPTION (it != INPUT_linear_con_.end (),std::invalid_argument,
7381 " >>> ROL::Problem: Constraint names must be distinct!" );
74- it = INPUT_proj_.find (name);
75- ROL_TEST_FOR_EXCEPTION (it != INPUT_proj_.end (),std::invalid_argument,
82+ auto itp = INPUT_proj_.find (name);
83+ ROL_TEST_FOR_EXCEPTION (itp != INPUT_proj_.end (),std::invalid_argument,
7684 " >>> ROL::Problem: Constraint names must be distinct!" );
7785
7886 INPUT_con_.insert ({name,ConstraintData<Real>(econ,emul,eres)});
@@ -98,8 +106,8 @@ void Problem<Real>::addConstraint( std::string name,
98106 it = INPUT_linear_con_.find (name);
99107 ROL_TEST_FOR_EXCEPTION (it != INPUT_linear_con_.end (),std::invalid_argument,
100108 " >>> ROL::Problem: Constraint names must be distinct!" );
101- it = INPUT_proj_.find (name);
102- ROL_TEST_FOR_EXCEPTION (it != INPUT_proj_.end (),std::invalid_argument,
109+ auto itp = INPUT_proj_.find (name);
110+ ROL_TEST_FOR_EXCEPTION (itp != INPUT_proj_.end (),std::invalid_argument,
103111 " >>> ROL::Problem: Constraint names must be distinct!" );
104112
105113 INPUT_con_.insert ({name,ConstraintData<Real>(icon,imul,ires,ibnd)});
@@ -125,8 +133,8 @@ void Problem<Real>::addConstraint( std::string name,
125133 it = INPUT_linear_con_.find (name);
126134 ROL_TEST_FOR_EXCEPTION (it != INPUT_linear_con_.end (),std::invalid_argument,
127135 " >>> ROL::Problem: Constraint names must be distinct!" );
128- it = INPUT_proj_.find (name);
129- ROL_TEST_FOR_EXCEPTION (it != INPUT_proj_.end (),std::invalid_argument,
136+ auto itp = INPUT_proj_.find (name);
137+ ROL_TEST_FOR_EXCEPTION (itp != INPUT_proj_.end (),std::invalid_argument,
130138 " >>> ROL::Problem: Constraint names must be distinct!" );
131139
132140 if (proj == nullPtr) {
@@ -152,9 +160,9 @@ void Problem<Real>::removeConstraint(std::string name) {
152160 }
153161 if (cnt_econ_==0 ) hasEquality_ = false ;
154162 if (cnt_icon_==0 ) hasInequality_ = false ;
155- it = INPUT_proj_.find (name);
156- if (itc !=INPUT_proj_.end ()) {
157- INPUT_proj_.erase (it );
163+ auto itp = INPUT_proj_.find (name);
164+ if (itp !=INPUT_proj_.end ()) {
165+ INPUT_proj_.erase (itp );
158166 }
159167}
160168
@@ -175,8 +183,8 @@ void Problem<Real>::addLinearConstraint( std::string name,
175183 it = INPUT_linear_con_.find (name);
176184 ROL_TEST_FOR_EXCEPTION (it != INPUT_linear_con_.end (),std::invalid_argument,
177185 " >>> ROL::Problem: Constraint names must be distinct!" );
178- it = INPUT_proj_.find (name);
179- ROL_TEST_FOR_EXCEPTION (it != INPUT_proj_.end (),std::invalid_argument,
186+ auto itp = INPUT_proj_.find (name);
187+ ROL_TEST_FOR_EXCEPTION (itp != INPUT_proj_.end (),std::invalid_argument,
180188 " >>> ROL::Problem: Constraint names must be distinct!" );
181189
182190 INPUT_linear_con_.insert ({name,ConstraintData<Real>(linear_econ,linear_emul,linear_eres)});
@@ -202,8 +210,8 @@ void Problem<Real>::addLinearConstraint( std::string name,
202210 it = INPUT_linear_con_.find (name);
203211 ROL_TEST_FOR_EXCEPTION (it != INPUT_linear_con_.end (),std::invalid_argument,
204212 " >>> ROL::Problem: Constraint names must be distinct!" );
205- it = INPUT_proj_.find (name);
206- ROL_TEST_FOR_EXCEPTION (it != INPUT_proj_.end (),std::invalid_argument,
213+ auto itp = INPUT_proj_.find (name);
214+ ROL_TEST_FOR_EXCEPTION (itp != INPUT_proj_.end (),std::invalid_argument,
207215 " >>> ROL::Problem: Constraint names must be distinct!" );
208216
209217 INPUT_linear_con_.insert ({name,ConstraintData<Real>(linear_icon,linear_imul,linear_ires,linear_ibnd)});
@@ -253,8 +261,8 @@ void Problem<Real>::removeProximableObjective() {
253261}
254262
255263template <typename Real>
256- void addAugmentedLagrangianGroup (std::string name,
257- const std::vector<std::string> &con_names) {
264+ void Problem<Real>:: addAugmentedLagrangianGroup(std::string name,
265+ const std::vector<std::string> &con_names) {
258266 ROL_TEST_FOR_EXCEPTION (isFinalized_,std::invalid_argument,
259267 " >>> ROL::Problem: Cannot add augmented Lagrangian group after problem is finalized!" );
260268 bool isFound;
@@ -272,7 +280,7 @@ void addAugmentedLagrangianGroup(std::string name,
272280}
273281
274282template <typename Real>
275- void removeAugmentedLagrangianGroup (std::string name) {
283+ void Problem<Real>:: removeAugmentedLagrangianGroup(std::string name) {
276284 ROL_TEST_FOR_EXCEPTION (isFinalized_,std::invalid_argument,
277285 " >>> ROL::Problem: Cannot remove augmented Lagrangian group after problem is finalized!" );
278286 auto it = al_groups_.find (name);
@@ -286,7 +294,7 @@ void removeAugmentedLagrangianGroup(std::string name) {
286294}
287295
288296template <typename Real>
289- Ptr<Problem<Real>> getAugmentedLagrangianSubproblem () {
297+ Ptr<Problem<Real>> Problem<Real>:: getAugmentedLagrangianSubproblem() {
290298
291299 ROL_TEST_FOR_EXCEPTION (isFinalized_,std::invalid_argument,
292300 " >>> ROL::Problem: Cannot build augmented Lagrangian subproblem after problem is finalized!" );
@@ -298,32 +306,32 @@ Ptr<Problem<Real>> getAugmentedLagrangianSubproblem() {
298306
299307 Ptr<Projection<Real>> projection;
300308
301- auto makePenalty[&] (const ConstraintData<Real> &constraint_data,
302- const Projection<Real> &projection)
303- -> Ptr<AugmentedLagrangianPenalty<Real>> {
304- Ptr<AugmentedLagrangianPenalty<Real> penalty = makePtr<AugmentedLagrangianPenalty<Real>>(
305- constraint_data.constraint ,
306- projection,
307- Real (1.0 ),
308- *INPUT_xdual_,
309- *constraint_data.residual ,
310- constraint_data.residual ->dual (),
311- 0 );
309+ auto makePenalty = [&] (const ConstraintData<Real> &constraint_data,
310+ const Ptr< Projection<Real>> &projection)
311+ -> Ptr<AugmentedLagrangianPenalty<Real>> {
312+ Ptr<AugmentedLagrangianPenalty<Real>> penalty = makePtr<AugmentedLagrangianPenalty<Real>>(
313+ constraint_data.constraint ,
314+ projection,
315+ Real (1.0 ),
316+ *INPUT_xdual_,
317+ *constraint_data.residual ,
318+ constraint_data.residual ->dual (),
319+ 0 );
312320 penalty->setMultiplier (*constraint_data.multiplier );
313321 return penalty;
314- }
322+ };
315323
316- Ptr<AugmentedLagrangianPenalty<Real>> penalty
317- std::vector<Ptr<AugmentedLagrangianPenalty<Real>> penalties;
324+ Ptr<AugmentedLagrangianPenalty<Real>> penalty;
325+ std::vector<Ptr<AugmentedLagrangianPenalty<Real>>> penalties;
318326
319327 // ========================================================================
320328 // STEP 1: Process user-defined groups.
321329 // ========================================================================
322330
323- std::vector<Ptr<Constraint<Real>> constraints;
324- std::vector<Ptr<Projection<Real>> projections;
325- std::vector<Ptr<Vector<Real>> con_vectors;
326- std::vector<Ptr<Vector<Real>> mul_vectors;
331+ std::vector<Ptr<Constraint<Real>>> constraints;
332+ std::vector<Ptr<Projection<Real>>> projections;
333+ std::vector<Ptr<Vector<Real>>> con_vectors;
334+ std::vector<Ptr<Vector<Real>>> mul_vectors;
327335
328336 Ptr<Constraint_Partitioned<Real>> partitioned_constraint;
329337 Ptr<Projection_Partitioned<Real>> partitioned_projection;
@@ -347,9 +355,9 @@ Ptr<Problem<Real>> getAugmentedLagrangianSubproblem() {
347355 con_vectors.push_back (constraint_data.residual );
348356 mul_vectors.push_back (constraint_data.multiplier );
349357 if (constraint_data.bounds != nullPtr)
350- projection = makePtr<PolyheralProjection <Real>>(constraint_data.bounds )
358+ projection = staticPtrCast<Projection<Real>>( makePtr<PolyhedralProjection <Real>>(constraint_data.bounds ));
351359 else
352- projection = makePtr<ZeroProjection<Real>>();
360+ projection = staticPtrCast<Projection<Real>>( makePtr<ZeroProjection<Real>>() );
353361 projections.push_back (projection);
354362 unprocessed_constraints.erase (constraint_name);
355363 }
@@ -359,7 +367,7 @@ Ptr<Problem<Real>> getAugmentedLagrangianSubproblem() {
359367 con_vectors.push_back (constraint_data.residual );
360368 mul_vectors.push_back (constraint_data.multiplier );
361369 if (constraint_data.bounds != nullPtr)
362- projection = makePtr<PolyheralProjection <Real>>(constraint_data.bounds );
370+ projection = makePtr<PolyhedralProjection <Real>>(constraint_data.bounds );
363371 else
364372 projection = makePtr<ZeroProjection<Real>>();
365373 projections.push_back (projection);
@@ -369,8 +377,8 @@ Ptr<Problem<Real>> getAugmentedLagrangianSubproblem() {
369377
370378 partitioned_constraint = makePtr<Constraint_Partitioned<Real>>(constraints);
371379 partitioned_projection = makePtr<Projection_Partitioned<Real>>(projections);
372- partitioned_con_vector = makePtr<ParitionedVector <Real>>(con_vectors);
373- partitioned_mul_vector = makePtr<ParitionedVector <Real>>(mul_vectors);
380+ partitioned_con_vector = makePtr<PartitionedVector <Real>>(con_vectors);
381+ partitioned_mul_vector = makePtr<PartitionedVector <Real>>(mul_vectors);
374382 ConstraintData<Real> constraint_data (partitioned_constraint,
375383 partitioned_mul_vector,
376384 partitioned_con_vector);
@@ -382,7 +390,7 @@ Ptr<Problem<Real>> getAugmentedLagrangianSubproblem() {
382390 // STEP 2: Process remaining constraints.
383391 // ========================================================================
384392
385- Ptr<Problem<Real>> subproblem = makePtr<Problem<Real>>(INPUT_obj ,INPUT_xprim_,INPUT_xdual );
393+ Ptr<Problem<Real>> subproblem = makePtr<Problem<Real>>(INPUT_obj_ ,INPUT_xprim_,INPUT_xdual_ );
386394 bool isSubproblemTypeE = false ;
387395
388396 for (const auto & constraint_name : unprocessed_constraints) {
@@ -394,7 +402,7 @@ Ptr<Problem<Real>> getAugmentedLagrangianSubproblem() {
394402 else if (INPUT_con_.count (constraint_name)) {
395403 auto & constraint_data = INPUT_con_.at (constraint_name);
396404 if (constraint_data.bounds != nullPtr) {
397- projection = makePtr<PolyheralProjection <Real>>(constraint_data.bounds );
405+ projection = staticPtrCast<Projection<Real>>( makePtr<PolyhedralProjection <Real>>(constraint_data.bounds ) );
398406 penalty = makePenalty (constraint_data,projection);
399407 penalties.push_back (penalty);
400408 }
@@ -409,7 +417,7 @@ Ptr<Problem<Real>> getAugmentedLagrangianSubproblem() {
409417 else if (INPUT_linear_con_.count (constraint_name)) {
410418 auto & constraint_data = INPUT_linear_con_.at (constraint_name);
411419 if (constraint_data.bounds != nullPtr) {
412- projection = makePtr<PolyheralProjection <Real>>(constraint_data.bounds );
420+ projection = makePtr<PolyhedralProjection <Real>>(constraint_data.bounds );
413421 penalty = makePenalty (constraint_data,projection);
414422 penalties.push_back (penalty);
415423 }
@@ -428,8 +436,8 @@ Ptr<Problem<Real>> getAugmentedLagrangianSubproblem() {
428436
429437 if (hasBounds_) {
430438 if (isSubproblemTypeE) {
431- projection = makePtr<PolyheralProjection <Real>>(INPUT_bnd_);
432- Ptr<Vector<Real>> b = INPUT_xprim_. clone ();
439+ projection = staticPtrCast<Projection<Real>>( makePtr<PolyhedralProjection <Real>>(INPUT_bnd_) );
440+ Ptr<Vector<Real>> b = INPUT_xprim_-> clone ();
433441 b->zero ();
434442 Ptr<LinearOperator<Real>> A = makePtr<IdentityOperator<Real>>();
435443 Ptr<Constraint<Real>> constraint = makePtr<LinearConstraint<Real>>(A,b);
@@ -440,8 +448,7 @@ Ptr<Problem<Real>> getAugmentedLagrangianSubproblem() {
440448 else subproblem->addBoundConstraint (INPUT_bnd_);
441449 }
442450
443- subproblem.INPUT_obj_ = makePtr<AugmentedLagrangianObjective2<Real>>(
444- subproblem.INPUT_obj_ ,penalties,*INPUT_xdual_,false );
451+ subproblem->INPUT_obj_ = makePtr<AugmentedLagrangianObjective2<Real>>(subproblem->INPUT_obj_ ,penalties,*INPUT_xdual_,false );
445452
446453 return subproblem;
447454}
0 commit comments