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 
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 
113 
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 
Bonmin::TMINLP2OsiLP::value_
vector< double > value_
Values of jacobian.
Definition: BonTMINLP2OsiLP.hpp:108
Bonmin::TMINLP2OsiLP::very_tiny_
double very_tiny_
If constraint coefficient is below this, we neglect it.
Definition: BonTMINLP2OsiLP.hpp:94
Bonmin::TMINLP2OsiLP::clone
virtual TMINLP2OsiLP * clone() const =0
virtual copy constructor
Bonmin
(C) Copyright International Business Machines Corporation 2007
Definition: BonAmplSetup.hpp:16
Bonmin::TMINLP2OsiLP::get_oas
virtual void get_oas(OsiCuts &cs, const double *x, bool getObj, bool global) const =0
Get OAs of nonlinear constraints in x.
Bonmin::TMINLP2OsiLP::const_types_
vector< Ipopt::TNLP::LinearityType > const_types_
Definition: BonTMINLP2OsiLP.hpp:110
Bonmin::TMINLP2OsiLP::set_tols
void set_tols(double tiny, double very_tiny, double rhs_relax, double infty)
Definition: BonTMINLP2OsiLP.hpp:46
Bonmin::vector< int >
Bonmin::TMINLP2OsiLP::iRow_
vector< int > iRow_
Rows of jacobian.
Definition: BonTMINLP2OsiLP.hpp:106
Bonmin::TMINLP2OsiLP::infty_
double infty_
infinity.
Definition: BonTMINLP2OsiLP.hpp:98
Bonmin::TMINLP2OsiLP::get_refined_oa
virtual void get_refined_oa(OsiCuts &cs) const =0
Get OAs of nonlinear constraints in x.
Bonmin::TMINLP2OsiLP::tiny_
double tiny_
If constraint coefficient is below this, we try to remove it.
Definition: BonTMINLP2OsiLP.hpp:92
BonTypes.hpp
Bonmin::TMINLP2OsiLP::extract
virtual void extract(OsiSolverInterface *si, const double *x, bool getObj)=0
Build the Outer approximation of model_ in x and put it in si.
Bonmin::TMINLP2OsiLP::~TMINLP2OsiLP
~TMINLP2OsiLP()
Destructor.
Definition: BonTMINLP2OsiLP.hpp:69
Ipopt::SmartPtr< Bonmin::TMINLP2TNLP >
Bonmin::TMINLP2OsiLP::model_
Ipopt::SmartPtr< Bonmin::TMINLP2TNLP > model_
Definition: BonTMINLP2OsiLP.hpp:114
Bonmin::TMINLP2TNLP
This is an adapter class that converts a TMINLP to a TNLP to be solved by Ipopt.
Definition: BonTMINLP2TNLP.hpp:33
Bonmin::TMINLP2OsiLP::nTimesCalled
static int nTimesCalled
Count the number of linear outer approximations taken.
Definition: BonTMINLP2OsiLP.hpp:100
OsiCuts
Bonmin::TMINLP2OsiLP::cleanNnz
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.
Definition: BonTMINLP2OsiLP.hpp:120
OsiSolverInterface
Bonmin::TMINLP2OsiLP::TMINLP2OsiLP
TMINLP2OsiLP(const TMINLP2OsiLP &other)
Copy constructor.
Definition: BonTMINLP2OsiLP.hpp:37
Bonmin::TMINLP2OsiLP::jCol_
vector< int > jCol_
Cache Jacobian matrix.
Definition: BonTMINLP2OsiLP.hpp:104
Bonmin::TMINLP2OsiLP::set_model
void set_model(Bonmin::TMINLP2TNLP *model)
Definition: BonTMINLP2OsiLP.hpp:53
Bonmin::TMINLP2OsiLP::operator=
TMINLP2OsiLP & operator=(const TMINLP2OsiLP &rhs)
Assignment operator.
Definition: BonTMINLP2OsiLP.hpp:59
Bonmin::TMINLP2OsiLP::TMINLP2OsiLP
TMINLP2OsiLP()
Default constructor.
Definition: BonTMINLP2OsiLP.hpp:31
IpSmartPtr.hpp
Bonmin::TMINLP2OsiLP::rhs_relax_
double rhs_relax_
Amount by which to relax OA constraints RHSes.
Definition: BonTMINLP2OsiLP.hpp:96
Bonmin::TMINLP2OsiLP::initialize_jac_storage
void initialize_jac_storage()
Bonmin::TMINLP2OsiLP
A transformer class to build outer approximations i.e.
Definition: BonTMINLP2OsiLP.hpp:26
Ipopt::ReferencedObject
IpTNLP.hpp