source: stable/2.4/Cbc/src/CbcHeuristicGreedy.hpp @ 1271

Last change on this file since 1271 was 1271, checked in by forrest, 10 years ago

Creating new stable branch 2.4 from trunk (rev 1270)

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