source: trunk/Cbc/src/CbcHeuristicFPump.hpp

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

script to format sources

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