source: trunk/Cbc/src/CbcHeuristicLocal.hpp

Last change on this file was 2467, checked in by unxusr, 10 months ago

spaces after angles

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
1/* $Id: CbcHeuristicLocal.hpp 2467 2019-01-03 21:26:29Z unxusr $ */
2// Copyright (C) 2002, 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 CbcHeuristicLocal_H
7#define CbcHeuristicLocal_H
8
9#include "CbcHeuristic.hpp"
10/** LocalSearch class
11 */
12
13class CbcHeuristicLocal : public CbcHeuristic {
14public:
15  // Default Constructor
16  CbcHeuristicLocal();
17
18  /* Constructor with model - assumed before cuts
19       Initial version does not do Lps
20    */
21  CbcHeuristicLocal(CbcModel &model);
22
23  // Copy constructor
24  CbcHeuristicLocal(const CbcHeuristicLocal &);
25
26  // Destructor
27  ~CbcHeuristicLocal();
28
29  /// Clone
30  virtual CbcHeuristic *clone() const;
31
32  /// Assignment operator
33  CbcHeuristicLocal &operator=(const CbcHeuristicLocal &rhs);
34
35  /// Create C++ lines to get to current state
36  virtual void generateCpp(FILE *fp);
37
38  /// Resets stuff if model changes
39  virtual void resetModel(CbcModel *model);
40
41  /// update model (This is needed if cliques update matrix etc)
42  virtual void setModel(CbcModel *model);
43
44  using CbcHeuristic::solution;
45  /** returns 0 if no solution, 1 if valid solution.
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        First tries setting a variable to better value.  If feasible then
49        tries setting others.  If not feasible then tries swaps
50
51        ********
52
53        This first version does not do LP's and does swaps of two integer
54        variables.  Later versions could do Lps.
55    */
56  virtual int solution(double &objectiveValue,
57    double *newSolution);
58  /// This version fixes stuff and does IP
59  int solutionFix(double &objectiveValue,
60    double *newSolution,
61    const int *keep);
62
63  /// Sets type of search
64  inline void setSearchType(int value)
65  {
66    swap_ = value;
67  }
68  /// Used array so we can set
69  inline int *used() const
70  {
71    return used_;
72  }
73
74protected:
75  // Data
76
77  // Original matrix by column
78  CoinPackedMatrix matrix_;
79
80  // Number of solutions so we only do after new solution
81  int numberSolutions_;
82  // Type of search 0=normal, 1=BAB
83  int swap_;
84  /// Whether a variable has been in a solution (also when)
85  int *used_;
86};
87
88/** Proximity Search class
89 */
90class CbcHeuristicFPump;
91class CbcHeuristicProximity : public CbcHeuristic {
92public:
93  // Default Constructor
94  CbcHeuristicProximity();
95
96  /* Constructor with model - assumed before cuts
97    */
98  CbcHeuristicProximity(CbcModel &model);
99
100  // Copy constructor
101  CbcHeuristicProximity(const CbcHeuristicProximity &);
102
103  // Destructor
104  ~CbcHeuristicProximity();
105
106  /// Clone
107  virtual CbcHeuristic *clone() const;
108
109  /// Assignment operator
110  CbcHeuristicProximity &operator=(const CbcHeuristicProximity &rhs);
111
112  /// Create C++ lines to get to current state
113  virtual void generateCpp(FILE *fp);
114
115  /// Resets stuff if model changes
116  virtual void resetModel(CbcModel *model);
117
118  /// update model (This is needed if cliques update matrix etc)
119  virtual void setModel(CbcModel *model);
120
121  using CbcHeuristic::solution;
122  /** returns 0 if no solution, 1 if valid solution.
123        Sets solution values if good, sets objective value (only if good)
124    */
125  virtual int solution(double &objectiveValue,
126    double *newSolution);
127  /// Set extra increment
128  inline void setIncrement(double value)
129  {
130    increment_ = value;
131  }
132  /// Used array so we can set
133  inline int *used() const
134  {
135    return used_;
136  }
137
138protected:
139  // Data
140  /// Increment to use if no change
141  double increment_;
142  /// Copy of Feasibility pump
143  CbcHeuristicFPump *feasibilityPump_;
144  /// Number of solutions so we only do after new solution
145  int numberSolutions_;
146  /// Whether a variable has been in a solution (also when)
147  int *used_;
148};
149
150/** Naive class
151    a) Fix all ints as close to zero as possible
152    b) Fix all ints with nonzero costs and < large to zero
153    c) Put bounds round continuous and UIs and maximize
154 */
155
156class CbcHeuristicNaive : public CbcHeuristic {
157public:
158  // Default Constructor
159  CbcHeuristicNaive();
160
161  /* Constructor with model - assumed before cuts
162       Initial version does not do Lps
163    */
164  CbcHeuristicNaive(CbcModel &model);
165
166  // Copy constructor
167  CbcHeuristicNaive(const CbcHeuristicNaive &);
168
169  // Destructor
170  ~CbcHeuristicNaive();
171
172  /// Clone
173  virtual CbcHeuristic *clone() const;
174
175  /// Assignment operator
176  CbcHeuristicNaive &operator=(const CbcHeuristicNaive &rhs);
177
178  /// Create C++ lines to get to current state
179  virtual void generateCpp(FILE *fp);
180
181  /// Resets stuff if model changes
182  virtual void resetModel(CbcModel *model);
183
184  /// update model (This is needed if cliques update matrix etc)
185  virtual void setModel(CbcModel *model);
186
187  using CbcHeuristic::solution;
188  /** returns 0 if no solution, 1 if valid solution.
189        Sets solution values if good, sets objective value (only if good)
190    */
191  virtual int solution(double &objectiveValue,
192    double *newSolution);
193
194  /// Sets large cost value
195  inline void setLargeValue(double value)
196  {
197    large_ = value;
198  }
199  /// Gets large cost value
200  inline double largeValue() const
201  {
202    return large_;
203  }
204
205protected:
206  /// Data
207  /// Large value
208  double large_;
209};
210
211/** Crossover Search class
212 */
213
214class CbcHeuristicCrossover : public CbcHeuristic {
215public:
216  // Default Constructor
217  CbcHeuristicCrossover();
218
219  /* Constructor with model - assumed before cuts
220       Initial version does not do Lps
221    */
222  CbcHeuristicCrossover(CbcModel &model);
223
224  // Copy constructor
225  CbcHeuristicCrossover(const CbcHeuristicCrossover &);
226
227  // Destructor
228  ~CbcHeuristicCrossover();
229
230  /// Clone
231  virtual CbcHeuristic *clone() const;
232
233  /// Assignment operator
234  CbcHeuristicCrossover &operator=(const CbcHeuristicCrossover &rhs);
235
236  /// Create C++ lines to get to current state
237  virtual void generateCpp(FILE *fp);
238
239  /// Resets stuff if model changes
240  virtual void resetModel(CbcModel *model);
241
242  /// update model (This is needed if cliques update matrix etc)
243  virtual void setModel(CbcModel *model);
244
245  using CbcHeuristic::solution;
246  /** returns 0 if no solution, 1 if valid solution.
247        Fix variables if agree in useNumber_ solutions
248        when_ 0 off, 1 only at new solutions, 2 also every now and then
249        add 10 to make only if agree at lower bound
250    */
251  virtual int solution(double &objectiveValue,
252    double *newSolution);
253
254  /// Sets number of solutions to use
255  inline void setNumberSolutions(int value)
256  {
257    if (value > 0 && value <= 10)
258      useNumber_ = value;
259  }
260
261protected:
262  // Data
263  /// Attempts
264  std::vector< double > attempts_;
265  /// Random numbers to stop same search happening
266  double random_[10];
267  /// Number of solutions so we only do after new solution
268  int numberSolutions_;
269  /// Number of solutions to use
270  int useNumber_;
271};
272
273#endif
274
275/* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
276*/
Note: See TracBrowser for help on using the repository browser.