Dip  0.92.4
CbcHeuristicDW.hpp
Go to the documentation of this file.
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 
16 class CbcHeuristicDW : public CbcHeuristic {
17 public:
18  // Default Constructor
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
35 
36  // Destructor
38 
40  virtual CbcHeuristic *clone() const;
41 
44 
46  virtual void generateCpp(FILE *fp);
47 
49  virtual void resetModel(CbcModel *model);
50 
52  virtual void setModel(CbcModel *model);
58  virtual int solution(double &objectiveValue,
59  double *newSolution);
62  inline int numberBlocks() const
63  {
64  return numberBlocks_;
65  }
67  void passInSolution(const double *solution);
69  void passInContinuousSolution(const double *solution);
75  void setProposalActions(int fullDWEverySoOften);
77  double objectiveValueWhen(int whichDW) const;
79  int numberColumnsDW(int whichDW) const;
81  inline OsiSolverInterface *solver() const
82  {
83  return solver_;
84  }
86  OsiSolverInterface *DWModel(int whichDW) const;
88  inline double bestObjective() const
89  {
90  return bestObjective_;
91  }
93  inline const double *bestSolution() const
94  {
95  return bestSolution_;
96  }
98  inline const double *continuousSolution() const
99  {
100  return continuousSolution_;
101  }
103  inline const double *fixedDj() const
104  {
105  return fixedDj_;
106  }
108  inline const double *objectiveDW() const
109  {
110  return objectiveDW_;
111  }
113  inline int numberDWTimes() const
114  {
115  return numberDWTimes_;
116  }
118  inline const int *numberColumnsDW() const
119  {
120  return numberColumnsDW_;
121  }
123  inline void setNumberPasses(int value)
124  {
125  numberPasses_ = value;
126  }
128  inline void setNumberBadPasses(int value)
129  {
130  numberBadPasses_ = value;
131  }
133  inline void setNumberNeeded(int value)
134  {
135  nNeededBase_ = value;
136  }
138  inline int getNumberNeeded() const
139  {
140  return nNeededBase_;
141  }
143  inline void setCurrentNumberNeeded(int value)
144  {
145  nNeeded_ = value;
146  }
148  inline int getCurrentNumberNeeded() const
149  {
150  return nNeeded_;
151  }
153  inline void setNumberNodes(int value)
154  {
155  nNodesBase_ = value;
156  }
158  inline int getNumberNodes() const
159  {
160  return nNodesBase_;
161  }
163  inline void setCurrentNumberNodes(int value)
164  {
165  nNodes_ = value;
166  }
168  inline int getCurrentNumberNodes() const
169  {
170  return nNodes_;
171  }
173  inline void setTargetObjective(double value)
174  {
175  targetObjective_ = value;
176  }
178  inline void setHowOften(int value)
179  {
180  howOften_ = value;
181  }
183  inline const int *whichRowBlock() const
184  {
185  return whichRowBlock_;
186  }
188  inline const int *whichColumnBlock() const
189  {
190  return whichColumnBlock_;
191  }
193  inline double *initialLower() const
194  {
195  return saveLower_;
196  }
198  inline double *initialUpper() const
199  {
200  return saveUpper_;
201  }
203  inline int *intArrays() const
204  {
205  return intArray_;
206  }
208  inline double *doubleArrays() const
209  {
210  return doubleArray_;
211  }
213  inline int phase() const
214  {
215  return phase_;
216  }
218  inline int pass() const
219  {
220  return pass_;
221  }
223  inline const int *columnsInBlock() const
224  {
225  return columnsInBlock_;
226  }
228  inline const int *startColumnBlock() const
229  {
230  return startColumnBlock_;
231  }
233  inline const int *intsInBlock() const
234  {
235  return intsInBlock_;
236  }
238  double objectiveValue(const double *solution);
239 
240 private:
242  void gutsOfCopy(const CbcHeuristicDW &rhs);
244  void gutsOfDelete();
246  void setDefaults();
248  void findStructure();
250  void setupDWStructures();
252  int addDW(const double *solution, int numberBlocksUsed,
253  const int *whichBlocks);
254 
255 protected:
256  typedef int (*heuristicCallBack)(CbcHeuristicDW *, CbcModel *, int);
257  // Data
280  int *intArray_;
282  double *doubleArray_;
288  double *bestSolution_;
292  double *fixedDj_;
294  double *saveLower_;
296  double *saveUpper_;
298  double *random_;
300  double *weights_;
302  double *objectiveDW_;
310  int *dwBlock_;
324  unsigned int *fingerPrint_;
326  unsigned short *affinity_;
354  int phase_;
356  int pass_;
362  int nNeeded_;
364  int nNodes_;
367  // 0 - fine, 1 can't be better, 2 max node
369 };
370 
371 #endif
372 
373 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
374 */
heuristicCallBack functionPointer_
Call back whereFrom - 0 - after blocks found but before data setup 1 - after blocks sorted but before...
void passInSolution(const double *solution)
Pass in a solution.
int getNumberNodes() const
Get number nodes (could be done in callback) (Base value)
const int * whichRowBlock() const
Block for every row.
double targetObjective_
Target objective.
void setupDWStructures()
Set up DW structure.
int * whichColumnBlock_
Block for every column.
int keepContinuous_
Action on decomposition - 1 keep continuous, 0 don't.
void findStructure()
Find structure.
int maximumDW_
Current maximum number of DW proposals.
double objectiveValueWhen(int whichDW) const
Objective value when whichDw created.
int * dwBlock_
Block number for each proposal.
int * intsInBlock_
Number of integer variables in each block.
int nNodes_
Base number of nodes needed.
This is unlike the other heuristics in that it is very very compute intensive.
double * objectiveDW_
Objective at which DW updated.
int * columnsInBlock_
Which columns are in block.
OsiSolverInterface * dwSolver_
DW solver.
const double * bestSolution() const
Best solution found so far.
int numberDWTimes() const
Number of times we have added to DW model.
double * random_
random numbers for master rows
double * bestSolution_
Best solution found so far.
int numberDWTimes_
Number of times we have added to DW model.
int * intArray_
Local integer arrays (each numberBlocks_ long)
int * startRowBlock_
Starts for rowsInBlock.
virtual CbcHeuristic * clone() const
Clone.
void setNumberPasses(int value)
Set number of passes.
int addDW(const double *solution, int numberBlocksUsed, const int *whichBlocks)
Add DW proposals.
double * continuousSolution_
Continuous solution.
virtual int solution(double &objectiveValue, double *newSolution)=0
returns 0 if no solution, 1 if valid solution with better objective value than one passed in Sets sol...
void setProposalActions(int fullDWEverySoOften)
DW Proposal actions fullDWEverySoOften - 0 - off k - every k times solution gets better.
const int * intsInBlock() const
Number of integer variables in each block.
int getCurrentNumberNeeded() const
Get number free integers needed (Current value)
int sizeFingerPrint_
Number of unsigned ints needed for each block of fingerPrint.
int numberMasterRows_
Number of rows in master.
int * startColumnBlock_
Starts for columnsInBlock.
double * initialUpper() const
Initial Upper bounds.
const double * continuousSolution() const
Continuous solution.
void passInContinuousSolution(const double *solution)
Pass in continuous solution.
OsiSolverInterface * solver_
Base solver.
const int * startColumnBlock() const
Starts for columnsInBlock.
void setNumberNeeded(int value)
Set number free integers needed (Base value)
int nNeeded_
Base number of integers needed.
unsigned short * affinity_
Affinity each block has for other (will be triangular?)
void setHowOften(int value)
Sets how often to do it.
void setNumberNodes(int value)
Set number nodes (could be done in callback) (Base value)
virtual int solution(double &objectiveValue, double *newSolution)
returns 0 if no solution, 1 if valid solution.
int fullDWEverySoOften_
DW Proposal actions fullDWEverySoOften - 0 - off k - every k times solution gets better.
const double * objectiveDW() const
Objective at which DW updated.
int numberBadPasses_
Number of passes without better solution.
double objectiveValue(const double *solution)
Objective value (could also check validity)
void setTargetObjective(double value)
Set target objective.
void setDefaults()
Set default values.
const double * fixedDj() const
Reduced costs of fixed solution.
virtual void generateCpp(FILE *fp)
Create C++ lines to get to current state.
double lastObjective_
Objective value last time.
int pass() const
Pass number.
int numberPasses_
Number of passes.
virtual void resetModel(CbcModel *model)
Resets stuff if model changes.
int * backwardRow_
Points back to master rows.
double bestObjective_
Best objective value.
double * weights_
Weights for each proposal.
void gutsOfCopy(const CbcHeuristicDW &rhs)
Guts of copy.
int(* heuristicCallBack)(CbcHeuristicDW *, CbcModel *, int)
void setNumberBadPasses(int value)
Set number of passes without better solution.
Abstract Base Class for describing an interface to a solver.
CbcHeuristicDW & operator=(const CbcHeuristicDW &rhs)
Assignment operator.
int * intArrays() const
Local integer arrays (each numberBlocks_ long)
unsigned int * fingerPrint_
Bits set for 1 integers in each block.
void gutsOfDelete()
Guts of delete.
int * whichRowBlock_
Block for every row.
const int * whichColumnBlock() const
Block for every column.
Heuristic base class.
int phase_
Phase of solution.
double bestObjective() const
Best objective value.
int howOften_
How often to do (code can change)
double * saveLower_
Original lower bounds.
const int * numberColumnsDW() const
Number of columns in DW.
double * fixedDj_
Reduced costs of fixed solution.
virtual void setModel(CbcModel *model)
update model (This is needed if cliques update matrix etc)
const int * columnsInBlock() const
Which columns are in block.
double * doubleArrays() const
Local double arrays (each numberBlocks_ long)
void setCurrentNumberNeeded(int value)
Set number free integers needed (Current value)
int phase() const
Phase of solution.
int pass_
Pass number.
int getCurrentNumberNodes() const
Get number nodes (could be done in callback) (Current value)
int getNumberNeeded() const
Get number free integers needed (Base value)
double * saveUpper_
Original Upper bounds.
OsiSolverInterface * solver() const
Solver.
int nNeededBase_
Base number of integers needed.
int numberBlocks_
Number of blocks.
int numberDW_
Number of DW proposals.
int nNodesBase_
Base number of nodes needed.
int * rowsInBlock_
Which rows are in blocke.
void setCurrentNumberNodes(int value)
Set number nodes (could be done in callback) (Current value)
int whereFrom() const
Simple Branch and bound class.
Definition: CbcModel.hpp:100
OsiSolverInterface * DWModel(int whichDW) const
DW model (user must delete)
int * numberColumnsDW_
Number of columns in each DW.
int numberMasterColumns_
Number of columns in master.
double * doubleArray_
Local double arrays (each numberBlocks_ long)
double * initialLower() const
Initial Lower bounds.
int numberBlocks() const
Return number of blocks <=0 - no usable structure.