source: releases/2.7.1/Cbc/src/CbcCountRowCut.cpp @ 1995

Last change on this file since 1995 was 1675, checked in by stefan, 8 years ago

sync with trunk rev1674

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