ConstrainedOptPack_vector_change_stats.cpp

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 <limits>
00030 
00031 #include "ConstrainedOptPack_vector_change_stats.hpp"
00032 #include "DenseLinAlgPack_DVectorClass.hpp"
00033 #include "DenseLinAlgPack_AssertOp.hpp"
00034 
00035 void ConstrainedOptPack::vector_change_stats(
00036     const DVectorSlice& x, const DVectorSlice& d
00037   , value_type* max_term, size_type* max_k
00038   , value_type* min_term, size_type* min_k
00039   , value_type* av_term )
00040 {
00041   DenseLinAlgPack::VopV_assert_sizes( x.size(), d.size() );
00042   const value_type
00043     min_num   = std::numeric_limits<value_type>::min(),
00044     inf     = std::numeric_limits<value_type>::max();
00045   // Initialize statistics
00046   *max_term = 0.0;
00047   *max_k    = 0;
00048   *min_term = inf;
00049   *min_k    = 0;
00050   *av_term  = 0.0;
00051   // Compute statistics
00052   DVectorSlice::const_iterator
00053     x_itr = x.begin(),
00054     d_itr = d.begin();
00055   for( size_type i = 1; x_itr != x.end(); ++i, ++d_itr, ++x_itr ) {
00056     // Compute this ratio and make sure we are not dividing by zero.
00057     // We only care about ratios less than 1.0 and also deal
00058     // with the case that both x(i) and d(i) are zero (in which
00059     // case the ratio should be zero since x(i) == x(i) + d(i)).
00060     const value_type
00061       term = ::fabs(*d_itr) / ( 1 + ::fabs(*x_itr) );
00062     if( term > *max_term ) {
00063       *max_term = term;
00064       *max_k    = i;
00065     }
00066     if( term < *min_term ) {
00067       *min_term = term;
00068       *min_k    = i;
00069     }
00070     *av_term += term;
00071   }
00072   *av_term = *av_term / x.size();
00073 }

Generated on Thu Sep 18 12:34:16 2008 for ConstrainedOptPack: C++ Tools for Constrained (and Unconstrained) Optimization by doxygen 1.3.9.1