49 #include "AbstractLinAlgPack/src/AbstractLinAlgPack_SpVectorClass.hpp"
51 #include "MiWorkspacePack.h"
53 namespace MoochoPack {
56 const ActSetStats &stats
62 typedef ActSetStats ASS;
64 num_active_indep = stats.num_active_indep(),
65 num_adds_indep = stats.num_adds_indep(),
66 num_drops_indep = stats.num_drops_indep();
69 = ( num_adds_indep == ASS::NOT_KNOWN || num_drops_indep == ASS::NOT_KNOWN || num_active_indep == 0
71 : std::_MAX(((
double)(num_active_indep)-num_adds_indep-num_drops_indep) / num_active_indep, 0.0 ) );
72 const bool act_set_calmed_down = ( num_active_indep > 0 && frac_same >= act_set_frac_proj_start );
74 out <<
"\nnum_active_indep = " << num_active_indep;
75 if( num_active_indep ) {
76 out <<
"\nmax(num_active_indep-num_adds_indep-num_drops_indep,0)/(num_active_indep) = "
77 <<
"max("<<num_active_indep<<
"-"<<num_adds_indep<<
"-"<<num_drops_indep<<
",0)/("<<num_active_indep<<
") = "
79 if( act_set_calmed_down )
83 out <<
"act_set_frac_proj_start = " << act_set_frac_proj_start;
84 if( act_set_calmed_down )
85 out <<
"\nThe active set has calmed down enough\n";
87 out <<
"\nThe active set has not calmed down enough\n";
104 n_pz = nu_indep.size();
105 SpVectorSlice::const_iterator
106 nu_indep_itr = nu_indep.begin(),
107 nu_indep_end = nu_indep.end();
108 const SpVectorSlice::difference_type
109 o = nu_indep.offset();
114 if( nu_indep_itr != nu_indep_end && nu_indep_itr->indice() + o == i ) {
122 (*sRTyR) += s_i*y(i);
143 n_pz = nu_indep.size();
149 typedef SpVector::element_type ele_t;
150 Workspace<ele_t> sort_array(wss,nu_indep.nz());
152 SpVectorSlice::const_iterator
153 nu_indep_itr = nu_indep.begin();
155 *itr = &sort_array[0];
156 for(
size_type l = 1 ; l <= nu_indep.nz(); ++l, ++itr, ++nu_indep_itr ) {
157 const size_type i = nu_indep_itr->indice() + nu_indep.offset();
162 s_i_B_ii_s_i = s_i*B_ii*s_i,
164 *sXTBXXsX += s_i_B_ii_s_i;
166 itr->initialize( l, s_i_B_ii_s_i/sRTBRRsR + ::fabs(s_i_y_i)/sRTyR );
171 &sort_array[0], &sort_array[0] + sort_array.size()
176 for(
size_type l = 0; l < nu_indep.nz(); ++l )
177 l_x_fixed_sorted[l] = sort_array[l].indice();
206 namespace COP = ConstrainedOptPack;
211 n_pz = nu_indep.size();
215 Workspace<long int> i_x_status(wss,n_pz);
216 std::fill_n( &i_x_status[0], n_pz, 0 );
217 {
for(
size_type l = 0; l < (*n_pz_R); ++l ) {
218 i_x_status[i_x_free[l]-1] = +1;
222 out <<
"\nDetermining which fixed variables to put in superbasis and which to leave out (must have at least one in superbasis)...\n";
227 all_fixed = n_pz == nu_indep.nz();
229 out <<
"\nmax{|nu_k(indep)|,i=r+1...n} = " << max_nu_indep << std::endl
230 <<
"super_basic_mult_drop_tol = " << super_basic_mult_drop_tol << std::endl
231 <<
"project_error_tol = " << project_error_tol << std::endl;
233 if( super_basic_mult_drop_tol > 1.0 ) {
235 out <<
"super_basic_mult_drop_tol = " << super_basic_mult_drop_tol <<
" > 1"
236 <<
"\nNo variables will be removed from the super basis! (You might consider decreasing super_basic_mult_drop_tol < 1)\n";
240 const int prec = out.precision();
243 <<
right << setw(10) <<
"i"
244 <<
right << setw(prec+12) <<
"nu_indep(i)"
245 <<
right << setw(1) <<
" "
246 <<
right << setw(prec+12) <<
"s(i)*B(ii)*s(i)"
247 <<
right << setw(prec+12) <<
"s_R'*B_RR*s_R"
248 <<
right << setw(prec+12) <<
"s_X'*B_XX*s_X"
249 <<
right << setw(1) <<
" "
250 <<
right << setw(prec+12) <<
"s(i)*y(i)"
251 <<
right << setw(prec+12) <<
"s_R'*y_R"
252 <<
right << setw(prec+12) <<
"s_X'*y_X"
253 <<
right << setw(1) <<
" "
254 <<
right << setw(14) <<
"status"
256 <<
right << setw(10) <<
"--------"
257 <<
right << setw(prec+12) <<
"---------------"
258 <<
right << setw(1) <<
" "
259 <<
right << setw(prec+12) <<
"---------------"
260 <<
right << setw(prec+12) <<
"---------------"
261 <<
right << setw(prec+12) <<
"---------------"
262 <<
right << setw(1) <<
" "
263 <<
right << setw(prec+12) <<
"---------------"
264 <<
right << setw(prec+12) <<
"---------------"
265 <<
right << setw(prec+12) <<
"---------------"
266 <<
right << setw(1) <<
" "
267 <<
right << setw(14) <<
"------------"
271 bool kept_one =
false;
272 for(
size_type k = 0; k < nu_indep.nz(); ++k ) {
274 l = l_x_fixed_sorted[k];
275 const SpVectorSlice::element_type
276 &nu_i = *(nu_indep.begin() + (l-1));
278 i = nu_i.indice() + nu_indep.offset();
280 abs_val_nu = ::fabs(nu_i.value()),
281 rel_val_nu = abs_val_nu / max_nu_indep,
285 s_i_B_ii_s_i = s_i*B_ii*s_i,
288 nu_cond = rel_val_nu < super_basic_mult_drop_tol,
289 sXTBXXsX_cond = (*sXTBXXsX) / (*sRTBRRsR) > project_error_tol,
290 sXTyX_cond = ::fabs(*sXTyX) / ::fabs(*sRTyR) > project_error_tol,
291 keep = ( (all_fixed && abs_val_nu == max_nu_indep && !kept_one)
292 || nu_cond || sXTBXXsX_cond || nu_cond );
294 out <<
right << setw(10) << i
295 <<
right << setw(prec+12) << nu_i.value()
296 <<
right << setw(1) << (nu_cond ?
"*" :
" ")
297 <<
right << setw(prec+12) << s_i_B_ii_s_i
298 <<
right << setw(prec+12) << (*sRTBRRsR)
299 <<
right << setw(prec+12) << (*sXTBXXsX)
300 <<
right << setw(1) << (sXTBXXsX_cond ?
"*" :
" ")
301 <<
right << setw(prec+12) << s_i_y_i
302 <<
right << setw(prec+12) << (*sRTyR)
303 <<
right << setw(prec+12) << (*sXTyX)
304 <<
right << setw(1) << (sXTyX_cond ?
"*" :
" ")
305 <<
right << setw(14) << (keep ?
"superbasic" :
"nonbasic")
310 *sRTBRRsR += s_i_B_ii_s_i;
311 *sXTBXXsX -= s_i_B_ii_s_i;
314 i_x_status[i-1] = +1;
318 i_x_status[i-1] = -1;
323 out <<
"\nFinal selection: n_pz_X = " << (*n_pz_X) <<
" nonbasic variables and n_pz_R = " << (*n_pz_R) <<
" superbasic variables\n";
327 SpVector::const_iterator
328 nu_itr = nu_indep.begin(),
329 nu_end = nu_indep.end();
330 SpVector::difference_type
331 nu_o = nu_indep.offset();
333 *i_x_free_itr = i_x_free,
334 *i_x_fixed_itr = i_x_fixed;
336 *bnd_fixed_itr = bnd_fixed;
337 {
for(
size_type i = 1; i <= n_pz; ++i ) {
338 long int status = i_x_status[i-1];
346 for( ; nu_itr->indice() + nu_o < i; ++nu_itr );
349 *i_x_fixed_itr++ = i;
350 *bnd_fixed_itr++ = ( nu_itr->value() > 0.0 ? COP::UPPER : COP::LOWER );
AbstractLinAlgPack::size_type size_type
void choose_fixed_free(const value_type project_error_tol, const value_type super_basic_mult_drop_tol, const SpVectorSlice &nu_indep, const DVectorSlice &s, const DVectorSlice &y, const DVectorSlice &B_XX, const size_type l_x_fixed_sorted[], EJournalOutputLevel olevel, std::ostream &out, value_type *sRTBRRsR, value_type *sRTyR, value_type *sXTBXXsX, value_type *sXTyX, size_type *n_pz_X, size_type *n_pz_R, size_type i_x_free[], size_type i_x_fixed[], ConstrainedOptPack::EBounds bnd_fixed[])
Choose the rest of i_x_free[] and i_x_fixed[].
void init_i_x_free_sRTsR_sRTyR(const SpVectorSlice &nu_indep, const DVectorSlice &s, const DVectorSlice &y, size_type *n_pz_R, size_type i_x_free[], value_type *sRTsR, value_type *sRTyR)
Initialize i_x_free[], s_R'*s_R and s_R'*y_R for free variables not in nu_indep.
EJournalOutputLevel
enum for journal output.
value_type norm_inf(const SparseVectorSlice< T_Ele > &sv_rhs)
result = ||sv_rhs||inf (BLAS IxAMAX)
bool act_set_calmed_down(const ActSetStats &act_set_stats, const value_type act_set_frac_proj_start, EJournalOutputLevel olevel, std::ostream &out)
Determine if the active set has calmed down enough and print this test.
void sort_fixed_max_cond_viol(const SpVectorSlice &nu_indep, const DVectorSlice &s, const DVectorSlice &y, const DVectorSlice &B_XX, const value_type sRTBRRsR, const value_type sRTyR, value_type *sXTBXXsX, value_type *sXTyX, size_type l_x_fixed_sorted[])
Sort fixed variables according to the condition:
SparseVectorSlice< SparseElement< index_type, value_type > > SpVectorSlice
DenseLinAlgPack::VectorSliceTmpl< value_type > DVectorSlice
AbstractLinAlgPack::value_type value_type
Function object class for sorting a sparse vectors in descending order by abs(v(i)).
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
TEUCHOSCORE_LIB_DLL_EXPORT Teuchos::RCP< WorkspaceStore > get_default_workspace_store()