MoochoPack : Framework for Large-Scale Optimization Algorithms Version of the Day
MoochoPack_get_init_fixed_free_indep.cpp
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 // Redistribution and use in source and binary forms, with or without
00013 // modification, are permitted provided that the following conditions are
00014 // met:
00015 //
00016 // 1. Redistributions of source code must retain the above copyright
00017 // notice, this list of conditions and the following disclaimer.
00018 //
00019 // 2. Redistributions in binary form must reproduce the above copyright
00020 // notice, this list of conditions and the following disclaimer in the
00021 // documentation and/or other materials provided with the distribution.
00022 //
00023 // 3. Neither the name of the Corporation nor the names of the
00024 // contributors may be used to endorse or promote products derived from
00025 // this software without specific prior written permission.
00026 //
00027 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00028 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00030 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00031 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00032 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00033 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00034 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00035 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00036 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00037 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038 //
00039 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00040 // 
00041 // ***********************************************************************
00042 // @HEADER
00043 
00044 #include <ostream>
00045 #include <iomanip>
00046 
00047 #include "MoochoPack_get_init_fixed_free_indep.hpp"
00048 #include "AbstractLinAlgPack/src/AbstractLinAlgPack_SpVectorClass.hpp"
00049 #include "AbstractLinAlgPack_SpVectorOp.hpp"
00050 
00051 void MoochoPack::get_init_fixed_free_indep(
00052   const size_type                        n
00053   ,const size_type                       r
00054   ,const SpVectorSlice                   &nu_indep
00055   ,const value_type                      super_basic_mult_drop_tol
00056   ,EJournalOutputLevel                   olevel
00057   ,std::ostream                          &out
00058   ,size_type                             *n_pz_X
00059   ,size_type                             *n_pz_R
00060   ,size_type                             i_x_free[]
00061   ,size_type                             i_x_fixed[]
00062   ,ConstrainedOptPack::EBounds  bnd_fixed[]
00063   )
00064 {
00065   using std::setw;
00066   using std::endl;
00067   using std::right;
00068   using AbstractLinAlgPack::norm_inf;
00069 
00070   const size_type
00071     n_pz = n-r;
00072 
00073   // Loop through and set i_x_free and i_x_fixed
00074   if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
00075     out << "\nDetermining which fixed variables to remove from rHL to form rHL_RR (can remove all but one)...\n";
00076   }
00077   const value_type
00078     max_nu_indep = norm_inf(nu_indep);
00079   const bool
00080     all_fixed = n_pz == nu_indep.nz();
00081   if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
00082     out << "\nmax{|nu_k(indep)|,i=r+1...n} = " << max_nu_indep << std::endl;
00083   }
00084   if( super_basic_mult_drop_tol > 1.0 ) {
00085     if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
00086       out << "super_basic_mult_drop_tol = " << super_basic_mult_drop_tol << " > 1"
00087         << "\nNo variables will be removed from the super basis!  (You might consider decreasing super_basic_mult_drop_tol < 1)\n";
00088     }
00089   }
00090   else {
00091     const int prec = out.precision();
00092     if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ACTIVE_SET) ) {
00093       out << endl
00094         << right << setw(10)      << "i"
00095         << right << setw(prec+12) << "nu(i)"
00096         << right << setw(8)       << "status"
00097         << endl
00098         << right << setw(10)      << "--------"
00099         << right << setw(prec+12) << "--------"
00100         << right << setw(8)       << "------"
00101         << endl;
00102     }
00103     SpVector::const_iterator
00104       nu_itr = nu_indep.begin(),
00105       nu_end = nu_indep.end();
00106     SpVector::difference_type
00107       nu_o = nu_indep.offset();
00108     size_type
00109       *i_x_free_itr  = i_x_free,
00110       *i_x_fixed_itr = i_x_fixed;
00111     ConstrainedOptPack::EBounds
00112       *bnd_fixed_itr = bnd_fixed;
00113     *n_pz_X = 0;
00114     *n_pz_R = 0;
00115     bool kept_one = false;
00116     {for( size_type i_indep = 1; i_indep <= n_pz; ++i_indep ) {
00117       if( nu_itr != nu_end && (nu_itr->indice() + nu_o) == i_indep ) {
00118         const value_type
00119           abs_val = ::fabs(nu_itr->value()),
00120           rel_val = abs_val / max_nu_indep;
00121         const bool
00122           keep = ( (all_fixed && abs_val == max_nu_indep && !kept_one)
00123                || rel_val < super_basic_mult_drop_tol );
00124         if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ACTIVE_SET) ) {
00125           out << right << setw(10)      << i_indep + r
00126             << right << setw(prec+12) << nu_itr->value()
00127             << right << setw(8)       << (keep ? "keep" : "drop")
00128             << endl;
00129         }
00130         if(!keep) {
00131           *i_x_fixed_itr++ = i_indep;
00132           namespace COP = ConstrainedOptPack;
00133           *bnd_fixed_itr++
00134             = ( nu_itr->value() > 0.0 ? COP::UPPER : COP::LOWER );
00135           // ToDo: Consider fixed variable bounds
00136           ++(*n_pz_X);
00137         }
00138         else {
00139           kept_one = true;
00140         }
00141         ++nu_itr;
00142         if(!keep) continue;
00143       }
00144       *i_x_free_itr++ = i_indep;
00145       ++(*n_pz_R);
00146     }}
00147     TEUCHOS_TEST_FOR_EXCEPT( !(  i_x_free_itr  - i_x_free  == *n_pz_R  ) );
00148     TEUCHOS_TEST_FOR_EXCEPT( !(  i_x_fixed_itr - i_x_fixed == *n_pz_X  ) );
00149     TEUCHOS_TEST_FOR_EXCEPT( !(  bnd_fixed_itr - bnd_fixed == *n_pz_X  ) );
00150     if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
00151       out << "\nRemoving n_pz_X = " << (*n_pz_X) << " from the superbasic set and keeping n_pz_R = " << (*n_pz_R) << std::endl;
00152     }
00153   }
00154 }
00155 
00156 #endif // 0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends