0
4
0
1 | 1 |
SET(COIN_ROOT_DIR "" CACHE PATH "COIN root directory") |
2 | 2 |
|
3 | 3 |
FIND_PATH(COIN_INCLUDE_DIR coin/CoinUtilsConfig.h |
4 | 4 |
HINTS ${COIN_ROOT_DIR}/include |
5 | 5 |
) |
6 | 6 |
FIND_LIBRARY(COIN_CBC_LIBRARY |
7 | 7 |
NAMES Cbc libCbc |
8 | 8 |
HINTS ${COIN_ROOT_DIR}/lib/coin |
9 | 9 |
HINTS ${COIN_ROOT_DIR}/lib |
10 | 10 |
) |
11 | 11 |
FIND_LIBRARY(COIN_CBC_SOLVER_LIBRARY |
12 | 12 |
NAMES CbcSolver libCbcSolver |
13 | 13 |
HINTS ${COIN_ROOT_DIR}/lib/coin |
14 | 14 |
HINTS ${COIN_ROOT_DIR}/lib |
15 | 15 |
) |
16 | 16 |
FIND_LIBRARY(COIN_CGL_LIBRARY |
17 | 17 |
NAMES Cgl libCgl |
18 | 18 |
HINTS ${COIN_ROOT_DIR}/lib/coin |
19 | 19 |
HINTS ${COIN_ROOT_DIR}/lib |
20 | 20 |
) |
21 | 21 |
FIND_LIBRARY(COIN_CLP_LIBRARY |
22 | 22 |
NAMES Clp libClp |
23 | 23 |
HINTS ${COIN_ROOT_DIR}/lib/coin |
24 | 24 |
HINTS ${COIN_ROOT_DIR}/lib |
25 | 25 |
) |
26 | 26 |
FIND_LIBRARY(COIN_COIN_UTILS_LIBRARY |
27 | 27 |
NAMES CoinUtils libCoinUtils |
28 | 28 |
HINTS ${COIN_ROOT_DIR}/lib/coin |
29 | 29 |
HINTS ${COIN_ROOT_DIR}/lib |
30 | 30 |
) |
31 | 31 |
FIND_LIBRARY(COIN_OSI_LIBRARY |
32 | 32 |
NAMES Osi libOsi |
33 | 33 |
HINTS ${COIN_ROOT_DIR}/lib/coin |
34 | 34 |
HINTS ${COIN_ROOT_DIR}/lib |
35 | 35 |
) |
36 | 36 |
FIND_LIBRARY(COIN_OSI_CBC_LIBRARY |
37 | 37 |
NAMES OsiCbc libOsiCbc |
38 | 38 |
HINTS ${COIN_ROOT_DIR}/lib/coin |
39 | 39 |
HINTS ${COIN_ROOT_DIR}/lib |
40 | 40 |
) |
41 | 41 |
FIND_LIBRARY(COIN_OSI_CLP_LIBRARY |
42 | 42 |
NAMES OsiClp libOsiClp |
43 | 43 |
HINTS ${COIN_ROOT_DIR}/lib/coin |
44 | 44 |
HINTS ${COIN_ROOT_DIR}/lib |
45 | 45 |
) |
46 | 46 |
FIND_LIBRARY(COIN_OSI_VOL_LIBRARY |
47 | 47 |
NAMES OsiVol libOsiVol |
48 | 48 |
HINTS ${COIN_ROOT_DIR}/lib/coin |
49 | 49 |
HINTS ${COIN_ROOT_DIR}/lib |
50 | 50 |
) |
51 | 51 |
FIND_LIBRARY(COIN_VOL_LIBRARY |
52 | 52 |
NAMES Vol libVol |
53 | 53 |
HINTS ${COIN_ROOT_DIR}/lib/coin |
54 | 54 |
HINTS ${COIN_ROOT_DIR}/lib |
55 | 55 |
) |
56 | 56 |
|
57 |
FIND_LIBRARY(COIN_ZLIB_LIBRARY |
|
58 |
NAMES z libz |
|
59 |
HINTS ${COIN_ROOT_DIR}/lib/coin |
|
60 |
HINTS ${COIN_ROOT_DIR}/lib |
|
61 |
) |
|
62 |
FIND_LIBRARY(COIN_BZ2_LIBRARY |
|
63 |
NAMES bz2 libbz2 |
|
64 |
HINTS ${COIN_ROOT_DIR}/lib/coin |
|
65 |
HINTS ${COIN_ROOT_DIR}/lib |
|
66 |
) |
|
67 |
|
|
57 | 68 |
INCLUDE(FindPackageHandleStandardArgs) |
58 | 69 |
FIND_PACKAGE_HANDLE_STANDARD_ARGS(COIN DEFAULT_MSG |
59 | 70 |
COIN_INCLUDE_DIR |
60 | 71 |
COIN_CBC_LIBRARY |
61 | 72 |
COIN_CBC_SOLVER_LIBRARY |
62 | 73 |
COIN_CGL_LIBRARY |
63 | 74 |
COIN_CLP_LIBRARY |
64 | 75 |
COIN_COIN_UTILS_LIBRARY |
65 | 76 |
COIN_OSI_LIBRARY |
66 | 77 |
COIN_OSI_CBC_LIBRARY |
67 | 78 |
COIN_OSI_CLP_LIBRARY |
68 | 79 |
# COIN_OSI_VOL_LIBRARY |
69 | 80 |
# COIN_VOL_LIBRARY |
70 | 81 |
) |
71 | 82 |
|
72 | 83 |
IF(COIN_FOUND) |
73 | 84 |
SET(COIN_INCLUDE_DIRS ${COIN_INCLUDE_DIR}) |
74 |
SET(COIN_LIBRARIES "${COIN_CBC_LIBRARY};${COIN_CBC_SOLVER_LIBRARY};${COIN_CGL_LIBRARY};${COIN_CLP_LIBRARY};${COIN_COIN_UTILS_LIBRARY};${COIN_OSI_LIBRARY};${COIN_OSI_CBC_LIBRARY};${COIN_OSI_CLP_LIBRARY}") |
|
75 |
SET(COIN_CLP_LIBRARIES "${COIN_CLP_LIBRARY};${COIN_COIN_UTILS_LIBRARY}") |
|
76 |
SET( |
|
85 |
SET(COIN_CLP_LIBRARIES "${COIN_CLP_LIBRARY};${COIN_COIN_UTILS_LIBRARY};${COIN_ZLIB_LIBRARY};${COIN_BZ2_LIBRARY}") |
|
86 |
IF(COIN_ZLIB_LIBRARY) |
|
87 |
SET(COIN_CLP_LIBRARIES "${COIN_CLP_LIBRARIES};${COIN_ZLIB_LIBRARY}") |
|
88 |
ENDIF(COIN_ZLIB_LIBRARY) |
|
89 |
IF(COIN_BZ2_LIBRARY) |
|
90 |
SET(COIN_CLP_LIBRARIES "${COIN_CLP_LIBRARIES};${COIN_BZ2_LIBRARY}") |
|
91 |
ENDIF(COIN_BZ2_LIBRARY) |
|
92 |
SET(COIN_CBC_LIBRARIES "${COIN_CBC_LIBRARY};${COIN_CBC_SOLVER_LIBRARY};${COIN_CGL_LIBRARY};${COIN_OSI_LIBRARY};${COIN_OSI_CBC_LIBRARY};${COIN_OSI_CLP_LIBRARY};${COIN_ZLIB_LIBRARY};${COIN_BZ2_LIBRARY};${COIN_CLP_LIBRARIES}") |
|
93 |
SET(COIN_LIBRARIES ${COIN_CBC_LIBRARIES}) |
|
77 | 94 |
ENDIF(COIN_FOUND) |
78 | 95 |
|
79 | 96 |
MARK_AS_ADVANCED( |
80 | 97 |
COIN_INCLUDE_DIR |
81 | 98 |
COIN_CBC_LIBRARY |
82 | 99 |
COIN_CBC_SOLVER_LIBRARY |
83 | 100 |
COIN_CGL_LIBRARY |
84 | 101 |
COIN_CLP_LIBRARY |
85 | 102 |
COIN_COIN_UTILS_LIBRARY |
86 | 103 |
COIN_OSI_LIBRARY |
87 | 104 |
COIN_OSI_CBC_LIBRARY |
88 | 105 |
COIN_OSI_CLP_LIBRARY |
89 | 106 |
COIN_OSI_VOL_LIBRARY |
90 | 107 |
COIN_VOL_LIBRARY |
108 |
COIN_ZLIB_LIBRARY |
|
109 |
COIN_BZ2_LIBRARY |
|
91 | 110 |
) |
92 | 111 |
|
93 | 112 |
IF(COIN_FOUND) |
94 | 113 |
SET(LEMON_HAVE_LP TRUE) |
95 | 114 |
SET(LEMON_HAVE_MIP TRUE) |
96 | 115 |
SET(LEMON_HAVE_CLP TRUE) |
97 | 116 |
SET(LEMON_HAVE_CBC TRUE) |
98 | 117 |
ENDIF(COIN_FOUND) |
1 | 1 |
SET(CPLEX_ROOT_DIR "" CACHE PATH "CPLEX root directory") |
2 | 2 |
|
3 | 3 |
FIND_PATH(CPLEX_INCLUDE_DIR |
4 | 4 |
ilcplex/cplex.h |
5 |
PATHS "C:/ILOG/CPLEX91/include" |
|
6 |
PATHS "/opt/ilog/cplex91/include" |
|
5 |
PATHS "C:/ILOG/CPLEX/include" |
|
6 |
PATHS "/opt/ilog/cplex/include" |
|
7 | 7 |
HINTS ${CPLEX_ROOT_DIR}/include |
8 | 8 |
) |
9 | 9 |
FIND_LIBRARY(CPLEX_LIBRARY |
10 |
cplex91 |
|
11 |
PATHS "C:/ILOG/CPLEX91/lib/msvc7/stat_mda" |
|
12 |
|
|
10 |
cplex |
|
11 |
PATHS "C:/ILOG/CPLEX/lib/msvc7/stat_mda" |
|
12 |
PATHS "/opt/ilog/cplex/bin" |
|
13 | 13 |
HINTS ${CPLEX_ROOT_DIR}/bin |
14 |
HINTS ${CPLEX_ROOT_DIR}/lib |
|
14 | 15 |
) |
15 | 16 |
|
16 | 17 |
INCLUDE(FindPackageHandleStandardArgs) |
17 | 18 |
FIND_PACKAGE_HANDLE_STANDARD_ARGS(CPLEX DEFAULT_MSG CPLEX_LIBRARY CPLEX_INCLUDE_DIR) |
18 | 19 |
|
19 | 20 |
FIND_PATH(CPLEX_BIN_DIR |
20 |
cplex91.dll |
|
21 |
PATHS "C:/ILOG/CPLEX91/bin/x86_win32" |
|
21 |
cplex.dll |
|
22 |
PATHS "C:/ILOG/CPLEX/bin/x86_win32" |
|
23 |
HINTS ${CPLEX_ROOT_DIR}/bin |
|
22 | 24 |
) |
23 | 25 |
|
24 | 26 |
IF(CPLEX_FOUND) |
25 | 27 |
SET(CPLEX_INCLUDE_DIRS ${CPLEX_INCLUDE_DIR}) |
26 | 28 |
SET(CPLEX_LIBRARIES ${CPLEX_LIBRARY}) |
27 | 29 |
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") |
28 | 30 |
SET(CPLEX_LIBRARIES "${CPLEX_LIBRARIES};m;pthread") |
29 | 31 |
ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Linux") |
30 | 32 |
ENDIF(CPLEX_FOUND) |
31 | 33 |
|
32 | 34 |
MARK_AS_ADVANCED(CPLEX_LIBRARY CPLEX_INCLUDE_DIR CPLEX_BIN_DIR) |
33 | 35 |
|
34 | 36 |
IF(CPLEX_FOUND) |
35 | 37 |
SET(LEMON_HAVE_LP TRUE) |
36 | 38 |
SET(LEMON_HAVE_MIP TRUE) |
37 | 39 |
SET(LEMON_HAVE_CPLEX TRUE) |
38 | 40 |
ENDIF(CPLEX_FOUND) |
1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2009 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
///\file |
20 | 20 |
///\brief Implementation of the CBC MIP solver interface. |
21 | 21 |
|
22 | 22 |
#include "cbc.h" |
23 | 23 |
|
24 | 24 |
#include <coin/CoinModel.hpp> |
25 | 25 |
#include <coin/CbcModel.hpp> |
26 | 26 |
#include <coin/OsiSolverInterface.hpp> |
27 | 27 |
|
28 |
#ifdef COIN_HAS_CLP |
|
29 | 28 |
#include "coin/OsiClpSolverInterface.hpp" |
30 |
#endif |
|
31 |
#ifdef COIN_HAS_OSL |
|
32 |
#include "coin/OsiOslSolverInterface.hpp" |
|
33 |
#endif |
|
34 | 29 |
|
35 | 30 |
#include "coin/CbcCutGenerator.hpp" |
36 | 31 |
#include "coin/CbcHeuristicLocal.hpp" |
37 | 32 |
#include "coin/CbcHeuristicGreedy.hpp" |
38 | 33 |
#include "coin/CbcHeuristicFPump.hpp" |
39 | 34 |
#include "coin/CbcHeuristicRINS.hpp" |
40 | 35 |
|
41 | 36 |
#include "coin/CglGomory.hpp" |
42 | 37 |
#include "coin/CglProbing.hpp" |
43 | 38 |
#include "coin/CglKnapsackCover.hpp" |
44 | 39 |
#include "coin/CglOddHole.hpp" |
45 | 40 |
#include "coin/CglClique.hpp" |
46 | 41 |
#include "coin/CglFlowCover.hpp" |
47 | 42 |
#include "coin/CglMixedIntegerRounding.hpp" |
48 | 43 |
|
49 | 44 |
#include "coin/CbcHeuristic.hpp" |
50 | 45 |
|
51 | 46 |
namespace lemon { |
52 | 47 |
|
53 | 48 |
CbcMip::CbcMip() { |
54 | 49 |
_prob = new CoinModel(); |
55 | 50 |
_prob->setProblemName("LEMON"); |
56 | 51 |
_osi_solver = 0; |
57 | 52 |
_cbc_model = 0; |
58 | 53 |
messageLevel(MESSAGE_NOTHING); |
59 | 54 |
} |
60 | 55 |
|
61 | 56 |
CbcMip::CbcMip(const CbcMip& other) { |
62 | 57 |
_prob = new CoinModel(*other._prob); |
63 | 58 |
_prob->setProblemName("LEMON"); |
64 | 59 |
_osi_solver = 0; |
65 | 60 |
_cbc_model = 0; |
66 | 61 |
messageLevel(MESSAGE_NOTHING); |
67 | 62 |
} |
68 | 63 |
|
69 | 64 |
CbcMip::~CbcMip() { |
70 | 65 |
delete _prob; |
71 | 66 |
if (_osi_solver) delete _osi_solver; |
72 | 67 |
if (_cbc_model) delete _cbc_model; |
73 | 68 |
} |
74 | 69 |
|
75 | 70 |
const char* CbcMip::_solverName() const { return "CbcMip"; } |
76 | 71 |
|
77 | 72 |
int CbcMip::_addCol() { |
78 | 73 |
_prob->addColumn(0, 0, 0, -COIN_DBL_MAX, COIN_DBL_MAX, 0.0, 0, false); |
79 | 74 |
return _prob->numberColumns() - 1; |
80 | 75 |
} |
81 | 76 |
|
82 | 77 |
CbcMip* CbcMip::newSolver() const { |
83 | 78 |
CbcMip* newlp = new CbcMip; |
84 | 79 |
return newlp; |
85 | 80 |
} |
86 | 81 |
|
87 | 82 |
CbcMip* CbcMip::cloneSolver() const { |
88 | 83 |
CbcMip* copylp = new CbcMip(*this); |
89 | 84 |
return copylp; |
90 | 85 |
} |
91 | 86 |
|
92 | 87 |
int CbcMip::_addRow() { |
93 | 88 |
_prob->addRow(0, 0, 0, -COIN_DBL_MAX, COIN_DBL_MAX); |
94 | 89 |
return _prob->numberRows() - 1; |
95 | 90 |
} |
96 | 91 |
|
97 | 92 |
int CbcMip::_addRow(Value l, ExprIterator b, ExprIterator e, Value u) { |
98 | 93 |
std::vector<int> indexes; |
99 | 94 |
std::vector<Value> values; |
100 | 95 |
|
101 | 96 |
for(ExprIterator it = b; it != e; ++it) { |
102 | 97 |
indexes.push_back(it->first); |
103 | 98 |
values.push_back(it->second); |
104 | 99 |
} |
105 | 100 |
|
106 | 101 |
_prob->addRow(values.size(), &indexes.front(), &values.front(), l, u); |
107 | 102 |
return _prob->numberRows() - 1; |
108 | 103 |
} |
109 | 104 |
|
110 | 105 |
void CbcMip::_eraseCol(int i) { |
111 | 106 |
_prob->deleteColumn(i); |
112 | 107 |
} |
113 | 108 |
|
114 | 109 |
void CbcMip::_eraseRow(int i) { |
115 | 110 |
_prob->deleteRow(i); |
116 | 111 |
} |
117 | 112 |
|
118 | 113 |
void CbcMip::_eraseColId(int i) { |
119 | 114 |
cols.eraseIndex(i); |
120 | 115 |
} |
121 | 116 |
|
122 | 117 |
void CbcMip::_eraseRowId(int i) { |
123 | 118 |
rows.eraseIndex(i); |
124 | 119 |
} |
125 | 120 |
|
126 | 121 |
void CbcMip::_getColName(int c, std::string& name) const { |
127 | 122 |
name = _prob->getColumnName(c); |
128 | 123 |
} |
129 | 124 |
|
... | ... |
@@ -177,257 +172,249 @@ |
177 | 172 |
int length = _prob->numberColumns(); |
178 | 173 |
|
179 | 174 |
std::vector<int> indices(length); |
180 | 175 |
std::vector<Value> values(length); |
181 | 176 |
|
182 | 177 |
length = _prob->getColumn(ix, &indices[0], &values[0]); |
183 | 178 |
|
184 | 179 |
for (int i = 0; i < length; ++i) { |
185 | 180 |
*b = std::make_pair(indices[i], values[i]); |
186 | 181 |
++b; |
187 | 182 |
} |
188 | 183 |
} |
189 | 184 |
|
190 | 185 |
void CbcMip::_setCoeff(int ix, int jx, Value value) { |
191 | 186 |
_prob->setElement(ix, jx, value); |
192 | 187 |
} |
193 | 188 |
|
194 | 189 |
CbcMip::Value CbcMip::_getCoeff(int ix, int jx) const { |
195 | 190 |
return _prob->getElement(ix, jx); |
196 | 191 |
} |
197 | 192 |
|
198 | 193 |
|
199 | 194 |
void CbcMip::_setColLowerBound(int i, Value lo) { |
200 | 195 |
LEMON_ASSERT(lo != INF, "Invalid bound"); |
201 | 196 |
_prob->setColumnLower(i, lo == - INF ? - COIN_DBL_MAX : lo); |
202 | 197 |
} |
203 | 198 |
|
204 | 199 |
CbcMip::Value CbcMip::_getColLowerBound(int i) const { |
205 | 200 |
double val = _prob->getColumnLower(i); |
206 | 201 |
return val == - COIN_DBL_MAX ? - INF : val; |
207 | 202 |
} |
208 | 203 |
|
209 | 204 |
void CbcMip::_setColUpperBound(int i, Value up) { |
210 | 205 |
LEMON_ASSERT(up != -INF, "Invalid bound"); |
211 | 206 |
_prob->setColumnUpper(i, up == INF ? COIN_DBL_MAX : up); |
212 | 207 |
} |
213 | 208 |
|
214 | 209 |
CbcMip::Value CbcMip::_getColUpperBound(int i) const { |
215 | 210 |
double val = _prob->getColumnUpper(i); |
216 | 211 |
return val == COIN_DBL_MAX ? INF : val; |
217 | 212 |
} |
218 | 213 |
|
219 | 214 |
void CbcMip::_setRowLowerBound(int i, Value lo) { |
220 | 215 |
LEMON_ASSERT(lo != INF, "Invalid bound"); |
221 | 216 |
_prob->setRowLower(i, lo == - INF ? - COIN_DBL_MAX : lo); |
222 | 217 |
} |
223 | 218 |
|
224 | 219 |
CbcMip::Value CbcMip::_getRowLowerBound(int i) const { |
225 | 220 |
double val = _prob->getRowLower(i); |
226 | 221 |
return val == - COIN_DBL_MAX ? - INF : val; |
227 | 222 |
} |
228 | 223 |
|
229 | 224 |
void CbcMip::_setRowUpperBound(int i, Value up) { |
230 | 225 |
LEMON_ASSERT(up != -INF, "Invalid bound"); |
231 | 226 |
_prob->setRowUpper(i, up == INF ? COIN_DBL_MAX : up); |
232 | 227 |
} |
233 | 228 |
|
234 | 229 |
CbcMip::Value CbcMip::_getRowUpperBound(int i) const { |
235 | 230 |
double val = _prob->getRowUpper(i); |
236 | 231 |
return val == COIN_DBL_MAX ? INF : val; |
237 | 232 |
} |
238 | 233 |
|
239 | 234 |
void CbcMip::_setObjCoeffs(ExprIterator b, ExprIterator e) { |
240 | 235 |
int num = _prob->numberColumns(); |
241 | 236 |
for (int i = 0; i < num; ++i) { |
242 | 237 |
_prob->setColumnObjective(i, 0.0); |
243 | 238 |
} |
244 | 239 |
for (ExprIterator it = b; it != e; ++it) { |
245 | 240 |
_prob->setColumnObjective(it->first, it->second); |
246 | 241 |
} |
247 | 242 |
} |
248 | 243 |
|
249 | 244 |
void CbcMip::_getObjCoeffs(InsertIterator b) const { |
250 | 245 |
int num = _prob->numberColumns(); |
251 | 246 |
for (int i = 0; i < num; ++i) { |
252 | 247 |
Value coef = _prob->getColumnObjective(i); |
253 | 248 |
if (coef != 0.0) { |
254 | 249 |
*b = std::make_pair(i, coef); |
255 | 250 |
++b; |
256 | 251 |
} |
257 | 252 |
} |
258 | 253 |
} |
259 | 254 |
|
260 | 255 |
void CbcMip::_setObjCoeff(int i, Value obj_coef) { |
261 | 256 |
_prob->setColumnObjective(i, obj_coef); |
262 | 257 |
} |
263 | 258 |
|
264 | 259 |
CbcMip::Value CbcMip::_getObjCoeff(int i) const { |
265 | 260 |
return _prob->getColumnObjective(i); |
266 | 261 |
} |
267 | 262 |
|
268 | 263 |
CbcMip::SolveExitStatus CbcMip::_solve() { |
269 | 264 |
|
270 | 265 |
if (_osi_solver) { |
271 | 266 |
delete _osi_solver; |
272 | 267 |
} |
273 |
#ifdef COIN_HAS_CLP |
|
274 | 268 |
_osi_solver = new OsiClpSolverInterface(); |
275 |
#elif COIN_HAS_OSL |
|
276 |
_osi_solver = new OsiOslSolverInterface(); |
|
277 |
#else |
|
278 |
#error Cannot instantiate Osi solver |
|
279 |
#endif |
|
280 | 269 |
|
281 | 270 |
_osi_solver->loadFromCoinModel(*_prob); |
282 | 271 |
|
283 | 272 |
if (_cbc_model) { |
284 | 273 |
delete _cbc_model; |
285 | 274 |
} |
286 | 275 |
_cbc_model= new CbcModel(*_osi_solver); |
287 | 276 |
|
288 | 277 |
_osi_solver->messageHandler()->setLogLevel(_message_level); |
289 | 278 |
_cbc_model->setLogLevel(_message_level); |
290 | 279 |
|
291 | 280 |
_cbc_model->initialSolve(); |
292 | 281 |
_cbc_model->solver()->setHintParam(OsiDoReducePrint, true, OsiHintTry); |
293 | 282 |
|
294 | 283 |
if (!_cbc_model->isInitialSolveAbandoned() && |
295 | 284 |
_cbc_model->isInitialSolveProvenOptimal() && |
296 | 285 |
!_cbc_model->isInitialSolveProvenPrimalInfeasible() && |
297 | 286 |
!_cbc_model->isInitialSolveProvenDualInfeasible()) { |
298 | 287 |
|
299 | 288 |
CglProbing generator1; |
300 | 289 |
generator1.setUsingObjective(true); |
301 | 290 |
generator1.setMaxPass(3); |
302 | 291 |
generator1.setMaxProbe(100); |
303 | 292 |
generator1.setMaxLook(50); |
304 | 293 |
generator1.setRowCuts(3); |
305 | 294 |
_cbc_model->addCutGenerator(&generator1, -1, "Probing"); |
306 | 295 |
|
307 | 296 |
CglGomory generator2; |
308 | 297 |
generator2.setLimit(300); |
309 | 298 |
_cbc_model->addCutGenerator(&generator2, -1, "Gomory"); |
310 | 299 |
|
311 | 300 |
CglKnapsackCover generator3; |
312 | 301 |
_cbc_model->addCutGenerator(&generator3, -1, "Knapsack"); |
313 | 302 |
|
314 | 303 |
CglOddHole generator4; |
315 | 304 |
generator4.setMinimumViolation(0.005); |
316 | 305 |
generator4.setMinimumViolationPer(0.00002); |
317 | 306 |
generator4.setMaximumEntries(200); |
318 | 307 |
_cbc_model->addCutGenerator(&generator4, -1, "OddHole"); |
319 | 308 |
|
320 | 309 |
CglClique generator5; |
321 | 310 |
generator5.setStarCliqueReport(false); |
322 | 311 |
generator5.setRowCliqueReport(false); |
323 | 312 |
_cbc_model->addCutGenerator(&generator5, -1, "Clique"); |
324 | 313 |
|
325 | 314 |
CglMixedIntegerRounding mixedGen; |
326 | 315 |
_cbc_model->addCutGenerator(&mixedGen, -1, "MixedIntegerRounding"); |
327 | 316 |
|
328 | 317 |
CglFlowCover flowGen; |
329 | 318 |
_cbc_model->addCutGenerator(&flowGen, -1, "FlowCover"); |
330 | 319 |
|
331 |
#ifdef COIN_HAS_CLP |
|
332 | 320 |
OsiClpSolverInterface* osiclp = |
333 | 321 |
dynamic_cast<OsiClpSolverInterface*>(_cbc_model->solver()); |
334 | 322 |
if (osiclp->getNumRows() < 300 && osiclp->getNumCols() < 500) { |
335 | 323 |
osiclp->setupForRepeatedUse(2, 0); |
336 | 324 |
} |
337 |
#endif |
|
338 | 325 |
|
339 | 326 |
CbcRounding heuristic1(*_cbc_model); |
340 | 327 |
heuristic1.setWhen(3); |
341 | 328 |
_cbc_model->addHeuristic(&heuristic1); |
342 | 329 |
|
343 | 330 |
CbcHeuristicLocal heuristic2(*_cbc_model); |
344 | 331 |
heuristic2.setWhen(3); |
345 | 332 |
_cbc_model->addHeuristic(&heuristic2); |
346 | 333 |
|
347 | 334 |
CbcHeuristicGreedyCover heuristic3(*_cbc_model); |
348 | 335 |
heuristic3.setAlgorithm(11); |
349 | 336 |
heuristic3.setWhen(3); |
350 | 337 |
_cbc_model->addHeuristic(&heuristic3); |
351 | 338 |
|
352 | 339 |
CbcHeuristicFPump heuristic4(*_cbc_model); |
353 | 340 |
heuristic4.setWhen(3); |
354 | 341 |
_cbc_model->addHeuristic(&heuristic4); |
355 | 342 |
|
356 | 343 |
CbcHeuristicRINS heuristic5(*_cbc_model); |
357 | 344 |
heuristic5.setWhen(3); |
358 | 345 |
_cbc_model->addHeuristic(&heuristic5); |
359 | 346 |
|
360 | 347 |
if (_cbc_model->getNumCols() < 500) { |
361 | 348 |
_cbc_model->setMaximumCutPassesAtRoot(-100); |
362 | 349 |
} else if (_cbc_model->getNumCols() < 5000) { |
363 | 350 |
_cbc_model->setMaximumCutPassesAtRoot(100); |
364 | 351 |
} else { |
365 | 352 |
_cbc_model->setMaximumCutPassesAtRoot(20); |
366 | 353 |
} |
367 | 354 |
|
368 | 355 |
if (_cbc_model->getNumCols() < 5000) { |
369 | 356 |
_cbc_model->setNumberStrong(10); |
370 | 357 |
} |
371 | 358 |
|
372 | 359 |
_cbc_model->solver()->setIntParam(OsiMaxNumIterationHotStart, 100); |
373 | 360 |
_cbc_model->branchAndBound(); |
374 | 361 |
} |
375 | 362 |
|
376 | 363 |
if (_cbc_model->isAbandoned()) { |
377 | 364 |
return UNSOLVED; |
378 | 365 |
} else { |
379 | 366 |
return SOLVED; |
380 | 367 |
} |
381 | 368 |
} |
382 | 369 |
|
383 | 370 |
CbcMip::Value CbcMip::_getSol(int i) const { |
384 | 371 |
return _cbc_model->getColSolution()[i]; |
385 | 372 |
} |
386 | 373 |
|
387 | 374 |
CbcMip::Value CbcMip::_getSolValue() const { |
388 | 375 |
return _cbc_model->getObjValue(); |
389 | 376 |
} |
390 | 377 |
|
391 | 378 |
CbcMip::ProblemType CbcMip::_getType() const { |
392 | 379 |
if (_cbc_model->isProvenOptimal()) { |
393 | 380 |
return OPTIMAL; |
394 | 381 |
} else if (_cbc_model->isContinuousUnbounded()) { |
395 | 382 |
return UNBOUNDED; |
396 | 383 |
} |
397 | 384 |
return FEASIBLE; |
398 | 385 |
} |
399 | 386 |
|
400 | 387 |
void CbcMip::_setSense(Sense sense) { |
401 | 388 |
switch (sense) { |
402 | 389 |
case MIN: |
403 | 390 |
_prob->setOptimizationDirection(1.0); |
404 | 391 |
break; |
405 | 392 |
case MAX: |
406 | 393 |
_prob->setOptimizationDirection(- 1.0); |
407 | 394 |
break; |
408 | 395 |
} |
409 | 396 |
} |
410 | 397 |
|
411 | 398 |
CbcMip::Sense CbcMip::_getSense() const { |
412 | 399 |
if (_prob->optimizationDirection() > 0.0) { |
413 | 400 |
return MIN; |
414 | 401 |
} else if (_prob->optimizationDirection() < 0.0) { |
415 | 402 |
return MAX; |
416 | 403 |
} else { |
417 | 404 |
LEMON_ASSERT(false, "Wrong sense"); |
418 | 405 |
return CbcMip::Sense(); |
419 | 406 |
} |
420 | 407 |
} |
421 | 408 |
|
422 | 409 |
void CbcMip::_setColType(int i, CbcMip::ColTypes col_type) { |
423 | 410 |
switch (col_type){ |
424 | 411 |
case INTEGER: |
425 | 412 |
_prob->setInteger(i); |
426 | 413 |
break; |
427 | 414 |
case REAL: |
428 | 415 |
_prob->setContinuous(i); |
429 | 416 |
break; |
430 | 417 |
default:; |
431 | 418 |
LEMON_ASSERT(false, "Wrong sense"); |
432 | 419 |
} |
433 | 420 |
} |
1 | 1 |
INCLUDE_DIRECTORIES( |
2 | 2 |
${PROJECT_SOURCE_DIR} |
3 | 3 |
${PROJECT_BINARY_DIR} |
4 | 4 |
) |
5 | 5 |
|
6 | 6 |
LINK_DIRECTORIES( |
7 | 7 |
${PROJECT_BINARY_DIR}/lemon |
8 | 8 |
) |
9 | 9 |
|
10 | 10 |
SET(TEST_WITH_VALGRIND "NO" CACHE STRING |
11 | 11 |
"Run the test with valgrind (YES/NO).") |
12 | 12 |
SET(VALGRIND_FLAGS "" CACHE STRING "Valgrind flags used by the tests.") |
13 | 13 |
|
14 | 14 |
SET(TESTS |
15 | 15 |
adaptors_test |
16 | 16 |
bellman_ford_test |
17 | 17 |
bfs_test |
18 | 18 |
circulation_test |
19 | 19 |
connectivity_test |
20 | 20 |
counter_test |
21 | 21 |
dfs_test |
22 | 22 |
digraph_test |
23 | 23 |
dijkstra_test |
24 | 24 |
dim_test |
25 | 25 |
edge_set_test |
26 | 26 |
error_test |
27 | 27 |
euler_test |
28 | 28 |
fractional_matching_test |
29 | 29 |
gomory_hu_test |
30 | 30 |
graph_copy_test |
31 | 31 |
graph_test |
32 | 32 |
graph_utils_test |
33 | 33 |
hao_orlin_test |
34 | 34 |
heap_test |
35 | 35 |
kruskal_test |
36 | 36 |
lgf_test |
37 | 37 |
maps_test |
38 | 38 |
matching_test |
39 | 39 |
min_cost_arborescence_test |
40 | 40 |
min_cost_flow_test |
41 | 41 |
min_mean_cycle_test |
42 | 42 |
path_test |
43 | 43 |
planarity_test |
44 | 44 |
preflow_test |
45 | 45 |
radix_sort_test |
46 | 46 |
random_test |
47 | 47 |
suurballe_test |
48 | 48 |
time_measure_test |
49 | 49 |
unionfind_test |
50 | 50 |
) |
51 | 51 |
|
52 | 52 |
IF(LEMON_HAVE_LP) |
53 | 53 |
IF(${CMAKE_BUILD_TYPE} STREQUAL "Maintainer") |
54 | 54 |
ADD_EXECUTABLE(lp_test lp_test.cc) |
55 | 55 |
ELSE() |
56 | 56 |
ADD_EXECUTABLE(lp_test EXCLUDE_FROM_ALL lp_test.cc) |
57 | 57 |
ENDIF() |
58 | 58 |
|
59 | 59 |
SET(LP_TEST_LIBS lemon) |
60 | 60 |
|
61 | 61 |
IF(LEMON_HAVE_GLPK) |
62 | 62 |
SET(LP_TEST_LIBS ${LP_TEST_LIBS} ${GLPK_LIBRARIES}) |
63 | 63 |
ENDIF() |
64 | 64 |
IF(LEMON_HAVE_CPLEX) |
65 | 65 |
SET(LP_TEST_LIBS ${LP_TEST_LIBS} ${CPLEX_LIBRARIES}) |
66 | 66 |
ENDIF() |
67 | 67 |
IF(LEMON_HAVE_CLP) |
68 | 68 |
SET(LP_TEST_LIBS ${LP_TEST_LIBS} ${COIN_CLP_LIBRARIES}) |
69 | 69 |
ENDIF() |
70 | 70 |
|
71 | 71 |
TARGET_LINK_LIBRARIES(lp_test ${LP_TEST_LIBS}) |
72 | 72 |
ADD_TEST(lp_test lp_test) |
73 | 73 |
ADD_DEPENDENCIES(check lp_test) |
74 | 74 |
|
75 | 75 |
IF(WIN32 AND LEMON_HAVE_GLPK) |
76 | 76 |
GET_TARGET_PROPERTY(TARGET_LOC lp_test LOCATION) |
77 | 77 |
GET_FILENAME_COMPONENT(TARGET_PATH ${TARGET_LOC} PATH) |
78 | 78 |
ADD_CUSTOM_COMMAND(TARGET lp_test POST_BUILD |
79 | 79 |
COMMAND ${CMAKE_COMMAND} -E copy ${GLPK_BIN_DIR}/glpk.dll ${TARGET_PATH} |
80 | 80 |
COMMAND ${CMAKE_COMMAND} -E copy ${GLPK_BIN_DIR}/libltdl3.dll ${TARGET_PATH} |
81 | 81 |
COMMAND ${CMAKE_COMMAND} -E copy ${GLPK_BIN_DIR}/zlib1.dll ${TARGET_PATH} |
82 | 82 |
) |
83 | 83 |
ENDIF() |
84 | 84 |
|
85 | 85 |
IF(WIN32 AND LEMON_HAVE_CPLEX) |
86 | 86 |
GET_TARGET_PROPERTY(TARGET_LOC lp_test LOCATION) |
87 | 87 |
GET_FILENAME_COMPONENT(TARGET_PATH ${TARGET_LOC} PATH) |
88 | 88 |
ADD_CUSTOM_COMMAND(TARGET lp_test POST_BUILD |
89 |
COMMAND ${CMAKE_COMMAND} -E copy ${CPLEX_BIN_DIR}/ |
|
89 |
COMMAND ${CMAKE_COMMAND} -E copy ${CPLEX_BIN_DIR}/cplex.dll ${TARGET_PATH} |
|
90 | 90 |
) |
91 | 91 |
ENDIF() |
92 | 92 |
ENDIF() |
93 | 93 |
|
94 | 94 |
IF(LEMON_HAVE_MIP) |
95 | 95 |
IF(${CMAKE_BUILD_TYPE} STREQUAL "Maintainer") |
96 | 96 |
ADD_EXECUTABLE(mip_test mip_test.cc) |
97 | 97 |
ELSE() |
98 | 98 |
ADD_EXECUTABLE(mip_test EXCLUDE_FROM_ALL mip_test.cc) |
99 | 99 |
ENDIF() |
100 | 100 |
|
101 | 101 |
SET(MIP_TEST_LIBS lemon) |
102 | 102 |
|
103 | 103 |
IF(LEMON_HAVE_GLPK) |
104 | 104 |
SET(MIP_TEST_LIBS ${MIP_TEST_LIBS} ${GLPK_LIBRARIES}) |
105 | 105 |
ENDIF() |
106 | 106 |
IF(LEMON_HAVE_CPLEX) |
107 | 107 |
SET(MIP_TEST_LIBS ${MIP_TEST_LIBS} ${CPLEX_LIBRARIES}) |
108 | 108 |
ENDIF() |
109 | 109 |
IF(LEMON_HAVE_CBC) |
110 | 110 |
SET(MIP_TEST_LIBS ${MIP_TEST_LIBS} ${COIN_CBC_LIBRARIES}) |
111 | 111 |
ENDIF() |
112 | 112 |
|
113 | 113 |
TARGET_LINK_LIBRARIES(mip_test ${MIP_TEST_LIBS}) |
114 | 114 |
ADD_TEST(mip_test mip_test) |
115 | 115 |
ADD_DEPENDENCIES(check mip_test) |
116 | 116 |
|
117 | 117 |
IF(WIN32 AND LEMON_HAVE_GLPK) |
118 | 118 |
GET_TARGET_PROPERTY(TARGET_LOC mip_test LOCATION) |
119 | 119 |
GET_FILENAME_COMPONENT(TARGET_PATH ${TARGET_LOC} PATH) |
120 | 120 |
ADD_CUSTOM_COMMAND(TARGET mip_test POST_BUILD |
121 | 121 |
COMMAND ${CMAKE_COMMAND} -E copy ${GLPK_BIN_DIR}/glpk.dll ${TARGET_PATH} |
122 | 122 |
COMMAND ${CMAKE_COMMAND} -E copy ${GLPK_BIN_DIR}/libltdl3.dll ${TARGET_PATH} |
123 | 123 |
COMMAND ${CMAKE_COMMAND} -E copy ${GLPK_BIN_DIR}/zlib1.dll ${TARGET_PATH} |
124 | 124 |
) |
125 | 125 |
ENDIF() |
126 | 126 |
|
127 | 127 |
IF(WIN32 AND LEMON_HAVE_CPLEX) |
128 | 128 |
GET_TARGET_PROPERTY(TARGET_LOC mip_test LOCATION) |
129 | 129 |
GET_FILENAME_COMPONENT(TARGET_PATH ${TARGET_LOC} PATH) |
130 | 130 |
ADD_CUSTOM_COMMAND(TARGET mip_test POST_BUILD |
131 |
COMMAND ${CMAKE_COMMAND} -E copy ${CPLEX_BIN_DIR}/ |
|
131 |
COMMAND ${CMAKE_COMMAND} -E copy ${CPLEX_BIN_DIR}/cplex.dll ${TARGET_PATH} |
|
132 | 132 |
) |
133 | 133 |
ENDIF() |
134 | 134 |
ENDIF() |
135 | 135 |
|
136 | 136 |
FOREACH(TEST_NAME ${TESTS}) |
137 | 137 |
IF(${CMAKE_BUILD_TYPE} STREQUAL "Maintainer") |
138 | 138 |
ADD_EXECUTABLE(${TEST_NAME} ${TEST_NAME}.cc) |
139 | 139 |
ELSE() |
140 | 140 |
ADD_EXECUTABLE(${TEST_NAME} EXCLUDE_FROM_ALL ${TEST_NAME}.cc) |
141 | 141 |
ENDIF() |
142 | 142 |
TARGET_LINK_LIBRARIES(${TEST_NAME} lemon) |
143 | 143 |
IF(TEST_WITH_VALGRIND) |
144 | 144 |
ADD_TEST(${TEST_NAME} |
145 | 145 |
valgrind --error-exitcode=1 ${VALGRIND_FLAGS} |
146 | 146 |
${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME} ) |
147 | 147 |
ELSE() |
148 | 148 |
ADD_TEST(${TEST_NAME} ${TEST_NAME}) |
149 | 149 |
ENDIF() |
150 | 150 |
ADD_DEPENDENCIES(check ${TEST_NAME}) |
151 | 151 |
ENDFOREACH() |
0 comments (0 inline)