47 #include "NLPInterfacePack_NLPTester.hpp"
48 #include "NLPInterfacePack_NLP.hpp"
49 #include "AbstractLinAlgPack_VectorSpace.hpp"
50 #include "AbstractLinAlgPack_VectorMutable.hpp"
51 #include "AbstractLinAlgPack_VectorOut.hpp"
52 #include "AbstractLinAlgPack_VectorStdOps.hpp"
53 #include "AbstractLinAlgPack_VectorAuxiliaryOps.hpp"
54 #include "AbstractLinAlgPack_assert_print_nan_inf.hpp"
55 #include "TestingHelperPack_update_success.hpp"
57 namespace NLPInterfacePack {
63 :print_all_(print_all), throw_exception_(throw_exception)
69 ,
bool print_all_warnings
73 using TestingHelperPack::update_success;
74 using AbstractLinAlgPack::assert_print_nan_inf;
80 *out << std::boolalpha
82 <<
"**************************************\n"
83 <<
"*** NLPTester::test_interface(...) ***\n"
84 <<
"**************************************\n";
91 *out <<
"\nnlp->force_xinit_in_bounds(true)";
94 *out <<
"\nnlp->initialize(true)\n";
101 *out <<
"\n*** Dimensions of the NLP ...\n"
102 <<
"\nnlp->n() = " << n
103 <<
"\nnlp->m() = " << m
107 *out <<
"Error! n = " << n <<
" < m = " << m <<
" is not allowed!\n";
109 throw_exception_, std::logic_error
110 ,
"NLPTester::test_interface(...): Error! n = " << n <<
" < m = " << m <<
" is not allowed!"
116 *out <<
"\n*** Validate the dimensions of the vector spaces ...\n";
118 result = nlp->space_x()->
dim() == nlp->
n();
119 update_success( result, &success );
121 *out <<
"\ncheck: nlp->space_x()->dim() = " << nlp->space_x()->
dim()
122 <<
" == nlp->n() = " << nlp->
n() <<
": " << result << std::endl;
125 result = nlp->space_c()->
dim() == nlp->
m();
126 update_success( result, &success );
128 *out <<
"\ncheck: nlp->space_c()->dim() = " << nlp->space_c()->
dim()
129 <<
" == nlp->m() = " << nlp->
m() <<
": " << result << std::endl;
132 result = nlp->space_c().get() == NULL;
133 update_success( result, &success );
135 *out <<
"\ncheck: nlp->space_c().get() = " << nlp->space_c().get()
136 <<
" == NULL: " << result << std::endl;
141 *out <<
"\n*** Validate that the initial starting point is in bounds ...\n";
142 const Vector &xinit = nlp->
xinit();
143 if(out) *out <<
"\n||nlp->xinit()||inf = " << xinit.
norm_inf() << std::endl;
144 if(out && print_all()) *out <<
"\nnlp->xinit() =\n" << xinit;
145 assert_print_nan_inf(xinit,
"xinit",
true,out);
149 if(out && print_all())
150 *out <<
"\nnlp->xl() =\n" << xl
151 <<
"\nnlp->xu() =\n" << xu;
152 assert_print_nan_inf(xl,
"xl",
true,out);
153 assert_print_nan_inf(xu,
"xu",
true,out);
156 VectorSpace::vec_mut_ptr_t
159 std::pair<value_type,value_type>
161 xinit, *d, nlp->
xl(), nlp->
xu(), 0.0
163 result = u.first >= 0.0;
164 update_success( result, &success );
166 *out <<
"\ncheck: xl <= x <= xu : " << result;
168 *out <<
"\nxinit is in bounds with { max |u| | xl <= x + u <= xu } -> "
169 << ( u.first > -u.second ? u.first : u.second ) << std::endl;
176 update_success( result, &success );
178 *out <<
"\ncheck: num_bounded(nlp->xl(),nlp->xu()) = " << num_bounded_x
180 <<
": " << result << std::endl;
184 *out <<
"\nGetting the initial estimates for the Lagrange mutipliers ...\n";
185 VectorSpace::vec_mut_ptr_t lambda, nu;
189 : (VectorMutable*)NULL )
192 : (VectorMutable*)NULL )
197 *out <<
"\n||lambda||inf = " << lambda->norm_inf();
199 *out <<
"\n||nu||inf = " << nu->norm_inf()
200 <<
"\nnu.nz() = " << nu->nz();
204 *out <<
"\nlambda =\n" << *lambda;
206 *out <<
"\nnu =\n" << *nu;
210 assert_print_nan_inf(*lambda,
"lambda",
true,out);
212 assert_print_nan_inf(*nu,
"nu",
true,out);
215 value_type *f_saved = NULL;
216 VectorMutable *c_saved = NULL;
217 f_saved = nlp->
get_f();
218 if( nlp->
m() ) c_saved = nlp->
get_c();
222 VectorSpace::vec_mut_ptr_t c;
228 if( nlp->
m() ) nlp->
set_c(c.get());
233 *out <<
"\n*** Evaluate the point xo ...\n";
235 if(out) *out <<
"\n||xo||inf = " << xo.norm_inf() << std::endl;
236 if(out && print_all()) *out <<
"\nxo =\n" << xo;
237 assert_print_nan_inf(xo,
"xo",
true,out);
240 if(nlp->
m()) nlp->
calc_c(xo,
false);
243 *out <<
"\nf(xo) = " << f;
245 *out <<
"\n||c(xo)||inf = " << nlp->
c().
norm_inf();
249 *out <<
"\nc(xo) =\n" << nlp->
c();
254 assert_print_nan_inf(*c,
"c(xo)",
true,out);
258 *out <<
"\n*** Report this point to the NLP as suboptimal ...\n";
263 *out <<
"\n*** Print the number of evaluations ...\n";
264 *out <<
"\nnlp->num_f_evals() = " << nlp->
num_f_evals();
266 *out <<
"\nnlp->num_c_evals() = " << nlp->
num_c_evals();
272 if(nlp->
m()) nlp->
set_c(c_saved);
275 catch(
const std::exception& except) {
277 *out <<
"Caught a std::exception: " << except.what() << std::endl;
279 if(throw_exception())
284 *out <<
"Caught an unknown exception!\n";
286 if(throw_exception())
virtual void calc_c(const Vector &x, bool newx=true) const
Update the constraint residual vector for c at the point x and put it in the stored reference...
virtual void report_final_solution(const Vector &x, const Vector *lambda, const Vector *nu, bool is_optimal)
Used by the solver to report the final solution and multipliers.
bool test_interface(NLP *nlp, const Vector &xo, bool print_all_warnings, std::ostream *out)
Test the NLP interface as the given base point xo.
virtual size_type num_c_evals() const
Gives the number of constraint function c(x) evaluations called by the solver since initialize() was ...
virtual value_type norm_inf() const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual void get_init_lagrange_mult(VectorMutable *lambda, VectorMutable *nu) const
Get the initial value of the Lagrange multipliers lambda.
virtual void calc_f(const Vector &x, bool newx=true) const
Update the value for the objective f at the point x and put it in the stored reference.
virtual size_type n() const
Return the number of variables.
virtual const Vector & xl() const =0
Returns the lower bounds on the variables x.
virtual size_type num_bounded_x() const =0
Returns the number of variables in x(i) for which xl(i)> -infinite_bound() or xu(i) < +infinite_bound...
virtual void set_c(VectorMutable *c)
Set a pointer to a vector to be updated when this->calc_c() is called.
virtual const Vector & xu() const =0
Returns a reference to the vector of upper bounds on the variables x.
virtual value_type * get_f()
Return pointer passed to this->set_f().
size_type num_bounded(const Vector &xl, const Vector &xu, value_type inf_bound)
virtual void force_xinit_in_bounds(bool force_xinit_in_bounds)=0
Set if the initial point must be within the bounds.
NLP interface class {abstract}.
NLPTester(bool print_all=false, bool throw_exception=true)
Constructor (default options)
virtual index_type dim() const =0
std::pair< value_type, value_type > max_near_feas_step(const Vector &x, const Vector &d, const Vector &xl, const Vector &xu, value_type max_bnd_viol)
virtual vec_mut_ptr_t create_member() const =0
virtual const Vector & xinit() const =0
Returns a reference to the vector of the initial guess for the solution x.
virtual size_type m() const
Return the number of general equality constraints.
virtual void initialize(bool test_setup=false)
Initialize the NLP before it is used.
virtual size_type num_f_evals() const
Gives the number of object function f(x) evaluations called by the solver since initialize() was call...
static value_type infinite_bound()
Value for an infinite bound.
virtual VectorMutable * get_c()
Return pointer passed to this->set_c().
virtual void set_f(value_type *f)
Set a pointer to an value to be updated when this->calc_f() is called.
virtual VectorMutable & c()
Returns non-const *this->get_c().