|
MoochoPack : Framework for Large-Scale Optimization Algorithms Version of the Day
|
00001 #if 0 00002 00003 // @HEADER 00004 // *********************************************************************** 00005 // 00006 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization 00007 // Copyright (2003) Sandia Corporation 00008 // 00009 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00010 // license for use of this work by or on behalf of the U.S. Government. 00011 // 00012 // This library is free software; you can redistribute it and/or modify 00013 // it under the terms of the GNU Lesser General Public License as 00014 // published by the Free Software Foundation; either version 2.1 of the 00015 // License, or (at your option) any later version. 00016 // 00017 // This library is distributed in the hope that it will be useful, but 00018 // WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 // Lesser General Public License for more details. 00021 // 00022 // You should have received a copy of the GNU Lesser General Public 00023 // License along with this library; if not, write to the Free Software 00024 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00025 // USA 00026 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00027 // 00028 // *********************************************************************** 00029 // @HEADER 00030 00031 #include <ostream> 00032 #include <iomanip> 00033 00034 #include "MoochoPack_get_init_fixed_free_indep.hpp" 00035 #include "AbstractLinAlgPack/src/AbstractLinAlgPack_SpVectorClass.hpp" 00036 #include "AbstractLinAlgPack_SpVectorOp.hpp" 00037 00038 void MoochoPack::get_init_fixed_free_indep( 00039 const size_type n 00040 ,const size_type r 00041 ,const SpVectorSlice &nu_indep 00042 ,const value_type super_basic_mult_drop_tol 00043 ,EJournalOutputLevel olevel 00044 ,std::ostream &out 00045 ,size_type *n_pz_X 00046 ,size_type *n_pz_R 00047 ,size_type i_x_free[] 00048 ,size_type i_x_fixed[] 00049 ,ConstrainedOptPack::EBounds bnd_fixed[] 00050 ) 00051 { 00052 using std::setw; 00053 using std::endl; 00054 using std::right; 00055 using AbstractLinAlgPack::norm_inf; 00056 00057 const size_type 00058 n_pz = n-r; 00059 00060 // Loop through and set i_x_free and i_x_fixed 00061 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) { 00062 out << "\nDetermining which fixed variables to remove from rHL to form rHL_RR (can remove all but one)...\n"; 00063 } 00064 const value_type 00065 max_nu_indep = norm_inf(nu_indep); 00066 const bool 00067 all_fixed = n_pz == nu_indep.nz(); 00068 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) { 00069 out << "\nmax{|nu_k(indep)|,i=r+1...n} = " << max_nu_indep << std::endl; 00070 } 00071 if( super_basic_mult_drop_tol > 1.0 ) { 00072 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) { 00073 out << "super_basic_mult_drop_tol = " << super_basic_mult_drop_tol << " > 1" 00074 << "\nNo variables will be removed from the super basis! (You might consider decreasing super_basic_mult_drop_tol < 1)\n"; 00075 } 00076 } 00077 else { 00078 const int prec = out.precision(); 00079 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ACTIVE_SET) ) { 00080 out << endl 00081 << right << setw(10) << "i" 00082 << right << setw(prec+12) << "nu(i)" 00083 << right << setw(8) << "status" 00084 << endl 00085 << right << setw(10) << "--------" 00086 << right << setw(prec+12) << "--------" 00087 << right << setw(8) << "------" 00088 << endl; 00089 } 00090 SpVector::const_iterator 00091 nu_itr = nu_indep.begin(), 00092 nu_end = nu_indep.end(); 00093 SpVector::difference_type 00094 nu_o = nu_indep.offset(); 00095 size_type 00096 *i_x_free_itr = i_x_free, 00097 *i_x_fixed_itr = i_x_fixed; 00098 ConstrainedOptPack::EBounds 00099 *bnd_fixed_itr = bnd_fixed; 00100 *n_pz_X = 0; 00101 *n_pz_R = 0; 00102 bool kept_one = false; 00103 {for( size_type i_indep = 1; i_indep <= n_pz; ++i_indep ) { 00104 if( nu_itr != nu_end && (nu_itr->indice() + nu_o) == i_indep ) { 00105 const value_type 00106 abs_val = ::fabs(nu_itr->value()), 00107 rel_val = abs_val / max_nu_indep; 00108 const bool 00109 keep = ( (all_fixed && abs_val == max_nu_indep && !kept_one) 00110 || rel_val < super_basic_mult_drop_tol ); 00111 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ACTIVE_SET) ) { 00112 out << right << setw(10) << i_indep + r 00113 << right << setw(prec+12) << nu_itr->value() 00114 << right << setw(8) << (keep ? "keep" : "drop") 00115 << endl; 00116 } 00117 if(!keep) { 00118 *i_x_fixed_itr++ = i_indep; 00119 namespace COP = ConstrainedOptPack; 00120 *bnd_fixed_itr++ 00121 = ( nu_itr->value() > 0.0 ? COP::UPPER : COP::LOWER ); 00122 // ToDo: Consider fixed variable bounds 00123 ++(*n_pz_X); 00124 } 00125 else { 00126 kept_one = true; 00127 } 00128 ++nu_itr; 00129 if(!keep) continue; 00130 } 00131 *i_x_free_itr++ = i_indep; 00132 ++(*n_pz_R); 00133 }} 00134 TEST_FOR_EXCEPT( !( i_x_free_itr - i_x_free == *n_pz_R ) ); 00135 TEST_FOR_EXCEPT( !( i_x_fixed_itr - i_x_fixed == *n_pz_X ) ); 00136 TEST_FOR_EXCEPT( !( bnd_fixed_itr - bnd_fixed == *n_pz_X ) ); 00137 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) { 00138 out << "\nRemoving n_pz_X = " << (*n_pz_X) << " from the superbasic set and keeping n_pz_R = " << (*n_pz_R) << std::endl; 00139 } 00140 } 00141 } 00142 00143 #endif // 0
1.7.4