ROL
ROL_TypeG_Algorithm_Def.hpp
Go to the documentation of this file.
1// @HEADER
2// ************************************************************************
3//
4// Rapid Optimization Library (ROL) Package
5// Copyright (2014) Sandia Corporation
6//
7// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8// license for use of this work by or on behalf of the U.S. Government.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact lead developers:
38// Drew Kouri (dpkouri@sandia.gov) and
39// Denis Ridzal (dridzal@sandia.gov)
40//
41// ************************************************************************
42// @HEADER
43
44#ifndef ROL_TYPEG_ALGORITHM_DEF_H
45#define ROL_TYPEG_ALGORITHM_DEF_H
46
49//#include "ROL_ConstraintManager.hpp"
52
53namespace ROL {
54namespace TypeG {
55
56template<typename Real>
58 : status_(makePtr<CombinedStatusTest<Real>>()),
59 state_(makePtr<AlgorithmState<Real>>()),
60 proj_(nullPtr) {
61 status_->reset();
62 status_->add(makePtr<ConstraintStatusTest<Real>>());
63}
64
65template<typename Real>
67 const Vector<Real> &g,
68 const Vector<Real> &mul,
69 const Vector<Real> &c) {
70 if (state_->iterateVec == nullPtr) {
71 state_->iterateVec = x.clone();
72 }
73 state_->iterateVec->set(x);
74 if (state_->lagmultVec == nullPtr) {
75 state_->lagmultVec = mul.clone();
76 }
77 state_->lagmultVec->set(mul);
78 if (state_->stepVec == nullPtr) {
79 state_->stepVec = x.clone();
80 }
81 state_->stepVec->zero();
82 if (state_->gradientVec == nullPtr) {
83 state_->gradientVec = g.clone();
84 }
85 if (state_->constraintVec == nullPtr) {
86 state_->constraintVec = c.clone();
87 }
88 state_->constraintVec->zero();
89 state_->gradientVec->set(g);
90 if (state_->minIterVec == nullPtr) {
91 state_->minIterVec = x.clone();
92 }
93 state_->minIterVec->set(x);
94 state_->minIter = state_->iter;
95 state_->minValue = state_->value;
96}
97
98template<typename Real>
100 const bool combineStatus) {
101 if (!combineStatus) { // Do not combine status tests
102 status_->reset();
103 }
104 status_->add(status); // Add user-defined StatusTest
105}
106
107template<typename Real>
109 std::ostream &outStream ) {
110 if (problem.getProblemType() == TYPE_EB) {
111 proj_ = problem.getPolyhedralProjection();
112 run(*problem.getPrimalOptimizationVector(),
113 *problem.getDualOptimizationVector(),
114 *problem.getObjective(),
115 *problem.getBoundConstraint(),
116 *problem.getConstraint(),
117 *problem.getMultiplierVector(),
118 *problem.getResidualVector(),
119 outStream);
120 problem.finalizeIteration();
121 }
122 else {
123 throw Exception::NotImplemented(">>> ROL::Algorithm::run : Optimization problem is not Type G!");
124 }
125}
126
127template<typename Real>
129 Objective<Real> &obj,
131 Constraint<Real> &econ,
132 Vector<Real> &emul,
133 std::ostream &outStream ) {
134 Problem<Real> problem(makePtrFromRef(obj),
135 makePtrFromRef(x));
136 problem.addBoundConstraint(makePtrFromRef(bnd));
137 problem.addConstraint("EqualityConstraint",makePtrFromRef(econ),
138 makePtrFromRef(emul));
139 problem.finalize(false,false,outStream);
140 run(problem,outStream);
141 //run(x,x.dual(),obj,bnd,econ,emul,emul.dual(),outStream);
142}
143
144template<typename Real>
146 Objective<Real> &obj,
147 Constraint<Real> &icon,
148 Vector<Real> &imul,
150 std::ostream &outStream ) {
151 Problem<Real> problem(makePtrFromRef(obj),
152 makePtrFromRef(x));
153 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
154 makePtrFromRef(imul),makePtrFromRef(ibnd));
155 problem.finalize(false,false,outStream);
156 run(problem,outStream);
157 //run(x,x.dual(),obj,icon,imul,ibnd,imul.dual(),outStream);
158}
159
160template<typename Real>
162 Objective<Real> &obj,
164 Constraint<Real> &icon,
165 Vector<Real> &imul,
167 std::ostream &outStream ) {
168 Problem<Real> problem(makePtrFromRef(obj),
169 makePtrFromRef(x));
170 problem.addBoundConstraint(makePtrFromRef(bnd));
171 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
172 makePtrFromRef(imul),makePtrFromRef(ibnd));
173 problem.finalize(false,false,outStream);
174 run(problem,outStream);
175 //run(x,x.dual(),obj,bnd,icon,imul,ibnd,imul.dual(),outStream);
176}
177
178template<typename Real>
180 Objective<Real> &obj,
181 Constraint<Real> &econ,
182 Vector<Real> &emul,
183 Constraint<Real> &icon,
184 Vector<Real> &imul,
186 std::ostream &outStream ) {
187 Problem<Real> problem(makePtrFromRef(obj),
188 makePtrFromRef(x));
189 problem.addConstraint("EqualityConstraint",makePtrFromRef(econ),
190 makePtrFromRef(emul));
191 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
192 makePtrFromRef(imul),makePtrFromRef(ibnd));
193 problem.finalize(false,false,outStream);
194 run(problem,outStream);
195 //run(x,x.dual(),obj,econ,emul,emul.dual(),icon,imul,ibnd,imul.dual(),outStream);
196}
197
198template<typename Real>
200 Objective<Real> &obj,
202 Constraint<Real> &econ,
203 Vector<Real> &emul,
204 Constraint<Real> &icon,
205 Vector<Real> &imul,
207 std::ostream &outStream ) {
208 Problem<Real> problem(makePtrFromRef(obj),
209 makePtrFromRef(x));
210 problem.addBoundConstraint(makePtrFromRef(bnd));
211 problem.addConstraint("EqualityConstraint",makePtrFromRef(econ),
212 makePtrFromRef(emul));
213 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
214 makePtrFromRef(imul),makePtrFromRef(ibnd));
215 problem.finalize(false,false,outStream);
216 run(problem,outStream);
217 //run(x,x.dual(),obj,bnd,econ,emul,emul.dual(),icon,imul,ibnd,imul.dual(),outStream);
218}
219
220
221
222template<typename Real>
224 const Vector<Real> &g,
225 Objective<Real> &obj,
226 Constraint<Real> &icon,
227 Vector<Real> &imul,
229 const Vector<Real> &ires,
230 std::ostream &outStream ) {
231 Ptr<Vector<Real>> gp = g.clone(), irp = ires.clone();
232 Problem<Real> problem(makePtrFromRef(obj),
233 makePtrFromRef(x),gp);
234 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
235 makePtrFromRef(imul),makePtrFromRef(ibnd),irp,false);
236 problem.finalize(false,false,outStream);
237 run(problem,outStream);
238 //ConstraintManager<Real> cm(makePtrFromRef(icon),makePtrFromRef(imul),
239 // makePtrFromRef(ibnd),makePtrFromRef(x));
240 //Ptr<Constraint<Real>> econ = cm.getConstraint();
241 //Ptr<Vector<Real>> emul = cm.getMultiplier();
242 //Ptr<BoundConstraint<Real>> xbnd = cm.getBoundConstraint();
243 //Ptr<Vector<Real>> xvec = cm.getOptVector();
244 //Ptr<Objective<Real>> sobj = makePtr<SlacklessObjective<Real>>(makePtrFromRef(obj));
245 //Ptr<Vector<Real>> xdual = xvec->dual().clone();
246 //run(*xvec,*xdual,*sobj,*xbnd,*econ,*emul,emul->dual(),outStream);
247}
248
249template<typename Real>
251 const Vector<Real> &g,
252 Objective<Real> &obj,
254 Constraint<Real> &icon,
255 Vector<Real> &imul,
257 const Vector<Real> &ires,
258 std::ostream &outStream ) {
259 Ptr<Vector<Real>> gp = g.clone(), irp = ires.clone();
260 Problem<Real> problem(makePtrFromRef(obj),
261 makePtrFromRef(x),gp);
262 problem.addBoundConstraint(makePtrFromRef(bnd));
263 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
264 makePtrFromRef(imul),makePtrFromRef(ibnd),irp,false);
265 problem.finalize(false,false,outStream);
266 run(problem,outStream);
267 //ConstraintManager<Real> cm(makePtrFromRef(icon),makePtrFromRef(imul),
268 // makePtrFromRef(ibnd),makePtrFromRef(x),
269 // makePtrFromRef(bnd));
270 //Ptr<Constraint<Real>> econ = cm.getConstraint();
271 //Ptr<Vector<Real>> emul = cm.getMultiplier();
272 //Ptr<BoundConstraint<Real>> xbnd = cm.getBoundConstraint();
273 //Ptr<Vector<Real>> xvec = cm.getOptVector();
274 //Ptr<Objective<Real>> sobj = makePtr<SlacklessObjective<Real>>(makePtrFromRef(obj));
275 //Ptr<Vector<Real>> xdual = xvec->dual().clone();
276 //run(*xvec,*xdual,*sobj,*xbnd,*econ,*emul,emul->dual(),outStream);
277}
278
279template<typename Real>
281 const Vector<Real> &g,
282 Objective<Real> &obj,
283 Constraint<Real> &econ,
284 Vector<Real> &emul,
285 const Vector<Real> &eres,
286 Constraint<Real> &icon,
287 Vector<Real> &imul,
289 const Vector<Real> &ires,
290 std::ostream &outStream ) {
291 Ptr<Vector<Real>> gp = g.clone(), erp = eres.clone(), irp = ires.clone();
292 Problem<Real> problem(makePtrFromRef(obj),
293 makePtrFromRef(x),gp);
294 problem.addConstraint("EqualityConstraint",makePtrFromRef(econ),
295 makePtrFromRef(emul),erp,false);
296 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
297 makePtrFromRef(imul),makePtrFromRef(ibnd),irp,false);
298 problem.finalize(false,false,outStream);
299 run(problem,outStream);
300 //std::vector<Ptr<Constraint<Real>>>
301 // cvec = {makePtrFromRef(econ), makePtrFromRef(icon)};
302 //std::vector<Ptr<Vector<Real>>>
303 // lvec = {makePtrFromRef(emul), makePtrFromRef(imul)};
304 //std::vector<Ptr<BoundConstraint<Real>>>
305 // bvec = { nullPtr, makePtrFromRef(ibnd)};
306 //ConstraintManager<Real> cm(cvec,lvec,bvec,makePtrFromRef(x));
307 //Ptr<Constraint<Real>> con = cm.getConstraint();
308 //Ptr<Vector<Real>> mul = cm.getMultiplier();
309 //Ptr<BoundConstraint<Real>> xbnd = cm.getBoundConstraint();
310 //Ptr<Vector<Real>> xvec = cm.getOptVector();
311 //Ptr<Objective<Real>> sobj = makePtr<SlacklessObjective<Real>>(makePtrFromRef(obj));
312 //Ptr<Vector<Real>> xdual = xvec->dual().clone();
313 //run(*xvec,*xdual,*sobj,*xbnd,*con,*mul,mul->dual(),outStream);
314}
315
316template<typename Real>
318 const Vector<Real> &g,
319 Objective<Real> &obj,
321 Constraint<Real> &econ,
322 Vector<Real> &emul,
323 const Vector<Real> &eres,
324 Constraint<Real> &icon,
325 Vector<Real> &imul,
327 const Vector<Real> &ires,
328 std::ostream &outStream ) {
329 Ptr<Vector<Real>> gp = g.clone(), erp = eres.clone(), irp = ires.clone();
330 Problem<Real> problem(makePtrFromRef(obj),
331 makePtrFromRef(x),gp);
332 problem.addBoundConstraint(makePtrFromRef(bnd));
333 problem.addConstraint("EqualityConstraint",makePtrFromRef(econ),
334 makePtrFromRef(emul),erp,false);
335 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
336 makePtrFromRef(imul),makePtrFromRef(ibnd),irp,false);
337 problem.finalize(false,false,outStream);
338 run(problem,outStream);
339 //std::vector<Ptr<Constraint<Real>>>
340 // cvec = {makePtrFromRef(econ), makePtrFromRef(icon)};
341 //std::vector<Ptr<Vector<Real>>>
342 // lvec = {makePtrFromRef(emul), makePtrFromRef(imul)};
343 //std::vector<Ptr<BoundConstraint<Real>>>
344 // bvec = { nullPtr, makePtrFromRef(ibnd)};
345 //ConstraintManager<Real> cm(cvec,lvec,bvec,makePtrFromRef(x),makePtrFromRef(bnd));
346 //Ptr<Constraint<Real>> con = cm.getConstraint();
347 //Ptr<Vector<Real>> mul = cm.getMultiplier();
348 //Ptr<BoundConstraint<Real>> xbnd = cm.getBoundConstraint();
349 //Ptr<Vector<Real>> xvec = cm.getOptVector();
350 //Ptr<Objective<Real>> sobj = makePtr<SlacklessObjective<Real>>(makePtrFromRef(obj));
351 //Ptr<Vector<Real>> xdual = xvec->dual().clone();
352 //run(*xvec,*xdual,*sobj,*xbnd,*con,*mul,mul->dual(),outStream);
353}
354
355
356
357template<typename Real>
359 Objective<Real> &obj,
361 Constraint<Real> &econ,
362 Vector<Real> &emul,
363 Constraint<Real> &linear_econ,
364 Vector<Real> &linear_emul,
365 std::ostream &outStream ) {
366 Problem<Real> problem(makePtrFromRef(obj),
367 makePtrFromRef(x));
368 problem.addBoundConstraint(makePtrFromRef(bnd));
369 problem.addConstraint("EqualityConstraint",makePtrFromRef(econ),
370 makePtrFromRef(emul));
371 problem.addLinearConstraint("LinearEqualityConstraint",
372 makePtrFromRef(linear_econ),
373 makePtrFromRef(linear_emul));
374 problem.finalize(false,false,outStream);
375 run(problem,outStream);
376// run(x,x.dual(),obj,bnd,econ,emul,emul.dual(),
377// linear_econ,linear_emul,linear_emul.dual(),outStream);
378}
379
380template<typename Real>
382 Objective<Real> &obj,
383 Constraint<Real> &icon,
384 Vector<Real> &imul,
386 Constraint<Real> &linear_econ,
387 Vector<Real> &linear_emul,
388 std::ostream &outStream ) {
389 Problem<Real> problem(makePtrFromRef(obj),
390 makePtrFromRef(x));
391 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
392 makePtrFromRef(imul),makePtrFromRef(ibnd));
393 problem.addLinearConstraint("LinearEqualityConstraint",
394 makePtrFromRef(linear_econ),
395 makePtrFromRef(linear_emul));
396 problem.finalize(false,false,outStream);
397 run(problem,outStream);
398 //run(x,x.dual(),obj,icon,imul,ibnd,imul.dual(),
399 // linear_econ,linear_emul,linear_emul.dual(),outStream);
400}
401
402template<typename Real>
404 Objective<Real> &obj,
406 Constraint<Real> &icon,
407 Vector<Real> &imul,
409 Constraint<Real> &linear_econ,
410 Vector<Real> &linear_emul,
411 std::ostream &outStream ) {
412 Problem<Real> problem(makePtrFromRef(obj),
413 makePtrFromRef(x));
414 problem.addBoundConstraint(makePtrFromRef(bnd));
415 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
416 makePtrFromRef(imul),makePtrFromRef(ibnd));
417 problem.addLinearConstraint("LinearEqualityConstraint",
418 makePtrFromRef(linear_econ),
419 makePtrFromRef(linear_emul));
420 problem.finalize(false,false,outStream);
421 run(problem,outStream);
422 //run(x,x.dual(),obj,bnd,icon,imul,ibnd,imul.dual(),
423 // linear_econ,linear_emul,linear_emul.dual(),outStream);
424}
425
426template<typename Real>
428 Objective<Real> &obj,
429 Constraint<Real> &econ,
430 Vector<Real> &emul,
431 Constraint<Real> &icon,
432 Vector<Real> &imul,
434 Constraint<Real> &linear_econ,
435 Vector<Real> &linear_emul,
436 std::ostream &outStream ) {
437 Problem<Real> problem(makePtrFromRef(obj),
438 makePtrFromRef(x));
439 problem.addConstraint("EqualityConstraint",makePtrFromRef(econ),
440 makePtrFromRef(emul));
441 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
442 makePtrFromRef(imul),makePtrFromRef(ibnd));
443 problem.addLinearConstraint("LinearEqualityConstraint",
444 makePtrFromRef(linear_econ),
445 makePtrFromRef(linear_emul));
446 problem.finalize(false,false,outStream);
447 run(problem,outStream);
448 //run(x,x.dual(),obj,econ,emul,emul.dual(),icon,imul,ibnd,imul.dual(),
449 // linear_econ,linear_emul,linear_emul.dual(),outStream);
450}
451
452template<typename Real>
454 Objective<Real> &obj,
456 Constraint<Real> &econ,
457 Vector<Real> &emul,
458 Constraint<Real> &icon,
459 Vector<Real> &imul,
461 Constraint<Real> &linear_econ,
462 Vector<Real> &linear_emul,
463 std::ostream &outStream ) {
464 Problem<Real> problem(makePtrFromRef(obj),
465 makePtrFromRef(x));
466 problem.addBoundConstraint(makePtrFromRef(bnd));
467 problem.addConstraint("EqualityConstraint",makePtrFromRef(econ),
468 makePtrFromRef(emul));
469 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
470 makePtrFromRef(imul),makePtrFromRef(ibnd));
471 problem.addLinearConstraint("LinearEqualityConstraint",
472 makePtrFromRef(linear_econ),
473 makePtrFromRef(linear_emul));
474 problem.finalize(false,false,outStream);
475 run(problem,outStream);
476 //run(x,x.dual(),obj,bnd,econ,emul,emul.dual(),icon,imul,ibnd,imul.dual(),
477 // linear_econ,linear_emul,linear_emul.dual(),outStream);
478}
479
480
481
482template<typename Real>
484 const Vector<Real> &g,
485 Objective<Real> &obj,
487 Constraint<Real> &econ,
488 Vector<Real> &emul,
489 const Vector<Real> &eres,
490 Constraint<Real> &linear_econ,
491 Vector<Real> &linear_emul,
492 const Vector<Real> &linear_eres,
493 std::ostream &outStream ) {
494 Ptr<Vector<Real>> gp = g.clone(), erp = eres.clone(), lerp = linear_eres.clone();
495 Problem<Real> problem(makePtrFromRef(obj),
496 makePtrFromRef(x),gp);
497 problem.addBoundConstraint(makePtrFromRef(bnd));
498 problem.addConstraint("EqualityConstraint",makePtrFromRef(econ),
499 makePtrFromRef(emul),erp,false);
500 problem.addLinearConstraint("LinearEqualityConstraint",
501 makePtrFromRef(linear_econ),
502 makePtrFromRef(linear_emul),
503 lerp,false);
504 problem.finalize(false,false,outStream);
505 run(problem,outStream);
506 //ParameterList list;
507 //proj_ = PolyhedralProjectionFactory<Real>(x,g,makePtrFromRef(bnd),makePtrFromRef(linear_econ),linear_emul,linear_eres,list);
508 //run(x,g,obj,bnd,econ,emul,eres,outStream);
509}
510
511template<typename Real>
513 const Vector<Real> &g,
514 Objective<Real> &obj,
515 Constraint<Real> &icon,
516 Vector<Real> &imul,
518 const Vector<Real> &ires,
519 Constraint<Real> &linear_econ,
520 Vector<Real> &linear_emul,
521 const Vector<Real> &linear_eres,
522 std::ostream &outStream ) {
523 Ptr<Vector<Real>> gp = g.clone(), irp = ires.clone(), lerp = linear_eres.clone();
524 Problem<Real> problem(makePtrFromRef(obj),
525 makePtrFromRef(x),gp);
526 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
527 makePtrFromRef(imul),makePtrFromRef(ibnd),
528 irp,false);
529 problem.addLinearConstraint("LinearEqualityConstraint",
530 makePtrFromRef(linear_econ),
531 makePtrFromRef(linear_emul),
532 lerp,false);
533 problem.finalize(false,false,outStream);
534 run(problem,outStream);
535 //Ptr<Vector<Real>> xfeas = x.clone(); xfeas->set(x);
536 //ReduceLinearConstraint<Real> rlc(makePtrFromRef(linear_econ),xfeas,makePtrFromRef(linear_eres));
537 //Ptr<Vector<Real>> s = x.clone(); s->zero();
538 //void output = run(*s,g,*rlc.transform(makePtrFromRef(obj)),
539 // *rlc.transform(makePtrFromRef(icon)),imul,ibnd,ires,outStream);
540 //rlc.project(x,*s);
541 //x.plus(*rlc.getFeasibleVector());
542 //return output;
543}
544
545template<typename Real>
547 const Vector<Real> &g,
548 Objective<Real> &obj,
550 Constraint<Real> &icon,
551 Vector<Real> &imul,
553 const Vector<Real> &ires,
554 Constraint<Real> &linear_econ,
555 Vector<Real> &linear_emul,
556 const Vector<Real> &linear_eres,
557 std::ostream &outStream ) {
558 Ptr<Vector<Real>> gp = g.clone(), irp = ires.clone(), lerp = linear_eres.clone();
559 Problem<Real> problem(makePtrFromRef(obj),
560 makePtrFromRef(x),gp);
561 problem.addBoundConstraint(makePtrFromRef(bnd));
562 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
563 makePtrFromRef(imul),makePtrFromRef(ibnd),
564 irp,false);
565 problem.addLinearConstraint("LinearEqualityConstraint",
566 makePtrFromRef(linear_econ),
567 makePtrFromRef(linear_emul),
568 lerp,false);
569 problem.finalize(false,false,outStream);
570 run(problem,outStream);
571 //ConstraintManager<Real> cm(makePtrFromRef(icon),makePtrFromRef(imul),makePtrFromRef(ibnd),
572 // makePtrFromRef(x), makePtrFromRef(bnd));
573 //Ptr<Vector<Real>> xvec = cm.getOptVector();
574 //Ptr<Constraint<Real>> econ = cm.getConstraint();
575 //Ptr<Vector<Real>> emul = cm.getMultiplier();
576 //Ptr<BoundConstraint<Real>> xbnd = cm.getBoundConstraint();
577 //Ptr<Objective<Real>> sobj = makePtr<SlacklessObjective<Real>>(makePtrFromRef(obj));
578 //Ptr<Constraint<Real>> scon = makePtr<SlacklessConstraint<Real>>(makePtrFromRef(linear_econ));
579 //Ptr<Vector<Real>> xdual = xvec->dual().clone();
580 //Ptr<Vector<Real>> eres = emul->dual().clone();
581 //run(*xvec,*xdual,*sobj,*xbnd,*econ,*emul,*eres,*scon,linear_emul,linear_eres,outStream);
582}
583
584template<typename Real>
586 const Vector<Real> &g,
587 Objective<Real> &obj,
588 Constraint<Real> &econ,
589 Vector<Real> &emul,
590 const Vector<Real> &eres,
591 Constraint<Real> &icon,
592 Vector<Real> &imul,
594 const Vector<Real> &ires,
595 Constraint<Real> &linear_econ,
596 Vector<Real> &linear_emul,
597 const Vector<Real> &linear_eres,
598 std::ostream &outStream ) {
599 Ptr<Vector<Real>> gp = g.clone(), erp = eres.clone(), irp = ires.clone(), lerp = linear_eres.clone();
600 Problem<Real> problem(makePtrFromRef(obj),
601 makePtrFromRef(x),gp);
602 problem.addConstraint("EqualityConstraint",makePtrFromRef(econ),
603 makePtrFromRef(emul),erp,false);
604 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
605 makePtrFromRef(imul),makePtrFromRef(ibnd),
606 irp,false);
607 problem.addLinearConstraint("LinearEqualityConstraint",
608 makePtrFromRef(linear_econ),
609 makePtrFromRef(linear_emul),
610 lerp,false);
611 problem.finalize(false,false,outStream);
612 run(problem,outStream);
613 //Ptr<Vector<Real>> xfeas = x.clone(); xfeas->set(x);
614 //ReduceLinearConstraint<Real> rlc(makePtrFromRef(linear_econ),xfeas,makePtrFromRef(linear_eres));
615 //Ptr<Vector<Real>> s = x.clone(); s->zero();
616 //void output = run(*s,g,*rlc.transform(makePtrFromRef(obj)),
617 // *rlc.transform(makePtrFromRef(econ)),emul,eres,
618 // *rlc.transform(makePtrFromRef(icon)),imul,ibnd,ires,outStream);
619 //rlc.project(x,*s);
620 //x.plus(*rlc.getFeasibleVector());
621 //return output;
622}
623
624template<typename Real>
626 const Vector<Real> &g,
627 Objective<Real> &obj,
629 Constraint<Real> &econ,
630 Vector<Real> &emul,
631 const Vector<Real> &eres,
632 Constraint<Real> &icon,
633 Vector<Real> &imul,
635 const Vector<Real> &ires,
636 Constraint<Real> &linear_econ,
637 Vector<Real> &linear_emul,
638 const Vector<Real> &linear_eres,
639 std::ostream &outStream ) {
640 Ptr<Vector<Real>> gp = g.clone(), erp = eres.clone(), irp = ires.clone(), lerp = linear_eres.clone();
641 Problem<Real> problem(makePtrFromRef(obj),
642 makePtrFromRef(x),gp);
643 problem.addBoundConstraint(makePtrFromRef(bnd));
644 problem.addConstraint("EqualityConstraint",makePtrFromRef(econ),
645 makePtrFromRef(emul),erp,false);
646 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
647 makePtrFromRef(imul),makePtrFromRef(ibnd),
648 irp,false);
649 problem.addLinearConstraint("LinearEqualityConstraint",
650 makePtrFromRef(linear_econ),
651 makePtrFromRef(linear_emul),
652 lerp,false);
653 problem.finalize(false,false,outStream);
654 run(problem,outStream);
655 //std::vector<Ptr<Constraint<Real>>> cvec = {makePtrFromRef(econ), makePtrFromRef(icon)};
656 //std::vector<Ptr<Vector<Real>>> lvec = {makePtrFromRef(emul), makePtrFromRef(imul)};
657 //std::vector<Ptr<BoundConstraint<Real>>> bvec = { nullPtr, makePtrFromRef(ibnd)};
658 //ConstraintManager<Real> cm(cvec, lvec, bvec, makePtrFromRef(x), makePtrFromRef(bnd));
659 //Ptr<Vector<Real>> xvec = cm.getOptVector();
660 //Ptr<Constraint<Real>> xcon = cm.getConstraint();
661 //Ptr<Vector<Real>> xmul = cm.getMultiplier();
662 //Ptr<BoundConstraint<Real>> xbnd = cm.getBoundConstraint();
663 //Ptr<Objective<Real>> sobj = makePtr<SlacklessObjective<Real>>(makePtrFromRef(obj));
664 //Ptr<Constraint<Real>> scon = makePtr<SlacklessConstraint<Real>>(makePtrFromRef(linear_econ));
665 //Ptr<Vector<Real>> xdual = xvec->dual().clone();
666 //Ptr<Vector<Real>> xres = xmul->dual().clone();
667 //run(*xvec,*xdual,*sobj,*xbnd,*xcon,*xmul,*xres,*scon,linear_emul,linear_eres,outStream);
668}
669
670
671template<typename Real>
672void Algorithm<Real>::writeHeader( std::ostream& os ) const {
673 std::stringstream hist;
674 hist << " ";
675 hist << std::setw(6) << std::left << "iter";
676 hist << std::setw(15) << std::left << "value";
677 hist << std::setw(15) << std::left << "gnorm";
678 hist << std::setw(15) << std::left << "snorm";
679 hist << std::setw(10) << std::left << "#fval";
680 hist << std::setw(10) << std::left << "#grad";
681 hist << std::endl;
682 os << hist.str();
683}
684
685template<typename Real>
686void Algorithm<Real>::writeName( std::ostream& os ) const {
687 throw Exception::NotImplemented(">>> ROL::TypeG::Algorithm::writeName() is not implemented!");
688}
689
690template<typename Real>
691void Algorithm<Real>::writeOutput( std::ostream& os, bool write_header ) const {
692 std::stringstream hist;
693 hist << std::scientific << std::setprecision(6);
694 if ( write_header ) writeHeader(os);
695 if ( state_->iter == 0 ) {
696 hist << " ";
697 hist << std::setw(6) << std::left << state_->iter;
698 hist << std::setw(15) << std::left << state_->value;
699 hist << std::setw(15) << std::left << state_->gnorm;
700 hist << std::endl;
701 }
702 else {
703 hist << " ";
704 hist << std::setw(6) << std::left << state_->iter;
705 hist << std::setw(15) << std::left << state_->value;
706 hist << std::setw(15) << std::left << state_->gnorm;
707 hist << std::setw(15) << std::left << state_->snorm;
708 hist << std::setw(10) << std::left << state_->nfval;
709 hist << std::setw(10) << std::left << state_->ngrad;
710 hist << std::endl;
711 }
712 os << hist.str();
713}
714
715template<typename Real>
716void Algorithm<Real>::writeExitStatus( std::ostream& os ) const {
717 std::stringstream hist;
718 hist << "Optimization Terminated with Status: ";
719 hist << EExitStatusToString(state_->statusFlag);
720 hist << std::endl;
721 os << hist.str();
722}
723
724template<typename Real>
725Ptr<const AlgorithmState<Real>> Algorithm<Real>::getState() const {
726//Ptr<const AlgorithmState<Real>>& Algorithm<Real>::getState() const {
727 return state_;
728}
729
730template<typename Real>
732 state_->reset();
733}
734} // namespace TypeG
735} // namespace ROL
736
737#endif
Provides the interface to apply upper and lower bound constraints.
Provides an interface to check two status tests of optimization algorithms.
Provides an interface to check status of optimization algorithms for problems with equality constrain...
Defines the general constraint operator interface.
Provides the interface to evaluate objective functions.
const Ptr< PolyhedralProjection< Real > > & getPolyhedralProjection()
Get the polyhedral projection object. This is a null pointer if no linear constraints and/or bounds a...
const Ptr< Vector< Real > > & getPrimalOptimizationVector()
Get the primal optimization space vector.
const Ptr< Vector< Real > > & getDualOptimizationVector()
Get the dual optimization space vector.
const Ptr< Vector< Real > > & getMultiplierVector()
Get the dual constraint space vector.
const Ptr< Constraint< Real > > & getConstraint()
Get the equality constraint.
EProblem getProblemType()
Get the optimization problem type (U, B, E, or G).
void addLinearConstraint(std::string name, const Ptr< Constraint< Real > > &linear_econ, const Ptr< Vector< Real > > &linear_emul, const Ptr< Vector< Real > > &linear_eres=nullPtr, bool reset=false)
Add a linear equality constraint.
void addBoundConstraint(const Ptr< BoundConstraint< Real > > &bnd)
Add a bound constraint.
void finalizeIteration()
Transform the optimization variables to the native parameterization after an optimization algorithm h...
void addConstraint(std::string name, const Ptr< Constraint< Real > > &econ, const Ptr< Vector< Real > > &emul, const Ptr< Vector< Real > > &eres=nullPtr, bool reset=false)
Add an equality constraint.
const Ptr< Objective< Real > > & getObjective()
Get the objective function.
const Ptr< BoundConstraint< Real > > & getBoundConstraint()
Get the bound constraint.
const Ptr< Vector< Real > > & getResidualVector()
Get the primal constraint space vector.
virtual void finalize(bool lumpConstraints=false, bool printToStream=false, std::ostream &outStream=std::cout)
Tranform user-supplied constraints to consist of only bounds and equalities. Optimization problem can...
Provides an interface to check status of optimization algorithms.
virtual void run(Problem< Real > &problem, std::ostream &outStream=std::cout)
Run algorithm on general constrained problems (Type-G). This is the primary Type-G interface.
virtual void writeName(std::ostream &os) const
Print step name.
Algorithm()
Constructor, given a step and a status test.
virtual void writeHeader(std::ostream &os) const
Print iterate header.
void initialize(const Vector< Real > &x, const Vector< Real > &g, const Vector< Real > &mul, const Vector< Real > &c)
virtual void writeOutput(std::ostream &os, bool write_header=false) const
Print iterate status.
Ptr< const AlgorithmState< Real > > getState() const
virtual void writeExitStatus(std::ostream &os) const
const Ptr< CombinedStatusTest< Real > > status_
void setStatusTest(const Ptr< StatusTest< Real > > &status, bool combineStatus=false)
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:84
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
@ TYPE_EB
Definition: ROL_Types.hpp:261
std::string EExitStatusToString(EExitStatus tr)
Definition: ROL_Types.hpp:126