44 #define OPTIMIZATION_PROBLEM_REFACTOR 48 #include "ROL_NonlinearProgram.hpp" 53 #include "HS_Problem_041.hpp" 71 Teuchos::RCP<const std::vector<Real> > xp =
74 outStream <<
"Standard Vector" << std::endl;
75 for(
size_t i=0; i<xp->size(); ++i ) {
76 outStream << (*xp)[i] << std::endl;
79 catch(
const std::bad_cast& e ) {
80 outStream <<
"Partitioned Vector" << std::endl;
83 typedef typename PV::size_type size_type;
85 const PV &xpv = Teuchos::dyn_cast<
const PV>(x);
87 for( size_type i=0; i<xpv.numVectors(); ++i ) {
88 outStream <<
"--------------------" << std::endl;
91 outStream <<
"--------------------" << std::endl;
101 typedef std::vector<Real> vector;
105 typedef typename PV::size_type size_type;
108 using Teuchos::dyn_cast;
109 using Teuchos::rcp_dynamic_cast;
111 const size_type OPT = 0;
112 const size_type EQUAL = 1;
113 const size_type LOWER = 2;
114 const size_type UPPER = 3;
116 const PV &sol_pv = dyn_cast<
const PV>(sol);
117 const vector &x = *(rcp_dynamic_cast<
const SV>(sol_pv.get(OPT))->getVector());
118 const vector &l = *(rcp_dynamic_cast<
const SV>(sol_pv.get(EQUAL))->getVector());
119 const vector &zl = *(rcp_dynamic_cast<
const SV>(sol_pv.get(LOWER))->getVector());
120 const vector &zu = *(rcp_dynamic_cast<
const SV>(sol_pv.get(UPPER))->getVector());
122 PV &c_pv = dyn_cast<PV>(c);
123 vector &cx = *(rcp_dynamic_cast<SV>(c_pv.get(OPT))->getVector());
124 vector &cl = *(rcp_dynamic_cast<SV>(c_pv.get(EQUAL))->getVector());
125 vector &czl = *(rcp_dynamic_cast<SV>(c_pv.get(LOWER))->getVector());
126 vector &czu = *(rcp_dynamic_cast<SV>(c_pv.get(UPPER))->getVector());
128 cx[0] = -x[1]*x[2] + l[0] - zl[0] + zu[0];
129 cx[1] = -x[0]*x[1] + 2*l[0] - zl[1] + zu[1];
130 cx[2] = -x[0]*x[1] + 2*l[0] - zl[2] + zu[2];
131 cx[3] = - l[0] - zl[3] + zu[3];
133 cl[0] = x[0] + 2*x[1] + 2*x[2] - x[3];
135 czl[0] = x[0]*zl[0] - mu;
136 czl[1] = x[1]*zl[1] - mu;
137 czl[2] = x[2]*zl[2] - mu;
138 czl[3] = x[3]*zl[3] - mu;
140 czu[0] = (1.0-x[0])*zu[0] - mu;
141 czu[1] = (1.0-x[1])*zu[1] - mu;
142 czu[2] = (1.0-x[2])*zl[2] - mu;
143 czu[3] = (2.0-x[3])*zl[3] - mu;
152 typedef std::vector<Real> vector;
156 typedef typename PV::size_type size_type;
159 using Teuchos::dyn_cast;
160 using Teuchos::rcp_dynamic_cast;
162 const size_type OPT = 0;
163 const size_type EQUAL = 1;
164 const size_type LOWER = 2;
165 const size_type UPPER = 3;
167 const PV &sol_pv = dyn_cast<
const PV>(sol);
168 const vector &x = *(rcp_dynamic_cast<
const SV>(sol_pv.get(OPT))->getVector());
170 const vector &zl = *(rcp_dynamic_cast<
const SV>(sol_pv.get(LOWER))->getVector());
171 const vector &zu = *(rcp_dynamic_cast<
const SV>(sol_pv.get(UPPER))->getVector());
173 const PV &v_pv = dyn_cast<
const PV>(v);
174 const vector &vx = *(rcp_dynamic_cast<
const SV>(v_pv.get(OPT))->getVector());
175 const vector &vl = *(rcp_dynamic_cast<
const SV>(v_pv.get(EQUAL))->getVector());
176 const vector &vzl = *(rcp_dynamic_cast<
const SV>(v_pv.get(LOWER))->getVector());
177 const vector &vzu = *(rcp_dynamic_cast<
const SV>(v_pv.get(UPPER))->getVector());
179 PV &jv_pv = dyn_cast<PV>(jv);
180 vector &jvx = *(rcp_dynamic_cast<SV>(jv_pv.get(OPT))->getVector());
181 vector &jvl = *(rcp_dynamic_cast<SV>(jv_pv.get(EQUAL))->getVector());
182 vector &jvzl = *(rcp_dynamic_cast<SV>(jv_pv.get(LOWER))->getVector());
183 vector &jvzu = *(rcp_dynamic_cast<SV>(jv_pv.get(UPPER))->getVector());
185 jvx[0] = -x[1]*vx[2] - x[2]*vx[1] + vl[0] - vzl[0] + vzu[0];
186 jvx[1] = -x[0]*vx[2] - x[2]*vx[0] + 2*vl[0] - vzl[1] + vzu[1];
187 jvx[2] = -x[0]*vx[1] - x[1]*vx[0] + 2*vl[0] - vzl[2] + vzu[2];
188 jvx[3] = - vl[0] - vzl[3] + vzu[3];
190 jvl[0] = vx[0] + 2*vx[1] + 2*vx[2] - vx[3];
192 jvzl[0] = zl[0]*vx[0] + vzl[0]*x[0];
193 jvzl[1] = zl[1]*vx[1] + vzl[1]*x[1];
194 jvzl[2] = zl[2]*vx[2] + vzl[2]*x[2];
195 jvzl[3] = zl[3]*vx[3] + vzl[3]*x[3];
197 jvzu[0] = -zu[0]*vx[0] + vzu[0]*(1.0-x[0]);
198 jvzu[1] = -zu[1]*vx[1] + vzu[1]*(1.0-x[1]);
199 jvzu[2] = -zu[2]*vx[2] + vzu[2]*(1.0-x[2]);
200 jvzu[3] = -zu[3]*vx[3] + vzu[3]*(2.0-x[3]);
207 int main(
int argc,
char *argv[]) {
211 typedef Teuchos::ParameterList PL;
219 typedef ROL::NonlinearProgram<RealT> NLP;
224 using Teuchos::RCP;
using Teuchos::rcp;
226 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
228 int iprint = argc - 1;
229 RCP<std::ostream> outStream;
230 Teuchos::oblackholestream bhs;
232 outStream = rcp(&std::cout,
false);
234 outStream = rcp(&bhs,
false);
242 RealT tol = std::sqrt(ROL::ROL_EPSILON<RealT>());
246 PL &iplist = parlist.sublist(
"Step").sublist(
"Primal Dual Interior Point");
247 PL &lblist = iplist.sublist(
"Barrier Objective");
249 iplist.set(
"Symmetrize Primal Dual System",
false);
251 lblist.set(
"Use Linear Damping",
true);
252 lblist.set(
"Linear Damping Coefficient",1.e-4);
253 lblist.set(
"Initial Barrier Parameter", mu);
259 RCP<NLP> nlp = rcp(
new HS::Problem_041<RealT>() );
260 RCP<OPT> opt = nlp->getOptimizationProblem();
262 RCP<V> x = opt->getSolutionVector();
263 RCP<V> l = opt->getMultiplierVector();
264 RCP<V> zl = x->clone();
265 RCP<V> zu = x->clone();
267 RCP<V> scratch = x->clone();
269 RCP<PV> x_pv = Teuchos::rcp_dynamic_cast<PV>(x);
273 RCP<V> c = sol->clone();
274 RCP<V> v = sol->clone();
275 RCP<V> jv = sol->clone();
277 RCP<V> c_exact = c->clone();
278 RCP<V> jv_exact = jv->clone();
284 RCP<OBJ> obj = opt->getObjective();
285 RCP<CON> con = opt->getEqualityConstraint();
286 RCP<BND> bnd = opt->getBoundConstraint();
288 PENALTY penalty(obj,bnd,parlist);
290 RCP<const V> maskL = penalty.getLowerMask();
291 RCP<const V> maskU = penalty.getUpperMask();
296 RCP<CON> res = rcp(
new RESIDUAL(obj,con,bnd,*sol,maskL,maskU,scratch,mu,
false) );
299 *outStream <<
"\n[x|lambda|zl|zu]" << std::endl;
302 res->value(*c,*sol,tol);
303 value(*c_exact,*sol,mu);
305 *outStream <<
"\n[cx|clambda|czl|czu]" << std::endl;
309 c->axpy(-1.0,*c_exact);
311 RealT cerror = c->norm();
317 *outStream <<
"\n\n||c-c_exact|| = " << cerror << std::endl;
319 res->applyJacobian(*jv,*v,*sol,tol);
322 *outStream <<
"\n[vx|vlambda|vzl|vzu]" << std::endl;
326 *outStream <<
"\n[jvx|jvlambda|jvzl|jvzu]" << std::endl;
330 jv->axpy(-1.0,*jv_exact);
332 RealT jverror = jv->norm();
334 if( jverror > tol ) {
338 *outStream <<
"\n\n||jv-jv_exact|| = " << jverror << std::endl;
340 *outStream <<
"Residual Jacobian Finite Difference Check" << std::endl;
341 res->checkApplyJacobian(*sol,*v,*v);
346 catch (std::logic_error err) {
347 *outStream << err.what() << std::endl;
352 std::cout <<
"End Result: TEST FAILED" << std::endl;
354 std::cout <<
"End Result: TEST PASSED" << std::endl;
Provides the interface to evaluate objective functions.
PartitionedVector< Real > PV
Defines the linear algebra of vector space on a generic partitioned vector.
int main(int argc, char *argv[])
void RandomizeVector(Vector< Real > &x, const Real &lower=0.0, const Real &upper=1.0)
Fill a ROL::Vector with uniformly-distributed random numbers in the interval [lower,upper].
Symmetrized form of the KKT operator for the Type-EB problem with equality and bound multipliers...
Teuchos::RCP< Vector< Real > > CreatePartitionedVector(const Teuchos::RCP< Vector< Real > > &a)
Defines the linear algebra or vector space interface.
void applyJacobian(ROL::Vector< Real > &jv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &sol)
Provides the interface to evaluate the Interior Pointy log barrier penalty function with upper and lo...
Defines the equality constraint operator interface.
Provides the interface to apply upper and lower bound constraints.
void printVector(const ROL::Vector< Real > &x, std::ostream &outStream)
void value(ROL::Vector< Real > &c, const ROL::Vector< Real > &sol, const Real &mu)