BonTMINLP2OsiLP.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef BonminTMINLP2OsiLP_H
00010 #define BonminTMINLP2OsiLP_H
00011
00012 #include <cmath>
00013 #include <cstdio>
00014 #include "IpSmartPtr.hpp"
00015 #include "IpTNLP.hpp"
00016 #include "BonTypes.hpp"
00017
00018 class OsiSolverInterface;
00019 class OsiCuts;
00020
00021 namespace Bonmin {
00022 class TMINLP2TNLP;
00023 class BabSetupBase;
00024
00026 class TMINLP2OsiLP: public Ipopt::ReferencedObject {
00027
00028 public:
00029
00031 TMINLP2OsiLP():
00032 tiny_(-0.),
00033 very_tiny_(-0.)
00034 {}
00035
00037 TMINLP2OsiLP(const TMINLP2OsiLP & other):
00038 tiny_(other.tiny_),
00039 very_tiny_(other.very_tiny_),
00040 model_(other.model_){
00041 }
00042
00044 virtual TMINLP2OsiLP * clone() const = 0;
00045
00046 void set_tols(double tiny, double very_tiny, double rhs_relax, double infty){
00047 tiny_ = tiny;
00048 very_tiny_ = very_tiny;
00049 rhs_relax_ = rhs_relax;
00050 infty_ = infty;
00051 }
00052
00053 void set_model(Bonmin::TMINLP2TNLP * model){
00054 model_ = model;
00055 initialize_jac_storage();
00056 }
00057
00059 TMINLP2OsiLP & operator=(const TMINLP2OsiLP& rhs){
00060 if(this != & rhs){
00061 tiny_ = rhs.tiny_;
00062 very_tiny_ = rhs.very_tiny_;
00063 model_ = rhs.model_;
00064 }
00065 return (*this);
00066 }
00067
00069 ~TMINLP2OsiLP(){}
00070
00072 virtual void extract(OsiSolverInterface *si,
00073 const double * x, bool getObj) = 0;
00074
00075
00077 virtual void get_refined_oa(OsiCuts & cs
00078 ) const = 0;
00079
00081 virtual void get_oas(OsiCuts & cs,
00082 const double * x, bool getObj, bool global) const = 0;
00083
00084
00085
00086 protected:
00088 inline bool cleanNnz(double &value, double colLower, double colUpper,
00089 double rowLower, double rowUpper, double colsol,
00090 double & lb, double &ub, double tiny, double veryTiny) const;
00092 double tiny_;
00094 double very_tiny_;
00096 double rhs_relax_;
00098 double infty_;
00100 static int nTimesCalled;
00101
00104 mutable vector<int> jCol_;
00106 mutable vector<int> iRow_;
00108 mutable vector<double> value_;
00109
00110 vector<Ipopt::TNLP::LinearityType> const_types_;
00111
00112 void initialize_jac_storage();
00113
00114 Ipopt::SmartPtr<Bonmin::TMINLP2TNLP> model_;
00115 };
00116
00117
00118 inline
00119 bool
00120 TMINLP2OsiLP::cleanNnz(double &value, double colLower, double colUpper,
00121 double rowLower, double rowUpper, double colsol,
00122 double & lb, double &ub, double tiny, double veryTiny) const
00123 {
00124 if(fabs(value)>= tiny) return 1;
00125
00126
00127 if(fabs(value)<veryTiny) return 0;
00128
00129
00130 double infty = 1e20;
00131 bool colUpBounded = colUpper < 10000;
00132 bool colLoBounded = colLower > -10000;
00133 bool rowNotLoBounded = rowLower <= - infty;
00134 bool rowNotUpBounded = rowUpper >= infty;
00135 bool pos = value > 0;
00136
00137 if(colLoBounded && !pos && rowNotUpBounded) {
00138 lb += value * (colsol - colLower);
00139 return 0;
00140 }
00141 else
00142 if(colLoBounded && pos && rowNotLoBounded) {
00143 ub += value * (colsol - colLower);
00144 return 0;
00145 }
00146 else
00147 if(colUpBounded && pos && rowNotUpBounded) {
00148 lb += value * (colsol - colUpper);
00149 return 0;
00150 }
00151 else
00152 if(colUpBounded && !pos && rowNotLoBounded) {
00153 ub += value * (colsol - colUpper);
00154 return 0;
00155 }
00156
00157 return 1;
00158 }
00159
00160
00161 }
00162
00163 #endif
00164