00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <math.h>
00030
00031 #include "NLPInterfacePack_NLPWBCounterExample.hpp"
00032 #include "DenseLinAlgPack_PermVecMat.hpp"
00033 #include "DenseLinAlgPack_LinAlgOpPack.hpp"
00034 #include "Teuchos_TestForException.hpp"
00035
00036 namespace NLPInterfacePack {
00037
00038
00039
00040 NLPWBCounterExample::NLPWBCounterExample(
00041 value_type xinit[3], value_type a, value_type b, bool nlp_selects_basis, bool linear_obj
00042 )
00043 :is_initialized_(false),nlp_selects_basis_(nlp_selects_basis),basis_selection_was_given_(false)
00044 ,linear_obj_(linear_obj),n_orig_(3),m_orig_(2),Gc_orig_nz_(4),a_(a),b_(b)
00045 {
00046 #ifdef TEUCHOS_DEBUG
00047 const char msg_err_head[] = "NLPWBCounterExample::NLPWBCounterExample(...) : Error";
00048 TEST_FOR_EXCEPTION( !(b >= 0), std::invalid_argument, msg_err_head<<"!" );
00049 TEST_FOR_EXCEPTION( !(a + b*b != 0), std::invalid_argument, msg_err_head<<"!" );
00050 TEST_FOR_EXCEPTION( !(xinit[1] >= 0), std::invalid_argument, msg_err_head<<"!" );
00051 TEST_FOR_EXCEPTION( !(xinit[2] >= 0), std::invalid_argument, msg_err_head<<"!" );
00052 #endif
00053
00054 xinit_orig_.resize(n_orig_); xl_orig_.resize(n_orig_); xu_orig_.resize(n_orig_);
00055 const value_type inf = NLP::infinite_bound();
00056 xinit_orig_(1) = xinit[0]; xl_orig_(1) = -inf; xu_orig_(1) = +inf;
00057 xinit_orig_(2) = xinit[1]; xl_orig_(2) = 0.0; xu_orig_(2) = +inf;
00058 xinit_orig_(3) = xinit[2]; xl_orig_(3) = 0.0; xu_orig_(3) = +inf;
00059 }
00060
00061
00062
00063 void NLPWBCounterExample::initialize(bool test_setup)
00064 {
00065
00066 NLPSerialPreprocessExplJac::initialize(test_setup);
00067 is_initialized_ = true;
00068 }
00069
00070 bool NLPWBCounterExample::is_initialized() const
00071 {
00072 return is_initialized_;
00073 }
00074
00075 value_type NLPWBCounterExample::max_var_bounds_viol() const
00076 {
00077 return +1e+20;
00078 }
00079
00080
00081
00082 bool NLPWBCounterExample::imp_nlp_has_changed() const
00083 {
00084 return !is_initialized_;
00085 }
00086
00087 size_type NLPWBCounterExample::imp_n_orig() const
00088 {
00089 return n_orig_;
00090 }
00091
00092 size_type NLPWBCounterExample::imp_m_orig() const
00093 {
00094 return m_orig_;
00095 }
00096
00097 size_type NLPWBCounterExample::imp_mI_orig() const
00098 {
00099 return 0;
00100 }
00101
00102 const DVectorSlice NLPWBCounterExample::imp_xinit_orig() const
00103 {
00104 return xinit_orig_();
00105 }
00106
00107 bool NLPWBCounterExample::imp_has_var_bounds() const
00108 {
00109 return true;
00110 }
00111
00112 const DVectorSlice NLPWBCounterExample::imp_xl_orig() const
00113 {
00114 return xl_orig_();
00115 }
00116
00117 const DVectorSlice NLPWBCounterExample::imp_xu_orig() const
00118 {
00119 return xu_orig_();
00120 }
00121
00122 const DVectorSlice NLPWBCounterExample::imp_hl_orig() const
00123 {
00124 TEST_FOR_EXCEPT(true);
00125 return xinit_orig_();
00126 }
00127
00128 const DVectorSlice NLPWBCounterExample::imp_hu_orig() const
00129 {
00130 TEST_FOR_EXCEPT(true);
00131 return xinit_orig_();
00132 }
00133
00134 void NLPWBCounterExample::imp_calc_f_orig(
00135 const DVectorSlice &x_full, bool newx, const ZeroOrderInfoSerial &zero_order_info ) const
00136 {
00137 DVectorSlice x = x_full(1,n_orig_);
00138 *zero_order_info.f = ( linear_obj_ ? x(1) : 0.5*x(1)*x(1) );
00139 }
00140
00141 void NLPWBCounterExample::imp_calc_c_orig(
00142 const DVectorSlice &x_full, bool newx, const ZeroOrderInfoSerial &zero_order_info ) const
00143 {
00144 DVectorSlice x = x_full(1,n_orig_);
00145 DVector &c = *zero_order_info.c;
00146 c(1) = x(1)*x(1) - x(2) + a_;
00147 c(2) = x(1) - x(3) - b_;
00148 }
00149
00150 void NLPWBCounterExample::imp_calc_h_orig(
00151 const DVectorSlice &x_full, bool newx, const ZeroOrderInfoSerial &zero_order_info ) const
00152 {
00153 TEST_FOR_EXCEPT(true);
00154 }
00155
00156 void NLPWBCounterExample::imp_calc_Gf_orig(
00157 const DVectorSlice &x_full, bool newx, const ObjGradInfoSerial &obj_grad_info ) const
00158 {
00159 DVectorSlice x = x_full(1,n_orig_);
00160 DVector &Gf = *obj_grad_info.Gf;
00161 Gf(1) = (linear_obj_ ? 1.0 : x(1) ); Gf(2) = 0.0; Gf(3) = 0.0;
00162 }
00163
00164 bool NLPWBCounterExample::imp_get_next_basis(
00165 IVector *var_perm_full
00166 ,IVector *equ_perm_full
00167 ,size_type *rank_full
00168 ,size_type *rank
00169 )
00170 {
00171 #ifdef TEUCHOS_DEBUG
00172 assert(var_perm_full); assert(equ_perm_full); assert(rank_full); assert(rank);
00173 #endif
00174 if(basis_selection_was_given_) return false;
00175
00176 var_perm_full->resize(n_orig_);
00177 (*var_perm_full)(1) = 2;
00178 (*var_perm_full)(2) = 3;
00179 (*var_perm_full)(3) = 1;
00180 equ_perm_full->resize(m_orig_);
00181 DenseLinAlgPack::identity_perm( equ_perm_full );
00182 *rank_full = m_orig_;
00183 *rank = m_orig_;
00184 basis_selection_was_given_ = true;
00185 return true;
00186 }
00187
00188 void NLPWBCounterExample::imp_report_orig_final_solution(
00189 const DVectorSlice &x_orig
00190 ,const DVectorSlice *lambda_orig
00191 ,const DVectorSlice *lambdaI_orig
00192 ,const DVectorSlice *nu_orig
00193 ,bool is_optimal
00194 ) const
00195 {
00196
00197 }
00198
00199 bool NLPWBCounterExample::nlp_selects_basis() const
00200 {
00201 return nlp_selects_basis_;
00202 }
00203
00204
00205
00206 size_type NLPWBCounterExample::imp_Gc_nz_orig() const
00207 {
00208 return Gc_orig_nz_;
00209 }
00210
00211 size_type NLPWBCounterExample::imp_Gh_nz_orig() const
00212 {
00213 return 0;
00214 }
00215
00216 void NLPWBCounterExample::imp_calc_Gc_orig(
00217 const DVectorSlice& x_full, bool newx, const FirstOrderExplInfo& first_order_expl_info ) const
00218 {
00219 DVectorSlice x = x_full(1,n_orig_);
00220
00221 index_type &Gc_nz = *first_order_expl_info.Gc_nz;
00222 value_type *Gc_v = &(*first_order_expl_info.Gc_val)[0];
00223 index_type *Gc_i = ( first_order_expl_info.Gc_ivect ? &(*first_order_expl_info.Gc_ivect)[0] : NULL );
00224 index_type *Gc_j = ( first_order_expl_info.Gc_jvect ? &(*first_order_expl_info.Gc_jvect)[0] : NULL );
00225
00226 if( Gc_i ) {
00227 Gc_j[0] = 1; Gc_i[0] = 1;
00228 Gc_j[1] = 1; Gc_i[1] = 2;
00229 Gc_j[2] = 2; Gc_i[2] = 1;
00230 Gc_j[3] = 2; Gc_i[3] = 3;
00231 }
00232
00233 Gc_v[0] = 2*x(1);
00234 Gc_v[1] = -1.0;
00235 Gc_v[2] = +1.0;
00236 Gc_v[3] = -1.0;
00237
00238 Gc_nz = Gc_orig_nz_;
00239 }
00240
00241 void NLPWBCounterExample::imp_calc_Gh_orig(
00242 const DVectorSlice& x_full, bool newx, const FirstOrderExplInfo& first_order_expl_info ) const
00243 {
00244 TEST_FOR_EXCEPT(true);
00245 }
00246
00247 }