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