source: branches/sandbox/Cbc/src/CbcIntegerBranchingObject.hpp @ 1293

Last change on this file since 1293 was 1293, checked in by EdwinStraver, 10 years ago
File size: 5.3 KB
Line 
1// Edwin 11/10/2009-- carved out of CbcBranchActual
2#ifndef CbcIntegerBranchingObject_H
3#define CbcIntegerBranchingObject_H
4
5/** Simple branching object for an integer variable
6
7  This object can specify a two-way branch on an integer variable. For each
8  arm of the branch, the upper and lower bounds on the variable can be
9  independently specified.
10
11  Variable_ holds the index of the integer variable in the integerVariable_
12  array of the model.
13*/
14
15class CbcIntegerBranchingObject : public CbcBranchingObject {
16
17public:
18
19    /// Default constructor
20    CbcIntegerBranchingObject ();
21
22    /** Create a standard floor/ceiling branch object
23
24      Specifies a simple two-way branch. Let \p value = x*. One arm of the
25      branch will be lb <= x <= floor(x*), the other ceil(x*) <= x <= ub.
26      Specify way = -1 to set the object state to perform the down arm first,
27      way = 1 for the up arm.
28    */
29    CbcIntegerBranchingObject (CbcModel *model, int variable,
30                               int way , double value) ;
31
32    /** Create a degenerate branch object
33
34      Specifies a `one-way branch'. Calling branch() for this object will
35      always result in lowerValue <= x <= upperValue. Used to fix a variable
36      when lowerValue = upperValue.
37    */
38
39    CbcIntegerBranchingObject (CbcModel *model, int variable, int way,
40                               double lowerValue, double upperValue) ;
41
42    /// Copy constructor
43    CbcIntegerBranchingObject ( const CbcIntegerBranchingObject &);
44
45    /// Assignment operator
46    CbcIntegerBranchingObject & operator= (const CbcIntegerBranchingObject& rhs);
47
48    /// Clone
49    virtual CbcBranchingObject * clone() const;
50
51    /// Destructor
52    virtual ~CbcIntegerBranchingObject ();
53
54    /// Does part of constructor
55    void fillPart ( int variable, int way , double value) ;
56    using CbcBranchingObject::branch ;
57    /** \brief Sets the bounds for the variable according to the current arm
58           of the branch and advances the object state to the next arm.
59           Returns change in guessed objective on next branch
60    */
61    virtual double branch();
62    /** Update bounds in solver as in 'branch' and update given bounds.
63        branchState is -1 for 'down' +1 for 'up' */
64    virtual void fix(OsiSolverInterface * solver,
65                     double * lower, double * upper,
66                     int branchState) const ;
67
68#if 0
69    // No need to override. Default works fine.
70    /** Reset every information so that the branching object appears to point to
71        the previous child. This method does not need to modify anything in any
72        solver. */
73    virtual void previousBranch();
74#endif
75
76    using CbcBranchingObject::print ;
77    /** \brief Print something about branch - only if log level high
78    */
79    virtual void print();
80
81    /// Lower and upper bounds for down branch
82    inline const double * downBounds() const {
83        return down_;
84    }
85    /// Lower and upper bounds for up branch
86    inline const double * upBounds() const {
87        return up_;
88    }
89    /// Set lower and upper bounds for down branch
90    inline void setDownBounds(const double bounds[2]) {
91        memcpy(down_, bounds, 2*sizeof(double));
92    }
93    /// Set lower and upper bounds for up branch
94    inline void setUpBounds(const double bounds[2]) {
95        memcpy(up_, bounds, 2*sizeof(double));
96    }
97#ifdef FUNNY_BRANCHING
98    /** Which variable (top bit if upper bound changing,
99        next bit if on down branch */
100    inline const int * variables() const {
101        return variables_;
102    }
103    // New bound
104    inline const double * newBounds() const {
105        return newBounds_;
106    }
107    /// Number of bound changes
108    inline int numberExtraChangedBounds() const {
109        return numberExtraChangedBounds_;
110    }
111    /// Just apply extra bounds to one variable - COIN_DBL_MAX ignore
112    int applyExtraBounds(int iColumn, double lower, double upper, int way) ;
113    /// Deactivate bounds for branching
114    void deactivate();
115    /// Are active bounds for branching
116    inline bool active() const {
117        return (down_[1] != -COIN_DBL_MAX);
118    }
119#endif
120
121    /** Return the type (an integer identifier) of \c this */
122    virtual int type() const {
123        return 100;
124    }
125
126    /** Compare the \c this with \c brObj. \c this and \c brObj must be os the
127        same type and must have the same original object, but they may have
128        different feasible regions.
129        Return the appropriate CbcRangeCompare value (first argument being the
130        sub/superset if that's the case). In case of overlap (and if \c
131        replaceIfOverlap is true) replace the current branching object with one
132        whose feasible region is the overlap.
133     */
134    virtual CbcRangeCompare compareBranchingObject
135    (const CbcBranchingObject* brObj, const bool replaceIfOverlap = false);
136
137protected:
138    /// Lower [0] and upper [1] bounds for the down arm (way_ = -1)
139    double down_[2];
140    /// Lower [0] and upper [1] bounds for the up arm (way_ = 1)
141    double up_[2];
142#ifdef FUNNY_BRANCHING
143    /** Which variable (top bit if upper bound changing)
144        next bit if changing on down branch only */
145    int * variables_;
146    // New bound
147    double * newBounds_;
148    /// Number of Extra bound changes
149    int numberExtraChangedBounds_;
150#endif
151};
152#endif
Note: See TracBrowser for help on using the repository browser.