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

Last change on this file since 1942 was 1802, checked in by forrest, 7 years ago

add Proximity heuristic (Fischetti and Monaci) - shouldn't break anything

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