source: trunk/Cbc/src/CbcHeuristicGreedy.hpp @ 765

Last change on this file since 765 was 765, checked in by andreasw, 14 years ago

merging changes from Bug Squashing Party Aug 2007 to regular trunk

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 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  // Data
72
73  // Original matrix by column
74  CoinPackedMatrix matrix_;
75  // original number of rows
76  int originalNumberRows_;
77  /* Algorithm
78     0 - use current upper bounds
79     1 - use original upper bounds
80     If 10 added perturb ratios more
81  */
82  int algorithm_;
83  /// Do this many times
84  int numberTimes_;
85
86};
87
88
89class CbcHeuristicGreedyEquality : public CbcHeuristic {
90public:
91
92  // Default Constructor
93  CbcHeuristicGreedyEquality ();
94
95  /* Constructor with model - assumed before cuts
96     Initial version does not do Lps
97  */
98  CbcHeuristicGreedyEquality (CbcModel & model);
99 
100  // Copy constructor
101  CbcHeuristicGreedyEquality ( const CbcHeuristicGreedyEquality &);
102   
103  // Destructor
104  ~CbcHeuristicGreedyEquality ();
105 
106  /// Clone
107  virtual CbcHeuristic * clone() const;
108  /// Assignment operator
109  CbcHeuristicGreedyEquality & operator=(const CbcHeuristicGreedyEquality& rhs);
110  /// Create C++ lines to get to current state
111  virtual void generateCpp( FILE * fp) ;
112
113  /// update model (This is needed if cliques update matrix etc)
114  virtual void setModel(CbcModel * model);
115 
116  using CbcHeuristic::solution ;
117  /** returns 0 if no solution, 1 if valid solution.
118      Sets solution values if good, sets objective value (only if good)
119      We leave all variables which are at one at this node of the
120      tree to that value and will
121      initially set all others to zero.  We then sort all variables in order of their cost
122      divided by the number of entries in rows which are not yet covered.  We randomize that
123      value a bit so that ties will be broken in different ways on different runs of the heuristic.
124      We then choose the best one and set it to one and repeat the exercise. 
125
126  */
127  virtual int solution(double & objectiveValue,
128                       double * newSolution);
129  /// Validate model i.e. sets when_ to 0 if necessary (may be NULL)
130  virtual void validate() ;
131  /// Resets stuff if model changes
132  virtual void resetModel(CbcModel * model);
133  /* Algorithm
134     0 - use current upper bounds
135     1 - use original upper bounds
136     If 10 added perturb ratios more
137     if 100 added round up all >=0.5
138  */
139  inline int algorithm() const
140  { return algorithm_; }
141  inline void setAlgorithm(int value)
142  { algorithm_=value; }
143  // Fraction of rhs to cover before branch and cut
144  inline void setFraction(double value)
145  { fraction_ = value;}
146  inline double fraction() const
147  { return fraction_;}
148  // Only do this many times
149  inline int numberTimes() const
150  { return numberTimes_; }
151  inline void setNumberTimes(int value)
152  { numberTimes_=value; }
153protected:
154  // Data
155
156  // Original matrix by column
157  CoinPackedMatrix matrix_;
158  // Fraction of rhs to cover before branch and cut
159  double fraction_;
160  // original number of rows
161  int originalNumberRows_;
162  /* Algorithm
163     0 - use current upper bounds
164     1 - use original upper bounds
165     If 10 added perturb ratios more
166  */
167  int algorithm_;
168  /// Do this many times
169  int numberTimes_;
170
171};
172
173
174#endif
Note: See TracBrowser for help on using the repository browser.