source: trunk/Cbc/src/CbcBranchingObject.hpp @ 1514

Last change on this file since 1514 was 1432, checked in by bjarni, 10 years ago

Added extra return at end of each source file where needed, to remove possible linefeed conflicts (NightlyBuild? errors)

File size: 7.4 KB
Line 
1// Edwin 11/12/2009 carved from CbcBranchBase
2#ifndef CbcBranchingObject_H
3#define CbcBranchingObject_H
4
5#include <string>
6#include <vector>
7#include "CbcBranchBase.hpp"
8#include "OsiBranchingObject.hpp"
9
10
11// The types of objects that will be derived from this class.
12enum CbcBranchObjType
13  {
14    SimpleIntegerBranchObj = 100,
15    SimpleIntegerDynamicPseudoCostBranchObj = 101,
16    CliqueBranchObj = 102,
17    LongCliqueBranchObj = 103,
18    SoSBranchObj = 104,
19    NWayBranchObj = 105,
20    FollowOnBranchObj = 106,
21    DummyBranchObj = 107,
22    GeneralDepthBranchObj = 108,
23    OneGeneralBranchingObj = 110,
24    CutBranchingObj = 200,
25    LotsizeBranchObj = 300,
26    DynamicPseudoCostBranchObj = 400
27  };
28
29/** \brief Abstract branching object base class
30    Now just difference with OsiBranchingObject
31
32  In the abstract, an CbcBranchingObject contains instructions for how to
33  branch. We want an abstract class so that we can describe how to branch on
34  simple objects (<i>e.g.</i>, integers) and more exotic objects
35  (<i>e.g.</i>, cliques or hyperplanes).
36
37  The #branch() method is the crucial routine: it is expected to be able to
38  step through a set of branch arms, executing the actions required to create
39  each subproblem in turn. The base class is primarily virtual to allow for
40  a wide range of problem modifications.
41
42  See CbcObject for an overview of the three classes (CbcObject,
43  CbcBranchingObject, and CbcBranchDecision) which make up cbc's branching
44  model.
45*/
46
47class CbcBranchingObject : public OsiBranchingObject {
48
49public:
50
51    /// Default Constructor
52    CbcBranchingObject ();
53
54    /// Constructor
55    CbcBranchingObject (CbcModel * model, int variable, int way , double value);
56
57    /// Copy constructor
58    CbcBranchingObject ( const CbcBranchingObject &);
59
60    /// Assignment operator
61    CbcBranchingObject & operator=( const CbcBranchingObject& rhs);
62
63    /// Clone
64    virtual CbcBranchingObject * clone() const = 0;
65
66    /// Destructor
67    virtual ~CbcBranchingObject ();
68
69    /** Some branchingObjects may claim to be able to skip
70        strong branching.  If so they have to fill in CbcStrongInfo.
71        The object mention in incoming CbcStrongInfo must match.
72        Returns nonzero if skip is wanted */
73    virtual int fillStrongInfo( CbcStrongInfo & ) {
74        return 0;
75    }
76    /// Reset number of branches left to original
77    inline void resetNumberBranchesLeft() {
78        branchIndex_ = 0;
79    }
80    /// Set number of branches to do
81    inline void setNumberBranches(int value) {
82        branchIndex_ = 0;
83        numberBranches_ = value;
84    }
85
86    /** \brief Execute the actions required to branch, as specified by the
87           current state of the branching object, and advance the object's
88           state.  Mainly for diagnostics, whether it is true branch or
89           strong branching is also passed.
90           Returns change in guessed objective on next branch
91    */
92    virtual double branch() = 0;
93    /** \brief Execute the actions required to branch, as specified by the
94           current state of the branching object, and advance the object's
95           state.  Mainly for diagnostics, whether it is true branch or
96           strong branching is also passed.
97           Returns change in guessed objective on next branch
98    */
99    virtual double branch(OsiSolverInterface * ) {
100        return branch();
101    }
102    /** Update bounds in solver as in 'branch' and update given bounds.
103        branchState is -1 for 'down' +1 for 'up' */
104    virtual void fix(OsiSolverInterface * ,
105                     double * , double * ,
106                     int ) const {}
107
108    /** Reset every information so that the branching object appears to point to
109        the previous child. This method does not need to modify anything in any
110        solver. */
111    virtual void previousBranch() {
112        assert(branchIndex_ > 0);
113        branchIndex_--;
114        way_ = -way_;
115    }
116
117    using OsiBranchingObject::print ;
118    /** \brief Print something about branch - only if log level high
119    */
120    virtual void print() const {}
121
122    /** \brief Index identifying the associated CbcObject within its class.
123
124      The name is misleading, and typically the index will <i>not</i> refer
125      directly to a variable.
126      Rather, it identifies an CbcObject within the class of similar
127      CbcObjects
128
129      <i>E.g.</i>, for an CbcSimpleInteger, variable() is the index of the
130      integer variable in the set of integer variables (<i>not</i> the index of
131      the variable in the set of all variables).
132    */
133    inline int variable() const {
134        return variable_;
135    }
136
137    /** Get the state of the branching object
138
139      Returns a code indicating the active arm of the branching object.
140      The precise meaning is defined in the derived class.
141
142      \sa #way_
143    */
144    inline int way() const {
145        return way_;
146    }
147
148    /** Set the state of the branching object.
149
150      See #way()
151    */
152    inline void way(int way) {
153        way_ = way;
154    }
155
156    /// update model
157    inline void setModel(CbcModel * model) {
158        model_ = model;
159    }
160    /// Return model
161    inline CbcModel * model() const {
162        return  model_;
163    }
164
165    /// Return pointer back to object which created
166    inline CbcObject * object() const {
167        return  originalCbcObject_;
168    }
169    /// Set pointer back to object which created
170    inline void setOriginalObject(CbcObject * object) {
171        originalCbcObject_ = object;
172    }
173
174    // Methods used in heuristics
175
176    /** Return the type (an integer identifier) of \c this.
177        See definition of CbcBranchObjType above for possibilities
178    */
179   
180    virtual CbcBranchObjType type() const = 0;
181
182    /** Compare the original object of \c this with the original object of \c
183        brObj. Assumes that there is an ordering of the original objects.
184        This method should be invoked only if \c this and brObj are of the same
185        type.
186        Return negative/0/positive depending on whether \c this is
187        smaller/same/larger than the argument.
188    */
189    virtual int compareOriginalObject(const CbcBranchingObject* brObj) const {
190        const CbcBranchingObject* br = dynamic_cast<const CbcBranchingObject*>(brObj);
191        return variable() - br->variable();
192    }
193
194    /** Compare the \c this with \c brObj. \c this and \c brObj must be of the
195        same type and must have the same original object, but they may have
196        different feasible regions.
197        Return the appropriate CbcRangeCompare value (first argument being the
198        sub/superset if that's the case). In case of overlap (and if \c
199        replaceIfOverlap is true) replace the current branching object with one
200        whose feasible region is the overlap.
201     */
202    virtual CbcRangeCompare compareBranchingObject
203    (const CbcBranchingObject* brObj, const bool replaceIfOverlap = false) = 0;
204
205protected:
206
207    /// The model that owns this branching object
208    CbcModel * model_;
209    /// Pointer back to object which created
210    CbcObject * originalCbcObject_;
211
212    /// Branching variable (0 is first integer)
213    int variable_;
214    // was - Way to branch - -1 down (first), 1 up, -2 down (second), 2 up (second)
215    /** The state of the branching object.
216
217      Specifies the active arm of the branching object. Coded as -1 to take
218      the `down' arm, +1 for the `up' arm. `Down' and `up' are defined based on
219      the natural meaning (floor and ceiling, respectively) for a simple integer.
220      The precise meaning is defined in the derived class.
221    */
222    int way_;
223
224};
225#endif
226
Note: See TracBrowser for help on using the repository browser.