source: branches/sandbox/Cbc/src/CbcHeuristicFPump.hpp @ 1286

Last change on this file since 1286 was 1286, checked in by EdwinStraver, 10 years ago

Changed formatting using AStyle -A4 -p

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.4 KB
Line 
1/* $Id: CbcHeuristicFPump.hpp 1286 2009-11-09 23:33:07Z EdwinStraver $ */
2// Copyright (C) 2004, International Business Machines
3// Corporation and others.  All Rights Reserved.
4#ifndef CbcHeuristicFeasibilityPump_H
5#define CbcHeuristicFeasibilityPump_H
6
7#include "CbcHeuristic.hpp"
8#include "OsiClpSolverInterface.hpp"
9
10/** Feasibility Pump class
11 */
12
13class CbcHeuristicFPump : public CbcHeuristic {
14public:
15
16    // Default Constructor
17    CbcHeuristicFPump ();
18
19    // Constructor with model - assumed before cuts
20    CbcHeuristicFPump (CbcModel & model,
21                       double downValue = 0.5, bool roundExpensive = false);
22
23    // Copy constructor
24    CbcHeuristicFPump ( const CbcHeuristicFPump &);
25
26    // Destructor
27    ~CbcHeuristicFPump ();
28
29    /// Assignment operator
30    CbcHeuristicFPump & operator=(const CbcHeuristicFPump& rhs);
31    /// Clone
32    virtual CbcHeuristic * clone() const;
33    /// Create C++ lines to get to current state
34    virtual void generateCpp( FILE * fp) ;
35
36    /// Resets stuff if model changes
37    virtual void resetModel(CbcModel * model);
38
39    /// update model (This is needed if cliques update matrix etc)
40    virtual void setModel(CbcModel * model);
41
42    using CbcHeuristic::solution ;
43    /** returns 0 if no solution, 1 if valid solution
44        with better objective value than one passed in
45        Sets solution values if good, sets objective value (only if good)
46        This is called after cuts have been added - so can not add cuts.
47
48        It may make sense for user to call this outside Branch and Cut to
49        get solution.  Or normally is just at root node.
50
51        * new meanings for when_ - on first try then set back to 1
52          11 - at end fix all integers at same bound throughout
53          12 - also fix all integers staying at same internal integral value throughout
54          13 - also fix all continuous variables staying at same bound throughout
55          14 - also fix all continuous variables staying at same internal value throughout
56          15 - as 13 but no internal integers
57    */
58    virtual int solution(double & objectiveValue,
59                         double * newSolution);
60
61    /// Set maximum Time (default off) - also sets starttime to current
62    void setMaximumTime(double value);
63    /// Get maximum Time (default 0.0 == time limit off)
64    inline double maximumTime() const {
65        return maximumTime_;
66    }
67    /// Set fake cutoff (default COIN_DBL_MAX == off)
68    inline void setFakeCutoff(double value) {
69        fakeCutoff_ = value;
70    }
71    /// Get fake cutoff (default 0.0 == off)
72    inline double fakeCutoff() const {
73        return fakeCutoff_;
74    }
75    /// Set absolute increment (default 0.0 == off)
76    inline void setAbsoluteIncrement(double value) {
77        absoluteIncrement_ = value;
78    }
79    /// Get absolute increment (default 0.0 == off)
80    inline double absoluteIncrement() const {
81        return absoluteIncrement_;
82    }
83    /// Set relative increment (default 0.0 == off)
84    inline void setRelativeIncrement(double value) {
85        relativeIncrement_ = value;
86    }
87    /// Get relative increment (default 0.0 == off)
88    inline double relativeIncrement() const {
89        return relativeIncrement_;
90    }
91    /// Set default rounding (default 0.5)
92    inline void setDefaultRounding(double value) {
93        defaultRounding_ = value;
94    }
95    /// Get default rounding (default 0.5)
96    inline double defaultRounding() const {
97        return defaultRounding_;
98    }
99    /// Set initial weight (default 0.0 == off)
100    inline void setInitialWeight(double value) {
101        initialWeight_ = value;
102    }
103    /// Get initial weight (default 0.0 == off)
104    inline double initialWeight() const {
105        return initialWeight_;
106    }
107    /// Set weight factor (default 0.1)
108    inline void setWeightFactor(double value) {
109        weightFactor_ = value;
110    }
111    /// Get weight factor (default 0.1)
112    inline double weightFactor() const {
113        return weightFactor_;
114    }
115    /// Set threshold cost for using original cost - even on continuous (default infinity)
116    inline void setArtificialCost(double value) {
117        artificialCost_ = value;
118    }
119    /// Get threshold cost for using original cost - even on continuous (default infinity)
120    inline double artificialCost() const {
121        return artificialCost_;
122    }
123    /// Get iteration to size ratio
124    inline double iterationRatio() const {
125        return iterationRatio_;
126    }
127    /// Set iteration to size ratio
128    inline void setIterationRatio(double value) {
129        iterationRatio_ = value;
130    }
131    /// Set maximum passes (default 100)
132    inline void setMaximumPasses(int value) {
133        maximumPasses_ = value;
134    }
135    /// Get maximum passes (default 100)
136    inline int maximumPasses() const {
137        return maximumPasses_;
138    }
139    /// Set maximum retries (default 1)
140    inline void setMaximumRetries(int value) {
141        maximumRetries_ = value;
142    }
143    /// Get maximum retries (default 1)
144    inline int maximumRetries() const {
145        return maximumRetries_;
146    }
147    /**  Set use of multiple solutions and solves
148         0 - do not reuse solves, do not accumulate integer solutions for local search
149         1 - do not reuse solves, accumulate integer solutions for local search
150         2 - reuse solves, do not accumulate integer solutions for local search
151         3 - reuse solves, accumulate integer solutions for local search
152         If we add 4 then use second form of problem (with extra rows and variables for general integers)
153         If we add 8 then can run after initial cuts (if no solution)
154    */
155    inline void setAccumulate(int value) {
156        accumulate_ = value;
157    }
158    /// Get accumulation option
159    inline int accumulate() const {
160        return accumulate_;
161    }
162    /**  Set whether to fix variables on known solution
163         0 - do not fix
164         1 - fix integers on reduced costs
165         2 - fix integers on reduced costs but only on entry
166    */
167    inline void setFixOnReducedCosts(int value) {
168        fixOnReducedCosts_ = value;
169    }
170    /// Get reduced cost option
171    inline int fixOnReducedCosts() const {
172        return fixOnReducedCosts_;
173    }
174    /**  Set reduced cost multiplier
175         1.0 as normal
176         <1.0 (x) - pretend gap is x* actual gap - just for fixing
177    */
178    inline void setReducedCostMultiplier(double value) {
179        reducedCostMultiplier_ = value;
180    }
181    /// Get reduced cost multiplier
182    inline double reducedCostMultiplier() const {
183        return reducedCostMultiplier_;
184    }
185
186protected:
187    // Data
188    /// Start time
189    double startTime_;
190    /// Maximum Cpu seconds
191    double maximumTime_;
192    /** Fake cutoff value.
193        If set then better of real cutoff and this used to add a constraint
194    */
195    double fakeCutoff_;
196    /// If positive carry on after solution expecting gain of at least this
197    double absoluteIncrement_;
198    /// If positive carry on after solution expecting gain of at least this times objective
199    double relativeIncrement_;
200    /// Default is round up if > this
201    double defaultRounding_;
202    /// Initial weight for true objective
203    double initialWeight_;
204    /// Factor for decreasing weight
205    double weightFactor_;
206    /// Threshold cost for using original cost - even on continuous
207    double artificialCost_;
208    /** If iterationRatio >0 use instead of maximumPasses_
209        test is iterations > ratio*(2*nrow+ncol) */
210    double iterationRatio_;
211    /**  Reduced cost multiplier
212         1.0 as normal
213         <1.0 (x) - pretend gap is x* actual gap - just for fixing
214    */
215    double reducedCostMultiplier_;
216    /// Maximum number of passes
217    int maximumPasses_;
218    /** Maximum number of retries if we find a solution.
219        If negative we clean out used array
220    */
221    int maximumRetries_;
222    /**  Set use of multiple solutions and solves
223         0 - do not reuse solves, do not accumulate integer solutions for local search
224         1 - do not reuse solves, accumulate integer solutions for local search
225         2 - reuse solves, do not accumulate integer solutions for local search
226         3 - reuse solves, accumulate integer solutions for local search
227         If we add 4 then use second form of problem (with extra rows and variables for general integers)
228         If we do not accumulate solutions then no mini branch and bounds will be done
229         reuse - refers to initial solve after adding in new "cut"
230         If we add 8 then can run after initial cuts (if no solution)
231    */
232    int accumulate_;
233    /**  Set whether to fix variables on known solution
234         0 - do not fix
235         1 - fix integers on reduced costs
236         2 - fix integers on reduced costs but only on entry
237    */
238    int fixOnReducedCosts_;
239    /// If true round to expensive
240    bool roundExpensive_;
241
242private:
243    /** Rounds solution - down if < downValue
244        If roundExpensive then always to more expnsive.
245        returns 0 if current is solution
246    */
247    int rounds(OsiSolverInterface * solver, double * solution,
248               /*const double * objective, */
249               int numberIntegers, const int * integerVariable,
250               /*char * pumpPrint,*/int passNumber,
251               /*bool roundExpensive=false,*/
252               double downValue = 0.5, int *flip = 0);
253    /* note for eagle eyed readers.
254       when_ can now be exotic -
255       <=10 normal
256    */
257};
258
259# ifdef COIN_HAS_CLP
260
261class CbcDisasterHandler : public OsiClpDisasterHandler {
262public:
263    /**@name Virtual methods that the derived classe should provide.
264    */
265    //@{
266#if 0
267    /// Into simplex
268    virtual void intoSimplex();
269    /// Checks if disaster
270    virtual bool check() const ;
271    /// saves information for next attempt
272    virtual void saveInfo();
273#endif
274    /// Type of disaster 0 can fix, 1 abort
275    virtual int typeOfDisaster();
276    //@}
277
278
279    /**@name Constructors, destructor */
280
281    //@{
282    /** Default constructor. */
283    CbcDisasterHandler(CbcModel * model = NULL);
284    /** Destructor */
285    virtual ~CbcDisasterHandler();
286    // Copy
287    CbcDisasterHandler(const CbcDisasterHandler&);
288    // Assignment
289    CbcDisasterHandler& operator=(const CbcDisasterHandler&);
290    /// Clone
291    virtual ClpDisasterHandler * clone() const;
292
293    //@}
294
295    /**@name Sets/gets */
296
297    //@{
298    /** set model. */
299    void setCbcModel(CbcModel * model);
300    /// Get model
301    inline CbcModel * cbcModel() const {
302        return cbcModel_;
303    }
304
305    //@}
306
307
308protected:
309    /**@name Data members
310       The data members are protected to allow access for derived classes. */
311    //@{
312    /// Pointer to model
313    CbcModel * cbcModel_;
314
315    //@}
316};
317#endif
318
319#endif
Note: See TracBrowser for help on using the repository browser.