1 | // Copyright (C) 2002, International Business Machines |
---|
2 | // Corporation and others. All Rights Reserved. |
---|
3 | #if defined(_MSC_VER) |
---|
4 | // Turn off compiler warning about long names |
---|
5 | # pragma warning(disable:4786) |
---|
6 | #endif |
---|
7 | #include <cassert> |
---|
8 | |
---|
9 | #include "OsiRowCut.hpp" |
---|
10 | #include "CbcCountRowCut.hpp" |
---|
11 | #include "CbcNode.hpp" |
---|
12 | //#define CHECK_CUT_COUNTS |
---|
13 | // Default Constructor |
---|
14 | CbcCountRowCut::CbcCountRowCut () |
---|
15 | : |
---|
16 | OsiRowCut(), |
---|
17 | owner_(NULL), |
---|
18 | ownerCut_(-1), |
---|
19 | numberPointingToThis_(0), |
---|
20 | whichCutGenerator_(-1) |
---|
21 | { |
---|
22 | #ifdef CBC_DETERMINISTIC_THREAD |
---|
23 | numberPointingToThis_=10; |
---|
24 | #endif |
---|
25 | #ifdef CHECK_CUT_COUNTS |
---|
26 | printf("CbcCountRowCut default constructor %x\n",this); |
---|
27 | #endif |
---|
28 | } |
---|
29 | |
---|
30 | // Copy Constructor |
---|
31 | CbcCountRowCut::CbcCountRowCut (const OsiRowCut & rhs) |
---|
32 | : OsiRowCut(rhs), |
---|
33 | owner_(NULL), |
---|
34 | ownerCut_(-1), |
---|
35 | numberPointingToThis_(0), |
---|
36 | whichCutGenerator_(-1) |
---|
37 | { |
---|
38 | #ifdef CBC_DETERMINISTIC_THREAD |
---|
39 | numberPointingToThis_=10; |
---|
40 | #endif |
---|
41 | #ifdef CHECK_CUT_COUNTS |
---|
42 | printf("CbcCountRowCut constructor %x from RowCut\n",this); |
---|
43 | #endif |
---|
44 | } |
---|
45 | // Copy Constructor |
---|
46 | CbcCountRowCut::CbcCountRowCut (const OsiRowCut & rhs, |
---|
47 | CbcNodeInfo * info, int whichOne, |
---|
48 | int whichGenerator) |
---|
49 | : OsiRowCut(rhs), |
---|
50 | owner_(info), |
---|
51 | ownerCut_(whichOne), |
---|
52 | numberPointingToThis_(0), |
---|
53 | whichCutGenerator_(whichGenerator) |
---|
54 | { |
---|
55 | #ifdef CBC_DETERMINISTIC_THREAD |
---|
56 | numberPointingToThis_=10; |
---|
57 | #endif |
---|
58 | #ifdef CHECK_CUT_COUNTS |
---|
59 | printf("CbcCountRowCut constructor %x from RowCut and info\n",this); |
---|
60 | #endif |
---|
61 | } |
---|
62 | CbcCountRowCut::~CbcCountRowCut() |
---|
63 | { |
---|
64 | #ifdef CHECK_CUT_COUNTS |
---|
65 | printf("CbcCountRowCut destructor %x - references %d\n",this, |
---|
66 | numberPointingToThis_); |
---|
67 | #endif |
---|
68 | // Look at owner and delete |
---|
69 | owner_->deleteCut(ownerCut_); |
---|
70 | ownerCut_=-1234567; |
---|
71 | } |
---|
72 | // Increment number of references |
---|
73 | void |
---|
74 | CbcCountRowCut::increment(int change) |
---|
75 | { |
---|
76 | assert(ownerCut_!=-1234567); |
---|
77 | #ifndef CBC_DETERMINISTIC_THREAD |
---|
78 | numberPointingToThis_+=change; |
---|
79 | #endif |
---|
80 | } |
---|
81 | |
---|
82 | // Decrement number of references and return number left |
---|
83 | int |
---|
84 | CbcCountRowCut::decrement(int change) |
---|
85 | { |
---|
86 | assert(ownerCut_!=-1234567); |
---|
87 | #ifndef CBC_DETERMINISTIC_THREAD |
---|
88 | //assert(numberPointingToThis_>=change); |
---|
89 | assert(numberPointingToThis_>=0); |
---|
90 | if(numberPointingToThis_<change) { |
---|
91 | assert(numberPointingToThis_>0); |
---|
92 | printf("negative cut count %d - %d\n",numberPointingToThis_, change); |
---|
93 | change = numberPointingToThis_; |
---|
94 | } |
---|
95 | numberPointingToThis_-=change; |
---|
96 | #else |
---|
97 | assert (numberPointingToThis_==10); |
---|
98 | #endif |
---|
99 | return numberPointingToThis_; |
---|
100 | } |
---|
101 | |
---|
102 | // Set information |
---|
103 | void |
---|
104 | CbcCountRowCut::setInfo(CbcNodeInfo * info, int whichOne) |
---|
105 | { |
---|
106 | owner_=info; |
---|
107 | ownerCut_=whichOne; |
---|
108 | } |
---|
109 | // Returns true if can drop cut if slack basic |
---|
110 | bool |
---|
111 | CbcCountRowCut::canDropCut(const OsiSolverInterface * solver, int iRow) const |
---|
112 | { |
---|
113 | // keep if COIN_DBL_MAX otherwise keep if slack zero |
---|
114 | if (effectiveness()<1.0e20) { |
---|
115 | return true; |
---|
116 | } else if (effectiveness()!=COIN_DBL_MAX) { |
---|
117 | if (iRow>=solver->getNumRows()) |
---|
118 | return true; |
---|
119 | const double * rowActivity = solver->getRowActivity(); |
---|
120 | const double * rowLower = solver->getRowLower(); |
---|
121 | const double * rowUpper = solver->getRowUpper(); |
---|
122 | double tolerance; |
---|
123 | solver->getDblParam(OsiPrimalTolerance,tolerance) ; |
---|
124 | double value = rowActivity[iRow]; |
---|
125 | if (value<rowLower[iRow]+tolerance|| |
---|
126 | value>rowUpper[iRow]-tolerance) |
---|
127 | return false; |
---|
128 | else |
---|
129 | return true; |
---|
130 | } else { |
---|
131 | return false; |
---|
132 | } |
---|
133 | } |
---|
134 | |
---|