29 #include "Teuchos_GlobalMPISession.hpp"
38 ROL::Ptr<ROL::Objective<Real>>
42 auto op = ROL::makePtr<ROL::DiagonalOperator<Real>>(a);
45 auto obj = ROL::makePtr<ROL::QuadraticObjective<Real>>(op,vec);
51 int main(
int argc,
char *argv[]) {
58 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
62 int iprint = argc - 1;
63 ROL::Ptr<std::ostream> outStream;
66 outStream = ROL::makePtrFromRef(std::cout);
68 outStream = ROL::makePtrFromRef(bhs);
74 auto parlist = ROL::getParametersFromXmlFile(
"binary_constraint.xml");
79 RealT INF = ROL::ROL_INF<RealT>();
80 RealT NINF = ROL::ROL_NINF<RealT>();
85 auto x0_ptr = ROL::makePtr<std::vector<RealT>>(4);
86 auto x0 = ROL::makePtr<SV>(x0_ptr);
89 auto x = x0->clone(); x->set(*x0);
94 auto d_ptr = ROL::makePtr<std::vector<RealT>>(4);
95 auto d = ROL::makePtr<SV>(d_ptr);
98 auto b_ptr = ROL::makePtr<std::vector<RealT>>(4);
99 auto b = ROL::makePtr<SV>(b_ptr);
102 (*b_ptr)[0] = 1.0; (*b_ptr)[1] = 1.0;
103 (*b_ptr)[2] = 1.0; (*b_ptr)[3] = 1.0;
105 (*d_ptr)[0] = 1.0; (*d_ptr)[1] = 2.0;
106 (*d_ptr)[2] = 4.0; (*d_ptr)[3] = 8.0;
116 auto xl_ptr = ROL::makePtr<std::vector<RealT>>(4);
117 auto xl = ROL::makePtr<SV>(xl_ptr);
120 auto xu_ptr = ROL::makePtr<std::vector<RealT>>(4);
121 auto xu = ROL::makePtr<SV>(xu_ptr);
124 (*xl_ptr)[0] = 0.0; (*xl_ptr)[1] = 0.0;
125 (*xl_ptr)[2] = NINF; (*xl_ptr)[3] = NINF;
127 (*xu_ptr)[0] = 1.0; (*xu_ptr)[1] = INF;
128 (*xu_ptr)[2] = 1.0; (*xu_ptr)[3] = INF;
131 auto bnd = ROL::makePtr<ROL::Bounds<RealT>>(xl,xu);
135 auto con = ROL::makePtr<ROL::BinaryConstraint<RealT>>( bnd, gamma );
138 auto l = x->dual().clone();
139 ROL::Elementwise::Fill<RealT> FillWithOnes(1.0);
140 l->applyUnary( ROL::Elementwise::Fill<RealT>(1.0) );
149 problem_E.
check( *outStream );
154 parlist->sublist(
"Step").set(
"Type",
"Composite Step");
156 solver_cs.
solve( *outStream );
157 *outStream <<
"\n\nFinal optimization vector:";
158 x->print(*outStream);
161 x->set(*x0); l->applyUnary(FillWithOnes);
166 parlist->sublist(
"Step").set(
"Type",
"Augmented Lagrangian");
168 solver_al.
solve( *outStream );
169 *outStream <<
"\n\nFinal optimization vector:";
170 x->print(*outStream);
174 x->set(*x0); l->applyUnary(FillWithOnes);
179 parlist->sublist(
"Step").set(
"Type",
"Moreau-Yosida Penalty");
181 solver_my.
solve( *outStream );
182 *outStream <<
"\n\nFinal optimization vector:";
183 x->print(*outStream);
188 catch (std::logic_error& err) {
189 *outStream << err.what() <<
"\n";
194 std::cout <<
"End Result: TEST FAILED\n";
196 std::cout <<
"End Result: TEST PASSED\n";
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
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].
Defines the linear algebra or vector space interface.
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
Provides a simplified interface for solving a wide range of optimization problems.
basic_nullstream< char, char_traits< char >> nullstream
ROL::Ptr< ROL::Objective< Real > > createDiagonalQuadraticObjective(const ROL::Vector< Real > &a, const ROL::Vector< Real > &b)
int main(int argc, char *argv[])
void check(std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
int solve(const ROL::Ptr< StatusTest< Real > > &status=ROL::nullPtr, const bool combineStatus=true)
Solve optimization problem with no iteration output.