|
AbstractLinAlgPack: C++ Interfaces For Vectors, Matrices And Related Linear Algebra Objects Version of the Day
|
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 #ifndef SPARSE_LIN_ALG_PACK_SPARSE_BOUNDS_H 00030 #define SPARSE_LIN_ALG_PACK_SPARSE_BOUNDS_H 00031 00032 #include "DenseLinAlgPack_DVectorClass.hpp" 00033 00034 namespace AbstractLinAlgPack { 00035 00042 class sparse_bounds_itr { 00043 private: 00044 enum EBound { LOWER, UPPER, BOTH }; 00045 public: 00046 00048 sparse_bounds_itr( 00049 const DVectorSlice::const_iterator &bl_begin 00050 ,const DVectorSlice::const_iterator &bl_end 00051 ,const DVectorSlice::const_iterator &bu_begin 00052 ,const DVectorSlice::const_iterator &bu_end 00053 ,value_type big_bnd 00054 ) 00055 :bl_itr_(bl_begin), bl_end_(bl_end), bu_itr_(bu_begin), bu_end_(bu_end) 00056 ,big_bnd_(big_bnd), index_(1) 00057 { 00058 if( !at_end() && ( *bl_itr_ <= -big_bnd_ && +big_bnd_ <= *bu_itr_ ) ) 00059 this->operator++(); 00060 else 00061 update(); 00062 } 00064 const value_type& big_bnd() const 00065 { return big_bnd_; } 00067 bool at_end() const 00068 { return bl_itr_ == bl_end_; } 00070 sparse_bounds_itr& operator++() { 00071 if(!at_end()) { ++bl_itr_; ++bu_itr_; ++index_; } 00072 for( ; !at_end() && ( *bl_itr_ <= -big_bnd_ && +big_bnd_ <= *bu_itr_ ) 00073 ; ++bl_itr_, ++bu_itr_, ++index_ ); 00074 update(); 00075 return *this; 00076 } 00078 index_type index() const 00079 { return index_; } 00081 value_type lbound() const 00082 { return lbound_; } 00084 value_type ubound() const 00085 { return ubound_; } 00086 00087 private: 00088 DVectorSlice::const_iterator 00089 bl_itr_, bl_end_, bu_itr_, bu_end_; 00090 value_type 00091 big_bnd_, lbound_, ubound_; 00092 index_type 00093 index_; 00094 EBound 00095 at_bound_; 00096 00097 void update() { 00098 if( bl_itr_ == bl_end_ ) { 00099 return; 00100 } 00101 else if( -big_bnd_ < *bl_itr_ && *bu_itr_ < +big_bnd_ ) { 00102 lbound_ = *bl_itr_; 00103 ubound_ = *bu_itr_; 00104 at_bound_ = BOTH; 00105 } 00106 else if( -big_bnd_ < *bl_itr_ ) { 00107 lbound_ = *bl_itr_; 00108 ubound_ = +big_bnd_; 00109 at_bound_ = LOWER; 00110 } 00111 else if( *bu_itr_ < +big_bnd_ ) { 00112 lbound_ = -big_bnd_; 00113 ubound_ = *bu_itr_; 00114 at_bound_ = UPPER; 00115 } 00116 } 00117 00118 // not defined and not to be called 00119 sparse_bounds_itr(); 00120 00121 }; // end class sparse_bounds_itr 00122 00123 } // end namespace AbstractLinAlgPack 00124 00125 #endif // SPARSE_LIN_ALG_PACK_SPARSE_BOUNDS_H
1.7.4