vtf-logo

FunctionWithQuadraticPenalty.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00008 #if !defined(__numerical_FunctionWithQuadraticPenalty_h__)
00009 #define __numerical_FunctionWithQuadraticPenalty_h__
00010 
00011 // If we are debugging the whole numerical package.
00012 #if defined(DEBUG_numerical) && !defined(DEBUG_FunctionWithQuadraticPenalty)
00013 #define DEBUG_FunctionWithQuadraticPenalty
00014 #endif
00015 
00016 #include "../defs.h"
00017 
00018 #include <functional>
00019 
00020 #include <cassert>
00021 
00022 BEGIN_NAMESPACE_NUMERICAL
00023 
00025 
00032 template <int N, class Function, class Constraint, 
00033           typename T = typename Function::result_type,
00034           typename Point = typename Function::argument_type>
00035 class FunctionWithQuadraticPenalty :
00036   public std::unary_function<Point,T>
00037 {
00038 private:
00039 
00040   typedef std::unary_function<Point,T> base_type;
00041 
00042 public:
00043 
00044   //
00045   // Public types.
00046   //
00047   
00049   typedef typename base_type::argument_type argument_type;
00050 
00052   typedef typename base_type::result_type result_type;
00053 
00054 private:
00055 
00056   //
00057   // Private types.
00058   //
00059   
00060   // The function type.
00061   typedef Function function_type;
00062 
00063   // The constraint type.
00064   typedef Constraint constraint_type;
00065 
00066   // The number type.
00067   typedef result_type number_type;
00068 
00069   // A point in N dimensions.
00070   typedef argument_type point_type;
00071 
00072 private:
00073 
00074   //
00075   // Member data.
00076   //
00077 
00078   // The objective function.
00079   const function_type& _function;
00080 
00081   // The constraint function.
00082   const constraint_type& _constraint;
00083 
00084   // The penalty parameter.
00085   mutable number_type _penalty_parameter;
00086 
00087   // The penalty parameter reduction factor.
00088   mutable number_type _reduction_factor;
00089 
00090   //
00091   // Not implemented.
00092   //
00093 
00094   // Default constructor not implemented.
00095   FunctionWithQuadraticPenalty();
00096 
00097   // Assignment operator not implemented.
00098   FunctionWithQuadraticPenalty&
00099   operator=( const FunctionWithQuadraticPenalty& );
00100 
00101 public:
00102 
00103   //--------------------------------------------------------------------------
00105   // @{
00106 
00108   FunctionWithQuadraticPenalty( const function_type& function, 
00109                                 const constraint_type& constraint, 
00110                                 const number_type penalty_parameter = 1,
00111                                 const number_type reduction_factor = 0.1 );
00112 
00114   FunctionWithQuadraticPenalty( const FunctionWithQuadraticPenalty& x );
00115 
00117   virtual
00118   ~FunctionWithQuadraticPenalty()
00119   {}
00120 
00121   // @}
00122   //--------------------------------------------------------------------------
00124   // @{
00125 
00127   result_type
00128   operator()( const argument_type& x ) const;
00129 
00131   void
00132   gradient( const argument_type& x, argument_type& gradient ) const;
00133 
00134   // @}
00135   //--------------------------------------------------------------------------
00137   // @{
00138 
00140   const function_type&
00141   function() const
00142   {
00143     return _function;
00144   }
00145 
00147   const constraint_type&
00148   constraint() const
00149   {
00150     return _constraint;
00151   }
00152 
00154   number_type 
00155   penalty_parameter() const
00156   {
00157     return _penalty_parameter;
00158   }
00159 
00161   number_type 
00162   reduction_factor() const
00163   {
00164     return _reduction_factor;
00165   }
00166 
00167   // @}
00168   //--------------------------------------------------------------------------
00170   // @{
00171 
00173   void
00174   increase_penalty() const
00175   {
00176     _penalty_parameter *= _reduction_factor;
00177   }
00178 
00180   void
00181   set_penalty_parameter( const number_type penalty_parameter ) const
00182   {
00183     _penalty_parameter = penalty_parameter;
00184   }
00185 
00187   void
00188   set_reduction_factor( const number_type reduction_factor ) const
00189   {
00190     _reduction_factor = reduction_factor;
00191   }
00192 
00193   // @}
00194 };
00195 
00196 END_NAMESPACE_NUMERICAL
00197 
00198 #define __FunctionWithQuadraticPenalty_ipp__
00199 #include "FunctionWithQuadraticPenalty.ipp"
00200 #undef __FunctionWithQuadraticPenalty_ipp__
00201 
00202 #endif

Generated on Fri Aug 24 12:56:05 2007 for Numerical Algorithms Package by  doxygen 1.4.7