Debian Codegraph @

Bonmin/src/Algorithms/QuadCuts/BonOuterApprox.hpp

raw
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 BonminOuterApprox_H
10 #define BonminOuterApprox_H
11
12 #include <cmath>
13
14 namespace Bonmin{
15 class OsiTMINLPInterface;
16 class BabSetupBase;
17 }
18 class OsiSolverInterface;
19 namespace Bonmin {
20 /** A class to build outer approximations.*/
21 class OuterApprox{
22
23 public:
24
25 /** Default constructor.*/
26 OuterApprox():
27 tiny_(-0.),
28 veryTiny_(-0.)
29 {}
30
31 /** Copy constructor.*/
32 OuterApprox(const OuterApprox & other):
33 tiny_(other.tiny_),
34 veryTiny_(other.veryTiny_){
35 }
36
37
38 /** Assignment operator.*/
39 OuterApprox & operator=(const OuterApprox& rhs){
40 if(this != & rhs){
41 tiny_ = rhs.tiny_;
42 veryTiny_ = rhs.veryTiny_;}
43 return (*this);
44 }
45
46 /** Destructor.*/
47 ~OuterApprox(){}
48
49 /** Initialize using options.*/
50 void initialize(Bonmin::BabSetupBase &b);
51
52 /** Build the Outer approximation in minlp and put it in si.*/
53 void extractLinearRelaxation(Bonmin::OsiTMINLPInterface &minlp,
54 OsiSolverInterface *si,
55 const double * x, bool getObj);
56 /** Operator() calls extractLinearRelaxation*/
57 void operator()(Bonmin::OsiTMINLPInterface &minlp,
58 OsiSolverInterface *si,
59 const double * x, bool getObj){
60 extractLinearRelaxation(minlp, si, x, getObj);}
61
62 private:
63 /** Facilitator to clean up coefficient.*/
64 inline bool cleanNnz(double &value, double colLower, double colUpper,
65 double rowLower, double rowUpper, double colsol,
66 double & lb, double &ub, double tiny, double veryTiny);
67 /** If constraint coefficient is below this, we try to remove it.*/
68 double tiny_;
69 /** If constraint coefficient is below this, we neglect it.*/
70 double veryTiny_;
71 /** Count the number of linear outer approximations taken.*/
72 static int nTimesCalled;
73 };
74
75 //A procedure to try to remove small coefficients in OA cuts (or make it non small
76 inline
77 bool
78 OuterApprox::cleanNnz(double &value, double colLower, double colUpper,
79 double rowLower, double rowUpper, double colsol,
80 double & lb, double &ub, double tiny, double veryTiny)
81 {
82 if(fabs(value)>= tiny) return 1;
83
84 if(fabs(value)<veryTiny) return 0;//Take the risk?
85
86 //try and remove
87 double infty = 1e20;
88 bool colUpBounded = colUpper < 10000;
89 bool colLoBounded = colLower > -10000;
90 bool rowNotLoBounded = rowLower <= - infty;
91 bool rowNotUpBounded = rowUpper >= infty;
92 bool pos = value > 0;
93
94 if(colLoBounded && pos && rowNotUpBounded) {
95 lb += value * (colsol - colLower);
96 return 0;
97 }
98 else
99 if(colLoBounded && !pos && rowNotLoBounded) {
100 ub += value * (colsol - colLower);
101 return 0;
102 }
103 else
104 if(colUpBounded && !pos && rowNotUpBounded) {
105 lb += value * (colsol - colUpper);
106 return 0;
107 }
108 else
109 if(colUpBounded && pos && rowNotLoBounded) {
110 ub += value * (colsol - colUpper);
111 return 0;
112 }
113 //can not remove coefficient increase it to smallest non zero
114 if(pos) value = tiny;
115 else
116 value = - tiny;
117 return 1;
118 }
119
120 }
121
122 #endif
123