source: trunk/Samples/CbcHeuristicGreedy.hpp @ 139

Last change on this file since 139 was 139, checked in by forrest, 16 years ago

add equality

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