source: stable/2.7/Cbc/src/CbcHeuristicLocal.hpp @ 2081

Last change on this file since 2081 was 1573, checked in by lou, 9 years ago

Change to EPL license notice.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1/* $Id: CbcHeuristicLocal.hpp 1573 2011-01-05 01:12:36Z forrest $ */
2// Copyright (C) 2002, International Business Machines
3// Corporation and others.  All Rights Reserved.
4// This code is licensed under the terms of the Eclipse Public License (EPL).
5
6#ifndef CbcHeuristicLocal_H
7#define CbcHeuristicLocal_H
8
9#include "CbcHeuristic.hpp"
10/** LocalSearch class
11 */
12
13class CbcHeuristicLocal : public CbcHeuristic {
14public:
15
16    // Default Constructor
17    CbcHeuristicLocal ();
18
19    /* Constructor with model - assumed before cuts
20       Initial version does not do Lps
21    */
22    CbcHeuristicLocal (CbcModel & model);
23
24    // Copy constructor
25    CbcHeuristicLocal ( const CbcHeuristicLocal &);
26
27    // Destructor
28    ~CbcHeuristicLocal ();
29
30    /// Clone
31    virtual CbcHeuristic * clone() const;
32
33    /// Assignment operator
34    CbcHeuristicLocal & operator=(const CbcHeuristicLocal& rhs);
35
36    /// Create C++ lines to get to current state
37    virtual void generateCpp( FILE * fp) ;
38
39    /// Resets stuff if model changes
40    virtual void resetModel(CbcModel * model);
41
42    /// update model (This is needed if cliques update matrix etc)
43    virtual void setModel(CbcModel * model);
44
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
73protected:
74    // Data
75
76    // Original matrix by column
77    CoinPackedMatrix matrix_;
78
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_;
85};
86
87
88/** Naive class
89    a) Fix all ints as close to zero as possible
90    b) Fix all ints with nonzero costs and < large to zero
91    c) Put bounds round continuous and UIs and maximize
92 */
93
94class CbcHeuristicNaive : public CbcHeuristic {
95public:
96
97    // Default Constructor
98    CbcHeuristicNaive ();
99
100    /* Constructor with model - assumed before cuts
101       Initial version does not do Lps
102    */
103    CbcHeuristicNaive (CbcModel & model);
104
105    // Copy constructor
106    CbcHeuristicNaive ( const CbcHeuristicNaive &);
107
108    // Destructor
109    ~CbcHeuristicNaive ();
110
111    /// Clone
112    virtual CbcHeuristic * clone() const;
113
114    /// Assignment operator
115    CbcHeuristicNaive & operator=(const CbcHeuristicNaive& rhs);
116
117    /// Create C++ lines to get to current state
118    virtual void generateCpp( FILE * fp) ;
119
120    /// Resets stuff if model changes
121    virtual void resetModel(CbcModel * model);
122
123    /// update model (This is needed if cliques update matrix etc)
124    virtual void setModel(CbcModel * model);
125
126    using CbcHeuristic::solution ;
127    /** returns 0 if no solution, 1 if valid solution.
128        Sets solution values if good, sets objective value (only if good)
129    */
130    virtual int solution(double & objectiveValue,
131                         double * newSolution);
132
133    /// Sets large cost value
134    inline void setLargeValue(double value) {
135        large_ = value;
136    }
137    /// Gets large cost value
138    inline double largeValue() const {
139        return large_;
140    }
141
142protected:
143    /// Data
144    /// Large value
145    double large_;
146};
147
148/** Crossover Search class
149 */
150
151class CbcHeuristicCrossover : public CbcHeuristic {
152public:
153
154    // Default Constructor
155    CbcHeuristicCrossover ();
156
157    /* Constructor with model - assumed before cuts
158       Initial version does not do Lps
159    */
160    CbcHeuristicCrossover (CbcModel & model);
161
162    // Copy constructor
163    CbcHeuristicCrossover ( const CbcHeuristicCrossover &);
164
165    // Destructor
166    ~CbcHeuristicCrossover ();
167
168    /// Clone
169    virtual CbcHeuristic * clone() const;
170
171    /// Assignment operator
172    CbcHeuristicCrossover & operator=(const CbcHeuristicCrossover& rhs);
173
174    /// Create C++ lines to get to current state
175    virtual void generateCpp( FILE * fp) ;
176
177    /// Resets stuff if model changes
178    virtual void resetModel(CbcModel * model);
179
180    /// update model (This is needed if cliques update matrix etc)
181    virtual void setModel(CbcModel * model);
182
183    using CbcHeuristic::solution ;
184    /** returns 0 if no solution, 1 if valid solution.
185        Fix variables if agree in useNumber_ solutions
186        when_ 0 off, 1 only at new solutions, 2 also every now and then
187        add 10 to make only if agree at lower bound
188    */
189    virtual int solution(double & objectiveValue,
190                         double * newSolution);
191
192    /// Sets number of solutions to use
193    inline void setNumberSolutions(int value) {
194        if (value > 0 && value <= 10)
195            useNumber_ = value;
196    }
197
198protected:
199    // Data
200    /// Attempts
201    std::vector <double> attempts_;
202    /// Random numbers to stop same search happening
203    double random_[10];
204    /// Number of solutions so we only do after new solution
205    int numberSolutions_;
206    /// Number of solutions to use
207    int useNumber_;
208};
209
210#endif
211
Note: See TracBrowser for help on using the repository browser.