1 | // $Id$ |
---|
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 | #include <cassert> |
---|
7 | |
---|
8 | #include "OsiConfig.h" |
---|
9 | #include "CoinTime.hpp" |
---|
10 | |
---|
11 | #include "CoinHelperFunctions.hpp" |
---|
12 | #include "CoinIndexedVector.hpp" |
---|
13 | |
---|
14 | /* |
---|
15 | Default solver configuration: In any environment, clp is the default if you |
---|
16 | do nothing. |
---|
17 | |
---|
18 | The necessary definitions will be handled by the configure script (based on |
---|
19 | the value specified for --with-osicbc-default-solver) in any environment |
---|
20 | where configure is available. The results can be found in inc/config_osi.h, |
---|
21 | which is created during configuration from config_osi.h.in and placed |
---|
22 | in the build directory. |
---|
23 | |
---|
24 | In an environment which does not use configure (MS Visual Studio, for example) |
---|
25 | the preferred method is to edit the definitions in inc/OsiConfig.h. The |
---|
26 | symbols are left undefined by default because some older environments (e.g., |
---|
27 | MS Visual Studio v7 or earlier) will not accept an #include directive which |
---|
28 | uses a macro to specify the file. In such an environment, if you want to use |
---|
29 | a solver other than OsiClp, you'll need to make the changes here. |
---|
30 | */ |
---|
31 | |
---|
32 | #ifndef OSICBC_DFLT_SOLVER |
---|
33 | #define OSICBC_DFLT_SOLVER OsiClpSolverInterface |
---|
34 | #define OSICBC_CLP_DFLT_SOLVER |
---|
35 | #include "OsiClpSolverInterface.hpp" |
---|
36 | #else |
---|
37 | #include OSICBC_DFLT_SOLVER_HPP |
---|
38 | #endif |
---|
39 | |
---|
40 | #include "OsiCbcSolverInterface.hpp" |
---|
41 | #include "OsiCuts.hpp" |
---|
42 | #include "OsiRowCut.hpp" |
---|
43 | #include "OsiColCut.hpp" |
---|
44 | #ifdef OSICBC_CLP_DFLT_SOLVER |
---|
45 | #include "ClpPresolve.hpp" |
---|
46 | #endif |
---|
47 | //############################################################################# |
---|
48 | // Solve methods |
---|
49 | //############################################################################# |
---|
50 | void OsiCbcSolverInterface::initialSolve() |
---|
51 | { |
---|
52 | modelPtr_->solver()->initialSolve(); |
---|
53 | } |
---|
54 | |
---|
55 | //----------------------------------------------------------------------------- |
---|
56 | void OsiCbcSolverInterface::resolve() |
---|
57 | { |
---|
58 | modelPtr_->solver()->resolve(); |
---|
59 | } |
---|
60 | //############################################################################# |
---|
61 | // Parameter related methods |
---|
62 | //############################################################################# |
---|
63 | |
---|
64 | bool |
---|
65 | OsiCbcSolverInterface::setIntParam(OsiIntParam key, int value) |
---|
66 | { |
---|
67 | return modelPtr_->solver()->setIntParam(key,value);; |
---|
68 | } |
---|
69 | |
---|
70 | //----------------------------------------------------------------------------- |
---|
71 | |
---|
72 | bool |
---|
73 | OsiCbcSolverInterface::setDblParam(OsiDblParam key, double value) |
---|
74 | { |
---|
75 | return modelPtr_->solver()->setDblParam(key,value); |
---|
76 | } |
---|
77 | |
---|
78 | //----------------------------------------------------------------------------- |
---|
79 | |
---|
80 | bool |
---|
81 | OsiCbcSolverInterface::setStrParam(OsiStrParam key, const std::string & value) |
---|
82 | { |
---|
83 | return modelPtr_->solver()->setStrParam(key,value); |
---|
84 | } |
---|
85 | |
---|
86 | |
---|
87 | //----------------------------------------------------------------------------- |
---|
88 | |
---|
89 | bool |
---|
90 | OsiCbcSolverInterface::getIntParam(OsiIntParam key, int& value) const |
---|
91 | { |
---|
92 | return modelPtr_->solver()->getIntParam(key,value); |
---|
93 | } |
---|
94 | |
---|
95 | //----------------------------------------------------------------------------- |
---|
96 | |
---|
97 | bool |
---|
98 | OsiCbcSolverInterface::getDblParam(OsiDblParam key, double& value) const |
---|
99 | { |
---|
100 | return modelPtr_->solver()->getDblParam(key,value); |
---|
101 | } |
---|
102 | |
---|
103 | //----------------------------------------------------------------------------- |
---|
104 | |
---|
105 | bool |
---|
106 | OsiCbcSolverInterface::getStrParam(OsiStrParam key, std::string & value) const |
---|
107 | { |
---|
108 | if ( key==OsiSolverName ) { |
---|
109 | std::string value2; |
---|
110 | modelPtr_->solver()->getStrParam(key,value2); |
---|
111 | value = "cbc"+value2; |
---|
112 | return true; |
---|
113 | } |
---|
114 | return modelPtr_->solver()->getStrParam(key,value); |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | //############################################################################# |
---|
119 | // Methods returning info on how the solution process terminated |
---|
120 | //############################################################################# |
---|
121 | |
---|
122 | bool OsiCbcSolverInterface::isAbandoned() const |
---|
123 | { |
---|
124 | return modelPtr_->solver()->isAbandoned(); |
---|
125 | } |
---|
126 | |
---|
127 | bool OsiCbcSolverInterface::isProvenOptimal() const |
---|
128 | { |
---|
129 | return modelPtr_->solver()->isProvenOptimal(); |
---|
130 | } |
---|
131 | |
---|
132 | bool OsiCbcSolverInterface::isProvenPrimalInfeasible() const |
---|
133 | { |
---|
134 | return modelPtr_->solver()->isProvenPrimalInfeasible(); |
---|
135 | } |
---|
136 | |
---|
137 | bool OsiCbcSolverInterface::isProvenDualInfeasible() const |
---|
138 | { |
---|
139 | return modelPtr_->solver()->isProvenDualInfeasible(); |
---|
140 | } |
---|
141 | bool OsiCbcSolverInterface::isPrimalObjectiveLimitReached() const |
---|
142 | { |
---|
143 | return modelPtr_->solver()->isPrimalObjectiveLimitReached(); |
---|
144 | } |
---|
145 | |
---|
146 | bool OsiCbcSolverInterface::isDualObjectiveLimitReached() const |
---|
147 | { |
---|
148 | return modelPtr_->solver()->isDualObjectiveLimitReached(); |
---|
149 | } |
---|
150 | |
---|
151 | bool OsiCbcSolverInterface::isIterationLimitReached() const |
---|
152 | { |
---|
153 | return modelPtr_->solver()->isIterationLimitReached(); |
---|
154 | } |
---|
155 | |
---|
156 | //############################################################################# |
---|
157 | // WarmStart related methods |
---|
158 | //############################################################################# |
---|
159 | CoinWarmStart *OsiCbcSolverInterface::getEmptyWarmStart () const |
---|
160 | { |
---|
161 | return modelPtr_->solver()->getEmptyWarmStart(); |
---|
162 | } |
---|
163 | |
---|
164 | CoinWarmStart* OsiCbcSolverInterface::getWarmStart() const |
---|
165 | { |
---|
166 | return modelPtr_->solver()->getWarmStart(); |
---|
167 | } |
---|
168 | |
---|
169 | //----------------------------------------------------------------------------- |
---|
170 | |
---|
171 | bool OsiCbcSolverInterface::setWarmStart(const CoinWarmStart* warmstart) |
---|
172 | { |
---|
173 | return modelPtr_->solver()->setWarmStart(warmstart); |
---|
174 | } |
---|
175 | |
---|
176 | //############################################################################# |
---|
177 | // Hotstart related methods (primarily used in strong branching) |
---|
178 | //############################################################################# |
---|
179 | |
---|
180 | void OsiCbcSolverInterface::markHotStart() |
---|
181 | { |
---|
182 | modelPtr_->solver()->markHotStart(); |
---|
183 | } |
---|
184 | |
---|
185 | void OsiCbcSolverInterface::solveFromHotStart() |
---|
186 | { |
---|
187 | modelPtr_->solver()->solveFromHotStart(); |
---|
188 | } |
---|
189 | |
---|
190 | void OsiCbcSolverInterface::unmarkHotStart() |
---|
191 | { |
---|
192 | modelPtr_->solver()->unmarkHotStart(); |
---|
193 | } |
---|
194 | |
---|
195 | //############################################################################# |
---|
196 | // Problem information methods (original data) |
---|
197 | //############################################################################# |
---|
198 | |
---|
199 | //------------------------------------------------------------------ |
---|
200 | const char * OsiCbcSolverInterface::getRowSense() const |
---|
201 | { |
---|
202 | return modelPtr_->solver()->getRowSense(); |
---|
203 | } |
---|
204 | //------------------------------------------------------------------ |
---|
205 | const double * OsiCbcSolverInterface::getRightHandSide() const |
---|
206 | { |
---|
207 | return modelPtr_->solver()->getRightHandSide(); |
---|
208 | } |
---|
209 | //------------------------------------------------------------------ |
---|
210 | const double * OsiCbcSolverInterface::getRowRange() const |
---|
211 | { |
---|
212 | return modelPtr_->solver()->getRowRange(); |
---|
213 | } |
---|
214 | //------------------------------------------------------------------ |
---|
215 | // Return information on integrality |
---|
216 | //------------------------------------------------------------------ |
---|
217 | bool OsiCbcSolverInterface::isContinuous(int colNumber) const |
---|
218 | { |
---|
219 | return modelPtr_->solver()->isContinuous(colNumber); |
---|
220 | } |
---|
221 | //------------------------------------------------------------------ |
---|
222 | |
---|
223 | //------------------------------------------------------------------ |
---|
224 | // Row and column copies of the matrix ... |
---|
225 | //------------------------------------------------------------------ |
---|
226 | const CoinPackedMatrix * OsiCbcSolverInterface::getMatrixByRow() const |
---|
227 | { |
---|
228 | return modelPtr_->solver()->getMatrixByRow(); |
---|
229 | } |
---|
230 | |
---|
231 | const CoinPackedMatrix * OsiCbcSolverInterface::getMatrixByCol() const |
---|
232 | { |
---|
233 | return modelPtr_->solver()->getMatrixByCol(); |
---|
234 | } |
---|
235 | |
---|
236 | //------------------------------------------------------------------ |
---|
237 | std::vector<double*> OsiCbcSolverInterface::getDualRays(int maxNumRays, |
---|
238 | bool fullRay) const |
---|
239 | { |
---|
240 | return modelPtr_->solver()->getDualRays(maxNumRays,fullRay); |
---|
241 | } |
---|
242 | //------------------------------------------------------------------ |
---|
243 | std::vector<double*> OsiCbcSolverInterface::getPrimalRays(int maxNumRays) const |
---|
244 | { |
---|
245 | return modelPtr_->solver()->getPrimalRays(maxNumRays); |
---|
246 | } |
---|
247 | //############################################################################# |
---|
248 | void |
---|
249 | OsiCbcSolverInterface::setContinuous(int index) |
---|
250 | { |
---|
251 | modelPtr_->solver()->setContinuous(index); |
---|
252 | } |
---|
253 | //----------------------------------------------------------------------------- |
---|
254 | void |
---|
255 | OsiCbcSolverInterface::setInteger(int index) |
---|
256 | { |
---|
257 | modelPtr_->solver()->setInteger(index); |
---|
258 | } |
---|
259 | //----------------------------------------------------------------------------- |
---|
260 | void |
---|
261 | OsiCbcSolverInterface::setContinuous(const int* indices, int len) |
---|
262 | { |
---|
263 | modelPtr_->solver()->setContinuous(indices,len); |
---|
264 | } |
---|
265 | //----------------------------------------------------------------------------- |
---|
266 | void |
---|
267 | OsiCbcSolverInterface::setInteger(const int* indices, int len) |
---|
268 | { |
---|
269 | modelPtr_->solver()->setInteger(indices,len); |
---|
270 | } |
---|
271 | //----------------------------------------------------------------------------- |
---|
272 | void OsiCbcSolverInterface::setColSolution(const double * cs) |
---|
273 | { |
---|
274 | modelPtr_->solver()->setColSolution(cs); |
---|
275 | } |
---|
276 | //----------------------------------------------------------------------------- |
---|
277 | void OsiCbcSolverInterface::setRowPrice(const double * rs) |
---|
278 | { |
---|
279 | modelPtr_->solver()->setRowPrice(rs); |
---|
280 | } |
---|
281 | |
---|
282 | //############################################################################# |
---|
283 | // Problem modifying methods (matrix) |
---|
284 | //############################################################################# |
---|
285 | void |
---|
286 | OsiCbcSolverInterface::addCol(const CoinPackedVectorBase& vec, |
---|
287 | const double collb, const double colub, |
---|
288 | const double obj) |
---|
289 | { |
---|
290 | modelPtr_->solver()->addCol(vec,collb,colub,obj); |
---|
291 | } |
---|
292 | /* Add a column (primal variable) to the problem. */ |
---|
293 | void |
---|
294 | OsiCbcSolverInterface::addCol(int numberElements, const int * rows, const double * elements, |
---|
295 | const double collb, const double colub, |
---|
296 | const double obj) |
---|
297 | { |
---|
298 | modelPtr_->solver()->addCol(numberElements, rows, elements, |
---|
299 | collb,colub,obj); |
---|
300 | } |
---|
301 | //----------------------------------------------------------------------------- |
---|
302 | void |
---|
303 | OsiCbcSolverInterface::addCols(const int numcols, |
---|
304 | const CoinPackedVectorBase * const * cols, |
---|
305 | const double* collb, const double* colub, |
---|
306 | const double* obj) |
---|
307 | { |
---|
308 | modelPtr_->solver()->addCols(numcols,cols,collb,colub,obj); |
---|
309 | } |
---|
310 | //----------------------------------------------------------------------------- |
---|
311 | void |
---|
312 | OsiCbcSolverInterface::deleteCols(const int num, const int * columnIndices) |
---|
313 | { |
---|
314 | modelPtr_->solver()->deleteCols(num,columnIndices); |
---|
315 | } |
---|
316 | //----------------------------------------------------------------------------- |
---|
317 | void |
---|
318 | OsiCbcSolverInterface::addRow(const CoinPackedVectorBase& vec, |
---|
319 | const double rowlb, const double rowub) |
---|
320 | { |
---|
321 | modelPtr_->solver()->addRow(vec,rowlb,rowub); |
---|
322 | } |
---|
323 | //----------------------------------------------------------------------------- |
---|
324 | void |
---|
325 | OsiCbcSolverInterface::addRow(const CoinPackedVectorBase& vec, |
---|
326 | const char rowsen, const double rowrhs, |
---|
327 | const double rowrng) |
---|
328 | { |
---|
329 | modelPtr_->solver()->addRow(vec,rowsen,rowrhs,rowrng); |
---|
330 | } |
---|
331 | //----------------------------------------------------------------------------- |
---|
332 | void |
---|
333 | OsiCbcSolverInterface::addRows(const int numrows, |
---|
334 | const CoinPackedVectorBase * const * rows, |
---|
335 | const double* rowlb, const double* rowub) |
---|
336 | { |
---|
337 | modelPtr_->solver()->addRows(numrows,rows,rowlb,rowub); |
---|
338 | } |
---|
339 | //----------------------------------------------------------------------------- |
---|
340 | void |
---|
341 | OsiCbcSolverInterface::addRows(const int numrows, |
---|
342 | const CoinPackedVectorBase * const * rows, |
---|
343 | const char* rowsen, const double* rowrhs, |
---|
344 | const double* rowrng) |
---|
345 | { |
---|
346 | modelPtr_->solver()->addRows(numrows,rows,rowsen,rowrhs,rowrng); |
---|
347 | } |
---|
348 | //----------------------------------------------------------------------------- |
---|
349 | void |
---|
350 | OsiCbcSolverInterface::deleteRows(const int num, const int * rowIndices) |
---|
351 | { |
---|
352 | modelPtr_->solver()->deleteRows(num,rowIndices); |
---|
353 | } |
---|
354 | |
---|
355 | //############################################################################# |
---|
356 | // Methods to input a problem |
---|
357 | //############################################################################# |
---|
358 | |
---|
359 | void |
---|
360 | OsiCbcSolverInterface::loadProblem(const CoinPackedMatrix& matrix, |
---|
361 | const double* collb, const double* colub, |
---|
362 | const double* obj, |
---|
363 | const double* rowlb, const double* rowub) |
---|
364 | { |
---|
365 | modelPtr_->solver()->loadProblem(matrix,collb,colub,obj,rowlb,rowub); |
---|
366 | } |
---|
367 | |
---|
368 | //----------------------------------------------------------------------------- |
---|
369 | |
---|
370 | void |
---|
371 | OsiCbcSolverInterface::assignProblem(CoinPackedMatrix*& matrix, |
---|
372 | double*& collb, double*& colub, |
---|
373 | double*& obj, |
---|
374 | double*& rowlb, double*& rowub) |
---|
375 | { |
---|
376 | modelPtr_->solver()->assignProblem(matrix,collb,colub,obj,rowlb,rowub); |
---|
377 | } |
---|
378 | |
---|
379 | //----------------------------------------------------------------------------- |
---|
380 | |
---|
381 | void |
---|
382 | OsiCbcSolverInterface::loadProblem(const CoinPackedMatrix& matrix, |
---|
383 | const double* collb, const double* colub, |
---|
384 | const double* obj, |
---|
385 | const char* rowsen, const double* rowrhs, |
---|
386 | const double* rowrng) |
---|
387 | { |
---|
388 | modelPtr_->solver()->loadProblem(matrix,collb,colub,obj,rowsen,rowrhs,rowrng); |
---|
389 | } |
---|
390 | |
---|
391 | //----------------------------------------------------------------------------- |
---|
392 | |
---|
393 | void |
---|
394 | OsiCbcSolverInterface::assignProblem(CoinPackedMatrix*& matrix, |
---|
395 | double*& collb, double*& colub, |
---|
396 | double*& obj, |
---|
397 | char*& rowsen, double*& rowrhs, |
---|
398 | double*& rowrng) |
---|
399 | { |
---|
400 | modelPtr_->solver()->assignProblem(matrix,collb,colub,obj,rowsen,rowrhs,rowrng); |
---|
401 | } |
---|
402 | |
---|
403 | //----------------------------------------------------------------------------- |
---|
404 | |
---|
405 | void |
---|
406 | OsiCbcSolverInterface::loadProblem(const int numcols, const int numrows, |
---|
407 | const CoinBigIndex * start, const int* index, |
---|
408 | const double* value, |
---|
409 | const double* collb, const double* colub, |
---|
410 | const double* obj, |
---|
411 | const double* rowlb, const double* rowub) |
---|
412 | { |
---|
413 | modelPtr_->solver()->loadProblem(numcols,numrows,start,index,value, |
---|
414 | collb,colub,obj,rowlb,rowub); |
---|
415 | } |
---|
416 | //----------------------------------------------------------------------------- |
---|
417 | |
---|
418 | void |
---|
419 | OsiCbcSolverInterface::loadProblem(const int numcols, const int numrows, |
---|
420 | const CoinBigIndex * start, const int* index, |
---|
421 | const double* value, |
---|
422 | const double* collb, const double* colub, |
---|
423 | const double* obj, |
---|
424 | const char* rowsen, const double* rowrhs, |
---|
425 | const double* rowrng) |
---|
426 | { |
---|
427 | modelPtr_->solver()->loadProblem(numcols,numrows,start,index,value, |
---|
428 | collb,colub,obj,rowsen,rowrhs,rowrng); |
---|
429 | } |
---|
430 | |
---|
431 | //----------------------------------------------------------------------------- |
---|
432 | // Write mps files |
---|
433 | //----------------------------------------------------------------------------- |
---|
434 | |
---|
435 | void OsiCbcSolverInterface::writeMps(const char * filename, |
---|
436 | const char * extension, |
---|
437 | double objSense) const |
---|
438 | { |
---|
439 | modelPtr_->solver()->writeMps(filename,extension,objSense); |
---|
440 | } |
---|
441 | |
---|
442 | int |
---|
443 | OsiCbcSolverInterface::writeMpsNative(const char *filename, |
---|
444 | const char ** rowNames, const char ** columnNames, |
---|
445 | int formatType,int numberAcross,double objSense) const |
---|
446 | { |
---|
447 | return modelPtr_->solver()->writeMpsNative(filename, rowNames, columnNames, |
---|
448 | formatType, numberAcross,objSense); |
---|
449 | } |
---|
450 | |
---|
451 | //############################################################################# |
---|
452 | // Constructors, destructors clone and assignment |
---|
453 | //############################################################################# |
---|
454 | //------------------------------------------------------------------- |
---|
455 | // Default Constructor |
---|
456 | //------------------------------------------------------------------- |
---|
457 | OsiCbcSolverInterface::OsiCbcSolverInterface (OsiSolverInterface * solver, |
---|
458 | CbcStrategy * strategy) |
---|
459 | : |
---|
460 | OsiSolverInterface() |
---|
461 | { |
---|
462 | if (solver) { |
---|
463 | modelPtr_=new CbcModel(*solver); |
---|
464 | } else { |
---|
465 | OSICBC_DFLT_SOLVER solverDflt; |
---|
466 | modelPtr_=new CbcModel(solverDflt); |
---|
467 | } |
---|
468 | if (strategy) { |
---|
469 | modelPtr_->setStrategy(*strategy); |
---|
470 | } else { |
---|
471 | CbcStrategyDefault defaultStrategy; |
---|
472 | modelPtr_->setStrategy(defaultStrategy); |
---|
473 | } |
---|
474 | } |
---|
475 | |
---|
476 | //------------------------------------------------------------------- |
---|
477 | // Clone |
---|
478 | //------------------------------------------------------------------- |
---|
479 | OsiSolverInterface * OsiCbcSolverInterface::clone(bool CopyData) const |
---|
480 | { |
---|
481 | if (CopyData) { |
---|
482 | return new OsiCbcSolverInterface(*this); |
---|
483 | } else { |
---|
484 | return new OsiCbcSolverInterface(); |
---|
485 | } |
---|
486 | } |
---|
487 | |
---|
488 | |
---|
489 | //------------------------------------------------------------------- |
---|
490 | // Copy constructor |
---|
491 | //------------------------------------------------------------------- |
---|
492 | OsiCbcSolverInterface::OsiCbcSolverInterface ( |
---|
493 | const OsiCbcSolverInterface & rhs) |
---|
494 | : |
---|
495 | OsiSolverInterface(rhs) |
---|
496 | { |
---|
497 | assert (rhs.modelPtr_); |
---|
498 | modelPtr_ = new CbcModel(*rhs.modelPtr_); |
---|
499 | } |
---|
500 | |
---|
501 | |
---|
502 | //------------------------------------------------------------------- |
---|
503 | // Destructor |
---|
504 | //------------------------------------------------------------------- |
---|
505 | OsiCbcSolverInterface::~OsiCbcSolverInterface () |
---|
506 | { |
---|
507 | delete modelPtr_; |
---|
508 | } |
---|
509 | |
---|
510 | //------------------------------------------------------------------- |
---|
511 | // Assignment operator |
---|
512 | //------------------------------------------------------------------- |
---|
513 | OsiCbcSolverInterface & |
---|
514 | OsiCbcSolverInterface::operator=(const OsiCbcSolverInterface& rhs) |
---|
515 | { |
---|
516 | if (this != &rhs) { |
---|
517 | OsiSolverInterface::operator=(rhs); |
---|
518 | delete modelPtr_; |
---|
519 | modelPtr_=new CbcModel(*rhs.modelPtr_); |
---|
520 | } |
---|
521 | return *this; |
---|
522 | } |
---|
523 | |
---|
524 | //############################################################################# |
---|
525 | // Applying cuts |
---|
526 | //############################################################################# |
---|
527 | |
---|
528 | void OsiCbcSolverInterface::applyRowCut( const OsiRowCut & rowCut ) |
---|
529 | { |
---|
530 | modelPtr_->solver()->applyRowCuts(1,&rowCut); |
---|
531 | } |
---|
532 | /* Apply a collection of row cuts which are all effective. |
---|
533 | applyCuts seems to do one at a time which seems inefficient. |
---|
534 | */ |
---|
535 | void |
---|
536 | OsiCbcSolverInterface::applyRowCuts(int numberCuts, const OsiRowCut * cuts) |
---|
537 | { |
---|
538 | modelPtr_->solver()->applyRowCuts(numberCuts,cuts); |
---|
539 | } |
---|
540 | /* Apply a collection of row cuts which are all effective. |
---|
541 | applyCuts seems to do one at a time which seems inefficient. |
---|
542 | */ |
---|
543 | void |
---|
544 | OsiCbcSolverInterface::applyRowCuts(int numberCuts, const OsiRowCut ** cuts) |
---|
545 | { |
---|
546 | modelPtr_->solver()->applyRowCuts(numberCuts, cuts); |
---|
547 | } |
---|
548 | //----------------------------------------------------------------------------- |
---|
549 | |
---|
550 | void OsiCbcSolverInterface::applyColCut( const OsiColCut & cc ) |
---|
551 | { |
---|
552 | const double * lower = modelPtr_->solver()->getColLower(); |
---|
553 | const double * upper = modelPtr_->solver()->getColUpper(); |
---|
554 | const CoinPackedVector & lbs = cc.lbs(); |
---|
555 | const CoinPackedVector & ubs = cc.ubs(); |
---|
556 | int i; |
---|
557 | |
---|
558 | for ( i=0; i<lbs.getNumElements(); i++ ) { |
---|
559 | int iCol = lbs.getIndices()[i]; |
---|
560 | double value = lbs.getElements()[i]; |
---|
561 | if ( value > lower[iCol] ) |
---|
562 | modelPtr_->solver()->setColLower(iCol, value); |
---|
563 | } |
---|
564 | for ( i=0; i<ubs.getNumElements(); i++ ) { |
---|
565 | int iCol = ubs.getIndices()[i]; |
---|
566 | double value = ubs.getElements()[i]; |
---|
567 | if ( value < upper[iCol] ) |
---|
568 | modelPtr_->solver()->setColUpper(iCol, value); |
---|
569 | } |
---|
570 | } |
---|
571 | /* Read an mps file from the given filename (defaults to Osi reader) - returns |
---|
572 | number of errors (see OsiMpsReader class) */ |
---|
573 | int |
---|
574 | OsiCbcSolverInterface::readMps(const char *filename, |
---|
575 | const char *extension ) |
---|
576 | { |
---|
577 | return modelPtr_->solver()->readMps(filename,extension); |
---|
578 | } |
---|
579 | // Get pointer to array[getNumCols()] of primal solution vector |
---|
580 | const double * |
---|
581 | OsiCbcSolverInterface::getColSolution() const |
---|
582 | { |
---|
583 | return modelPtr_->solver()->getColSolution(); |
---|
584 | } |
---|
585 | |
---|
586 | // Get pointer to array[getNumRows()] of dual prices |
---|
587 | const double * |
---|
588 | OsiCbcSolverInterface::getRowPrice() const |
---|
589 | { |
---|
590 | return modelPtr_->solver()->getRowPrice(); |
---|
591 | } |
---|
592 | |
---|
593 | // Get a pointer to array[getNumCols()] of reduced costs |
---|
594 | const double * |
---|
595 | OsiCbcSolverInterface::getReducedCost() const |
---|
596 | { |
---|
597 | return modelPtr_->solver()->getReducedCost(); |
---|
598 | } |
---|
599 | |
---|
600 | /* Get pointer to array[getNumRows()] of row activity levels (constraint |
---|
601 | matrix times the solution vector */ |
---|
602 | const double * |
---|
603 | OsiCbcSolverInterface::getRowActivity() const |
---|
604 | { |
---|
605 | return modelPtr_->solver()->getRowActivity(); |
---|
606 | } |
---|
607 | double |
---|
608 | OsiCbcSolverInterface::getObjValue() const |
---|
609 | { |
---|
610 | return modelPtr_->solver()->getObjValue(); |
---|
611 | } |
---|
612 | |
---|
613 | /* Set an objective function coefficient */ |
---|
614 | void |
---|
615 | OsiCbcSolverInterface::setObjCoeff( int elementIndex, double elementValue ) |
---|
616 | { |
---|
617 | modelPtr_->solver()->setObjCoeff(elementIndex,elementValue); |
---|
618 | } |
---|
619 | |
---|
620 | /* Set a single column lower bound<br> |
---|
621 | Use -DBL_MAX for -infinity. */ |
---|
622 | void |
---|
623 | OsiCbcSolverInterface::setColLower( int elementIndex, double elementValue ) |
---|
624 | { |
---|
625 | modelPtr_->solver()->setColLower(elementIndex,elementValue); |
---|
626 | } |
---|
627 | |
---|
628 | /* Set a single column upper bound<br> |
---|
629 | Use DBL_MAX for infinity. */ |
---|
630 | void |
---|
631 | OsiCbcSolverInterface::setColUpper( int elementIndex, double elementValue ) |
---|
632 | { |
---|
633 | modelPtr_->solver()->setColUpper(elementIndex,elementValue); |
---|
634 | } |
---|
635 | |
---|
636 | /* Set a single column lower and upper bound */ |
---|
637 | void |
---|
638 | OsiCbcSolverInterface::setColBounds( int elementIndex, |
---|
639 | double lower, double upper ) |
---|
640 | { |
---|
641 | modelPtr_->solver()->setColBounds(elementIndex,lower,upper); |
---|
642 | } |
---|
643 | void OsiCbcSolverInterface::setColSetBounds(const int* indexFirst, |
---|
644 | const int* indexLast, |
---|
645 | const double* boundList) |
---|
646 | { |
---|
647 | modelPtr_->solver()->setColSetBounds(indexFirst,indexLast,boundList); |
---|
648 | } |
---|
649 | //------------------------------------------------------------------ |
---|
650 | /* Set a single row lower bound<br> |
---|
651 | Use -DBL_MAX for -infinity. */ |
---|
652 | void |
---|
653 | OsiCbcSolverInterface::setRowLower( int elementIndex, double elementValue ) { |
---|
654 | modelPtr_->solver()->setRowLower(elementIndex,elementValue); |
---|
655 | } |
---|
656 | |
---|
657 | /* Set a single row upper bound<br> |
---|
658 | Use DBL_MAX for infinity. */ |
---|
659 | void |
---|
660 | OsiCbcSolverInterface::setRowUpper( int elementIndex, double elementValue ) { |
---|
661 | modelPtr_->solver()->setRowUpper(elementIndex,elementValue); |
---|
662 | } |
---|
663 | |
---|
664 | /* Set a single row lower and upper bound */ |
---|
665 | void |
---|
666 | OsiCbcSolverInterface::setRowBounds( int elementIndex, |
---|
667 | double lower, double upper ) { |
---|
668 | modelPtr_->solver()->setRowBounds(elementIndex,lower,upper); |
---|
669 | } |
---|
670 | //----------------------------------------------------------------------------- |
---|
671 | void |
---|
672 | OsiCbcSolverInterface::setRowType(int i, char sense, double rightHandSide, |
---|
673 | double range) |
---|
674 | { |
---|
675 | modelPtr_->solver()->setRowType(i,sense,rightHandSide,range); |
---|
676 | } |
---|
677 | //----------------------------------------------------------------------------- |
---|
678 | void OsiCbcSolverInterface::setRowSetBounds(const int* indexFirst, |
---|
679 | const int* indexLast, |
---|
680 | const double* boundList) |
---|
681 | { |
---|
682 | modelPtr_->solver()->setRowSetBounds(indexFirst,indexLast,boundList); |
---|
683 | } |
---|
684 | //----------------------------------------------------------------------------- |
---|
685 | void |
---|
686 | OsiCbcSolverInterface::setRowSetTypes(const int* indexFirst, |
---|
687 | const int* indexLast, |
---|
688 | const char* senseList, |
---|
689 | const double* rhsList, |
---|
690 | const double* rangeList) |
---|
691 | { |
---|
692 | modelPtr_->solver()->setRowSetTypes(indexFirst,indexLast,senseList,rhsList,rangeList); |
---|
693 | } |
---|
694 | // Set a hint parameter |
---|
695 | bool |
---|
696 | OsiCbcSolverInterface::setHintParam(OsiHintParam key, bool yesNo, |
---|
697 | OsiHintStrength strength, |
---|
698 | void * otherInformation) |
---|
699 | { |
---|
700 | return modelPtr_->solver()->setHintParam(key,yesNo, strength, otherInformation); |
---|
701 | } |
---|
702 | |
---|
703 | // Get a hint parameter |
---|
704 | bool |
---|
705 | OsiCbcSolverInterface::getHintParam(OsiHintParam key, bool & yesNo, |
---|
706 | OsiHintStrength & strength, |
---|
707 | void *& otherInformation) const |
---|
708 | { |
---|
709 | return modelPtr_->solver()->getHintParam(key,yesNo, strength, otherInformation); |
---|
710 | } |
---|
711 | |
---|
712 | // Get a hint parameter |
---|
713 | bool |
---|
714 | OsiCbcSolverInterface::getHintParam(OsiHintParam key, bool & yesNo, |
---|
715 | OsiHintStrength & strength) const |
---|
716 | { |
---|
717 | return modelPtr_->solver()->getHintParam(key,yesNo, strength); |
---|
718 | } |
---|
719 | |
---|
720 | |
---|
721 | int |
---|
722 | OsiCbcSolverInterface::getNumCols() const |
---|
723 | { |
---|
724 | return modelPtr_->solver()->getNumCols(); |
---|
725 | } |
---|
726 | int |
---|
727 | OsiCbcSolverInterface::getNumRows() const |
---|
728 | { |
---|
729 | return modelPtr_->solver()->getNumRows(); |
---|
730 | } |
---|
731 | int |
---|
732 | OsiCbcSolverInterface::getNumElements() const |
---|
733 | { |
---|
734 | return modelPtr_->solver()->getNumElements(); |
---|
735 | } |
---|
736 | const double * |
---|
737 | OsiCbcSolverInterface::getColLower() const |
---|
738 | { |
---|
739 | return modelPtr_->solver()->getColLower(); |
---|
740 | } |
---|
741 | const double * |
---|
742 | OsiCbcSolverInterface::getColUpper() const |
---|
743 | { |
---|
744 | return modelPtr_->solver()->getColUpper(); |
---|
745 | } |
---|
746 | const double * |
---|
747 | OsiCbcSolverInterface::getRowLower() const |
---|
748 | { |
---|
749 | return modelPtr_->solver()->getRowLower(); |
---|
750 | } |
---|
751 | const double * |
---|
752 | OsiCbcSolverInterface::getRowUpper() const |
---|
753 | { |
---|
754 | return modelPtr_->solver()->getRowUpper(); |
---|
755 | } |
---|
756 | const double * |
---|
757 | OsiCbcSolverInterface::getObjCoefficients() const |
---|
758 | { |
---|
759 | return modelPtr_->solver()->getObjCoefficients(); |
---|
760 | } |
---|
761 | double |
---|
762 | OsiCbcSolverInterface::getObjSense() const |
---|
763 | { |
---|
764 | return modelPtr_->solver()->getObjSense(); |
---|
765 | } |
---|
766 | double |
---|
767 | OsiCbcSolverInterface::getInfinity() const |
---|
768 | { |
---|
769 | return modelPtr_->solver()->getInfinity(); |
---|
770 | } |
---|
771 | int |
---|
772 | OsiCbcSolverInterface::getIterationCount() const |
---|
773 | { |
---|
774 | return modelPtr_->solver()->getIterationCount(); |
---|
775 | } |
---|
776 | void |
---|
777 | OsiCbcSolverInterface::setObjSense(double s ) |
---|
778 | { |
---|
779 | modelPtr_->setObjSense(s); |
---|
780 | } |
---|
781 | // Invoke solver's built-in enumeration algorithm |
---|
782 | void |
---|
783 | OsiCbcSolverInterface::branchAndBound() |
---|
784 | { |
---|
785 | modelPtr_->branchAndBound(); |
---|
786 | } |
---|
787 | |
---|
788 | /* |
---|
789 | Name discipline support -- lh, 070328 -- |
---|
790 | |
---|
791 | For safety, there's really nothing to it but to pass each call of an impure |
---|
792 | virtual method on to the underlying solver. Otherwise we just can't know if |
---|
793 | it's been overridden or not. |
---|
794 | */ |
---|
795 | |
---|
796 | std::string |
---|
797 | OsiCbcSolverInterface::dfltRowColName (char rc, int ndx, unsigned digits) const |
---|
798 | { |
---|
799 | return (modelPtr_->solver()->dfltRowColName(rc,ndx,digits)) ; |
---|
800 | } |
---|
801 | |
---|
802 | std::string OsiCbcSolverInterface::getObjName (unsigned maxLen) const |
---|
803 | { |
---|
804 | return (modelPtr_->solver()->getObjName(maxLen)) ; |
---|
805 | } |
---|
806 | |
---|
807 | std::string OsiCbcSolverInterface::getRowName (int ndx, unsigned maxLen) const |
---|
808 | { |
---|
809 | return (modelPtr_->solver()->getRowName(ndx,maxLen)) ; |
---|
810 | } |
---|
811 | |
---|
812 | const OsiSolverInterface::OsiNameVec &OsiCbcSolverInterface::getRowNames () |
---|
813 | { |
---|
814 | return (modelPtr_->solver()->getRowNames()) ; |
---|
815 | } |
---|
816 | |
---|
817 | std::string OsiCbcSolverInterface::getColName (int ndx, unsigned maxLen) const |
---|
818 | { |
---|
819 | return (modelPtr_->solver()->getColName(ndx,maxLen)) ; |
---|
820 | } |
---|
821 | |
---|
822 | const OsiSolverInterface::OsiNameVec &OsiCbcSolverInterface::getColNames () |
---|
823 | { |
---|
824 | return (modelPtr_->solver()->getColNames()) ; |
---|
825 | } |
---|
826 | |
---|
827 | void OsiCbcSolverInterface::setRowNames (OsiNameVec &srcNames, |
---|
828 | int srcStart, int len, int tgtStart) |
---|
829 | { |
---|
830 | modelPtr_->solver()->setRowNames(srcNames,srcStart,len,tgtStart) ; |
---|
831 | } |
---|
832 | |
---|
833 | void OsiCbcSolverInterface::deleteRowNames (int tgtStart, int len) |
---|
834 | { |
---|
835 | modelPtr_->solver()->deleteRowNames(tgtStart,len) ; |
---|
836 | } |
---|
837 | |
---|
838 | void OsiCbcSolverInterface::setColNames (OsiNameVec &srcNames, |
---|
839 | int srcStart, int len, int tgtStart) |
---|
840 | { |
---|
841 | modelPtr_->solver()->setColNames(srcNames,srcStart,len,tgtStart) ; |
---|
842 | } |
---|
843 | |
---|
844 | void OsiCbcSolverInterface::deleteColNames (int tgtStart, int len) |
---|
845 | { |
---|
846 | modelPtr_->solver()->deleteColNames(tgtStart,len) ; |
---|
847 | } |
---|
848 | |
---|
849 | /* |
---|
850 | These last three are the only functions that would normally be overridden. |
---|
851 | */ |
---|
852 | |
---|
853 | /* |
---|
854 | Set objective function name. |
---|
855 | */ |
---|
856 | void OsiCbcSolverInterface::setObjName (std::string name) |
---|
857 | { |
---|
858 | modelPtr_->solver()->setObjName(name) ; |
---|
859 | } |
---|
860 | |
---|
861 | /* |
---|
862 | Set a row name, to make sure both the solver and OSI see the same name. |
---|
863 | */ |
---|
864 | void OsiCbcSolverInterface::setRowName (int ndx, std::string name) |
---|
865 | |
---|
866 | { |
---|
867 | modelPtr_->solver()->setRowName(ndx,name) ; |
---|
868 | } |
---|
869 | |
---|
870 | /* |
---|
871 | Set a column name, to make sure both the solver and OSI see the same name. |
---|
872 | */ |
---|
873 | void OsiCbcSolverInterface::setColName (int ndx, std::string name) |
---|
874 | |
---|
875 | { |
---|
876 | modelPtr_->solver()->setColName(ndx,name) ; |
---|
877 | } |
---|
878 | // Pass in Message handler (not deleted at end) |
---|
879 | void |
---|
880 | OsiCbcSolverInterface::passInMessageHandler(CoinMessageHandler * handler) |
---|
881 | { |
---|
882 | OsiSolverInterface::passInMessageHandler(handler); |
---|
883 | if (modelPtr_) |
---|
884 | modelPtr_->passInMessageHandler(handler); |
---|
885 | } |
---|
886 | // So unit test can find out if NDEBUG set |
---|
887 | bool OsiCbcHasNDEBUG() |
---|
888 | { |
---|
889 | #ifdef NDEBUG |
---|
890 | return true; |
---|
891 | #else |
---|
892 | return false; |
---|
893 | #endif |
---|
894 | } |
---|