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