44 #include "NLPInterfacePack_ExampleNLPBanded.hpp"
45 #include "DenseLinAlgPack_PermVecMat.hpp"
46 #include "DenseLinAlgPack_LinAlgOpPack.hpp"
47 #include "Teuchos_Assert.hpp"
49 namespace NLPInterfacePack {
53 ExampleNLPBanded::ExampleNLPBanded(
66 ,
bool nlp_selects_basis
72 ,
bool ignore_constraints
74 :is_initialized_(false)
75 ,nlp_selects_basis_(nlp_selects_basis)
76 ,basis_selection_was_given_(false)
77 ,has_var_bounds_(false)
84 ,ignore_constraints_(ignore_constraints)
85 ,diag_scal_(diag_scal)
86 ,diag_vary_(diag_vary)
87 ,fu_( sym_basis ? 3 : 6 )
90 const char msg_err_head[] =
"ExampleNLPBanded::ExampleNLPBanded(...) : Error";
92 nD <= 0, std::invalid_argument
95 nI <= 0 || nD < nI, std::invalid_argument
98 bw < 1 || nD < bw, std::invalid_argument
101 mU < 0, std::invalid_argument
102 ,msg_err_head<<
"!" );
104 mI < 0, std::invalid_argument
105 ,msg_err_head<<
"!" );
107 mU != 0, std::invalid_argument
108 ,msg_err_head<<
", can't handle undecomposed equalities yet!" );
110 Gc_orig_nz_ = nD_ * ( 1 + 2*(bw_-1) + nI_ );
113 xinit_orig_.resize(nD_ + nI_);
114 xl_orig_.resize(xinit_orig_.dim());
115 xu_orig_.resize(xinit_orig_.dim());
116 hl_orig_.resize(mI_);
117 hu_orig_.resize(mI_);
118 co_orig_.resize(nD_ + mU_);
121 xl_orig_(1,nD_) = xDl;
122 xu_orig_(1,nD_) = xDu;
123 xl_orig_(nD_+1,nD_+nI_) = xIl;
124 xu_orig_(nD_+1,nD_+nI_) = xIu;
132 if( xDl > -inf || xDu < +inf || xIl > -inf || xIu < +inf )
133 has_var_bounds_ =
true;
135 has_var_bounds_ =
false;
142 if(is_initialized_) {
148 is_initialized_ =
true;
153 return is_initialized_;
165 return !is_initialized_;
175 if(ignore_constraints_)
return 0;
181 if(ignore_constraints_)
return 0;
187 return xinit_orig_();
192 return has_var_bounds_;
216 const DVectorSlice &x_full
221 inform_new_point(newx);
227 const DVectorSlice &x_full
232 inform_new_point(newx);
237 &
c = *zero_order_info.
c;
239 num_I_per_D = nD_ / nI_,
240 I_remainder = nD_ % nI_;
243 ds_alpha = nD_ > 1 ? diag_scal_ * (diag_vary_ - 1.0)/(nD_ - 1.0) : 0.0,
244 ds_beta = diag_scal_;
245 for(
size_type q_i = 1; q_i <= nI_; ++q_i ) {
246 const size_type num_I_per_D_local = num_I_per_D + ( q_i <= I_remainder ? 1 : 0 );
247 for(
size_type q_k = 0; q_k < num_I_per_D_local; ++q_k ) {
250 klu = ( j - bw_ >= 0 ? bw_-1 : j-1 ),
251 kuu = ( j + bw_ - 1 <= nD_ ? bw_-1 : nD_-j );
253 ds_j = ds_alpha * (j-1) + ds_beta;
255 &c_j = (
c(j) = ds_j *
x_full(j));
257 c_j -= (3.0 / k) *
x_full(j-k);
260 c_j -= (fu_ / k) *
x_full(j+k);
263 term =
x_full(nD_ + q_i) + 1;
264 c_j *= (term * term);
268 c_orig_updated_ =
true;
272 const DVectorSlice &x_full
277 inform_new_point(newx);
279 &h = *zero_order_info.
h;
281 num_I_per_D = nD_ / nI_,
282 I_remainder = nD_ % nI_;
284 for(
size_type q_i = 1; q_i <= nI_; ++q_i ) {
285 const value_type x_q =
x_full(nD_ + q_i);
286 const size_type num_I_per_D_local = num_I_per_D + ( q_i <= I_remainder ? 1 : 0 );
287 for(
size_type q_k = 0; q_k < num_I_per_D_local; ++q_k ) {
289 if( jI > mI_ )
return;
296 const DVectorSlice &x_full
301 inform_new_point(newx);
303 (*obj_grad_info.
Gf)(var_orig) =
x_full(var_orig);
307 IVector *var_perm_full
308 ,IVector *equ_perm_full
313 if(basis_selection_was_given_)
328 var_perm_full->resize(n_full);
329 equ_perm_full->resize(m_full);
331 index_type k, i_perm = 1;;
333 for( k = 1; k <= nD_; ++k, ++i_perm )
334 (*var_perm_full)(i_perm) = k;
335 for( k = 1; k <= mI_; ++k, ++i_perm )
336 (*var_perm_full)(i_perm) = n_orig + k;
338 for( k = 1; k <= nI_; ++k, ++i_perm )
339 (*var_perm_full)(i_perm) = nD_ + k;
342 DenseLinAlgPack::identity_perm( var_perm_full );
344 DenseLinAlgPack::identity_perm( equ_perm_full );
347 index_type num_fixed = 0;
348 for( index_type k = 1; k <= nD_; ++k ) {
349 if( xl_orig_(k) == xu_orig_(k) )
353 for( index_type k = 1; k <= mI_; ++k ) {
354 if( hl_orig_(k) == hu_orig_(k) )
360 *rank = m_full - num_fixed;
361 basis_selection_was_given_ =
true;
366 const DVectorSlice &x_orig
367 ,
const DVectorSlice *lambda_orig
368 ,
const DVectorSlice *lambdaI_orig
369 ,
const DVectorSlice *nu_orig
378 return nlp_selects_basis_;
394 const DVectorSlice& x_full,
bool newx
398 inform_new_point(newx);
403 &
c = *first_order_expl_info.
c;
406 &Gc_nz = *first_order_expl_info.
Gc_nz;
408 *Gc_val = &(*first_order_expl_info.
Gc_val)[0];
410 *Gc_ivect = ( first_order_expl_info.
Gc_ivect
411 ? &(*first_order_expl_info.
Gc_ivect)[0] : NULL ),
412 *Gc_jvect = ( first_order_expl_info.
Gc_jvect
413 ? &(*first_order_expl_info.
Gc_jvect)[0] : NULL );
417 num_I_per_D = nD_ / nI_,
418 I_remainder = nD_ % nI_;
422 ds_alpha = nD_ > 1 ? diag_scal_ * (diag_vary_ - 1.0)/(nD_ - 1.0) : 0.0,
423 ds_beta = diag_scal_;
424 for(
size_type q_i = 1; q_i <= nI_; ++q_i ) {
427 x_q_term = (x_q + 1) * (x_q + 1);
428 const size_type num_I_per_D_local = num_I_per_D + ( q_i <= I_remainder ? 1 : 0 );
429 for(
size_type q_k = 0; q_k < num_I_per_D_local; ++q_k ) {
432 klu = ( j - bw_ >= 0 ? bw_-1 : j-1 ),
433 kuu = ( j + bw_ - 1 <= nD_ ? bw_-1 : nD_-j );
435 ds_j = ds_alpha * (j-1) + ds_beta;
437 {
for( index_type k = klu; k >= 1; --k ) {
439 *Gc_val++ = -3.0 / k * x_q_term;
447 *Gc_val++ = ds_j * x_q_term;
453 {
for( index_type k = 1; k <= kuu; ++k ) {
455 *Gc_val++ = -fu_ / k * x_q_term;
463 *Gc_val++ = 2.0 * (
c(j) - co_orig_(j)) / (x_q + 1);
465 *Gc_ivect++ = nD_ + q_i;
473 const DVectorSlice& x_full,
bool newx
477 inform_new_point(newx);
480 &Gh_nz = *first_order_expl_info.
Gh_nz;
482 *Gh_val = &(*first_order_expl_info.
Gh_val)[0];
484 *Gh_ivect = ( first_order_expl_info.
Gh_ivect
485 ? &(*first_order_expl_info.
Gh_ivect)[0] : NULL ),
486 *Gh_jvect = ( first_order_expl_info.
Gh_jvect
487 ? &(*first_order_expl_info.
Gh_jvect)[0] : NULL );
491 num_I_per_D = nD_ / nI_,
492 I_remainder = nD_ % nI_;
495 for(
size_type q_i = 1; q_i <= nI_; ++q_i ) {
497 const size_type num_I_per_D_local = num_I_per_D + ( q_i <= I_remainder ? 1 : 0 );
498 for(
size_type q_k = 0; q_k < num_I_per_D_local; ++q_k ) {
500 if( jI > mI_ )
return;
512 *Gh_ivect++ = nD_q_i;
521 void ExampleNLPBanded::assert_is_initialized()
const
526 void ExampleNLPBanded::inform_new_point(
bool newx)
const
529 c_orig_updated_ =
false;
size_type imp_mI_orig() const
size_type imp_Gh_nz_orig() const
bool nlp_selects_basis() const
size_type imp_n_orig() const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
bool is_initialized() const
DVectorSlice x_full() const
size_type imp_Gc_nz_orig() const
const DVectorSlice imp_xu_orig() const
const DVectorSlice imp_hu_orig() const
bool imp_nlp_has_changed() const
bool imp_get_next_basis(IVector *var_perm_full, IVector *equ_perm_full, size_type *rank_full, size_type *rank)
void initialize(bool test_setup)
void imp_calc_h_orig(const DVectorSlice &x_full, bool newx, const ZeroOrderInfoSerial &zero_order_info) const
void imp_calc_Gc_orig(const DVectorSlice &x_full, bool newx, const FirstOrderExplInfo &first_order_expl_info) const
value_type dot(const Vector &v_rhs1, const Vector &v_rhs2)
void imp_calc_c_orig(const DVectorSlice &x_full, bool newx, const ZeroOrderInfoSerial &zero_order_info) const
value_type max_var_bounds_viol() const
const DVectorSlice imp_hl_orig() const
const ZeroOrderInfoSerial zero_order_orig_info() const
void imp_calc_Gf_orig(const DVectorSlice &x_full, bool newx, const ObjGradInfoSerial &obj_grad_info) const
void imp_calc_f_orig(const DVectorSlice &x_full, bool newx, const ZeroOrderInfoSerial &zero_order_info) const
void imp_report_orig_final_solution(const DVectorSlice &x_orig, const DVectorSlice *lambda_orig, const DVectorSlice *lambdaI_orig, const DVectorSlice *nu_orig, bool is_optimal)
const DVectorSlice imp_xinit_orig() const
static value_type infinite_bound()
size_type imp_m_orig() const
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
void imp_calc_Gh_orig(const DVectorSlice &x_full, bool newx, const FirstOrderExplInfo &first_order_expl_info) const
virtual VectorMutable & c()
void initialize(bool test_setup)
bool imp_has_var_bounds() const
const DVectorSlice imp_xl_orig() const