source: branches/heur/Cbc/src/CbcHeuristicGreedy.hpp @ 885

Last change on this file since 885 was 860, checked in by forrest, 12 years ago

fix seg fault on preprocessed problem

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 KB
Line 
1// Copyright (C) 2005, International Business Machines
2// Corporation and others.  All Rights Reserved.
3#ifndef CbcHeuristicGreedy_H
4#define CbcHeuristicGreedy_H
5
6#include "CbcHeuristic.hpp"
7/** Greedy heuristic classes
8 */
9
10class CbcHeuristicGreedyCover : public CbcHeuristic {
11public:
12
13  // Default Constructor
14  CbcHeuristicGreedyCover ();
15
16  /* Constructor with model - assumed before cuts
17     Initial version does not do Lps
18  */
19  CbcHeuristicGreedyCover (CbcModel & model);
20 
21  // Copy constructor
22  CbcHeuristicGreedyCover ( const CbcHeuristicGreedyCover &);
23   
24  // Destructor
25  ~CbcHeuristicGreedyCover ();
26 
27  /// Clone
28  virtual CbcHeuristic * clone() const;
29  /// Assignment operator
30  CbcHeuristicGreedyCover & operator=(const CbcHeuristicGreedyCover& rhs);
31  /// Create C++ lines to get to current state
32  virtual void generateCpp( FILE * fp) ;
33
34  /// update model (This is needed if cliques update matrix etc)
35  virtual void setModel(CbcModel * model);
36 
37  using CbcHeuristic::solution ;
38  /** returns 0 if no solution, 1 if valid solution.
39      Sets solution values if good, sets objective value (only if good)
40      We leave all variables which are at one at this node of the
41      tree to that value and will
42      initially set all others to zero.  We then sort all variables in order of their cost
43      divided by the number of entries in rows which are not yet covered.  We randomize that
44      value a bit so that ties will be broken in different ways on different runs of the heuristic.
45      We then choose the best one and set it to one and repeat the exercise. 
46
47  */
48  virtual int solution(double & objectiveValue,
49                       double * newSolution);
50  /// Validate model i.e. sets when_ to 0 if necessary (may be NULL)
51  virtual void validate() ;
52  /// Resets stuff if model changes
53  virtual void resetModel(CbcModel * model);
54  /* Algorithm
55     0 - use current upper bounds
56     1 - use original upper bounds
57     If 10 added perturb ratios more
58     if 100 added round up all >=0.5
59  */
60  inline int algorithm() const
61  { return algorithm_; }
62  inline void setAlgorithm(int value)
63  { algorithm_=value; }
64  // Only do this many times
65  inline int numberTimes() const
66  { return numberTimes_; }
67  inline void setNumberTimes(int value)
68  { numberTimes_=value; }
69
70protected:
71  /// Guts of constructor from a CbcModel
72  void gutsOfConstructor(CbcModel * model);
73  // Data
74
75  // Original matrix by column
76  CoinPackedMatrix matrix_;
77  // original number of rows
78  int originalNumberRows_;
79  /* Algorithm
80     0 - use current upper bounds
81     1 - use original upper bounds
82     If 10 added perturb ratios more
83  */
84  int algorithm_;
85  /// Do this many times
86  int numberTimes_;
87
88};
89
90
91class CbcHeuristicGreedyEquality : public CbcHeuristic {
92public:
93
94  // Default Constructor
95  CbcHeuristicGreedyEquality ();
96
97  /* Constructor with model - assumed before cuts
98     Initial version does not do Lps
99  */
100  CbcHeuristicGreedyEquality (CbcModel & model);
101 
102  // Copy constructor
103  CbcHeuristicGreedyEquality ( const CbcHeuristicGreedyEquality &);
104   
105  // Destructor
106  ~CbcHeuristicGreedyEquality ();
107 
108  /// Clone
109  virtual CbcHeuristic * clone() const;
110  /// Assignment operator
111  CbcHeuristicGreedyEquality & operator=(const CbcHeuristicGreedyEquality& rhs);
112  /// Create C++ lines to get to current state
113  virtual void generateCpp( FILE * fp) ;
114
115  /// update model (This is needed if cliques update matrix etc)
116  virtual void setModel(CbcModel * model);
117 
118  using CbcHeuristic::solution ;
119  /** returns 0 if no solution, 1 if valid solution.
120      Sets solution values if good, sets objective value (only if good)
121      We leave all variables which are at one at this node of the
122      tree to that value and will
123      initially set all others to zero.  We then sort all variables in order of their cost
124      divided by the number of entries in rows which are not yet covered.  We randomize that
125      value a bit so that ties will be broken in different ways on different runs of the heuristic.
126      We then choose the best one and set it to one and repeat the exercise. 
127
128  */
129  virtual int solution(double & objectiveValue,
130                       double * newSolution);
131  /// Validate model i.e. sets when_ to 0 if necessary (may be NULL)
132  virtual void validate() ;
133  /// Resets stuff if model changes
134  virtual void resetModel(CbcModel * model);
135  /* Algorithm
136     0 - use current upper bounds
137     1 - use original upper bounds
138     If 10 added perturb ratios more
139     if 100 added round up all >=0.5
140  */
141  inline int algorithm() const
142  { return algorithm_; }
143  inline void setAlgorithm(int value)
144  { algorithm_=value; }
145  // Fraction of rhs to cover before branch and cut
146  inline void setFraction(double value)
147  { fraction_ = value;}
148  inline double fraction() const
149  { return fraction_;}
150  // Only do this many times
151  inline int numberTimes() const
152  { return numberTimes_; }
153  inline void setNumberTimes(int value)
154  { numberTimes_=value; }
155protected:
156  /// Guts of constructor from a CbcModel
157  void gutsOfConstructor(CbcModel * model);
158  // Data
159
160  // Original matrix by column
161  CoinPackedMatrix matrix_;
162  // Fraction of rhs to cover before branch and cut
163  double fraction_;
164  // original number of rows
165  int originalNumberRows_;
166  /* Algorithm
167     0 - use current upper bounds
168     1 - use original upper bounds
169     If 10 added perturb ratios more
170  */
171  int algorithm_;
172  /// Do this many times
173  int numberTimes_;
174
175};
176
177
178#endif
Note: See TracBrowser for help on using the repository browser.