source: trunk/Cbc/src/CbcCountRowCut.cpp @ 952

Last change on this file since 952 was 952, checked in by forrest, 12 years ago

for stored cuts

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
Line 
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
14CbcCountRowCut::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
31CbcCountRowCut::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
46CbcCountRowCut::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}
62CbcCountRowCut::~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
73void 
74CbcCountRowCut::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
83int 
84CbcCountRowCut::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
103void 
104CbcCountRowCut::setInfo(CbcNodeInfo * info, int whichOne)
105{
106  owner_=info;
107  ownerCut_=whichOne;
108}
109// Returns true if can drop cut if slack basic
110bool 
111CbcCountRowCut::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    const double * rowActivity = solver->getRowActivity();
118    const double * rowLower = solver->getRowLower();
119    const double * rowUpper = solver->getRowUpper();
120    double tolerance;
121    solver->getDblParam(OsiPrimalTolerance,tolerance) ;
122    double value = rowActivity[iRow];
123    if (value<rowLower[iRow]+tolerance||
124        value>rowUpper[iRow]-tolerance)
125      return false;
126    else
127      return true;
128  } else {
129    return false;
130  }
131}
132
Note: See TracBrowser for help on using the repository browser.