Bonmin
1.7
|
00001 00002 // All Rights Reserved. 00003 // This code is published under the Common Public License. 00004 // 00005 // Authors : 00006 // Pierre Bonami, International Business Machines Corporation 00007 // 00008 // Date : 10/06/2007 00009 00010 #ifndef BonQuadRow_H 00011 #define BonQuadRow_H 00012 00013 #include "CoinPackedVector.hpp" 00014 #include "BonTMatrix.hpp" 00015 #include "BonQuadCut.hpp" 00016 00017 namespace Bonmin{ 00018 00020 typedef std::pair<int, int> matEntry; 00022 typedef std::pair<int, int> matIdx; 00023 #if HAS_HASH_MAP 00024 typedef std::has_map<matEntry, matIdx, std::hash< matEntry> > AdjustableMat; 00025 #else 00026 typedef std::map<matEntry, matIdx> AdjustableMat; 00027 #endif 00028 00032 class QuadRow { 00033 public: 00035 QuadRow(); 00036 00038 QuadRow(const QuadRow & other); 00039 00041 QuadRow& operator=(const QuadRow& rhs); 00042 00044 QuadRow(const QuadCut &cut); 00045 00047 QuadRow& operator=(const QuadCut & rhs); 00048 00050 QuadRow(const OsiRowCut &cut); 00051 00053 QuadRow& operator=(const OsiRowCut & rhs); 00054 00056 double eval_f(const double *x, bool new_x); 00057 00059 int nnz_grad(); 00061 void gradiant_struct(const int nnz, int * indices, bool offset); 00063 void eval_grad(const int nnz, const double * x, bool new_x, double * values); 00064 00066 int nnz_hessian(){ 00067 return Q_.nnz_;} 00068 00070 bool isLinear(){ 00071 return Q_.nnz_ == 0;} 00072 00074 void eval_hessian(double lambda, double * values); 00075 00077 void add_to_hessian(AdjustableMat &H, bool offset); 00078 00080 void remove_from_hessian(AdjustableMat &H); 00082 void print(); 00083 00084 private: 00086 void initialize(); 00087 00089 void internal_eval_grad(const double *x); 00090 00092 double lb_; 00094 double ub_; 00096 double c_; 00098 CoinPackedVector a_; 00100 TMat Q_; 00101 00102 00103 #if HAS_HASH_MAP 00104 typedef std::has_map<int, std::pair<double, double >, std::hash<int> > gStore; 00105 #else 00106 typedef std::map<int, std::pair<double, double> > gStore; 00107 #endif 00108 00109 gStore g_; 00111 std::vector<gStore::iterator> a_grad_idx_; 00113 std::vector<gStore::iterator> Q_row_grad_idx_; 00115 std::vector<gStore::iterator> Q_col_grad_idx_; 00117 std::vector<AdjustableMat::iterator> Q_hessian_idx_; 00119 bool grad_evaled_; 00120 }; 00121 }//End Bonmin namespace 00122 #endif