source: branches/devel/Cbc/src/CbcHeuristicGreedy.hpp @ 601

Last change on this file since 601 was 502, checked in by forrest, 13 years ago

mostly for rins

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