source: trunk/Cbc/src/CbcGeneralDepth.hpp @ 1424

Last change on this file since 1424 was 1389, checked in by caphillSNL, 10 years ago

Start at adding documentation, removing magic numbers, removing dead code, etc.
Added an enum for type in classes derived from CbCBranchingObject. It's safer,
handier for debugging (inspection in a debugger), and clearly shows the relationship
between the dozen or so special numbers. Numbers are the same as they were before to
ensure no changes in correctness.

File size: 8.2 KB
Line 
1// Edwin 11/10/2009-- carved out of CbcBranchActual
2#ifndef CbcGeneralDepth_H
3#define CbcGeneralDepth_H
4
5#include "CbcGeneral.hpp"
6#include "CbcBranchBase.hpp"
7#include "CbcSubProblem.hpp"
8
9#ifdef COIN_HAS_CLP
10
11/** Define a catch all class.
12    This will create a list of subproblems using partial evaluation
13*/
14#include "ClpSimplex.hpp"
15#include "ClpNode.hpp"
16
17
18class CbcGeneralDepth : public CbcGeneral {
19
20public:
21
22    // Default Constructor
23    CbcGeneralDepth ();
24
25    /** Useful constructor
26        Just needs to point to model.
27        Initial version does evaluation to depth N
28        This is stored in CbcModel but may be
29        better here
30    */
31    CbcGeneralDepth (CbcModel * model, int maximumDepth);
32
33    // Copy constructor
34    CbcGeneralDepth ( const CbcGeneralDepth &);
35
36    /// Clone
37    virtual CbcObject * clone() const;
38
39    // Assignment operator
40    CbcGeneralDepth & operator=( const CbcGeneralDepth& rhs);
41
42    // Destructor
43    ~CbcGeneralDepth ();
44
45    /// Infeasibility - large is 0.5
46    virtual double infeasibility(const OsiBranchingInformation * info,
47                                 int &preferredWay) const;
48
49    using CbcObject::feasibleRegion ;
50    /// This looks at solution and sets bounds to contain solution
51    virtual void feasibleRegion();
52
53    /// Creates a branching object
54    virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) ;
55    /// Return maximum number of nodes
56    inline int maximumNodes() const {
57        return maximumNodes_;
58    }
59    /// Get maximum depth
60    inline int maximumDepth() const {
61        return maximumDepth_;
62    }
63    /// Set maximum depth
64    inline void setMaximumDepth(int value) {
65        maximumDepth_ = value;
66    }
67    /// Get which solution
68    inline int whichSolution() const {
69        return whichSolution_;
70    }
71    /// Get ClpNode info
72    inline ClpNode * nodeInfo(int which) {
73        return nodeInfo_->nodeInfo_[which];
74    }
75
76    /// Redoes data when sequence numbers change
77    virtual void redoSequenceEtc(CbcModel * model, int numberColumns, const int * originalColumns);
78
79protected:
80    /// data
81    /// Maximum depth
82    int maximumDepth_;
83    /// Maximum nodes
84    int maximumNodes_;
85    /// Which node has solution (or -1)
86    mutable int whichSolution_;
87    /// Number of valid nodes (including whichSolution_)
88    mutable int numberNodes_;
89    /// For solving nodes
90    mutable ClpNodeStuff * nodeInfo_;
91};
92/** Branching object for general objects
93
94 */
95class CbcNode;
96class CbcGeneralBranchingObject : public CbcBranchingObject {
97
98public:
99
100    // Default Constructor
101    CbcGeneralBranchingObject ();
102
103    // Useful constructor
104    CbcGeneralBranchingObject (CbcModel * model);
105
106    // Copy constructor
107    CbcGeneralBranchingObject ( const CbcGeneralBranchingObject &);
108
109    // Assignment operator
110    CbcGeneralBranchingObject & operator=( const CbcGeneralBranchingObject& rhs);
111
112    /// Clone
113    virtual CbcBranchingObject * clone() const;
114
115    // Destructor
116    virtual ~CbcGeneralBranchingObject ();
117
118    using CbcBranchingObject::branch ;
119    /// Does next branch and updates state
120    virtual double branch();
121    /** Double checks in case node can change its mind!
122        Can change objective etc */
123    virtual void checkIsCutoff(double cutoff);
124
125    using CbcBranchingObject::print ;
126    /** \brief Print something about branch - only if log level high
127    */
128    virtual void print();
129    /// Fill in current objective etc
130    void state(double & objectiveValue, double & sumInfeasibilities,
131               int & numberUnsatisfied, int which) const;
132    /// Set CbcNode
133    inline void setNode(CbcNode * node) {
134        node_ = node;
135    }
136    /** Return the type (an integer identifier) of \c this */
137    virtual CbcBranchObjType type() const {
138        return GeneralDepthBranchObj;
139    }
140
141    /** Compare the original object of \c this with the original object of \c
142        brObj. Assumes that there is an ordering of the original objects.
143        This method should be invoked only if \c this and brObj are of the same
144        type.
145        Return negative/0/positive depending on whether \c this is
146        smaller/same/larger than the argument.
147    */
148    virtual int compareOriginalObject(const CbcBranchingObject* brObj) const;
149
150    /** Compare the \c this with \c brObj. \c this and \c brObj must be os the
151        same type and must have the same original object, but they may have
152        different feasible regions.
153        Return the appropriate CbcRangeCompare value (first argument being the
154        sub/superset if that's the case). In case of overlap (and if \c
155        replaceIfOverlap is true) replace the current branching object with one
156        whose feasible region is the overlap.
157     */
158    virtual CbcRangeCompare compareBranchingObject
159    (const CbcBranchingObject* brObj, const bool replaceIfOverlap = false);
160    /// Number of subproblems
161    inline int numberSubProblems() const {
162        return numberSubProblems_;
163    }
164    /// Decrement number left and return number
165    inline int decrementNumberLeft() {
166        numberSubLeft_--;
167        return numberSubLeft_;
168    }
169    /// Which node we want to use
170    inline int whichNode() const {
171        return whichNode_;
172    }
173    /// Set which node we want to use
174    inline void setWhichNode(int value) {
175        whichNode_ = value;
176    }
177    // Sub problem
178    const CbcSubProblem * subProblem(int which) const {
179        return subProblems_ + which;
180    }
181
182public:
183    /// data
184    // Sub problems
185    CbcSubProblem * subProblems_;
186    /// Node
187    CbcNode * node_;
188    /// Number of subproblems
189    int numberSubProblems_;
190    /// Number of subproblems left
191    int numberSubLeft_;
192    /// Which node we want to use (-1 for default)
193    int whichNode_;
194    /// Number of rows
195    int numberRows_;
196};
197/** Branching object for general objects - just one
198
199 */
200class CbcOneGeneralBranchingObject : public CbcBranchingObject {
201
202public:
203
204    // Default Constructor
205    CbcOneGeneralBranchingObject ();
206
207    // Useful constructor
208    CbcOneGeneralBranchingObject (CbcModel * model,
209                                  CbcGeneralBranchingObject * object,
210                                  int whichOne);
211
212    // Copy constructor
213    CbcOneGeneralBranchingObject ( const CbcOneGeneralBranchingObject &);
214
215    // Assignment operator
216    CbcOneGeneralBranchingObject & operator=( const CbcOneGeneralBranchingObject& rhs);
217
218    /// Clone
219    virtual CbcBranchingObject * clone() const;
220
221    // Destructor
222    virtual ~CbcOneGeneralBranchingObject ();
223
224    using CbcBranchingObject::branch ;
225    /// Does next branch and updates state
226    virtual double branch();
227    /** Double checks in case node can change its mind!
228        Can change objective etc */
229    virtual void checkIsCutoff(double cutoff);
230
231    using CbcBranchingObject::print ;
232    /** \brief Print something about branch - only if log level high
233    */
234    virtual void print();
235    /** Return the type (an integer identifier) of \c this */
236    virtual CbcBranchObjType type() const {
237        return OneGeneralBranchingObj;
238    }
239
240    /** Compare the original object of \c this with the original object of \c
241        brObj. Assumes that there is an ordering of the original objects.
242        This method should be invoked only if \c this and brObj are of the same
243        type.
244        Return negative/0/positive depending on whether \c this is
245        smaller/same/larger than the argument.
246    */
247    virtual int compareOriginalObject(const CbcBranchingObject* brObj) const;
248
249    /** Compare the \c this with \c brObj. \c this and \c brObj must be os the
250        same type and must have the same original object, but they may have
251        different feasible regions.
252        Return the appropriate CbcRangeCompare value (first argument being the
253        sub/superset if that's the case). In case of overlap (and if \c
254        replaceIfOverlap is true) replace the current branching object with one
255        whose feasible region is the overlap.
256     */
257    virtual CbcRangeCompare compareBranchingObject
258    (const CbcBranchingObject* brObj, const bool replaceIfOverlap = false);
259
260public:
261    /// data
262    /// Object
263    CbcGeneralBranchingObject * object_;
264    /// Which one
265    int whichOne_;
266};
267#endif //COIN_HAS_CLP
268#endif
Note: See TracBrowser for help on using the repository browser.