ROL
ROL_TypeG_Algorithm_Def.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Rapid Optimization Library (ROL) Package
4//
5// Copyright 2014 NTESS and the ROL contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef ROL_TYPEG_ALGORITHM_DEF_H
11#define ROL_TYPEG_ALGORITHM_DEF_H
12
15//#include "ROL_ConstraintManager.hpp"
18
19namespace ROL {
20namespace TypeG {
21
22template<typename Real>
24 : status_(makePtr<CombinedStatusTest<Real>>()),
25 state_(makePtr<AlgorithmState<Real>>()),
26 proj_(nullPtr) {
27 status_->reset();
28 status_->add(makePtr<ConstraintStatusTest<Real>>());
29}
30
31template<typename Real>
33 const Vector<Real> &g,
34 const Vector<Real> &mul,
35 const Vector<Real> &c) {
36 if (state_->iterateVec == nullPtr) {
37 state_->iterateVec = x.clone();
38 }
39 state_->iterateVec->set(x);
40 if (state_->lagmultVec == nullPtr) {
41 state_->lagmultVec = mul.clone();
42 }
43 state_->lagmultVec->set(mul);
44 if (state_->stepVec == nullPtr) {
45 state_->stepVec = x.clone();
46 }
47 state_->stepVec->zero();
48 if (state_->gradientVec == nullPtr) {
49 state_->gradientVec = g.clone();
50 }
51 if (state_->constraintVec == nullPtr) {
52 state_->constraintVec = c.clone();
53 }
54 state_->constraintVec->zero();
55 state_->gradientVec->set(g);
56 if (state_->minIterVec == nullPtr) {
57 state_->minIterVec = x.clone();
58 }
59 state_->minIterVec->set(x);
60 state_->minIter = state_->iter;
61 state_->minValue = state_->value;
62}
63
64template<typename Real>
66 const bool combineStatus) {
67 if (!combineStatus) { // Do not combine status tests
68 status_->reset();
69 }
70 status_->add(status); // Add user-defined StatusTest
71}
72
73template<typename Real>
75 std::ostream &outStream ) {
76 if (problem.getProblemType() == TYPE_EB) {
80 *problem.getObjective(),
81 *problem.getBoundConstraint(),
82 *problem.getConstraint(),
83 *problem.getMultiplierVector(),
84 *problem.getResidualVector(),
85 outStream);
86 problem.finalizeIteration();
87 }
88 else {
89 throw Exception::NotImplemented(">>> ROL::Algorithm::run : Optimization problem is not Type G!");
90 }
91}
92
93template<typename Real>
95 Objective<Real> &obj,
97 Constraint<Real> &econ,
98 Vector<Real> &emul,
99 std::ostream &outStream ) {
100 Problem<Real> problem(makePtrFromRef(obj),
101 makePtrFromRef(x));
102 problem.addBoundConstraint(makePtrFromRef(bnd));
103 problem.addConstraint("EqualityConstraint",makePtrFromRef(econ),
104 makePtrFromRef(emul));
105 problem.finalize(false,false,outStream);
106 run(problem,outStream);
107 //run(x,x.dual(),obj,bnd,econ,emul,emul.dual(),outStream);
108}
109
110template<typename Real>
112 Objective<Real> &obj,
113 Constraint<Real> &icon,
114 Vector<Real> &imul,
116 std::ostream &outStream ) {
117 Problem<Real> problem(makePtrFromRef(obj),
118 makePtrFromRef(x));
119 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
120 makePtrFromRef(imul),makePtrFromRef(ibnd));
121 problem.finalize(false,false,outStream);
122 run(problem,outStream);
123 //run(x,x.dual(),obj,icon,imul,ibnd,imul.dual(),outStream);
124}
125
126template<typename Real>
128 Objective<Real> &obj,
130 Constraint<Real> &icon,
131 Vector<Real> &imul,
133 std::ostream &outStream ) {
134 Problem<Real> problem(makePtrFromRef(obj),
135 makePtrFromRef(x));
136 problem.addBoundConstraint(makePtrFromRef(bnd));
137 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
138 makePtrFromRef(imul),makePtrFromRef(ibnd));
139 problem.finalize(false,false,outStream);
140 run(problem,outStream);
141 //run(x,x.dual(),obj,bnd,icon,imul,ibnd,imul.dual(),outStream);
142}
143
144template<typename Real>
146 Objective<Real> &obj,
147 Constraint<Real> &econ,
148 Vector<Real> &emul,
149 Constraint<Real> &icon,
150 Vector<Real> &imul,
152 std::ostream &outStream ) {
153 Problem<Real> problem(makePtrFromRef(obj),
154 makePtrFromRef(x));
155 problem.addConstraint("EqualityConstraint",makePtrFromRef(econ),
156 makePtrFromRef(emul));
157 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
158 makePtrFromRef(imul),makePtrFromRef(ibnd));
159 problem.finalize(false,false,outStream);
160 run(problem,outStream);
161 //run(x,x.dual(),obj,econ,emul,emul.dual(),icon,imul,ibnd,imul.dual(),outStream);
162}
163
164template<typename Real>
166 Objective<Real> &obj,
168 Constraint<Real> &econ,
169 Vector<Real> &emul,
170 Constraint<Real> &icon,
171 Vector<Real> &imul,
173 std::ostream &outStream ) {
174 Problem<Real> problem(makePtrFromRef(obj),
175 makePtrFromRef(x));
176 problem.addBoundConstraint(makePtrFromRef(bnd));
177 problem.addConstraint("EqualityConstraint",makePtrFromRef(econ),
178 makePtrFromRef(emul));
179 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
180 makePtrFromRef(imul),makePtrFromRef(ibnd));
181 problem.finalize(false,false,outStream);
182 run(problem,outStream);
183 //run(x,x.dual(),obj,bnd,econ,emul,emul.dual(),icon,imul,ibnd,imul.dual(),outStream);
184}
185
186
187
188template<typename Real>
190 const Vector<Real> &g,
191 Objective<Real> &obj,
192 Constraint<Real> &icon,
193 Vector<Real> &imul,
195 const Vector<Real> &ires,
196 std::ostream &outStream ) {
197 Ptr<Vector<Real>> gp = g.clone(), irp = ires.clone();
198 Problem<Real> problem(makePtrFromRef(obj),
199 makePtrFromRef(x),gp);
200 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
201 makePtrFromRef(imul),makePtrFromRef(ibnd),irp,false);
202 problem.finalize(false,false,outStream);
203 run(problem,outStream);
204 //ConstraintManager<Real> cm(makePtrFromRef(icon),makePtrFromRef(imul),
205 // makePtrFromRef(ibnd),makePtrFromRef(x));
206 //Ptr<Constraint<Real>> econ = cm.getConstraint();
207 //Ptr<Vector<Real>> emul = cm.getMultiplier();
208 //Ptr<BoundConstraint<Real>> xbnd = cm.getBoundConstraint();
209 //Ptr<Vector<Real>> xvec = cm.getOptVector();
210 //Ptr<Objective<Real>> sobj = makePtr<SlacklessObjective<Real>>(makePtrFromRef(obj));
211 //Ptr<Vector<Real>> xdual = xvec->dual().clone();
212 //run(*xvec,*xdual,*sobj,*xbnd,*econ,*emul,emul->dual(),outStream);
213}
214
215template<typename Real>
217 const Vector<Real> &g,
218 Objective<Real> &obj,
220 Constraint<Real> &icon,
221 Vector<Real> &imul,
223 const Vector<Real> &ires,
224 std::ostream &outStream ) {
225 Ptr<Vector<Real>> gp = g.clone(), irp = ires.clone();
226 Problem<Real> problem(makePtrFromRef(obj),
227 makePtrFromRef(x),gp);
228 problem.addBoundConstraint(makePtrFromRef(bnd));
229 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
230 makePtrFromRef(imul),makePtrFromRef(ibnd),irp,false);
231 problem.finalize(false,false,outStream);
232 run(problem,outStream);
233 //ConstraintManager<Real> cm(makePtrFromRef(icon),makePtrFromRef(imul),
234 // makePtrFromRef(ibnd),makePtrFromRef(x),
235 // makePtrFromRef(bnd));
236 //Ptr<Constraint<Real>> econ = cm.getConstraint();
237 //Ptr<Vector<Real>> emul = cm.getMultiplier();
238 //Ptr<BoundConstraint<Real>> xbnd = cm.getBoundConstraint();
239 //Ptr<Vector<Real>> xvec = cm.getOptVector();
240 //Ptr<Objective<Real>> sobj = makePtr<SlacklessObjective<Real>>(makePtrFromRef(obj));
241 //Ptr<Vector<Real>> xdual = xvec->dual().clone();
242 //run(*xvec,*xdual,*sobj,*xbnd,*econ,*emul,emul->dual(),outStream);
243}
244
245template<typename Real>
247 const Vector<Real> &g,
248 Objective<Real> &obj,
249 Constraint<Real> &econ,
250 Vector<Real> &emul,
251 const Vector<Real> &eres,
252 Constraint<Real> &icon,
253 Vector<Real> &imul,
255 const Vector<Real> &ires,
256 std::ostream &outStream ) {
257 Ptr<Vector<Real>> gp = g.clone(), erp = eres.clone(), irp = ires.clone();
258 Problem<Real> problem(makePtrFromRef(obj),
259 makePtrFromRef(x),gp);
260 problem.addConstraint("EqualityConstraint",makePtrFromRef(econ),
261 makePtrFromRef(emul),erp,false);
262 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
263 makePtrFromRef(imul),makePtrFromRef(ibnd),irp,false);
264 problem.finalize(false,false,outStream);
265 run(problem,outStream);
266 //std::vector<Ptr<Constraint<Real>>>
267 // cvec = {makePtrFromRef(econ), makePtrFromRef(icon)};
268 //std::vector<Ptr<Vector<Real>>>
269 // lvec = {makePtrFromRef(emul), makePtrFromRef(imul)};
270 //std::vector<Ptr<BoundConstraint<Real>>>
271 // bvec = { nullPtr, makePtrFromRef(ibnd)};
272 //ConstraintManager<Real> cm(cvec,lvec,bvec,makePtrFromRef(x));
273 //Ptr<Constraint<Real>> con = cm.getConstraint();
274 //Ptr<Vector<Real>> mul = cm.getMultiplier();
275 //Ptr<BoundConstraint<Real>> xbnd = cm.getBoundConstraint();
276 //Ptr<Vector<Real>> xvec = cm.getOptVector();
277 //Ptr<Objective<Real>> sobj = makePtr<SlacklessObjective<Real>>(makePtrFromRef(obj));
278 //Ptr<Vector<Real>> xdual = xvec->dual().clone();
279 //run(*xvec,*xdual,*sobj,*xbnd,*con,*mul,mul->dual(),outStream);
280}
281
282template<typename Real>
284 const Vector<Real> &g,
285 Objective<Real> &obj,
287 Constraint<Real> &econ,
288 Vector<Real> &emul,
289 const Vector<Real> &eres,
290 Constraint<Real> &icon,
291 Vector<Real> &imul,
293 const Vector<Real> &ires,
294 std::ostream &outStream ) {
295 Ptr<Vector<Real>> gp = g.clone(), erp = eres.clone(), irp = ires.clone();
296 Problem<Real> problem(makePtrFromRef(obj),
297 makePtrFromRef(x),gp);
298 problem.addBoundConstraint(makePtrFromRef(bnd));
299 problem.addConstraint("EqualityConstraint",makePtrFromRef(econ),
300 makePtrFromRef(emul),erp,false);
301 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
302 makePtrFromRef(imul),makePtrFromRef(ibnd),irp,false);
303 problem.finalize(false,false,outStream);
304 run(problem,outStream);
305 //std::vector<Ptr<Constraint<Real>>>
306 // cvec = {makePtrFromRef(econ), makePtrFromRef(icon)};
307 //std::vector<Ptr<Vector<Real>>>
308 // lvec = {makePtrFromRef(emul), makePtrFromRef(imul)};
309 //std::vector<Ptr<BoundConstraint<Real>>>
310 // bvec = { nullPtr, makePtrFromRef(ibnd)};
311 //ConstraintManager<Real> cm(cvec,lvec,bvec,makePtrFromRef(x),makePtrFromRef(bnd));
312 //Ptr<Constraint<Real>> con = cm.getConstraint();
313 //Ptr<Vector<Real>> mul = cm.getMultiplier();
314 //Ptr<BoundConstraint<Real>> xbnd = cm.getBoundConstraint();
315 //Ptr<Vector<Real>> xvec = cm.getOptVector();
316 //Ptr<Objective<Real>> sobj = makePtr<SlacklessObjective<Real>>(makePtrFromRef(obj));
317 //Ptr<Vector<Real>> xdual = xvec->dual().clone();
318 //run(*xvec,*xdual,*sobj,*xbnd,*con,*mul,mul->dual(),outStream);
319}
320
321
322
323template<typename Real>
325 Objective<Real> &obj,
327 Constraint<Real> &econ,
328 Vector<Real> &emul,
329 Constraint<Real> &linear_econ,
330 Vector<Real> &linear_emul,
331 std::ostream &outStream ) {
332 Problem<Real> problem(makePtrFromRef(obj),
333 makePtrFromRef(x));
334 problem.addBoundConstraint(makePtrFromRef(bnd));
335 problem.addConstraint("EqualityConstraint",makePtrFromRef(econ),
336 makePtrFromRef(emul));
337 problem.addLinearConstraint("LinearEqualityConstraint",
338 makePtrFromRef(linear_econ),
339 makePtrFromRef(linear_emul));
340 problem.finalize(false,false,outStream);
341 run(problem,outStream);
342// run(x,x.dual(),obj,bnd,econ,emul,emul.dual(),
343// linear_econ,linear_emul,linear_emul.dual(),outStream);
344}
345
346template<typename Real>
348 Objective<Real> &obj,
349 Constraint<Real> &icon,
350 Vector<Real> &imul,
352 Constraint<Real> &linear_econ,
353 Vector<Real> &linear_emul,
354 std::ostream &outStream ) {
355 Problem<Real> problem(makePtrFromRef(obj),
356 makePtrFromRef(x));
357 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
358 makePtrFromRef(imul),makePtrFromRef(ibnd));
359 problem.addLinearConstraint("LinearEqualityConstraint",
360 makePtrFromRef(linear_econ),
361 makePtrFromRef(linear_emul));
362 problem.finalize(false,false,outStream);
363 run(problem,outStream);
364 //run(x,x.dual(),obj,icon,imul,ibnd,imul.dual(),
365 // linear_econ,linear_emul,linear_emul.dual(),outStream);
366}
367
368template<typename Real>
370 Objective<Real> &obj,
372 Constraint<Real> &icon,
373 Vector<Real> &imul,
375 Constraint<Real> &linear_econ,
376 Vector<Real> &linear_emul,
377 std::ostream &outStream ) {
378 Problem<Real> problem(makePtrFromRef(obj),
379 makePtrFromRef(x));
380 problem.addBoundConstraint(makePtrFromRef(bnd));
381 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
382 makePtrFromRef(imul),makePtrFromRef(ibnd));
383 problem.addLinearConstraint("LinearEqualityConstraint",
384 makePtrFromRef(linear_econ),
385 makePtrFromRef(linear_emul));
386 problem.finalize(false,false,outStream);
387 run(problem,outStream);
388 //run(x,x.dual(),obj,bnd,icon,imul,ibnd,imul.dual(),
389 // linear_econ,linear_emul,linear_emul.dual(),outStream);
390}
391
392template<typename Real>
394 Objective<Real> &obj,
395 Constraint<Real> &econ,
396 Vector<Real> &emul,
397 Constraint<Real> &icon,
398 Vector<Real> &imul,
400 Constraint<Real> &linear_econ,
401 Vector<Real> &linear_emul,
402 std::ostream &outStream ) {
403 Problem<Real> problem(makePtrFromRef(obj),
404 makePtrFromRef(x));
405 problem.addConstraint("EqualityConstraint",makePtrFromRef(econ),
406 makePtrFromRef(emul));
407 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
408 makePtrFromRef(imul),makePtrFromRef(ibnd));
409 problem.addLinearConstraint("LinearEqualityConstraint",
410 makePtrFromRef(linear_econ),
411 makePtrFromRef(linear_emul));
412 problem.finalize(false,false,outStream);
413 run(problem,outStream);
414 //run(x,x.dual(),obj,econ,emul,emul.dual(),icon,imul,ibnd,imul.dual(),
415 // linear_econ,linear_emul,linear_emul.dual(),outStream);
416}
417
418template<typename Real>
420 Objective<Real> &obj,
422 Constraint<Real> &econ,
423 Vector<Real> &emul,
424 Constraint<Real> &icon,
425 Vector<Real> &imul,
427 Constraint<Real> &linear_econ,
428 Vector<Real> &linear_emul,
429 std::ostream &outStream ) {
430 Problem<Real> problem(makePtrFromRef(obj),
431 makePtrFromRef(x));
432 problem.addBoundConstraint(makePtrFromRef(bnd));
433 problem.addConstraint("EqualityConstraint",makePtrFromRef(econ),
434 makePtrFromRef(emul));
435 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
436 makePtrFromRef(imul),makePtrFromRef(ibnd));
437 problem.addLinearConstraint("LinearEqualityConstraint",
438 makePtrFromRef(linear_econ),
439 makePtrFromRef(linear_emul));
440 problem.finalize(false,false,outStream);
441 run(problem,outStream);
442 //run(x,x.dual(),obj,bnd,econ,emul,emul.dual(),icon,imul,ibnd,imul.dual(),
443 // linear_econ,linear_emul,linear_emul.dual(),outStream);
444}
445
446
447
448template<typename Real>
450 const Vector<Real> &g,
451 Objective<Real> &obj,
453 Constraint<Real> &econ,
454 Vector<Real> &emul,
455 const Vector<Real> &eres,
456 Constraint<Real> &linear_econ,
457 Vector<Real> &linear_emul,
458 const Vector<Real> &linear_eres,
459 std::ostream &outStream ) {
460 Ptr<Vector<Real>> gp = g.clone(), erp = eres.clone(), lerp = linear_eres.clone();
461 Problem<Real> problem(makePtrFromRef(obj),
462 makePtrFromRef(x),gp);
463 problem.addBoundConstraint(makePtrFromRef(bnd));
464 problem.addConstraint("EqualityConstraint",makePtrFromRef(econ),
465 makePtrFromRef(emul),erp,false);
466 problem.addLinearConstraint("LinearEqualityConstraint",
467 makePtrFromRef(linear_econ),
468 makePtrFromRef(linear_emul),
469 lerp,false);
470 problem.finalize(false,false,outStream);
471 run(problem,outStream);
472 //ParameterList list;
473 //proj_ = PolyhedralProjectionFactory<Real>(x,g,makePtrFromRef(bnd),makePtrFromRef(linear_econ),linear_emul,linear_eres,list);
474 //run(x,g,obj,bnd,econ,emul,eres,outStream);
475}
476
477template<typename Real>
479 const Vector<Real> &g,
480 Objective<Real> &obj,
481 Constraint<Real> &icon,
482 Vector<Real> &imul,
484 const Vector<Real> &ires,
485 Constraint<Real> &linear_econ,
486 Vector<Real> &linear_emul,
487 const Vector<Real> &linear_eres,
488 std::ostream &outStream ) {
489 Ptr<Vector<Real>> gp = g.clone(), irp = ires.clone(), lerp = linear_eres.clone();
490 Problem<Real> problem(makePtrFromRef(obj),
491 makePtrFromRef(x),gp);
492 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
493 makePtrFromRef(imul),makePtrFromRef(ibnd),
494 irp,false);
495 problem.addLinearConstraint("LinearEqualityConstraint",
496 makePtrFromRef(linear_econ),
497 makePtrFromRef(linear_emul),
498 lerp,false);
499 problem.finalize(false,false,outStream);
500 run(problem,outStream);
501 //Ptr<Vector<Real>> xfeas = x.clone(); xfeas->set(x);
502 //ReduceLinearConstraint<Real> rlc(makePtrFromRef(linear_econ),xfeas,makePtrFromRef(linear_eres));
503 //Ptr<Vector<Real>> s = x.clone(); s->zero();
504 //void output = run(*s,g,*rlc.transform(makePtrFromRef(obj)),
505 // *rlc.transform(makePtrFromRef(icon)),imul,ibnd,ires,outStream);
506 //rlc.project(x,*s);
507 //x.plus(*rlc.getFeasibleVector());
508 //return output;
509}
510
511template<typename Real>
513 const Vector<Real> &g,
514 Objective<Real> &obj,
516 Constraint<Real> &icon,
517 Vector<Real> &imul,
519 const Vector<Real> &ires,
520 Constraint<Real> &linear_econ,
521 Vector<Real> &linear_emul,
522 const Vector<Real> &linear_eres,
523 std::ostream &outStream ) {
524 Ptr<Vector<Real>> gp = g.clone(), irp = ires.clone(), lerp = linear_eres.clone();
525 Problem<Real> problem(makePtrFromRef(obj),
526 makePtrFromRef(x),gp);
527 problem.addBoundConstraint(makePtrFromRef(bnd));
528 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
529 makePtrFromRef(imul),makePtrFromRef(ibnd),
530 irp,false);
531 problem.addLinearConstraint("LinearEqualityConstraint",
532 makePtrFromRef(linear_econ),
533 makePtrFromRef(linear_emul),
534 lerp,false);
535 problem.finalize(false,false,outStream);
536 run(problem,outStream);
537 //ConstraintManager<Real> cm(makePtrFromRef(icon),makePtrFromRef(imul),makePtrFromRef(ibnd),
538 // makePtrFromRef(x), makePtrFromRef(bnd));
539 //Ptr<Vector<Real>> xvec = cm.getOptVector();
540 //Ptr<Constraint<Real>> econ = cm.getConstraint();
541 //Ptr<Vector<Real>> emul = cm.getMultiplier();
542 //Ptr<BoundConstraint<Real>> xbnd = cm.getBoundConstraint();
543 //Ptr<Objective<Real>> sobj = makePtr<SlacklessObjective<Real>>(makePtrFromRef(obj));
544 //Ptr<Constraint<Real>> scon = makePtr<SlacklessConstraint<Real>>(makePtrFromRef(linear_econ));
545 //Ptr<Vector<Real>> xdual = xvec->dual().clone();
546 //Ptr<Vector<Real>> eres = emul->dual().clone();
547 //run(*xvec,*xdual,*sobj,*xbnd,*econ,*emul,*eres,*scon,linear_emul,linear_eres,outStream);
548}
549
550template<typename Real>
552 const Vector<Real> &g,
553 Objective<Real> &obj,
554 Constraint<Real> &econ,
555 Vector<Real> &emul,
556 const Vector<Real> &eres,
557 Constraint<Real> &icon,
558 Vector<Real> &imul,
560 const Vector<Real> &ires,
561 Constraint<Real> &linear_econ,
562 Vector<Real> &linear_emul,
563 const Vector<Real> &linear_eres,
564 std::ostream &outStream ) {
565 Ptr<Vector<Real>> gp = g.clone(), erp = eres.clone(), irp = ires.clone(), lerp = linear_eres.clone();
566 Problem<Real> problem(makePtrFromRef(obj),
567 makePtrFromRef(x),gp);
568 problem.addConstraint("EqualityConstraint",makePtrFromRef(econ),
569 makePtrFromRef(emul),erp,false);
570 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
571 makePtrFromRef(imul),makePtrFromRef(ibnd),
572 irp,false);
573 problem.addLinearConstraint("LinearEqualityConstraint",
574 makePtrFromRef(linear_econ),
575 makePtrFromRef(linear_emul),
576 lerp,false);
577 problem.finalize(false,false,outStream);
578 run(problem,outStream);
579 //Ptr<Vector<Real>> xfeas = x.clone(); xfeas->set(x);
580 //ReduceLinearConstraint<Real> rlc(makePtrFromRef(linear_econ),xfeas,makePtrFromRef(linear_eres));
581 //Ptr<Vector<Real>> s = x.clone(); s->zero();
582 //void output = run(*s,g,*rlc.transform(makePtrFromRef(obj)),
583 // *rlc.transform(makePtrFromRef(econ)),emul,eres,
584 // *rlc.transform(makePtrFromRef(icon)),imul,ibnd,ires,outStream);
585 //rlc.project(x,*s);
586 //x.plus(*rlc.getFeasibleVector());
587 //return output;
588}
589
590template<typename Real>
592 const Vector<Real> &g,
593 Objective<Real> &obj,
595 Constraint<Real> &econ,
596 Vector<Real> &emul,
597 const Vector<Real> &eres,
598 Constraint<Real> &icon,
599 Vector<Real> &imul,
601 const Vector<Real> &ires,
602 Constraint<Real> &linear_econ,
603 Vector<Real> &linear_emul,
604 const Vector<Real> &linear_eres,
605 std::ostream &outStream ) {
606 Ptr<Vector<Real>> gp = g.clone(), erp = eres.clone(), irp = ires.clone(), lerp = linear_eres.clone();
607 Problem<Real> problem(makePtrFromRef(obj),
608 makePtrFromRef(x),gp);
609 problem.addBoundConstraint(makePtrFromRef(bnd));
610 problem.addConstraint("EqualityConstraint",makePtrFromRef(econ),
611 makePtrFromRef(emul),erp,false);
612 problem.addConstraint("InequalityConstraint",makePtrFromRef(icon),
613 makePtrFromRef(imul),makePtrFromRef(ibnd),
614 irp,false);
615 problem.addLinearConstraint("LinearEqualityConstraint",
616 makePtrFromRef(linear_econ),
617 makePtrFromRef(linear_emul),
618 lerp,false);
619 problem.finalize(false,false,outStream);
620 run(problem,outStream);
621 //std::vector<Ptr<Constraint<Real>>> cvec = {makePtrFromRef(econ), makePtrFromRef(icon)};
622 //std::vector<Ptr<Vector<Real>>> lvec = {makePtrFromRef(emul), makePtrFromRef(imul)};
623 //std::vector<Ptr<BoundConstraint<Real>>> bvec = { nullPtr, makePtrFromRef(ibnd)};
624 //ConstraintManager<Real> cm(cvec, lvec, bvec, makePtrFromRef(x), makePtrFromRef(bnd));
625 //Ptr<Vector<Real>> xvec = cm.getOptVector();
626 //Ptr<Constraint<Real>> xcon = cm.getConstraint();
627 //Ptr<Vector<Real>> xmul = cm.getMultiplier();
628 //Ptr<BoundConstraint<Real>> xbnd = cm.getBoundConstraint();
629 //Ptr<Objective<Real>> sobj = makePtr<SlacklessObjective<Real>>(makePtrFromRef(obj));
630 //Ptr<Constraint<Real>> scon = makePtr<SlacklessConstraint<Real>>(makePtrFromRef(linear_econ));
631 //Ptr<Vector<Real>> xdual = xvec->dual().clone();
632 //Ptr<Vector<Real>> xres = xmul->dual().clone();
633 //run(*xvec,*xdual,*sobj,*xbnd,*xcon,*xmul,*xres,*scon,linear_emul,linear_eres,outStream);
634}
635
636
637template<typename Real>
638void Algorithm<Real>::writeHeader( std::ostream& os ) const {
639 std::ios_base::fmtflags osFlags(os.flags());
640 os << " ";
641 os << std::setw(6) << std::left << "iter";
642 os << std::setw(15) << std::left << "value";
643 os << std::setw(15) << std::left << "gnorm";
644 os << std::setw(15) << std::left << "snorm";
645 os << std::setw(10) << std::left << "#fval";
646 os << std::setw(10) << std::left << "#grad";
647 os << std::endl;
648 os.flags(osFlags);
649}
650
651template<typename Real>
652void Algorithm<Real>::writeName( std::ostream& os ) const {
653 throw Exception::NotImplemented(">>> ROL::TypeG::Algorithm::writeName() is not implemented!");
654}
655
656template<typename Real>
657void Algorithm<Real>::writeOutput( std::ostream& os, bool write_header ) const {
658 std::ios_base::fmtflags osFlags(os.flags());
659 os << std::scientific << std::setprecision(6);
660 if ( write_header ) writeHeader(os);
661 if ( state_->iter == 0 ) {
662 os << " ";
663 os << std::setw(6) << std::left << state_->iter;
664 os << std::setw(15) << std::left << state_->value;
665 os << std::setw(15) << std::left << state_->gnorm;
666 os << std::endl;
667 }
668 else {
669 os << " ";
670 os << std::setw(6) << std::left << state_->iter;
671 os << std::setw(15) << std::left << state_->value;
672 os << std::setw(15) << std::left << state_->gnorm;
673 os << std::setw(15) << std::left << state_->snorm;
674 os << std::setw(10) << std::left << state_->nfval;
675 os << std::setw(10) << std::left << state_->ngrad;
676 os << std::endl;
677 }
678 os.flags(osFlags);
679}
680
681template<typename Real>
682void Algorithm<Real>::writeExitStatus( std::ostream& os ) const {
683 std::ios_base::fmtflags osFlags(os.flags());
684 os << "Optimization Terminated with Status: ";
685 os << EExitStatusToString(state_->statusFlag);
686 os << std::endl;
687 os.flags(osFlags);
688}
689
690template<typename Real>
691Ptr<const AlgorithmState<Real>> Algorithm<Real>::getState() const {
692//Ptr<const AlgorithmState<Real>>& Algorithm<Real>::getState() const {
693 return state_;
694}
695
696template<typename Real>
698 state_->reset();
699}
700} // namespace TypeG
701} // namespace ROL
702
703#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 writeOutput(std::ostream &os, const bool write_header=false) const
Print iterate status.
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)
Ptr< const AlgorithmState< Real > > getState() const
virtual void writeExitStatus(std::ostream &os) const
const Ptr< CombinedStatusTest< Real > > status_
Ptr< PolyhedralProjection< Real > > proj_
void setStatusTest(const Ptr< StatusTest< Real > > &status, bool combineStatus=false)
const Ptr< AlgorithmState< Real > > state_
Defines the linear algebra or vector space interface.
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
@ TYPE_EB
std::string EExitStatusToString(EExitStatus tr)
Definition ROL_Types.hpp:92