File: CbcHeuristicLocal.hpp

package info (click to toggle)
coinor-cbc 2.9.9+repack1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,848 kB
  • ctags: 5,787
  • sloc: cpp: 104,337; sh: 8,921; xml: 2,950; makefile: 520; ansic: 491; awk: 197
file content (271 lines) | stat: -rw-r--r-- 7,411 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/* $Id: CbcHeuristicLocal.hpp 1943 2013-07-21 09:05:45Z forrest $ */
// Copyright (C) 2002, International Business Machines
// Corporation and others.  All Rights Reserved.
// This code is licensed under the terms of the Eclipse Public License (EPL).

#ifndef CbcHeuristicLocal_H
#define CbcHeuristicLocal_H

#include "CbcHeuristic.hpp"
/** LocalSearch class
 */

class CbcHeuristicLocal : public CbcHeuristic {
public:

    // Default Constructor
    CbcHeuristicLocal ();

    /* Constructor with model - assumed before cuts
       Initial version does not do Lps
    */
    CbcHeuristicLocal (CbcModel & model);

    // Copy constructor
    CbcHeuristicLocal ( const CbcHeuristicLocal &);

    // Destructor
    ~CbcHeuristicLocal ();

    /// Clone
    virtual CbcHeuristic * clone() const;

    /// Assignment operator
    CbcHeuristicLocal & operator=(const CbcHeuristicLocal& rhs);

    /// Create C++ lines to get to current state
    virtual void generateCpp( FILE * fp) ;

    /// Resets stuff if model changes
    virtual void resetModel(CbcModel * model);

    /// update model (This is needed if cliques update matrix etc)
    virtual void setModel(CbcModel * model);

    using CbcHeuristic::solution ;
    /** returns 0 if no solution, 1 if valid solution.
        Sets solution values if good, sets objective value (only if good)
        This is called after cuts have been added - so can not add cuts
        First tries setting a variable to better value.  If feasible then
        tries setting others.  If not feasible then tries swaps

        ********

        This first version does not do LP's and does swaps of two integer
        variables.  Later versions could do Lps.
    */
    virtual int solution(double & objectiveValue,
                         double * newSolution);
    /// This version fixes stuff and does IP
    int solutionFix(double & objectiveValue,
                    double * newSolution,
                    const int * keep);

    /// Sets type of search
    inline void setSearchType(int value) {
        swap_ = value;
    }
    /// Used array so we can set
    inline int * used() const {
        return used_;
    }

protected:
    // Data

    // Original matrix by column
    CoinPackedMatrix matrix_;

    // Number of solutions so we only do after new solution
    int numberSolutions_;
    // Type of search 0=normal, 1=BAB
    int swap_;
    /// Whether a variable has been in a solution (also when)
    int * used_;
};

/** Proximity Search class
 */
class CbcHeuristicFPump;
class CbcHeuristicProximity : public CbcHeuristic {
public:

    // Default Constructor
    CbcHeuristicProximity ();

    /* Constructor with model - assumed before cuts
    */
    CbcHeuristicProximity (CbcModel & model);

    // Copy constructor
    CbcHeuristicProximity ( const CbcHeuristicProximity &);

    // Destructor
    ~CbcHeuristicProximity ();

    /// Clone
    virtual CbcHeuristic * clone() const;

    /// Assignment operator
    CbcHeuristicProximity & operator=(const CbcHeuristicProximity& rhs);

    /// Create C++ lines to get to current state
    virtual void generateCpp( FILE * fp) ;

    /// Resets stuff if model changes
    virtual void resetModel(CbcModel * model);

    /// update model (This is needed if cliques update matrix etc)
    virtual void setModel(CbcModel * model);

    using CbcHeuristic::solution ;
    /** returns 0 if no solution, 1 if valid solution.
        Sets solution values if good, sets objective value (only if good)
    */
    virtual int solution(double & objectiveValue,
                         double * newSolution);
    /// Set extra increment
    inline void setIncrement(double value)
    { increment_ = value;}
    /// Used array so we can set
    inline int * used() const {
        return used_;
    }

protected:
    // Data
    /// Increment to use if no change
    double increment_;
    /// Copy of Feasibility pump
    CbcHeuristicFPump * feasibilityPump_;
    /// Number of solutions so we only do after new solution
    int numberSolutions_;
    /// Whether a variable has been in a solution (also when)
    int * used_;
};


/** Naive class
    a) Fix all ints as close to zero as possible
    b) Fix all ints with nonzero costs and < large to zero
    c) Put bounds round continuous and UIs and maximize
 */

class CbcHeuristicNaive : public CbcHeuristic {
public:

    // Default Constructor
    CbcHeuristicNaive ();

    /* Constructor with model - assumed before cuts
       Initial version does not do Lps
    */
    CbcHeuristicNaive (CbcModel & model);

    // Copy constructor
    CbcHeuristicNaive ( const CbcHeuristicNaive &);

    // Destructor
    ~CbcHeuristicNaive ();

    /// Clone
    virtual CbcHeuristic * clone() const;

    /// Assignment operator
    CbcHeuristicNaive & operator=(const CbcHeuristicNaive& rhs);

    /// Create C++ lines to get to current state
    virtual void generateCpp( FILE * fp) ;

    /// Resets stuff if model changes
    virtual void resetModel(CbcModel * model);

    /// update model (This is needed if cliques update matrix etc)
    virtual void setModel(CbcModel * model);

    using CbcHeuristic::solution ;
    /** returns 0 if no solution, 1 if valid solution.
        Sets solution values if good, sets objective value (only if good)
    */
    virtual int solution(double & objectiveValue,
                         double * newSolution);

    /// Sets large cost value
    inline void setLargeValue(double value) {
        large_ = value;
    }
    /// Gets large cost value
    inline double largeValue() const {
        return large_;
    }

protected:
    /// Data
    /// Large value
    double large_;
};

/** Crossover Search class
 */

class CbcHeuristicCrossover : public CbcHeuristic {
public:

    // Default Constructor
    CbcHeuristicCrossover ();

    /* Constructor with model - assumed before cuts
       Initial version does not do Lps
    */
    CbcHeuristicCrossover (CbcModel & model);

    // Copy constructor
    CbcHeuristicCrossover ( const CbcHeuristicCrossover &);

    // Destructor
    ~CbcHeuristicCrossover ();

    /// Clone
    virtual CbcHeuristic * clone() const;

    /// Assignment operator
    CbcHeuristicCrossover & operator=(const CbcHeuristicCrossover& rhs);

    /// Create C++ lines to get to current state
    virtual void generateCpp( FILE * fp) ;

    /// Resets stuff if model changes
    virtual void resetModel(CbcModel * model);

    /// update model (This is needed if cliques update matrix etc)
    virtual void setModel(CbcModel * model);

    using CbcHeuristic::solution ;
    /** returns 0 if no solution, 1 if valid solution.
        Fix variables if agree in useNumber_ solutions
        when_ 0 off, 1 only at new solutions, 2 also every now and then
        add 10 to make only if agree at lower bound
    */
    virtual int solution(double & objectiveValue,
                         double * newSolution);

    /// Sets number of solutions to use
    inline void setNumberSolutions(int value) {
        if (value > 0 && value <= 10)
            useNumber_ = value;
    }

protected:
    // Data
    /// Attempts
    std::vector <double> attempts_;
    /// Random numbers to stop same search happening
    double random_[10];
    /// Number of solutions so we only do after new solution
    int numberSolutions_;
    /// Number of solutions to use
    int useNumber_;
};

#endif