Bonmin 1.8.9
Loading...
Searching...
No Matches
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
19class OsiCuts;
20
21namespace 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_),
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_;
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
118inline
119bool
120TMINLP2OsiLP::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
A transformer class to build outer approximations i.e.
virtual void get_oas(OsiCuts &cs, const double *x, bool getObj, bool global) const =0
Get OAs of nonlinear constraints in x.
virtual void get_refined_oa(OsiCuts &cs) const =0
Get OAs of nonlinear constraints in x.
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.
virtual void extract(OsiSolverInterface *si, const double *x, bool getObj)=0
Build the Outer approximation of model_ in x and put it in si.
vector< int > iRow_
Rows of jacobian.
void set_model(Bonmin::TMINLP2TNLP *model)
TMINLP2OsiLP & operator=(const TMINLP2OsiLP &rhs)
Assignment operator.
TMINLP2OsiLP()
Default constructor.
virtual TMINLP2OsiLP * clone() const =0
virtual copy constructor
static int nTimesCalled
Count the number of linear outer approximations taken.
double tiny_
If constraint coefficient is below this, we try to remove it.
vector< int > jCol_
Cache Jacobian matrix.
void set_tols(double tiny, double very_tiny, double rhs_relax, double infty)
vector< double > value_
Values of jacobian.
double very_tiny_
If constraint coefficient is below this, we neglect it.
vector< Ipopt::TNLP::LinearityType > const_types_
double rhs_relax_
Amount by which to relax OA constraints RHSes.
Ipopt::SmartPtr< Bonmin::TMINLP2TNLP > model_
TMINLP2OsiLP(const TMINLP2OsiLP &other)
Copy constructor.
This is an adapter class that converts a TMINLP to a TNLP to be solved by Ipopt.
A small wrap around std::vector to give easy access to array for interfacing with fortran code.
Definition BonTypes.hpp:9
(C) Copyright International Business Machines Corporation 2007