source: trunk/Cbc/src/CbcCountRowCut.hpp @ 2094

Last change on this file since 2094 was 2094, checked in by forrest, 4 years ago

for memory leaks and heuristics and some experimental stuff

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