MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MoochoPack_get_init_fixed_free_indep.cpp
Go to the documentation of this file.
1 #if 0
2 
3 // @HEADER
4 // ***********************************************************************
5 //
6 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
7 // Copyright (2003) Sandia Corporation
8 //
9 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
10 // license for use of this work by or on behalf of the U.S. Government.
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions are
14 // met:
15 //
16 // 1. Redistributions of source code must retain the above copyright
17 // notice, this list of conditions and the following disclaimer.
18 //
19 // 2. Redistributions in binary form must reproduce the above copyright
20 // notice, this list of conditions and the following disclaimer in the
21 // documentation and/or other materials provided with the distribution.
22 //
23 // 3. Neither the name of the Corporation nor the names of the
24 // contributors may be used to endorse or promote products derived from
25 // this software without specific prior written permission.
26 //
27 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
28 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
31 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 //
39 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
40 //
41 // ***********************************************************************
42 // @HEADER
43 
44 #include <ostream>
45 #include <iomanip>
46 
48 #include "AbstractLinAlgPack/src/AbstractLinAlgPack_SpVectorClass.hpp"
50 
52  const size_type n
53  ,const size_type r
54  ,const SpVectorSlice &nu_indep
55  ,const value_type super_basic_mult_drop_tol
56  ,EJournalOutputLevel olevel
57  ,std::ostream &out
58  ,size_type *n_pz_X
59  ,size_type *n_pz_R
60  ,size_type i_x_free[]
61  ,size_type i_x_fixed[]
62  ,ConstrainedOptPack::EBounds bnd_fixed[]
63  )
64 {
65  using std::setw;
66  using std::endl;
67  using std::right;
69 
70  const size_type
71  n_pz = n-r;
72 
73  // Loop through and set i_x_free and i_x_fixed
74  if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
75  out << "\nDetermining which fixed variables to remove from rHL to form rHL_RR (can remove all but one)...\n";
76  }
77  const value_type
78  max_nu_indep = norm_inf(nu_indep);
79  const bool
80  all_fixed = n_pz == nu_indep.nz();
81  if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
82  out << "\nmax{|nu_k(indep)|,i=r+1...n} = " << max_nu_indep << std::endl;
83  }
84  if( super_basic_mult_drop_tol > 1.0 ) {
85  if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
86  out << "super_basic_mult_drop_tol = " << super_basic_mult_drop_tol << " > 1"
87  << "\nNo variables will be removed from the super basis! (You might consider decreasing super_basic_mult_drop_tol < 1)\n";
88  }
89  }
90  else {
91  const int prec = out.precision();
92  if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ACTIVE_SET) ) {
93  out << endl
94  << right << setw(10) << "i"
95  << right << setw(prec+12) << "nu(i)"
96  << right << setw(8) << "status"
97  << endl
98  << right << setw(10) << "--------"
99  << right << setw(prec+12) << "--------"
100  << right << setw(8) << "------"
101  << endl;
102  }
103  SpVector::const_iterator
104  nu_itr = nu_indep.begin(),
105  nu_end = nu_indep.end();
106  SpVector::difference_type
107  nu_o = nu_indep.offset();
108  size_type
109  *i_x_free_itr = i_x_free,
110  *i_x_fixed_itr = i_x_fixed;
112  *bnd_fixed_itr = bnd_fixed;
113  *n_pz_X = 0;
114  *n_pz_R = 0;
115  bool kept_one = false;
116  {for( size_type i_indep = 1; i_indep <= n_pz; ++i_indep ) {
117  if( nu_itr != nu_end && (nu_itr->indice() + nu_o) == i_indep ) {
118  const value_type
119  abs_val = ::fabs(nu_itr->value()),
120  rel_val = abs_val / max_nu_indep;
121  const bool
122  keep = ( (all_fixed && abs_val == max_nu_indep && !kept_one)
123  || rel_val < super_basic_mult_drop_tol );
124  if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ACTIVE_SET) ) {
125  out << right << setw(10) << i_indep + r
126  << right << setw(prec+12) << nu_itr->value()
127  << right << setw(8) << (keep ? "keep" : "drop")
128  << endl;
129  }
130  if(!keep) {
131  *i_x_fixed_itr++ = i_indep;
132  namespace COP = ConstrainedOptPack;
133  *bnd_fixed_itr++
134  = ( nu_itr->value() > 0.0 ? COP::UPPER : COP::LOWER );
135  // ToDo: Consider fixed variable bounds
136  ++(*n_pz_X);
137  }
138  else {
139  kept_one = true;
140  }
141  ++nu_itr;
142  if(!keep) continue;
143  }
144  *i_x_free_itr++ = i_indep;
145  ++(*n_pz_R);
146  }}
147  TEUCHOS_TEST_FOR_EXCEPT( !( i_x_free_itr - i_x_free == *n_pz_R ) );
148  TEUCHOS_TEST_FOR_EXCEPT( !( i_x_fixed_itr - i_x_fixed == *n_pz_X ) );
149  TEUCHOS_TEST_FOR_EXCEPT( !( bnd_fixed_itr - bnd_fixed == *n_pz_X ) );
150  if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
151  out << "\nRemoving n_pz_X = " << (*n_pz_X) << " from the superbasic set and keeping n_pz_R = " << (*n_pz_R) << std::endl;
152  }
153  }
154 }
155 
156 #endif // 0
AbstractLinAlgPack::size_type size_type
void get_init_fixed_free_indep(const size_type n, const size_type r, const SpVectorSlice &nu_indep, const value_type super_basic_mult_drop_tol, EJournalOutputLevel olevel, std::ostream &out, size_type *n_pz_X, size_type *n_pz_R, size_type i_x_free[], size_type i_x_fixed[], ConstrainedOptPack::EBounds bnd_fixed[])
Determine the set of initially fixed and free independent variables.
EJournalOutputLevel
enum for journal output.
std::ostream * out
value_type norm_inf(const SparseVectorSlice< T_Ele > &sv_rhs)
result = ||sv_rhs||inf (BLAS IxAMAX)
SparseVectorSlice< SparseElement< index_type, value_type > > SpVectorSlice
AbstractLinAlgPack::value_type value_type
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)