source: trunk/Cbc/src/CbcHeuristicDW.hpp @ 1955

Last change on this file since 1955 was 1955, checked in by forrest, 6 years ago

add more twiddles for advanced use of heuristics

File size: 9.7 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
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
17class CbcHeuristicDW : public CbcHeuristic {
18public:
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    void setProposalActions(int fullDWEverySoOften);
77    /// Objective value when whichDw created
78    double objectiveValueWhen(int whichDW) const;
79    /// Number of columns in DW
80    int numberColumnsDW(int whichDW) const;
81    /// Solver
82    inline OsiSolverInterface * solver() const
83    { return solver_;}
84    /// DW model (user must delete)
85    OsiSolverInterface * DWModel(int whichDW) const;
86    /// Best objective value
87    inline double bestObjective() const
88    { return bestObjective_;}
89    /// Best solution found so far
90    inline const double * bestSolution() const
91    { return bestSolution_;}
92    /// Continuous solution
93    inline const double * continuousSolution() const
94    { return continuousSolution_;}
95    /// Reduced costs of fixed solution
96    inline const double * fixedDj() const
97    { return fixedDj_;}
98    /// Objective at which DW updated
99    inline const double * objectiveDW() const
100    { return objectiveDW_;}
101    /// Number of times we have added to DW model
102    inline int numberDWTimes() const
103    { return numberDWTimes_;}
104    /// Number of columns in DW
105    inline const int * numberColumnsDW() const
106    { return numberColumnsDW_;}
107    /// Set number of passes
108    inline void setNumberPasses(int value)
109    { numberPasses_ = value;}
110    /// Set number free integers needed (Base value)
111    inline void setNumberNeeded(int value)
112    { nNeededBase_ = value;}
113    /// Get number free integers needed (Base value)
114    inline int getNumberNeeded() const
115    {return nNeededBase_;}
116    /// Set number free integers needed (Current value)
117    inline void setCurrentNumberNeeded(int value)
118    { nNeeded_ = value;}
119    /// Get number free integers needed (Current value)
120    inline int getCurrentNumberNeeded() const
121    {return nNeeded_;}
122    /// Set number nodes (could be done in callback) (Base value)
123    inline void setNumberNodes(int value)
124    { nNodesBase_ = value;}
125    /// Get number nodes (could be done in callback) (Base value)
126    inline int getNumberNodes() const
127    {return nNodesBase_;}
128    /// Set number nodes (could be done in callback) (Current value)
129    inline void setCurrentNumberNodes(int value)
130    { nNodes_ = value;}
131    /// Get number nodes (could be done in callback) (Current value)
132    inline int getCurrentNumberNodes() const
133    {return nNodes_;}
134    /// Set target objective
135    inline void setTargetObjective(double value)
136    { targetObjective_ = value;}
137    /// Sets how often to do it
138    inline void setHowOften(int value) {
139        howOften_ = value;
140    }
141    /// Block for every row
142    inline const int * whichRowBlock() const
143    { return whichRowBlock_;}
144    /// Block for every column
145    inline const int * whichColumnBlock() const
146    { return whichColumnBlock_;}
147    /// Initial Lower bounds
148    inline double * initialLower() const
149    { return saveLower_;}
150    /// Initial Upper bounds
151    inline double * initialUpper() const
152    { return saveUpper_;}
153    /// Local integer arrays (each numberBlocks_ long)
154    inline int * intArrays() const
155    { return intArray_;}
156    /// Local double arrays (each numberBlocks_ long)
157    inline double * doubleArrays() const
158    { return doubleArray_;}
159    /// Phase of solution
160    inline int phase() const
161    { return phase_;}
162    /// Pass number
163    inline int pass() const
164    { return pass_;}
165    /// Which columns are in block
166    inline const int * columnsInBlock() const
167    { return columnsInBlock_;}
168    /// Starts for columnsInBlock
169    inline const int * startColumnBlock() const
170    { return startColumnBlock_;}
171    /// Number of integer variables in each block
172    inline const int * intsInBlock() const
173    { return intsInBlock_;}
174    /// Objective value (could also check validity)
175    double objectiveValue(const double * solution);
176private:
177    /// Guts of copy
178    void gutsOfCopy(const CbcHeuristicDW & rhs);
179    /// Guts of delete
180    void gutsOfDelete();
181    /// Set default values
182    void setDefaults();
183    /// Find structure
184    void findStructure();
185    /// Set up DW structure
186    void setupDWStructures();
187    /// Add DW proposals
188    int addDW(const double * solution,int numberBlocksUsed, 
189              const int * whichBlocks);
190protected:
191    typedef int (*heuristicCallBack) (CbcHeuristicDW * ,CbcModel *, int) ;
192    // Data
193    /// Target objective
194    double targetObjective_;
195    /// Best objective value
196    double bestObjective_;
197    /// Objective value last time
198    double lastObjective_;
199    /** Call back
200        whereFrom -
201        0 - after blocks found but before data setup
202        1 - after blocks sorted but before used
203        2 - just before normal branch and bound
204        3 - after DW has been updated
205        4 - if better solution found
206        5 - every time a block might be used
207        next few for adjustment of nNeeded etc
208        6 - complete search done - no solution
209        7 - stopped on nodes - no improvement
210        8 - improving (same as 4 but after nNeeded changed
211        Pointers to local data given by following pointers
212    */
213    heuristicCallBack functionPointer_;
214    /// Local integer arrays (each numberBlocks_ long)
215    int * intArray_;
216    /// Local double arrays (each numberBlocks_ long)
217    double * doubleArray_;
218    /// Base solver
219    OsiSolverInterface * solver_;
220    /// DW solver
221    OsiSolverInterface * dwSolver_;
222    /// Best solution found so far
223    double * bestSolution_;
224    /// Continuous solution
225    double * continuousSolution_;
226    /// Reduced costs of fixed solution
227    double * fixedDj_;
228    /// Original lower bounds
229    double * saveLower_;
230    /// Original Upper bounds
231    double * saveUpper_;
232    /// random numbers for master rows
233    double * random_;
234    /// Weights for each proposal
235    double * weights_;
236    /// Objective at which DW updated
237    double * objectiveDW_;
238    /// Number of columns in each DW
239    int * numberColumnsDW_;
240    /// Block for every row
241    int * whichRowBlock_;
242    /// Block for every column
243    int * whichColumnBlock_;
244    /// Block number for each proposal
245    int * dwBlock_;
246    /// Points back to master rows
247    int * backwardRow_;
248    /// Which rows are in blocke
249    int * rowsInBlock_;
250    /// Which columns are in block
251    int * columnsInBlock_;
252    /// Starts for rowsInBlock
253    int * startRowBlock_;
254    /// Starts for columnsInBlock
255    int * startColumnBlock_;
256    /// Number of integer variables in each block
257    int * intsInBlock_;
258    /// Bits set for 1 integers in each block
259    unsigned int * fingerPrint_;
260    /// Affinity each block has for other (will be triangular?)
261    unsigned short * affinity_;
262    /** DW Proposal actions
263        fullDWEverySoOften -
264        0 - off
265        k - every k times solution gets better
266     */
267    int fullDWEverySoOften_;
268    /// Number of passes
269    int numberPasses_;
270    /// How often to do (code can change)
271    int howOften_;
272    /// Current maximum number of DW proposals
273    int maximumDW_;
274    /// Number of DW proposals
275    int numberDW_;
276    /// Number of times we have added to DW model
277    int numberDWTimes_;
278    /// Number of unsigned ints needed for each block of fingerPrint
279    int sizeFingerPrint_;
280    /// Number of columns in master
281    int numberMasterColumns_;
282    /// Number of rows in master
283    int numberMasterRows_;
284    /// Number of blocks
285    int numberBlocks_;
286    /// Action on decomposition - 1 keep continuous, 0 don't
287    int keepContinuous_;
288    /// Phase of solution
289    int phase_;
290    /// Pass number
291    int pass_;
292    /// Base number of integers needed
293    int nNeededBase_;
294    /// Base number of nodes needed
295    int nNodesBase_;
296    /// Base number of integers needed
297    int nNeeded_;
298    /// Base number of nodes needed
299    int nNodes_;
300    // 0 - fine, 1 can't be better, 2 max node
301    int solveState_;
302};
303
304#endif
Note: See TracBrowser for help on using the repository browser.