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

Last change on this file since 1424 was 1393, checked in by lou, 10 years ago

Mark #if 0 with JJF_ZERO and #if 1 with JJF_ONE as a historical reference
point.

File size: 4.9 KB
Line 
1// Edwin 11/9/2009-- carved out of CbcBranchActual
2/** Define an n-way class for variables.
3    Only valid value is one at UB others at LB
4    Normally 0-1
5*/
6#ifndef CbcNWay_H
7#define CbcNWay_H
8
9class CbcNWay : public CbcObject {
10
11public:
12
13    // Default Constructor
14    CbcNWay ();
15
16    /** Useful constructor (which are matrix indices)
17    */
18    CbcNWay (CbcModel * model, int numberMembers,
19             const int * which, int identifier);
20
21    // Copy constructor
22    CbcNWay ( const CbcNWay &);
23
24    /// Clone
25    virtual CbcObject * clone() const;
26
27    /// Assignment operator
28    CbcNWay & operator=( const CbcNWay& rhs);
29
30    /// Destructor
31    virtual ~CbcNWay ();
32
33    /// Set up a consequence for a single member
34    void setConsequence(int iColumn, const CbcConsequence & consequence);
35
36    /// Applies a consequence for a single member
37    void applyConsequence(int iSequence, int state) const;
38
39    /// Infeasibility - large is 0.5 (and 0.5 will give this)
40    virtual double infeasibility(const OsiBranchingInformation * info,
41                                 int &preferredWay) const;
42
43    using CbcObject::feasibleRegion ;
44    /// This looks at solution and sets bounds to contain solution
45    virtual void feasibleRegion();
46
47    /// Creates a branching object
48    virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) ;
49
50    /// Number of members
51    inline int numberMembers() const {
52        return numberMembers_;
53    }
54
55    /// Members (indices in range 0 ... numberColumns-1)
56    inline const int * members() const {
57        return members_;
58    }
59    /// Redoes data when sequence numbers change
60    virtual void redoSequenceEtc(CbcModel * model, int numberColumns, const int * originalColumns);
61
62protected:
63    /// data
64    /// Number of members
65    int numberMembers_;
66
67    /// Members (indices in range 0 ... numberColumns-1)
68    int * members_;
69    /// Consequences (normally NULL)
70    CbcConsequence ** consequence_;
71};
72/** N way branching Object class.
73    Variable is number of set.
74 */
75class CbcNWayBranchingObject : public CbcBranchingObject {
76
77public:
78
79    // Default Constructor
80    CbcNWayBranchingObject ();
81
82    /** Useful constructor - order had matrix indices
83        way_ -1 corresponds to setting first, +1 to second, +3 etc.
84        this is so -1 and +1 have similarity to normal
85    */
86    CbcNWayBranchingObject (CbcModel * model,  const CbcNWay * nway,
87                            int numberBranches, const int * order);
88
89    // Copy constructor
90    CbcNWayBranchingObject ( const CbcNWayBranchingObject &);
91
92    // Assignment operator
93    CbcNWayBranchingObject & operator=( const CbcNWayBranchingObject& rhs);
94
95    /// Clone
96    virtual CbcBranchingObject * clone() const;
97
98    // Destructor
99    virtual ~CbcNWayBranchingObject ();
100
101    using CbcBranchingObject::branch ;
102    /// Does next branch and updates state
103    virtual double branch();
104
105#ifdef JJF_ZERO
106    // FIXME: what do we need to do here?
107    /** Reset every information so that the branching object appears to point to
108        the previous child. This method does not need to modify anything in any
109        solver. */
110    virtual void previousBranch();
111#endif
112
113    using CbcBranchingObject::print ;
114    /** \brief Print something about branch - only if log level high
115    */
116    virtual void print();
117    /** The number of branch arms created for this branching object
118    */
119    virtual int numberBranches() const {
120        return numberInSet_;
121    }
122    /// Is this a two way object (-1 down, +1 up)
123    virtual bool twoWay() const {
124        return false;
125    }
126
127    /** Return the type (an integer identifier) of \c this */
128    virtual CbcBranchObjType type() const {
129        return NWayBranchObj;
130    }
131
132    /** Compare the original object of \c this with the original object of \c
133        brObj. Assumes that there is an ordering of the original objects.
134        This method should be invoked only if \c this and brObj are of the same
135        type.
136        Return negative/0/positive depending on whether \c this is
137        smaller/same/larger than the argument.
138    */
139    virtual int compareOriginalObject(const CbcBranchingObject* brObj) const;
140
141    /** Compare the \c this with \c brObj. \c this and \c brObj must be os the
142        same type and must have the same original object, but they may have
143        different feasible regions.
144        Return the appropriate CbcRangeCompare value (first argument being the
145        sub/superset if that's the case). In case of overlap (and if \c
146        replaceIfOverlap is true) replace the current branching object with one
147        whose feasible region is the overlap.
148     */
149    virtual CbcRangeCompare compareBranchingObject
150    (const CbcBranchingObject* brObj, const bool replaceIfOverlap = false);
151
152private:
153    /// order of branching - points back to CbcNWay
154    int * order_;
155    /// Points back to object
156    const CbcNWay * object_;
157    /// Number in set
158    int numberInSet_;
159};
160#endif
Note: See TracBrowser for help on using the repository browser.