source: trunk/Cbc/src/CbcHeuristicLocal.hpp @ 1424

Last change on this file since 1424 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.5 KB
Line 
1/* $Id: CbcHeuristicLocal.hpp 1286 2009-11-09 23:33:07Z forrest $ */
2// Copyright (C) 2002, International Business Machines
3// Corporation and others.  All Rights Reserved.
4#ifndef CbcHeuristicLocal_H
5#define CbcHeuristicLocal_H
6
7#include "CbcHeuristic.hpp"
8/** LocalSearch class
9 */
10
11class CbcHeuristicLocal : public CbcHeuristic {
12public:
13
14    // Default Constructor
15    CbcHeuristicLocal ();
16
17    /* Constructor with model - assumed before cuts
18       Initial version does not do Lps
19    */
20    CbcHeuristicLocal (CbcModel & model);
21
22    // Copy constructor
23    CbcHeuristicLocal ( const CbcHeuristicLocal &);
24
25    // Destructor
26    ~CbcHeuristicLocal ();
27
28    /// Clone
29    virtual CbcHeuristic * clone() const;
30
31    /// Assignment operator
32    CbcHeuristicLocal & operator=(const CbcHeuristicLocal& rhs);
33
34    /// Create C++ lines to get to current state
35    virtual void generateCpp( FILE * fp) ;
36
37    /// Resets stuff if model changes
38    virtual void resetModel(CbcModel * model);
39
40    /// update model (This is needed if cliques update matrix etc)
41    virtual void setModel(CbcModel * model);
42
43    using CbcHeuristic::solution ;
44    /** returns 0 if no solution, 1 if valid solution.
45        Sets solution values if good, sets objective value (only if good)
46        This is called after cuts have been added - so can not add cuts
47        First tries setting a variable to better value.  If feasible then
48        tries setting others.  If not feasible then tries swaps
49
50        ********
51
52        This first version does not do LP's and does swaps of two integer
53        variables.  Later versions could do Lps.
54    */
55    virtual int solution(double & objectiveValue,
56                         double * newSolution);
57    /// This version fixes stuff and does IP
58    int solutionFix(double & objectiveValue,
59                    double * newSolution,
60                    const int * keep);
61
62    /// Sets type of search
63    inline void setSearchType(int value) {
64        swap_ = value;
65    }
66    /// Used array so we can set
67    inline int * used() const {
68        return used_;
69    }
70
71protected:
72    // Data
73
74    // Original matrix by column
75    CoinPackedMatrix matrix_;
76
77    // Number of solutions so we only do after new solution
78    int numberSolutions_;
79    // Type of search 0=normal, 1=BAB
80    int swap_;
81    /// Whether a variable has been in a solution (also when)
82    int * used_;
83};
84
85
86/** Naive class
87    a) Fix all ints as close to zero as possible
88    b) Fix all ints with nonzero costs and < large to zero
89    c) Put bounds round continuous and UIs and maximize
90 */
91
92class CbcHeuristicNaive : public CbcHeuristic {
93public:
94
95    // Default Constructor
96    CbcHeuristicNaive ();
97
98    /* Constructor with model - assumed before cuts
99       Initial version does not do Lps
100    */
101    CbcHeuristicNaive (CbcModel & model);
102
103    // Copy constructor
104    CbcHeuristicNaive ( const CbcHeuristicNaive &);
105
106    // Destructor
107    ~CbcHeuristicNaive ();
108
109    /// Clone
110    virtual CbcHeuristic * clone() const;
111
112    /// Assignment operator
113    CbcHeuristicNaive & operator=(const CbcHeuristicNaive& rhs);
114
115    /// Create C++ lines to get to current state
116    virtual void generateCpp( FILE * fp) ;
117
118    /// Resets stuff if model changes
119    virtual void resetModel(CbcModel * model);
120
121    /// update model (This is needed if cliques update matrix etc)
122    virtual void setModel(CbcModel * model);
123
124    using CbcHeuristic::solution ;
125    /** returns 0 if no solution, 1 if valid solution.
126        Sets solution values if good, sets objective value (only if good)
127    */
128    virtual int solution(double & objectiveValue,
129                         double * newSolution);
130
131    /// Sets large cost value
132    inline void setLargeValue(double value) {
133        large_ = value;
134    }
135    /// Gets large cost value
136    inline double largeValue() const {
137        return large_;
138    }
139
140protected:
141    /// Data
142    /// Large value
143    double large_;
144};
145
146/** Crossover Search class
147 */
148
149class CbcHeuristicCrossover : public CbcHeuristic {
150public:
151
152    // Default Constructor
153    CbcHeuristicCrossover ();
154
155    /* Constructor with model - assumed before cuts
156       Initial version does not do Lps
157    */
158    CbcHeuristicCrossover (CbcModel & model);
159
160    // Copy constructor
161    CbcHeuristicCrossover ( const CbcHeuristicCrossover &);
162
163    // Destructor
164    ~CbcHeuristicCrossover ();
165
166    /// Clone
167    virtual CbcHeuristic * clone() const;
168
169    /// Assignment operator
170    CbcHeuristicCrossover & operator=(const CbcHeuristicCrossover& rhs);
171
172    /// Create C++ lines to get to current state
173    virtual void generateCpp( FILE * fp) ;
174
175    /// Resets stuff if model changes
176    virtual void resetModel(CbcModel * model);
177
178    /// update model (This is needed if cliques update matrix etc)
179    virtual void setModel(CbcModel * model);
180
181    using CbcHeuristic::solution ;
182    /** returns 0 if no solution, 1 if valid solution.
183        Fix variables if agree in useNumber_ solutions
184        when_ 0 off, 1 only at new solutions, 2 also every now and then
185        add 10 to make only if agree at lower bound
186    */
187    virtual int solution(double & objectiveValue,
188                         double * newSolution);
189
190    /// Sets number of solutions to use
191    inline void setNumberSolutions(int value) {
192        if (value > 0 && value <= 10)
193            useNumber_ = value;
194    }
195
196protected:
197    // Data
198    /// Attempts
199    std::vector <double> attempts_;
200    /// Random numbers to stop same search happening
201    double random_[10];
202    /// Number of solutions so we only do after new solution
203    int numberSolutions_;
204    /// Number of solutions to use
205    int useNumber_;
206};
207
208#endif
Note: See TracBrowser for help on using the repository browser.