MeshKit  1.0
IAIntParabolaNlp.hpp
Go to the documentation of this file.
00001 // IAIntParabolaNlp.hpp
00002 // Interval Assignment for Meshkit
00003 //
00004 // use a cosine-"wave" function as a constraint, so that the only feasible solutions are integer
00005 // use a cosine-"wave" with twice the period to enforce the evenality constraints
00006 
00007 #ifndef MESHKIT_IA_IAINTPARABOLANLP_HP
00008 #define MESHKIT_IA_IAINTPARABOLANLP_HP
00009 
00010 #include "meshkit/IAIntWaveNlp.hpp"
00011 
00012 #include <math.h>
00013 #include <limits.h>
00014 
00015 namespace MeshKit 
00016 {
00017 
00018 class IAIntParabolaNlp : public IAIntWaveNlp
00019 {
00020   // first set of functions required by TNLP
00021 public:
00023   IAIntParabolaNlp(const IAData *data_ptr, const IPData *ip_data_ptr, IASolution *solution_ptr,
00024                const bool set_silent = true) :
00025     IAIntWaveNlp(data_ptr, ip_data_ptr, solution_ptr, set_silent)
00026   {}
00027 
00029   virtual ~IAIntParabolaNlp() {}
00030 
00031 protected:
00032 
00033   // nearest integer
00034   const double nearest_int( const double x )
00035   {
00036     const double xm = floor(x);
00037     const double xp = ceil(x);
00038     return (fabs(xm - x) < fabs(xp - x)) ? xm : xp;
00039   }
00040   const double nearest_even( const double s )
00041   {
00042     return 2. * nearest_int( s / 2. );
00043   }
00044   const double delta_x( const double x )
00045   {
00046     return x - nearest_int(x);
00047   }
00048   const double delta_s( const double s )
00049   {
00050     return s - nearest_even(s);
00051   }
00052 
00053   virtual double eval_g_int_x( const double x )
00054   {
00055     const double d = delta_x(x);
00056     return 1. - d * d;
00057   }
00058   virtual double eval_g_int_s( const double s )
00059   {
00060     const double d = delta_s(s);
00061     return 1. - d * d;
00062   }
00063   virtual double eval_jac_int_x( const double x )
00064   {
00065     const double d = delta_x( x );
00066     return -2. * d; // d' is 1
00067   }
00068   virtual double eval_jac_int_s( const double s )
00069   {
00070     double d = delta_s(s);
00071     return -2. * d; // d' is 1
00072   }
00073   virtual double eval_hess_int_x( const double x )
00074   {
00075     return -2.; 
00076   }
00077   virtual double eval_hess_int_s( const double s )
00078   {
00079     return -2.;
00080   }
00081   
00082 };
00083 
00084 
00085 } // namespace MeshKit
00086 
00087 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines