1 | // $Id: CbcFollowOn.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/10/2009-- carved out of CbcBranchActual |
---|
7 | |
---|
8 | #ifndef CbcFollowOn_H |
---|
9 | #define CbcFollowOn_H |
---|
10 | |
---|
11 | #include "CbcBranchBase.hpp" |
---|
12 | #include "OsiRowCut.hpp" |
---|
13 | #include "CoinHelperFunctions.hpp" |
---|
14 | #include "CoinPackedMatrix.hpp" |
---|
15 | |
---|
16 | /** Define a follow on class. |
---|
17 | The idea of this is that in air-crew scheduling problems crew may fly in on flight A |
---|
18 | and out on flight B or on some other flight. A useful branch is one which on one side |
---|
19 | fixes all which go out on flight B to 0, while the other branch fixes all those that do NOT |
---|
20 | go out on flight B to 0. |
---|
21 | |
---|
22 | This branching rule should be in addition to normal rules and have a high priority. |
---|
23 | */ |
---|
24 | |
---|
25 | class CbcFollowOn : public CbcObject { |
---|
26 | |
---|
27 | public: |
---|
28 | |
---|
29 | // Default Constructor |
---|
30 | CbcFollowOn (); |
---|
31 | |
---|
32 | /** Useful constructor |
---|
33 | */ |
---|
34 | CbcFollowOn (CbcModel * model); |
---|
35 | |
---|
36 | // Copy constructor |
---|
37 | CbcFollowOn ( const CbcFollowOn &); |
---|
38 | |
---|
39 | /// Clone |
---|
40 | virtual CbcObject * clone() const; |
---|
41 | |
---|
42 | // Assignment operator |
---|
43 | CbcFollowOn & operator=( const CbcFollowOn& rhs); |
---|
44 | |
---|
45 | // Destructor |
---|
46 | ~CbcFollowOn (); |
---|
47 | |
---|
48 | /// Infeasibility - large is 0.5 |
---|
49 | virtual double infeasibility(const OsiBranchingInformation * info, |
---|
50 | int &preferredWay) const; |
---|
51 | |
---|
52 | using CbcObject::feasibleRegion ; |
---|
53 | /// This looks at solution and sets bounds to contain solution |
---|
54 | virtual void feasibleRegion(); |
---|
55 | |
---|
56 | /// Creates a branching object |
---|
57 | virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) ; |
---|
58 | /// As some computation is needed in more than one place - returns row |
---|
59 | virtual int gutsOfFollowOn(int & otherRow, int & preferredWay) const; |
---|
60 | |
---|
61 | protected: |
---|
62 | /// data |
---|
63 | /// Matrix |
---|
64 | CoinPackedMatrix matrix_; |
---|
65 | /// Matrix by row |
---|
66 | CoinPackedMatrix matrixByRow_; |
---|
67 | /// Possible rhs (if 0 then not possible) |
---|
68 | int * rhs_; |
---|
69 | }; |
---|
70 | |
---|
71 | /** General Branching Object class. |
---|
72 | Each way fixes some variables to lower bound |
---|
73 | */ |
---|
74 | class CbcFixingBranchingObject : public CbcBranchingObject { |
---|
75 | |
---|
76 | public: |
---|
77 | |
---|
78 | // Default Constructor |
---|
79 | CbcFixingBranchingObject (); |
---|
80 | |
---|
81 | // Useful constructor |
---|
82 | CbcFixingBranchingObject (CbcModel * model, |
---|
83 | int way, |
---|
84 | int numberOnDownSide, const int * down, |
---|
85 | int numberOnUpSide, const int * up); |
---|
86 | |
---|
87 | // Copy constructor |
---|
88 | CbcFixingBranchingObject ( const CbcFixingBranchingObject &); |
---|
89 | |
---|
90 | // Assignment operator |
---|
91 | CbcFixingBranchingObject & operator=( const CbcFixingBranchingObject& rhs); |
---|
92 | |
---|
93 | /// Clone |
---|
94 | virtual CbcBranchingObject * clone() const; |
---|
95 | |
---|
96 | // Destructor |
---|
97 | virtual ~CbcFixingBranchingObject (); |
---|
98 | |
---|
99 | using CbcBranchingObject::branch ; |
---|
100 | /// Does next branch and updates state |
---|
101 | virtual double branch(); |
---|
102 | |
---|
103 | #ifdef JJF_ZERO |
---|
104 | // No need to override. Default works fine. |
---|
105 | /** Reset every information so that the branching object appears to point to |
---|
106 | the previous child. This method does not need to modify anything in any |
---|
107 | solver. */ |
---|
108 | virtual void previousBranch(); |
---|
109 | #endif |
---|
110 | |
---|
111 | using CbcBranchingObject::print ; |
---|
112 | /** \brief Print something about branch - only if log level high |
---|
113 | */ |
---|
114 | virtual void print(); |
---|
115 | |
---|
116 | /** Return the type (an integer identifier) of \c this */ |
---|
117 | virtual CbcBranchObjType type() const { |
---|
118 | return FollowOnBranchObj; |
---|
119 | } |
---|
120 | |
---|
121 | /** Compare the original object of \c this with the original object of \c |
---|
122 | brObj. Assumes that there is an ordering of the original objects. |
---|
123 | This method should be invoked only if \c this and brObj are of the same |
---|
124 | type. |
---|
125 | Return negative/0/positive depending on whether \c this is |
---|
126 | smaller/same/larger than the argument. |
---|
127 | */ |
---|
128 | virtual int compareOriginalObject(const CbcBranchingObject* brObj) const; |
---|
129 | |
---|
130 | /** Compare the \c this with \c brObj. \c this and \c brObj must be os the |
---|
131 | same type and must have the same original object, but they may have |
---|
132 | different feasible regions. |
---|
133 | Return the appropriate CbcRangeCompare value (first argument being the |
---|
134 | sub/superset if that's the case). In case of overlap (and if \c |
---|
135 | replaceIfOverlap is true) replace the current branching object with one |
---|
136 | whose feasible region is the overlap. |
---|
137 | */ |
---|
138 | virtual CbcRangeCompare compareBranchingObject |
---|
139 | (const CbcBranchingObject* brObj, const bool replaceIfOverlap = false); |
---|
140 | |
---|
141 | private: |
---|
142 | /// data |
---|
143 | /// Number on down list |
---|
144 | int numberDown_; |
---|
145 | /// Number on up list |
---|
146 | int numberUp_; |
---|
147 | /// downList - variables to fix to lb on down branch |
---|
148 | int * downList_; |
---|
149 | /// upList - variables to fix to lb on up branch |
---|
150 | int * upList_; |
---|
151 | }; |
---|
152 | |
---|
153 | /** Define an idiotic idea class. |
---|
154 | The idea of this is that we take some integer variables away from integer and |
---|
155 | sum them with some randomness to get signed sum close to 0.5. We then can |
---|
156 | branch to exclude that gap. |
---|
157 | |
---|
158 | This branching rule should be in addition to normal rules and have a high priority. |
---|
159 | */ |
---|
160 | |
---|
161 | class CbcIdiotBranch : public CbcObject { |
---|
162 | |
---|
163 | public: |
---|
164 | |
---|
165 | // Default Constructor |
---|
166 | CbcIdiotBranch (); |
---|
167 | |
---|
168 | /** Useful constructor |
---|
169 | */ |
---|
170 | CbcIdiotBranch (CbcModel * model); |
---|
171 | |
---|
172 | // Copy constructor |
---|
173 | CbcIdiotBranch ( const CbcIdiotBranch &); |
---|
174 | |
---|
175 | /// Clone |
---|
176 | virtual CbcObject * clone() const; |
---|
177 | |
---|
178 | // Assignment operator |
---|
179 | CbcIdiotBranch & operator=( const CbcIdiotBranch& rhs); |
---|
180 | |
---|
181 | // Destructor |
---|
182 | ~CbcIdiotBranch (); |
---|
183 | |
---|
184 | /// Infeasibility - large is 0.5 |
---|
185 | virtual double infeasibility(const OsiBranchingInformation * info, |
---|
186 | int &preferredWay) const; |
---|
187 | |
---|
188 | using CbcObject::feasibleRegion ; |
---|
189 | /// This looks at solution and sets bounds to contain solution |
---|
190 | virtual void feasibleRegion(); |
---|
191 | |
---|
192 | /// Creates a branching object |
---|
193 | virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) ; |
---|
194 | /// Initialize for branching |
---|
195 | virtual void initializeForBranching(CbcModel * ); |
---|
196 | protected: |
---|
197 | /// Build "cut" |
---|
198 | OsiRowCut buildCut(const OsiBranchingInformation * info,int type,int & preferredWay) const; |
---|
199 | /// data |
---|
200 | /// Thread specific random number generator |
---|
201 | mutable CoinThreadRandom randomNumberGenerator_; |
---|
202 | /// Saved version of thread specific random number generator |
---|
203 | mutable CoinThreadRandom savedRandomNumberGenerator_; |
---|
204 | }; |
---|
205 | |
---|
206 | #endif |
---|
207 | |
---|