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