[1271] | 1 | /* $Id: CbcHeuristicLocal.hpp 1943 2013-07-21 09:05:45Z forrest $ */ |
---|
[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 | |
---|
| 13 | class CbcHeuristicLocal : public CbcHeuristic { |
---|
| 14 | public: |
---|
| 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] | 73 | protected: |
---|
[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 | */ |
---|
| 89 | class CbcHeuristicFPump; |
---|
| 90 | class CbcHeuristicProximity : public CbcHeuristic { |
---|
| 91 | public: |
---|
[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); |
---|
[1943] | 127 | /// Set extra increment |
---|
| 128 | inline void setIncrement(double value) |
---|
| 129 | { increment_ = value;} |
---|
[1802] | 130 | /// Used array so we can set |
---|
| 131 | inline int * used() const { |
---|
| 132 | return used_; |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | protected: |
---|
| 136 | // Data |
---|
[1943] | 137 | /// Increment to use if no change |
---|
| 138 | double increment_; |
---|
| 139 | /// Copy of Feasibility pump |
---|
[1802] | 140 | CbcHeuristicFPump * feasibilityPump_; |
---|
[1943] | 141 | /// Number of solutions so we only do after new solution |
---|
[1802] | 142 | int numberSolutions_; |
---|
| 143 | /// Whether a variable has been in a solution (also when) |
---|
| 144 | int * used_; |
---|
| 145 | }; |
---|
| 146 | |
---|
| 147 | |
---|
[1100] | 148 | /** Naive class |
---|
| 149 | a) Fix all ints as close to zero as possible |
---|
| 150 | b) Fix all ints with nonzero costs and < large to zero |
---|
| 151 | c) Put bounds round continuous and UIs and maximize |
---|
| 152 | */ |
---|
| 153 | |
---|
| 154 | class CbcHeuristicNaive : public CbcHeuristic { |
---|
| 155 | public: |
---|
| 156 | |
---|
[1286] | 157 | // Default Constructor |
---|
| 158 | CbcHeuristicNaive (); |
---|
[1100] | 159 | |
---|
[1286] | 160 | /* Constructor with model - assumed before cuts |
---|
| 161 | Initial version does not do Lps |
---|
| 162 | */ |
---|
| 163 | CbcHeuristicNaive (CbcModel & model); |
---|
[1100] | 164 | |
---|
[1286] | 165 | // Copy constructor |
---|
| 166 | CbcHeuristicNaive ( const CbcHeuristicNaive &); |
---|
[1100] | 167 | |
---|
[1286] | 168 | // Destructor |
---|
| 169 | ~CbcHeuristicNaive (); |
---|
[1100] | 170 | |
---|
[1286] | 171 | /// Clone |
---|
| 172 | virtual CbcHeuristic * clone() const; |
---|
[1100] | 173 | |
---|
[1286] | 174 | /// Assignment operator |
---|
| 175 | CbcHeuristicNaive & operator=(const CbcHeuristicNaive& rhs); |
---|
[1100] | 176 | |
---|
[1286] | 177 | /// Create C++ lines to get to current state |
---|
| 178 | virtual void generateCpp( FILE * fp) ; |
---|
[1100] | 179 | |
---|
[1286] | 180 | /// Resets stuff if model changes |
---|
| 181 | virtual void resetModel(CbcModel * model); |
---|
| 182 | |
---|
| 183 | /// update model (This is needed if cliques update matrix etc) |
---|
| 184 | virtual void setModel(CbcModel * model); |
---|
| 185 | |
---|
| 186 | using CbcHeuristic::solution ; |
---|
| 187 | /** returns 0 if no solution, 1 if valid solution. |
---|
| 188 | Sets solution values if good, sets objective value (only if good) |
---|
| 189 | */ |
---|
| 190 | virtual int solution(double & objectiveValue, |
---|
| 191 | double * newSolution); |
---|
| 192 | |
---|
| 193 | /// Sets large cost value |
---|
| 194 | inline void setLargeValue(double value) { |
---|
| 195 | large_ = value; |
---|
| 196 | } |
---|
| 197 | /// Gets large cost value |
---|
| 198 | inline double largeValue() const { |
---|
| 199 | return large_; |
---|
| 200 | } |
---|
| 201 | |
---|
[1100] | 202 | protected: |
---|
[1286] | 203 | /// Data |
---|
| 204 | /// Large value |
---|
| 205 | double large_; |
---|
[1100] | 206 | }; |
---|
| 207 | |
---|
[1271] | 208 | /** Crossover Search class |
---|
| 209 | */ |
---|
[1100] | 210 | |
---|
[1271] | 211 | class CbcHeuristicCrossover : public CbcHeuristic { |
---|
| 212 | public: |
---|
| 213 | |
---|
[1286] | 214 | // Default Constructor |
---|
| 215 | CbcHeuristicCrossover (); |
---|
[1271] | 216 | |
---|
[1286] | 217 | /* Constructor with model - assumed before cuts |
---|
| 218 | Initial version does not do Lps |
---|
| 219 | */ |
---|
| 220 | CbcHeuristicCrossover (CbcModel & model); |
---|
[1271] | 221 | |
---|
[1286] | 222 | // Copy constructor |
---|
| 223 | CbcHeuristicCrossover ( const CbcHeuristicCrossover &); |
---|
[1271] | 224 | |
---|
[1286] | 225 | // Destructor |
---|
| 226 | ~CbcHeuristicCrossover (); |
---|
[1271] | 227 | |
---|
[1286] | 228 | /// Clone |
---|
| 229 | virtual CbcHeuristic * clone() const; |
---|
[1271] | 230 | |
---|
[1286] | 231 | /// Assignment operator |
---|
| 232 | CbcHeuristicCrossover & operator=(const CbcHeuristicCrossover& rhs); |
---|
[1271] | 233 | |
---|
[1286] | 234 | /// Create C++ lines to get to current state |
---|
| 235 | virtual void generateCpp( FILE * fp) ; |
---|
[1271] | 236 | |
---|
[1286] | 237 | /// Resets stuff if model changes |
---|
| 238 | virtual void resetModel(CbcModel * model); |
---|
| 239 | |
---|
| 240 | /// update model (This is needed if cliques update matrix etc) |
---|
| 241 | virtual void setModel(CbcModel * model); |
---|
| 242 | |
---|
| 243 | using CbcHeuristic::solution ; |
---|
| 244 | /** returns 0 if no solution, 1 if valid solution. |
---|
| 245 | Fix variables if agree in useNumber_ solutions |
---|
| 246 | when_ 0 off, 1 only at new solutions, 2 also every now and then |
---|
| 247 | add 10 to make only if agree at lower bound |
---|
| 248 | */ |
---|
| 249 | virtual int solution(double & objectiveValue, |
---|
| 250 | double * newSolution); |
---|
| 251 | |
---|
| 252 | /// Sets number of solutions to use |
---|
| 253 | inline void setNumberSolutions(int value) { |
---|
| 254 | if (value > 0 && value <= 10) |
---|
| 255 | useNumber_ = value; |
---|
| 256 | } |
---|
| 257 | |
---|
[1271] | 258 | protected: |
---|
[1286] | 259 | // Data |
---|
| 260 | /// Attempts |
---|
| 261 | std::vector <double> attempts_; |
---|
| 262 | /// Random numbers to stop same search happening |
---|
| 263 | double random_[10]; |
---|
| 264 | /// Number of solutions so we only do after new solution |
---|
| 265 | int numberSolutions_; |
---|
| 266 | /// Number of solutions to use |
---|
| 267 | int useNumber_; |
---|
[1271] | 268 | }; |
---|
| 269 | |
---|
[175] | 270 | #endif |
---|
[1432] | 271 | |
---|