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

Last change on this file since 1422 was 1286, checked in by EdwinStraver, 10 years ago

Changed formatting using AStyle -A4 -p

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