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

Last change on this file since 1948 was 1948, checked in by forrest, 8 years ago

yet more changes for dubious idea

File size: 8.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
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    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);
156private:
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);
168protected:
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        5 - every time a block might be used
185        Pointers to local data given by following pointers
186    */
187    heuristicCallBack functionPointer_;
188    /// Local integer arrays (each numberBlocks_ long)
189    int * intArray_;
190    /// Local double arrays (each numberBlocks_ long)
191    double * doubleArray_;
192    /// Base solver
193    OsiSolverInterface * solver_;
194    /// DW solver
195    OsiSolverInterface * dwSolver_;
196    /// Best solution found so far
197    double * bestSolution_;
198    /// Continuous solution
199    double * continuousSolution_;
200    /// Reduced costs of fixed solution
201    double * fixedDj_;
202    /// Original lower bounds
203    double * saveLower_;
204    /// Original Upper bounds
205    double * saveUpper_;
206    /// random numbers for master rows
207    double * random_;
208    /// Weights for each proposal
209    double * weights_;
210    /// Objective at which DW updated
211    double * objectiveDW_;
212    /// Number of columns in each DW
213    int * numberColumnsDW_;
214    /// Block for every row
215    int * whichRowBlock_;
216    /// Block for every column
217    int * whichColumnBlock_;
218    /// Block number for each proposal
219    int * dwBlock_;
220    /// Points back to master rows
221    int * backwardRow_;
222    /// Which rows are in blocke
223    int * rowsInBlock_;
224    /// Which columns are in block
225    int * columnsInBlock_;
226    /// Starts for rowsInBlock
227    int * startRowBlock_;
228    /// Starts for columnsInBlock
229    int * startColumnBlock_;
230    /// Number of integer variables in each block
231    int * intsInBlock_;
232    /// Bits set for 1 integers in each block
233    unsigned int * fingerPrint_;
234    /// Affinity each block has for other (will be triangular?)
235    unsigned short * affinity_;
236    /** DW Proposal actions
237        fullDWEverySoOften -
238        0 - off
239        k - every k times solution gets better
240     */
241    int fullDWEverySoOften_;
242    /// Number of passes
243    int numberPasses_;
244    /// How often to do (code can change)
245    int howOften_;
246    /// Current maximum number of DW proposals
247    int maximumDW_;
248    /// Number of DW proposals
249    int numberDW_;
250    /// Number of times we have added to DW model
251    int numberDWTimes_;
252    /// Number of unsigned ints needed for each block of fingerPrint
253    int sizeFingerPrint_;
254    /// Number of columns in master
255    int numberMasterColumns_;
256    /// Number of rows in master
257    int numberMasterRows_;
258    /// Number of blocks
259    int numberBlocks_;
260    /// Action on decomposition - 1 keep continuous, 0 don't
261    int keepContinuous_;
262    /// Phase of solution
263    int phase_;
264    /// Pass number
265    int pass_;
266    /// Base number of integers needed
267    int nNeededBase_;
268    /// Base number of nodes needed
269    int nNodesBase_;
270    /// Base number of integers needed
271    int nNeeded_;
272    /// Base number of nodes needed
273    int nNodes_;
274    // 0 - fine, 1 can't be better, 2 max node
275    int solveState_;
276};
277
278#endif
Note: See TracBrowser for help on using the repository browser.