61 #include "Teuchos_oblackholestream.hpp" 62 #include "Teuchos_GlobalMPISession.hpp" 63 #include "Teuchos_XMLParameterListHelpers.hpp" 71 Teuchos::RCP<ROL::Objective<Real>>
84 int main(
int argc,
char *argv[]) {
89 using Teuchos::RCP;
using Teuchos::rcp;
91 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
95 int iprint = argc - 1;
96 Teuchos::RCP<std::ostream> outStream;
97 Teuchos::oblackholestream bhs;
99 outStream = Teuchos::rcp(&std::cout,
false);
101 outStream = Teuchos::rcp(&bhs,
false);
107 auto parlist = Teuchos::getParametersFromXmlFile(
"binary_constraint.xml");
112 RealT INF = ROL::ROL_INF<RealT>();
113 RealT NINF = ROL::ROL_NINF<RealT>();
118 auto x0_rcp = rcp(
new std::vector<RealT>(4) );
119 auto x0 = rcp(
new SV(x0_rcp) );
122 auto x = x0->clone(); x->set(*x0);
127 auto d_rcp = rcp(
new std::vector<RealT>(4) );
128 auto d = rcp(
new SV(d_rcp) );
131 auto b_rcp = rcp(
new std::vector<RealT>(4) );
132 auto b = rcp(
new SV(b_rcp) );
135 (*b_rcp)[0] = 1.0; (*b_rcp)[1] = 1.0;
136 (*b_rcp)[2] = 1.0; (*b_rcp)[3] = 1.0;
138 (*d_rcp)[0] = 1.0; (*d_rcp)[1] = 2.0;
139 (*d_rcp)[2] = 4.0; (*d_rcp)[3] = 8.0;
149 auto xl_rcp = rcp(
new std::vector<RealT>(4) );
150 auto xl = rcp(
new SV(xl_rcp) );
153 auto xu_rcp = rcp(
new std::vector<RealT>(4) );
154 auto xu = rcp(
new SV(xu_rcp) );
157 (*xl_rcp)[0] = 0.0; (*xl_rcp)[1] = 0.0;
158 (*xl_rcp)[2] = NINF; (*xl_rcp)[3] = NINF;
160 (*xu_rcp)[0] = 1.0; (*xu_rcp)[1] = INF;
161 (*xu_rcp)[2] = 1.0; (*xu_rcp)[3] = INF;
171 auto l = x->dual().clone();
172 ROL::Elementwise::Fill<RealT> FillWithOnes(1.0);
173 l->applyUnary( ROL::Elementwise::Fill<RealT>(1.0) );
182 problem_E.
check( *outStream );
187 parlist->sublist(
"Step").set(
"Type",
"Composite Step");
189 solver_cs.
solve( *outStream );
190 *outStream <<
"\n\nFinal optimization vector:";
191 x->print(*outStream);
194 x->set(*x0); l->applyUnary(FillWithOnes);
199 parlist->sublist(
"Step").set(
"Type",
"Augmented Lagrangian");
201 solver_al.
solve( *outStream );
202 *outStream <<
"\n\nFinal optimization vector:";
203 x->print(*outStream);
207 x->set(*x0); l->applyUnary(FillWithOnes);
212 parlist->sublist(
"Step").set(
"Type",
"Moreau-Yosida Penalty");
214 solver_my.
solve( *outStream );
215 *outStream <<
"\n\nFinal optimization vector:";
216 x->print(*outStream);
221 catch (std::logic_error err) {
222 *outStream << err.what() <<
"\n";
227 std::cout <<
"End Result: TEST FAILED\n";
229 std::cout <<
"End Result: TEST PASSED\n";
Implements an equality constraint function that evaluates to zero on the surface of a bounded paralle...
Provides the interface to evaluate quadratic objective functions.
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].
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
Defines the linear algebra or vector space interface.
int main(int argc, char *argv[])
Provides the interface to apply a diagonal operator which acts like elementwise multiplication when a...
Provides the std::vector implementation of the ROL::Vector interface.
Provides the interface to apply upper and lower bound constraints.
Provides a simplified interface for solving a wide range of optimization problems.
Teuchos::RCP< ROL::Objective< Real > > createDiagonalQuadraticObjective(const ROL::Vector< Real > &a, const ROL::Vector< Real > &b)
void check(std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)