MoochoPack_get_init_fixed_free_indep.cpp

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

Generated on Tue Oct 20 12:51:47 2009 for MOOCHO (Single Doxygen Collection) by doxygen 1.4.7