|
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 // 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 <assert.h> 00045 00046 #include <iomanip> 00047 #include <ostream> 00048 00049 #include "MoochoPack_active_set_change.hpp" 00050 #include "AbstractLinAlgPack/src/AbstractLinAlgPack_SpVectorClass.hpp" 00051 00052 void MoochoPack::active_set_change( 00053 const SpVectorSlice& nu_k, const SpVectorSlice& nu_km1, Range1D indep 00054 ,EJournalOutputLevel olevel, std::ostream* out 00055 ,size_type* num_adds, size_type* num_drops 00056 ,size_type* num_active_indep, size_type* num_adds_indep, size_type* num_drops_indep 00057 ) 00058 { 00059 using std::setw; 00060 using std::endl; 00061 00062 const int w = 12; 00063 00064 *num_adds = *num_drops = *num_adds_indep = *num_drops_indep = 0; 00065 *num_active_indep = nu_k(indep).nz(); 00066 00067 if( !nu_k.nz() && !nu_km1.nz() ) 00068 return; 00069 00070 TEUCHOS_TEST_FOR_EXCEPT( !( nu_k.is_sorted() && nu_km1.is_sorted() ) ); 00071 00072 bool dump_change = (int)olevel >= (int)PRINT_ACTIVE_SET; 00073 00074 if( dump_change ) { 00075 *out 00076 << "\n*** Changes in active set\n\n" 00077 << setw(w) << "i" 00078 << setw(w) << "uplo" 00079 << setw(w) << "dep/indep" 00080 << setw(w) << "change\n" 00081 << setw(w) << "----------" 00082 << setw(w) << "----------" 00083 << setw(w) << "----------" 00084 << setw(w) << "----------\n"; 00085 } 00086 00087 SpVectorSlice::const_iterator 00088 nu_k_itr = nu_k.begin(), 00089 nu_k_end = nu_k.end(), 00090 nu_km1_itr = nu_km1.begin(), 00091 nu_km1_end = nu_km1.end(); 00092 00093 while( nu_k_itr != nu_k_end || nu_km1_itr != nu_km1_end ) { 00094 if( nu_k_itr != nu_k_end && ( nu_km1_itr == nu_km1_end || ( nu_k_itr != nu_k_end 00095 && nu_k_itr->indice()+nu_k.offset() < nu_km1_itr->indice()+nu_km1.offset() ) ) ) 00096 { 00097 // *nu_k_itr was added to active set. 00098 const size_type i = nu_k_itr->indice() + nu_k.offset(); 00099 const bool is_indep = indep.in_range(i); 00100 if(is_indep) 00101 (*num_adds_indep)++; 00102 (*num_adds)++; 00103 if(dump_change) 00104 *out 00105 << setw(w) << i 00106 << setw(w) << ( nu_k_itr->value() >= 0.0 ? "upper" : "lower" ) 00107 << setw(w) << ( is_indep ? "indep" : "dep" ) 00108 << setw(w) << "added" << endl; 00109 nu_k_itr++; 00110 } 00111 else if( nu_km1_itr != nu_km1_end && ( nu_k_itr == nu_k_end || ( nu_km1_itr != nu_km1_end 00112 && nu_k_itr->indice()+nu_k.offset() > nu_km1_itr->indice()+nu_km1.offset() ) ) ) 00113 { 00114 // *nu_km1_itr was removed from the active set. 00115 const size_type i = nu_km1_itr->indice() + nu_km1.offset(); 00116 const bool is_indep = indep.in_range(i); 00117 if(is_indep) 00118 (*num_drops_indep)++; 00119 (*num_drops)++; 00120 if(dump_change) 00121 *out 00122 << setw(w) << i 00123 << setw(w) << ( nu_km1_itr->value() >= 0.0 ? "upper" : "lower" ) 00124 << setw(w) << ( is_indep ? "indep" : "dep" ) 00125 << setw(w) << "dropped" << endl; 00126 nu_km1_itr++; 00127 } 00128 else { 00129 // same variable (but the bound may have changed) 00130 const size_type i = nu_k_itr->indice() + nu_k.offset(); 00131 const bool is_indep = indep.in_range(i); 00132 if( nu_k_itr->value() * nu_km1_itr->value() < 0.0 ) { 00133 // Switched bounds. 00134 if(is_indep) { 00135 (*num_adds_indep)++; 00136 (*num_drops_indep)++; 00137 } 00138 (*num_adds)++; 00139 (*num_drops)++; 00140 if(dump_change) 00141 *out 00142 << setw(w) << i 00143 << setw(w) << ( nu_k_itr->value() >= 0.0 ? "upper" : "lower" ) 00144 << setw(w) << ( is_indep ? "indep" : "dep" ) 00145 << setw(w) << "switch bnd" << endl; 00146 } 00147 nu_k_itr++; 00148 nu_km1_itr++; 00149 } 00150 } 00151 00152 // Output summary 00153 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) { 00154 *out 00155 << "\n*** Active set change summary\n" 00156 << "nact_old = " << nu_km1.nz() << endl 00157 << "nact_new = " << nu_k.nz() << endl 00158 << "num_adds = " << *num_adds << endl 00159 << "num_drops = " << *num_drops << endl 00160 << "nact_indep_old = " << nu_km1(indep).nz() << endl 00161 << "nact_indep_new = " << *num_active_indep << endl 00162 << "num_indep_adds = " << *num_adds_indep << endl 00163 << "num_indep_drops = " << *num_drops_indep << endl; 00164 } 00165 } 00166 00167 #endif // 0
1.7.6.1