Bonmin  1.8.8
BonTMINLP2OsiLP.hpp
Go to the documentation of this file.
1 // (C) Copyright International Business Machines Corporation 2007
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // Authors :
6 // Pierre Bonami, International Business Machines Corporation
7 //
8 // Date : 10/16/2007
9 #ifndef BonminTMINLP2OsiLP_H
10 #define BonminTMINLP2OsiLP_H
11 
12 #include <cmath>
13 #include <cstdio>
14 #include "IpSmartPtr.hpp"
15 #include "IpTNLP.hpp"
16 #include "BonTypes.hpp"
17 
18 class OsiSolverInterface;
19 class OsiCuts;
20 
21 namespace Bonmin {
22  class TMINLP2TNLP;
23  class BabSetupBase;
24 
26  class TMINLP2OsiLP: public Ipopt::ReferencedObject {
27 
28  public:
29 
32  tiny_(-0.),
33  very_tiny_(-0.)
34  {}
35 
37  TMINLP2OsiLP(const TMINLP2OsiLP & other):
38  tiny_(other.tiny_),
39  very_tiny_(other.very_tiny_),
40  model_(other.model_){
41  }
42 
44  virtual TMINLP2OsiLP * clone() const = 0;
45 
46  void set_tols(double tiny, double very_tiny, double rhs_relax, double infty){
47  tiny_ = tiny;
48  very_tiny_ = very_tiny;
49  rhs_relax_ = rhs_relax;
50  infty_ = infty;
51  }
52 
54  model_ = model;
56  }
57 
60  if(this != & rhs){
61  tiny_ = rhs.tiny_;
62  very_tiny_ = rhs.very_tiny_;
63  model_ = rhs.model_;
64  }
65  return (*this);
66  }
67 
70 
72  virtual void extract(OsiSolverInterface *si,
73  const double * x, bool getObj) = 0;
74 
75 
77  virtual void get_refined_oa(OsiCuts & cs
78  ) const = 0;
79 
81  virtual void get_oas(OsiCuts & cs,
82  const double * x, bool getObj, bool global) const = 0;
83 
84 
85 
86  protected:
88  inline bool cleanNnz(double &value, double colLower, double colUpper,
89  double rowLower, double rowUpper, double colsol,
90  double & lb, double &ub, double tiny, double veryTiny) const;
92  double tiny_;
94  double very_tiny_;
96  double rhs_relax_;
98  double infty_;
100  static int nTimesCalled;
101 
109 
111 
112  void initialize_jac_storage();
113 
114  Ipopt::SmartPtr<Bonmin::TMINLP2TNLP> model_;
115  };
116 
117 //A procedure to try to remove small coefficients in OA cuts (or make it non small
118 inline
119 bool
120 TMINLP2OsiLP::cleanNnz(double &value, double colLower, double colUpper,
121  double rowLower, double rowUpper, double colsol,
122  double & lb, double &ub, double tiny, double veryTiny) const
123 {
124  if(fabs(value)>= tiny) return 1;
125  //fprintf(stderr, "Warning: small coefficient %g\n", tiny);
126 
127  if(fabs(value)<veryTiny) return 0;//Take the risk?
128 
129  //try and remove
130  double infty = 1e20;
131  bool colUpBounded = colUpper < 10000;
132  bool colLoBounded = colLower > -10000;
133  bool rowNotLoBounded = rowLower <= - infty;
134  bool rowNotUpBounded = rowUpper >= infty;
135  bool pos = value > 0;
136 
137  if(colLoBounded && !pos && rowNotUpBounded) {
138  lb += value * (colsol - colLower);
139  return 0;
140  }
141  else
142  if(colLoBounded && pos && rowNotLoBounded) {
143  ub += value * (colsol - colLower);
144  return 0;
145  }
146  else
147  if(colUpBounded && pos && rowNotUpBounded) {
148  lb += value * (colsol - colUpper);
149  return 0;
150  }
151  else
152  if(colUpBounded && !pos && rowNotLoBounded) {
153  ub += value * (colsol - colUpper);
154  return 0;
155  }
156  //can not remove coefficient
157  return 1;
158 }
159 
160 
161 }
162 
163 #endif
164 
TMINLP2OsiLP(const TMINLP2OsiLP &other)
Copy constructor.
static int nTimesCalled
Count the number of linear outer approximations taken.
virtual TMINLP2OsiLP * clone() const =0
virtual copy constructor
double tiny_
If constraint coefficient is below this, we try to remove it.
Ipopt::SmartPtr< Bonmin::TMINLP2TNLP > model_
double rhs_relax_
Amount by which to relax OA constraints RHSes.
void set_tols(double tiny, double very_tiny, double rhs_relax, double infty)
TMINLP2OsiLP & operator=(const TMINLP2OsiLP &rhs)
Assignment operator.
double very_tiny_
If constraint coefficient is below this, we neglect it.
vector< double > value_
Values of jacobian.
virtual void get_oas(OsiCuts &cs, const double *x, bool getObj, bool global) const =0
Get OAs of nonlinear constraints in x.
void set_model(Bonmin::TMINLP2TNLP *model)
A transformer class to build outer approximations i.e.
bool cleanNnz(double &value, double colLower, double colUpper, double rowLower, double rowUpper, double colsol, double &lb, double &ub, double tiny, double veryTiny) const
Facilitator to clean up coefficient.
~TMINLP2OsiLP()
Destructor.
TMINLP2OsiLP()
Default constructor.
vector< int > jCol_
Cache Jacobian matrix.
This is an adapter class that converts a TMINLP to a TNLP to be solved by Ipopt.
virtual void get_refined_oa(OsiCuts &cs) const =0
Get OAs of nonlinear constraints in x.
vector< Ipopt::TNLP::LinearityType > const_types_
double infty_
infinity.
vector< int > iRow_
Rows of jacobian.
virtual void extract(OsiSolverInterface *si, const double *x, bool getObj)=0
Build the Outer approximation of model_ in x and put it in si.