source: branches/sandbox/Cbc/src/CbcCountRowCut.cpp @ 1286

Last change on this file since 1286 was 1286, checked in by EdwinStraver, 10 years ago

Changed formatting using AStyle -A4 -p

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 KB
Line 
1/* $Id: CbcCountRowCut.cpp 1286 2009-11-09 23:33:07Z EdwinStraver $ */
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
16CbcCountRowCut::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
30CbcCountRowCut::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
42CbcCountRowCut::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}
58CbcCountRowCut::~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    owner_->deleteCut(ownerCut_);
66    ownerCut_ = -1234567;
67}
68// Increment number of references
69void
70CbcCountRowCut::increment(int change)
71{
72    assert(ownerCut_ != -1234567);
73    numberPointingToThis_ += change;
74}
75
76// Decrement number of references and return number left
77int
78CbcCountRowCut::decrement(int change)
79{
80    assert(ownerCut_ != -1234567);
81    // See if plausible number
82    if (change < 900000000) {
83        //assert(numberPointingToThis_>=change);
84        assert(numberPointingToThis_ >= 0);
85        if (numberPointingToThis_ < change) {
86            assert(numberPointingToThis_ > 0);
87            printf("negative cut count %d - %d\n", numberPointingToThis_, change);
88            change = numberPointingToThis_;
89        }
90        numberPointingToThis_ -= change;
91    }
92    return numberPointingToThis_;
93}
94
95// Set information
96void
97CbcCountRowCut::setInfo(CbcNodeInfo * info, int whichOne)
98{
99    owner_ = info;
100    ownerCut_ = whichOne;
101}
102// Returns true if can drop cut if slack basic
103bool
104CbcCountRowCut::canDropCut(const OsiSolverInterface * solver, int iRow) const
105{
106    // keep if COIN_DBL_MAX otherwise keep if slack zero
107    if (effectiveness() < 1.0e20) {
108        return true;
109    } else if (effectiveness() != COIN_DBL_MAX) {
110        if (iRow >= solver->getNumRows())
111            return true;
112        const double * rowActivity = solver->getRowActivity();
113        const double * rowLower = solver->getRowLower();
114        const double * rowUpper = solver->getRowUpper();
115        double tolerance;
116        solver->getDblParam(OsiPrimalTolerance, tolerance) ;
117        double value = rowActivity[iRow];
118        if (value < rowLower[iRow] + tolerance ||
119                value > rowUpper[iRow] - tolerance)
120            return false;
121        else
122            return true;
123    } else {
124        return false;
125    }
126}
127
Note: See TracBrowser for help on using the repository browser.