MeshKit  1.0
IAIntWaveNlp.hpp
Go to the documentation of this file.
00001 // IAIntWaveNlp.hpp
00002 // Interval Assignment for Meshkit
00003 //
00004 // ipopt mixed-integer solution
00005 // The idea is the optimal solution will be an integer one, if one exists
00006 // Define some region around the relaxed solution and search for an integer solution
00007 //
00008 // use some non-linear function as a constraint, so that the only feasible solutions are integer
00009 
00010 #ifndef MESHKIT_IA_IAINTHESSNLP_HP
00011 #define MESHKIT_IA_IAINTHESSNLP_HP
00012 
00013 #include "meshkit/IANlp.hpp"
00014 
00015 // from Ipopt
00016 #include "IpTNLP.hpp"
00017 
00018 #include <vector>
00019 #include <map>
00020 
00021 namespace MeshKit 
00022 {
00023     
00024 class IAData;
00025 class IPData;
00026 class IASolution;
00027 
00028 class IAIntWaveNlp : public TNLP
00029 {
00030   // first set of functions required by TNLP
00031 public:
00033   IAIntWaveNlp(const IAData *data_ptr, const IPData *ip_data_ptr, IASolution *solution_ptr,
00034                const bool set_silent = true); 
00035 
00037   virtual ~IAIntWaveNlp();
00038 
00042   virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
00043                             Index& nnz_h_lag, IndexStyleEnum& index_style);
00044 
00046   virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u,
00047                                Index m, Number* g_l, Number* g_u);
00048 
00050   virtual bool get_starting_point(Index n, bool init_x, Number* x_init,
00051                                   bool init_z, Number* z_L, Number* z_U,
00052                                   Index m, bool init_lambda,
00053                                   Number* lambda);
00054 
00056   virtual bool eval_f(Index n, const Number* x, bool new_x, Number& obj_value);
00057 
00059   virtual bool eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f);
00060 
00062   virtual bool eval_g(Index n, const Number* x, bool new_x, Index m, Number* g);
00063 
00068   virtual bool eval_jac_g(Index n, const Number* x, bool new_x,
00069                           Index m, Index nele_jac, Index* iRow, Index *jCol,
00070                           Number* values);
00071 
00076   virtual bool eval_h(Index n, const Number* x, bool new_x,
00077                       Number obj_factor, Index m, const Number* lambda,
00078                       bool new_lambda, Index nele_hess, Index* iRow,
00079                       Index* jCol, Number* values);
00080 
00082 
00086   virtual void finalize_solution(SolverReturn status,
00087                                  Index n, const Number* x, const Number* z_L, const Number* z_U,
00088                                  Index m, const Number* g, const Number* lambda,
00089                                  Number obj_value,
00090                                  const IpoptData* ip_data,
00091                                  IpoptCalculatedQuantities* ip_cq);
00093 
00094 // extra stuff not required by TNLP
00095   
00096 private:  
00097   // hide untrusted default methods
00099   //  IA_NLP();
00100   IAIntWaveNlp();
00101   IAIntWaveNlp(const IAIntWaveNlp&);
00102   IAIntWaveNlp& operator=(const IAIntWaveNlp&);
00104   
00105 protected:
00106   // input data
00107   const IAData *data;
00108   const IPData *ipData;
00109 
00110   // solution data
00111   IASolution *solution;
00112   
00113   
00114   // implemented using an overlay over an IANlp
00115   IANlp baseNlp;  
00116   
00117   const int base_n, base_m;
00118   const int problem_n, problem_m;
00119   const int wave_even_constraint_start;
00120   const int wave_int_constraint_start;
00121   
00122   double f_x_value( double I_i, double x_i );
00123 
00124   const bool silent;
00125   const bool debugging;
00126   const bool verbose; // verbose debugging
00127   
00128   struct SparseMatrixEntry
00129         {
00130           // position in matrix
00131           // column must be less than row, j <= i
00132           int i; // row
00133           int j; // col
00134           
00135           // order in sequence for hessian values array, etc.
00136           int k;
00137         
00138           static int n; // matrix is n x n
00139           int key() const { return i * n + j; }
00140           
00141           SparseMatrixEntry(const int iset, const int jset, const int kset);
00142           SparseMatrixEntry() : i(-1), j(-1), k(-1) {} // bad values if unspecified
00143         };
00144         
00145         typedef std::map<int, SparseMatrixEntry> SparseMatrixMap; 
00146         
00147         SparseMatrixMap hessian_map;  // sorted by key
00148         std::vector< SparseMatrixEntry > hessian_vector; // from 0..k
00149 
00150         void add_hessian_entry( int i, int j, int &k );
00151         void build_hessian();
00152         int get_hessian_k( int i, int j );
00153   void print_hessian(); // debug
00154   
00155   // derived classes must define these
00156   // the first two should have a max of 1 for integer/even values, and be less than that elsewhere
00157   virtual double eval_g_int_x( const double x ) = 0;
00158   virtual double eval_g_int_s( const double s ) = 0;
00159   virtual double eval_jac_int_x( const double x ) = 0;
00160   virtual double eval_jac_int_s( const double s ) = 0;
00161   virtual double eval_hess_int_x( const double x ) = 0;
00162   virtual double eval_hess_int_s( const double s ) = 0;
00163 
00164 };
00165 
00166 } // namespace MeshKit
00167 
00168 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines