source: trunk/Cbc/src/CbcHeuristicDW.hpp

Last change on this file was 2465, checked in by unxusr, 10 months ago

script to format sources

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