1 | // $Id: CbcHeuristicDW.hpp 1899 2013-04-09 18:12:08Z stefan $ |
---|
2 | // Copyright (C) 2006, 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 | |
---|
7 | #ifndef CbcHeuristicDW_H |
---|
8 | #define CbcHeuristicDW_H |
---|
9 | |
---|
10 | #include "CbcHeuristic.hpp" |
---|
11 | |
---|
12 | /** |
---|
13 | This is unlike the other heuristics in that it is very very compute intensive. |
---|
14 | It tries to find a DW structure and use that |
---|
15 | */ |
---|
16 | |
---|
17 | class CbcHeuristicDW : public CbcHeuristic { |
---|
18 | public: |
---|
19 | |
---|
20 | // Default Constructor |
---|
21 | CbcHeuristicDW (); |
---|
22 | |
---|
23 | /* Constructor with model - assumed before cuts |
---|
24 | */ |
---|
25 | CbcHeuristicDW (CbcModel & model, int keepContinuous=0); |
---|
26 | |
---|
27 | /* Constructor with model - assumed before cuts |
---|
28 | */ |
---|
29 | CbcHeuristicDW (CbcModel & model, |
---|
30 | int callBack(CbcHeuristicDW * currentHeuristic, |
---|
31 | CbcModel * thisModel, |
---|
32 | int whereFrom), |
---|
33 | int keepContinuous=0); |
---|
34 | |
---|
35 | // Copy constructor |
---|
36 | CbcHeuristicDW ( const CbcHeuristicDW &); |
---|
37 | |
---|
38 | // Destructor |
---|
39 | ~CbcHeuristicDW (); |
---|
40 | |
---|
41 | /// Clone |
---|
42 | virtual CbcHeuristic * clone() const; |
---|
43 | |
---|
44 | |
---|
45 | /// Assignment operator |
---|
46 | CbcHeuristicDW & operator=(const CbcHeuristicDW& rhs); |
---|
47 | |
---|
48 | /// Create C++ lines to get to current state |
---|
49 | virtual void generateCpp( FILE * fp) ; |
---|
50 | |
---|
51 | /// Resets stuff if model changes |
---|
52 | virtual void resetModel(CbcModel * model); |
---|
53 | |
---|
54 | /// update model (This is needed if cliques update matrix etc) |
---|
55 | virtual void setModel(CbcModel * model); |
---|
56 | using CbcHeuristic::solution ; |
---|
57 | /** returns 0 if no solution, 1 if valid solution. |
---|
58 | Sets solution values if good, sets objective value (only if good) |
---|
59 | This does Relaxation Induced Neighborhood Search |
---|
60 | */ |
---|
61 | virtual int solution(double & objectiveValue, |
---|
62 | double * newSolution); |
---|
63 | /** Return number of blocks |
---|
64 | <=0 - no usable structure */ |
---|
65 | inline int numberBlocks() const |
---|
66 | { return numberBlocks_;} |
---|
67 | /// Pass in a solution |
---|
68 | void passInSolution(const double * solution); |
---|
69 | /// Pass in continuous solution |
---|
70 | void passInContinuousSolution(const double * solution); |
---|
71 | /** DW Proposal actions |
---|
72 | fullDWEverySoOften - |
---|
73 | 0 - off |
---|
74 | k - every k times solution gets better |
---|
75 | */ |
---|
76 | inline void setProposalActions(int fullDWEverySoOften) |
---|
77 | { fullDWEverySoOften_=fullDWEverySoOften;} |
---|
78 | /// Objective value when whichDw created |
---|
79 | double objectiveValueWhen(int whichDW) const; |
---|
80 | /// Number of columns in DW |
---|
81 | int numberColumnsDW(int whichDW) const; |
---|
82 | /// Solver |
---|
83 | inline OsiSolverInterface * solver() const |
---|
84 | { return solver_;} |
---|
85 | /// DW model (user must delete) |
---|
86 | OsiSolverInterface * DWModel(int whichDW) const; |
---|
87 | /// Best objective value |
---|
88 | inline double bestObjective() const |
---|
89 | { return bestObjective_;} |
---|
90 | /// Best solution found so far |
---|
91 | inline const double * bestSolution() const |
---|
92 | { return bestSolution_;} |
---|
93 | /// Continuous solution |
---|
94 | inline const double * continuousSolution() const |
---|
95 | { return continuousSolution_;} |
---|
96 | /// Reduced costs of fixed solution |
---|
97 | inline const double * fixedDj() const |
---|
98 | { return fixedDj_;} |
---|
99 | /// Objective at which DW updated |
---|
100 | inline const double * objectiveDW() const |
---|
101 | { return objectiveDW_;} |
---|
102 | /// Number of times we have added to DW model |
---|
103 | inline int numberDWTimes() const |
---|
104 | { return numberDWTimes_;} |
---|
105 | /// Number of columns in DW |
---|
106 | inline const int * numberColumnsDW() const |
---|
107 | { return numberColumnsDW_;} |
---|
108 | /// Set number of passes |
---|
109 | inline void setNumberPasses(int value) |
---|
110 | { numberPasses_ = value;} |
---|
111 | /// Set number free integers needed |
---|
112 | inline void setNumberNeeded(int value) |
---|
113 | { nNeededBase_ = value;} |
---|
114 | /// Set target objective |
---|
115 | inline void setTargetObjective(double value) |
---|
116 | { targetObjective_ = value;} |
---|
117 | /// Sets how often to do it |
---|
118 | inline void setHowOften(int value) { |
---|
119 | howOften_ = value; |
---|
120 | } |
---|
121 | /// Block for every row |
---|
122 | inline const int * whichRowBlock() const |
---|
123 | { return whichRowBlock_;} |
---|
124 | /// Block for every column |
---|
125 | inline const int * whichColumnBlock() const |
---|
126 | { return whichColumnBlock_;} |
---|
127 | /// Initial Lower bounds |
---|
128 | inline const double * initialLower() const |
---|
129 | { return saveLower_;} |
---|
130 | /// Initial Upper bounds |
---|
131 | inline const double * initialUpper() const |
---|
132 | { return saveUpper_;} |
---|
133 | /// Local integer arrays (each numberBlocks_ long) |
---|
134 | inline int * intArrays() const |
---|
135 | { return intArray_;} |
---|
136 | /// Local double arrays (each numberBlocks_ long) |
---|
137 | inline double * doubleArrays() const |
---|
138 | { return doubleArray_;} |
---|
139 | /// Phase of solution |
---|
140 | inline int phase() const |
---|
141 | { return phase_;} |
---|
142 | /// Pass number |
---|
143 | inline int pass() const |
---|
144 | { return pass_;} |
---|
145 | /// Which columns are in block |
---|
146 | inline const int * columnsInBlock() const |
---|
147 | { return columnsInBlock_;} |
---|
148 | /// Starts for columnsInBlock |
---|
149 | inline const int * startColumnBlock() const |
---|
150 | { return startColumnBlock_;} |
---|
151 | /// Number of integer variables in each block |
---|
152 | inline const int * intsInBlock() const |
---|
153 | { return intsInBlock_;} |
---|
154 | /// Objective value (could also check validity) |
---|
155 | double objectiveValue(const double * solution); |
---|
156 | private: |
---|
157 | /// Guts of copy |
---|
158 | void gutsOfCopy(const CbcHeuristicDW & rhs); |
---|
159 | /// Guts of delete |
---|
160 | void gutsOfDelete(); |
---|
161 | /// Set default values |
---|
162 | void setDefaults(); |
---|
163 | /// Find structure |
---|
164 | void findStructure(); |
---|
165 | /// Add DW proposals |
---|
166 | int addDW(const double * solution,int numberBlocksUsed, |
---|
167 | const int * whichBlocks); |
---|
168 | protected: |
---|
169 | typedef int (*heuristicCallBack) (CbcHeuristicDW * ,CbcModel *, int) ; |
---|
170 | // Data |
---|
171 | /// Target objective |
---|
172 | double targetObjective_; |
---|
173 | /// Best objective value |
---|
174 | double bestObjective_; |
---|
175 | /// Objective value last time |
---|
176 | double lastObjective_; |
---|
177 | /** Call back |
---|
178 | whereFrom - |
---|
179 | 0 - after blocks found but before data setup |
---|
180 | 1 - after blocks sorted but before used |
---|
181 | 2 - just before normal branch and bound |
---|
182 | 3 - after DW has been updated |
---|
183 | 4 - if better solution found |
---|
184 | Pointers to local data given by following pointers |
---|
185 | */ |
---|
186 | heuristicCallBack functionPointer_; |
---|
187 | /// Local integer arrays (each numberBlocks_ long) |
---|
188 | int * intArray_; |
---|
189 | /// Local double arrays (each numberBlocks_ long) |
---|
190 | double * doubleArray_; |
---|
191 | /// Base solver |
---|
192 | OsiSolverInterface * solver_; |
---|
193 | /// DW solver |
---|
194 | OsiSolverInterface * dwSolver_; |
---|
195 | /// Best solution found so far |
---|
196 | double * bestSolution_; |
---|
197 | /// Continuous solution |
---|
198 | double * continuousSolution_; |
---|
199 | /// Reduced costs of fixed solution |
---|
200 | double * fixedDj_; |
---|
201 | /// Original lower bounds |
---|
202 | double * saveLower_; |
---|
203 | /// Original Upper bounds |
---|
204 | double * saveUpper_; |
---|
205 | /// random numbers for master rows |
---|
206 | double * random_; |
---|
207 | /// Weights for each proposal |
---|
208 | double * weights_; |
---|
209 | /// Objective at which DW updated |
---|
210 | double * objectiveDW_; |
---|
211 | /// Number of columns in each DW |
---|
212 | int * numberColumnsDW_; |
---|
213 | /// Block for every row |
---|
214 | int * whichRowBlock_; |
---|
215 | /// Block for every column |
---|
216 | int * whichColumnBlock_; |
---|
217 | /// Block number for each proposal |
---|
218 | int * dwBlock_; |
---|
219 | /// Points back to master rows |
---|
220 | int * backwardRow_; |
---|
221 | /// Which rows are in blocke |
---|
222 | int * rowsInBlock_; |
---|
223 | /// Which columns are in block |
---|
224 | int * columnsInBlock_; |
---|
225 | /// Starts for rowsInBlock |
---|
226 | int * startRowBlock_; |
---|
227 | /// Starts for columnsInBlock |
---|
228 | int * startColumnBlock_; |
---|
229 | /// Number of integer variables in each block |
---|
230 | int * intsInBlock_; |
---|
231 | /// Bits set for 1 integers in each block |
---|
232 | unsigned int * fingerPrint_; |
---|
233 | /// Affinity each block has for other (will be triangular?) |
---|
234 | unsigned short * affinity_; |
---|
235 | /** DW Proposal actions |
---|
236 | fullDWEverySoOften - |
---|
237 | 0 - off |
---|
238 | k - every k times solution gets better |
---|
239 | */ |
---|
240 | int fullDWEverySoOften_; |
---|
241 | /// Number of passes |
---|
242 | int numberPasses_; |
---|
243 | /// How often to do (code can change) |
---|
244 | int howOften_; |
---|
245 | /// Current maximum number of DW proposals |
---|
246 | int maximumDW_; |
---|
247 | /// Number of DW proposals |
---|
248 | int numberDW_; |
---|
249 | /// Number of times we have added to DW model |
---|
250 | int numberDWTimes_; |
---|
251 | /// Number of unsigned ints needed for each block of fingerPrint |
---|
252 | int sizeFingerPrint_; |
---|
253 | /// Number of columns in master |
---|
254 | int numberMasterColumns_; |
---|
255 | /// Number of rows in master |
---|
256 | int numberMasterRows_; |
---|
257 | /// Number of blocks |
---|
258 | int numberBlocks_; |
---|
259 | /// Action on decomposition - 1 keep continuous, 0 don't |
---|
260 | int keepContinuous_; |
---|
261 | /// Phase of solution |
---|
262 | int phase_; |
---|
263 | /// Pass number |
---|
264 | int pass_; |
---|
265 | /// Base number of integers needed |
---|
266 | int nNeededBase_; |
---|
267 | /// Base number of nodes needed |
---|
268 | int nNodesBase_; |
---|
269 | /// Base number of integers needed |
---|
270 | int nNeeded_; |
---|
271 | /// Base number of nodes needed |
---|
272 | int nNodes_; |
---|
273 | // 0 - fine, 1 can't be better, 2 max node |
---|
274 | int solveState_; |
---|
275 | }; |
---|
276 | |
---|
277 | #endif |
---|