| 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 |
#include "Teuchos_GlobalMPISession.hpp" |
| 11 |
#include "compressed_sensing.hpp" |
| 12 |
#include "ROL_OptimizationSolver.hpp" |
| 13 |
#include <iostream> |
| 14 |
|
| 15 |
using OrdinalT = int; |
| 16 |
using RealT = double; |
| 17 |
using ROL::Ptr; |
| 18 |
using ROL::makePtr; |
| 19 |
|
| 20 |
using VectorT = ROL::Vector<RealT>; |
| 21 |
using ObjectiveT = ROL::Objective<RealT>; |
| 22 |
using ConstraintT = ROL::Constraint<RealT>; |
| 23 |
|
| 24 |
using TeuchosVectorT = ROL::TeuchosVector<OrdinalT,RealT>; |
| 25 |
|
| 26 |
int main( int argc, char* argv[] ) { |
| 27 |
|
| 28 |
Teuchos::GlobalMPISession mpiSession(&argc, &argv); |
| 29 |
|
| 30 |
ROL::Ptr<std::ostream> os_ptr; |
| 31 |
ROL::nullstream bhs; |
| 32 |
os_ptr = ROL::makePtrFromRef(argc > 1 ? std::cout : bhs); |
| 33 |
auto& os = *os_ptr; |
| 34 |
|
| 35 |
int errorFlag{0}; |
| 36 |
|
| 37 |
try { |
| 38 |
|
| 39 |
std::string paramfile = "input.xml"; |
| 40 |
auto parlist = ROL::getParametersFromXmlFile(paramfile); |
| 41 |
|
| 42 |
int rows{4}, cols{12}; |
| 43 |
|
| 44 |
Ptr<ObjectiveT> obj = make_CompressedSensingObjective<OrdinalT,RealT>(rows,cols); |
| 45 |
Ptr<VectorT> x = makePtr<TeuchosVectorT>(cols); |
| 46 |
|
| 47 |
auto v = x->clone(); |
| 48 |
x->randomize(-1.0,1.0); |
| 49 |
v->randomize(-1.0,1.0); |
| 50 |
|
| 51 |
RealT gamma = 1e-2; |
| 52 |
|
| 53 |
auto opt = ROL::make_l1_penalty_problem( obj, x, gamma ); |
| 54 |
ROL::OptimizationSolver<RealT> solver(*opt, *parlist); |
| 55 |
solver.solve(os); |
| 56 |
} catch( std::exception& e ) { |
| 57 |
os << e.what() << std::endl; |
| 58 |
errorFlag = -1000; |
| 59 |
}; // end try |
| 60 |
|
| 61 |
if(errorFlag==0) |
| 62 |
std::cout << "End Result: TEST PASSED" << std::endl; |
| 63 |
else |
| 64 |
std::cout << "End Result: TEST FAILED" << std::endl; |
| 65 |
|
| 66 |
return 0; |
| 67 |
} |