source: trunk/Cbc/src/CbcCountRowCut.hpp

Last change on this file was 2465, checked in by unxusr, 10 months ago

script to format sources

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 KB
Line 
1/* $Id: CbcCountRowCut.hpp 2465 2019-01-03 19:26:52Z unxusr $ */
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#ifndef CbcCountRowCut_H
7#define CbcCountRowCut_H
8
9class OsiCuts;
10class OsiRowCut;
11class CbcNodeInfo;
12
13//#############################################################################
14/** \brief OsiRowCut augmented with bookkeeping
15
16  CbcCountRowCut is an OsiRowCut object augmented with bookkeeping
17  information: a reference count and information that specifies the
18  the generator that created the cut and the node to which it's associated.
19
20  The general principles for handling the reference count are as follows:
21  <ul>
22    <li> Once it's determined how the node will branch, increment the
23         reference count under the assumption that all children will use
24         all cuts currently tight at the node and will survive to be placed
25         in the search tree.
26    <li> As this assumption is proven incorrect (a cut becomes loose, or a
27         child is fathomed), decrement the reference count accordingly.
28  </ul>
29  When all possible uses of a cut have been demonstrated to be unnecessary,
30  the reference count (#numberPointingToThis_) will fall to zero. The
31  CbcCountRowCut object (and its included OsiRowCut object) are then deleted.
32*/
33
34class CbcCountRowCut : public OsiRowCut {
35
36public:
37  /** @name Constructors & destructors */
38  //@{
39
40  /// Default Constructor
41  CbcCountRowCut();
42
43  /// `Copy' constructor using an OsiRowCut
44  CbcCountRowCut(const OsiRowCut &);
45
46  /// `Copy' constructor using an OsiRowCut and an CbcNodeInfo
47  CbcCountRowCut(const OsiRowCut &, CbcNodeInfo *, int whichOne,
48    int whichGenerator = -1, int numberPointingToThis = 0);
49
50  /** Destructor
51
52      \note The destructor will reach out (via #owner_) and NULL the
53      reference to the cut in the owner's
54      \link CbcNodeInfo::cuts_ cuts_ \endlink list.
55    */
56  virtual ~CbcCountRowCut();
57  //@}
58
59  /// Increment the number of references
60  void increment(int change = 1);
61
62  /// Decrement the number of references and return the number left.
63  int decrement(int change = 1);
64
65  /** \brief Set the information associating this cut with a node
66
67      An CbcNodeInfo object and an index in the cut set of the node.
68      For locally valid cuts, the node will be the  search tree node where the
69      cut was generated. For globally valid cuts, it's the node where the cut
70      was activated.
71    */
72  void setInfo(CbcNodeInfo *, int whichOne);
73
74  /// Number of other CbcNodeInfo objects pointing to this row cut
75  inline int numberPointingToThis()
76  {
77    return numberPointingToThis_;
78  }
79
80  /// Which generator for cuts - as user order
81  inline int whichCutGenerator() const
82  {
83    return whichCutGenerator_;
84  }
85
86  /// Returns true if can drop cut if slack basic
87  bool canDropCut(const OsiSolverInterface *solver, int row) const;
88
89#ifdef CHECK_CUT_COUNTS
90  // Just for printing sanity checks
91  int tempNumber_;
92#endif
93
94private:
95  /// Standard copy is illegal (reference counts would be incorrect)
96  CbcCountRowCut(const CbcCountRowCut &);
97
98  /// Standard assignment is illegal (reference counts would be incorrect)
99  CbcCountRowCut &operator=(const CbcCountRowCut &rhs);
100
101  /// Backward pointer to owning CbcNodeInfo
102  CbcNodeInfo *owner_;
103
104  /// Index of cut in owner's cut set
105  /// (\link CbcNodeInfo::cuts_ cuts_ \endlink).
106  int ownerCut_;
107
108  /// Number of other CbcNodeInfo objects pointing to this cut
109  int numberPointingToThis_;
110
111  /** Which generator created this cut
112        (add 10000 if globally valid)
113        if -1 then from global cut pool
114        -2 cut branch
115        -3 unknown
116    */
117  int whichCutGenerator_;
118};
119/**
120   Really for Conflict cuts to -
121   a) stop duplicates
122   b) allow half baked cuts
123   The whichRow_ field in OsiRowCut2 is used for a type
124   0 - normal
125   1 - processed cut (conflict)
126   2 - unprocessed cut i.e. dual ray computation
127*/
128// for hashing
129typedef struct {
130  int index, next;
131} CoinHashLink;
132class CbcRowCuts {
133public:
134  CbcRowCuts(int initialMaxSize = 0, int hashMultiplier = 4);
135  ~CbcRowCuts();
136  CbcRowCuts(const CbcRowCuts &rhs);
137  CbcRowCuts &operator=(const CbcRowCuts &rhs);
138  inline OsiRowCut2 *cut(int sequence) const
139  {
140    return rowCut_[sequence];
141  }
142  inline int numberCuts() const
143  {
144    return numberCuts_;
145  }
146  inline int sizeRowCuts() const
147  {
148    return numberCuts_;
149  }
150  inline OsiRowCut *rowCutPtr(int sequence)
151  {
152    return rowCut_[sequence];
153  }
154  void eraseRowCut(int sequence);
155  // Return 0 if added, 1 if not, -1 if not added because of space
156  int addCutIfNotDuplicate(const OsiRowCut &cut, int whichType = 0);
157  // Return 0 if added, 1 if not, -1 if not added because of space
158  int addCutIfNotDuplicateWhenGreedy(const OsiRowCut &cut, int whichType = 0);
159  // Add in cuts as normal cuts (and delete)
160  void addCuts(OsiCuts &cs);
161  // Truncate
162  void truncate(int numberAfter);
163
164private:
165  OsiRowCut2 **rowCut_;
166  /// Hash table
167  CoinHashLink *hash_;
168  int size_;
169  int hashMultiplier_;
170  int numberCuts_;
171  int lastHash_;
172};
173#endif
174
175/* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
176*/
Note: See TracBrowser for help on using the repository browser.