CYCLUS
Loading...
Searching...
No Matches
OsiCbcSolverInterface_2_10.hpp
Go to the documentation of this file.
1// $Id: OsiCbcSolverInterface.hpp 1899 2013-04-09 18:12:08Z stefan $
2// Copyright (C) 2000, International Business Machines
3// Corporation and others. All Rights Reserved.
4// This code is licensed under the terms of the Eclipse Public License (EPL).
5
6#ifndef OsiCbcSolverInterface_2_10_H
7#define OsiCbcSolverInterface_2_10_H
8
9#include <string>
10#include <cfloat>
11#include <map>
12#include "CbcModel.hpp"
13#include "CoinPackedMatrix.hpp"
14#include "OsiSolverInterface.hpp"
15#include "CbcStrategy.hpp"
16#include "CoinWarmStartBasis.hpp"
17
18class OsiRowCut;
19class OsiClpSolverInterface;
20static const double OsiCbcInfinity = COIN_DBL_MAX;
21
22// #############################################################################
23
24/** Cbc Solver Interface
25
26Instantiation of OsiCbcSolverInterface for the Model Algorithm.
27
28*/
29
30class OsiCbcSolverInterface : virtual public OsiSolverInterface {
31 friend void OsiCbcSolverInterfaceUnitTest(const std::string& mpsDir,
32 const std::string& netlibDir);
33
34 public:
35 //---------------------------------------------------------------------------
36 /**@name Solve methods */
37 //@{
38 /// Solve initial LP relaxation
39 virtual void initialSolve();
40
41 /// Resolve an LP relaxation after problem modification
42 virtual void resolve();
43
44 /// Invoke solver's built-in enumeration algorithm
45 virtual void branchAndBound();
46 //@}
47
48 //---------------------------------------------------------------------------
49 /**@name Parameter set/get methods
50
51 The set methods return true if the parameter was set to the given value,
52 false otherwise. There can be various reasons for failure: the given
53 parameter is not applicable for the solver (e.g., refactorization
54 frequency for the cbc algorithm), the parameter is not yet implemented
55 for the solver or simply the value of the parameter is out of the range
56 the solver accepts. If a parameter setting call returns false check the
57 details of your solver.
58
59 The get methods return true if the given parameter is applicable for the
60 solver and is implemented. In this case the value of the parameter is
61 returned in the second argument. Otherwise they return false.
62 */
63 //@{
64 // Set an integer parameter
65 bool setIntParam(OsiIntParam key, int value);
66 // Set an double parameter
67 bool setDblParam(OsiDblParam key, double value);
68 // Set a string parameter
69 bool setStrParam(OsiStrParam key, const std::string& value);
70 // Get an integer parameter
71 bool getIntParam(OsiIntParam key, int& value) const;
72 // Get an double parameter
73 bool getDblParam(OsiDblParam key, double& value) const;
74 // Get a string parameter
75 bool getStrParam(OsiStrParam key, std::string& value) const;
76 // Set a hint parameter - overrides OsiSolverInterface
77 virtual bool setHintParam(OsiHintParam key, bool yesNo = true,
78 OsiHintStrength strength = OsiHintTry,
79 void* otherInformation = NULL);
80 /// Get a hint parameter
81 virtual bool getHintParam(OsiHintParam key, bool& yesNo,
82 OsiHintStrength& strength,
83 void*& otherInformation) const;
84
85 using OsiSolverInterface::getHintParam;
86 /// Get a hint parameter
87 virtual bool getHintParam(OsiHintParam key, bool& yesNo,
88 OsiHintStrength& strength) const;
89 //@}
90
91 //---------------------------------------------------------------------------
92 ///@name Methods returning info on how the solution process terminated
93 //@{
94 /// Are there a numerical difficulties?
95 virtual bool isAbandoned() const;
96 /// Is optimality proven?
97 virtual bool isProvenOptimal() const;
98 /// Is primal infeasiblity proven?
99 virtual bool isProvenPrimalInfeasible() const;
100 /// Is dual infeasiblity proven?
101 virtual bool isProvenDualInfeasible() const;
102 /// Is the given primal objective limit reached?
103 virtual bool isPrimalObjectiveLimitReached() const;
104 /// Is the given dual objective limit reached?
105 virtual bool isDualObjectiveLimitReached() const;
106 /// Iteration limit reached?
107 virtual bool isIterationLimitReached() const;
108 //@}
109
110 //---------------------------------------------------------------------------
111 /**@name WarmStart related methods */
112 //@{
113
114 /*! \brief Get an empty warm start object
115
116 This routine returns an empty CoinWarmStartBasis object. Its purpose is
117 to provide a way to give a client a warm start basis object of the
118 appropriate type, which can resized and modified as desired.
119 */
120
121 virtual CoinWarmStart* getEmptyWarmStart() const;
122
123 /// Get warmstarting information
124 virtual CoinWarmStart* getWarmStart() const;
125 /** Set warmstarting information. Return true/false depending on whether
126 the warmstart information was accepted or not. */
127 virtual bool setWarmStart(const CoinWarmStart* warmstart);
128 //@}
129
130 //---------------------------------------------------------------------------
131 /**@name Hotstart related methods (primarily used in strong branching). <br>
132 The user can create a hotstart (a snapshot) of the optimization process
133 then reoptimize over and over again always starting from there.<br>
134 <strong>NOTE</strong>: between hotstarted optimizations only
135 bound changes are allowed. */
136 //@{
137 /// Create a hotstart point of the optimization process
138 virtual void markHotStart();
139 /// Optimize starting from the hotstart
140 virtual void solveFromHotStart();
141 /// Delete the snapshot
142 virtual void unmarkHotStart();
143 //@}
144
145 //---------------------------------------------------------------------------
146 /**@name Problem information methods
147
148 These methods call the solver's query routines to return
149 information about the problem referred to by the current object.
150 Querying a problem that has no data associated with it result in
151 zeros for the number of rows and columns, and NULL pointers from
152 the methods that return vectors.
153
154 Const pointers returned from any data-query method are valid as
155 long as the data is unchanged and the solver is not called.
156 */
157 //@{
158 /**@name Methods related to querying the input data */
159 //@{
160 /// Get number of columns
161 virtual int getNumCols() const;
162
163 /// Get number of rows
164 virtual int getNumRows() const;
165
166 /// Get number of nonzero elements
167 virtual int getNumElements() const;
168
169 /// Get pointer to array[getNumCols()] of column lower bounds
170 virtual const double* getColLower() const;
171
172 /// Get pointer to array[getNumCols()] of column upper bounds
173 virtual const double* getColUpper() const;
174
175 /** Get pointer to array[getNumRows()] of row constraint senses.
176 <ul>
177 <li>'L' <= constraint
178 <li>'E' = constraint
179 <li>'G' >= constraint
180 <li>'R' ranged constraint
181 <li>'N' free constraint
182 </ul>
183 */
184 virtual const char* getRowSense() const;
185
186 /** Get pointer to array[getNumRows()] of rows right-hand sides
187 <ul>
188 <li> if rowsense()[i] == 'L' then rhs()[i] == rowupper()[i]
189 <li> if rowsense()[i] == 'G' then rhs()[i] == rowlower()[i]
190 <li> if rowsense()[i] == 'R' then rhs()[i] == rowupper()[i]
191 <li> if rowsense()[i] == 'N' then rhs()[i] == 0.0
192 </ul>
193 */
194 virtual const double* getRightHandSide() const;
195
196 /** Get pointer to array[getNumRows()] of row ranges.
197 <ul>
198 <li> if rowsense()[i] == 'R' then
199 rowrange()[i] == rowupper()[i] - rowlower()[i]
200 <li> if rowsense()[i] != 'R' then
201 rowrange()[i] is undefined
202 </ul>
203 */
204 virtual const double* getRowRange() const;
205
206 /// Get pointer to array[getNumRows()] of row lower bounds
207 virtual const double* getRowLower() const;
208
209 /// Get pointer to array[getNumRows()] of row upper bounds
210 virtual const double* getRowUpper() const;
211
212 /// Get pointer to array[getNumCols()] of objective function coefficients
213 virtual const double* getObjCoefficients() const;
214
215 /// Get objective function sense (1 for min (default), -1 for max)
216 virtual double getObjSense() const;
217
218 /// Return true if column is continuous
219 virtual bool isContinuous(int colNumber) const;
220
221 /// Get pointer to row-wise copy of matrix
222 virtual const CoinPackedMatrix* getMatrixByRow() const;
223
224 /// Get pointer to column-wise copy of matrix
225 virtual const CoinPackedMatrix* getMatrixByCol() const;
226
227 /// Get solver's value for infinity
228 virtual double getInfinity() const;
229 //@}
230
231 /**@name Methods related to querying the solution */
232 //@{
233 /// Get pointer to array[getNumCols()] of primal solution vector
234 virtual const double* getColSolution() const;
235
236 /// Get pointer to array[getNumRows()] of dual prices
237 virtual const double* getRowPrice() const;
238
239 /// Get a pointer to array[getNumCols()] of reduced costs
240 virtual const double* getReducedCost() const;
241
242 /** Get pointer to array[getNumRows()] of row activity levels (constraint
243 matrix times the solution vector */
244 virtual const double* getRowActivity() const;
245
246 /// Get objective function value
247 virtual double getObjValue() const;
248
249 /** Get how many iterations it took to solve the problem (whatever
250 "iteration" mean to the solver. */
251 virtual int getIterationCount() const;
252
253 /** Get as many dual rays as the solver can provide. (In case of proven
254 primal infeasibility there should be at least one.)
255
256 The first getNumRows() ray components will always be associated with
257 the row duals (as returned by getRowPrice()). If \c fullRay is true,
258 the final getNumCols() entries will correspond to the ray components
259 associated with the nonbasic variables. If the full ray is requested
260 and the method cannot provide it, it will throw an exception.
261
262 <strong>NOTE for implementers of solver interfaces:</strong> <br>
263 The double pointers in the vector should point to arrays of length
264 getNumRows() and they should be allocated via new[]. <br>
265
266 <strong>NOTE for users of solver interfaces:</strong> <br>
267 It is the user's responsibility to free the double pointers in the
268 vector using delete[].
269 */
270 virtual std::vector<double*> getDualRays(int maxNumRays,
271 bool fullRay = false) const;
272 /** Get as many primal rays as the solver can provide. (In case of proven
273 dual infeasibility there should be at least one.)
274
275 <strong>NOTE for implementers of solver interfaces:</strong> <br>
276 The double pointers in the vector should point to arrays of length
277 getNumCols() and they should be allocated via new[]. <br>
278
279 <strong>NOTE for users of solver interfaces:</strong> <br>
280 It is the user's responsibility to free the double pointers in the
281 vector using delete[].
282 */
283 virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
284
285 //@}
286
287 /*! \name Methods for row and column names.
288
289 Because OsiCbc is a pass-through class, it's necessary to override any
290 virtual method in order to be sure we catch an override by the underlying
291 solver. See the OsiSolverInterface class documentation for detailed
292 descriptions.
293 */
294 //@{
295
296 /*! \brief Generate a standard name of the form Rnnnnnnn or Cnnnnnnn */
297
298 virtual std::string dfltRowColName(char rc, int ndx,
299 unsigned digits = 7) const;
300
301 /*! \brief Return the name of the objective function */
302
303 virtual std::string getObjName(unsigned maxLen = std::string::npos) const;
304
305 /*! \brief Set the name of the objective function */
306
307 virtual void setObjName(std::string name);
308
309 /*! \brief Return the name of the row. */
310
311 virtual std::string getRowName(int rowIndex,
312 unsigned maxLen = std::string::npos) const;
313
314 /*! \brief Return a pointer to a vector of row names */
315
316 virtual const OsiNameVec& getRowNames();
317
318 /*! \brief Set a row name */
319
320 virtual void setRowName(int ndx, std::string name);
321
322 /*! \brief Set multiple row names */
323
324 virtual void setRowNames(OsiNameVec& srcNames, int srcStart, int len,
325 int tgtStart);
326
327 /*! \brief Delete len row names starting at index tgtStart */
328
329 virtual void deleteRowNames(int tgtStart, int len);
330
331 /*! \brief Return the name of the column */
332
333 virtual std::string getColName(int colIndex,
334 unsigned maxLen = std::string::npos) const;
335
336 /*! \brief Return a pointer to a vector of column names */
337
338 virtual const OsiNameVec& getColNames();
339
340 /*! \brief Set a column name */
341
342 virtual void setColName(int ndx, std::string name);
343
344 /*! \brief Set multiple column names */
345
346 virtual void setColNames(OsiNameVec& srcNames, int srcStart, int len,
347 int tgtStart);
348
349 /*! \brief Delete len column names starting at index tgtStart */
350 virtual void deleteColNames(int tgtStart, int len);
351
352 //@}
353
354 //@}
355
356 //---------------------------------------------------------------------------
357
358 /**@name Problem modifying methods */
359 //@{
360 //-------------------------------------------------------------------------
361 /**@name Changing bounds on variables and constraints */
362 //@{
363 /** Set an objective function coefficient */
364 virtual void setObjCoeff(int elementIndex, double elementValue);
365
366 using OsiSolverInterface::setColLower;
367 /** Set a single column lower bound<br>
368 Use -DBL_MAX for -infinity. */
369 virtual void setColLower(int elementIndex, double elementValue);
370
371 using OsiSolverInterface::setColUpper;
372 /** Set a single column upper bound<br>
373 Use DBL_MAX for infinity. */
374 virtual void setColUpper(int elementIndex, double elementValue);
375
376 /** Set a single column lower and upper bound */
377 virtual void setColBounds(int elementIndex, double lower, double upper);
378
379 /** Set the bounds on a number of columns simultaneously<br>
380 The default implementation just invokes setColLower() and
381 setColUpper() over and over again.
382 @param indexFirst,indexLast pointers to the beginning and after the
383 end of the array of the indices of the variables whose
384 <em>either</em> bound changes
385 @param boundList the new lower/upper bound pairs for the variables
386 */
387 virtual void setColSetBounds(const int* indexFirst,
388 const int* indexLast,
389 const double* boundList);
390
391 /** Set a single row lower bound<br>
392 Use -DBL_MAX for -infinity. */
393 virtual void setRowLower(int elementIndex, double elementValue);
394
395 /** Set a single row upper bound<br>
396 Use DBL_MAX for infinity. */
397 virtual void setRowUpper(int elementIndex, double elementValue);
398
399 /** Set a single row lower and upper bound */
400 virtual void setRowBounds(int elementIndex, double lower, double upper);
401
402 /** Set the type of a single row<br> */
403 virtual void setRowType(int index, char sense, double rightHandSide,
404 double range);
405
406 /** Set the bounds on a number of rows simultaneously<br>
407 The default implementation just invokes setRowLower() and
408 setRowUpper() over and over again.
409 @param indexFirst,indexLast pointers to the beginning and after the
410 end of the array of the indices of the constraints whose
411 <em>either</em> bound changes
412 @param boundList the new lower/upper bound pairs for the constraints
413 */
414 virtual void setRowSetBounds(const int* indexFirst,
415 const int* indexLast,
416 const double* boundList);
417
418 /** Set the type of a number of rows simultaneously<br>
419 The default implementation just invokes setRowType()
420 over and over again.
421 @param indexFirst,indexLast pointers to the beginning and after the
422 end of the array of the indices of the constraints whose
423 <em>any</em> characteristics changes
424 @param senseList the new senses
425 @param rhsList the new right hand sides
426 @param rangeList the new ranges
427 */
428 virtual void setRowSetTypes(const int* indexFirst,
429 const int* indexLast,
430 const char* senseList,
431 const double* rhsList,
432 const double* rangeList);
433 //@}
434
435 //-------------------------------------------------------------------------
436 /**@name Integrality related changing methods */
437 //@{
438 /** Set the index-th variable to be a continuous variable */
439 virtual void setContinuous(int index);
440 /** Set the index-th variable to be an integer variable */
441 virtual void setInteger(int index);
442 /** Set the variables listed in indices (which is of length len) to be
443 continuous variables */
444 virtual void setContinuous(const int* indices, int len);
445 /** Set the variables listed in indices (which is of length len) to be
446 integer variables */
447 virtual void setInteger(const int* indices, int len);
448 //@}
449
450 //-------------------------------------------------------------------------
451 /// Set objective function sense (1 for min (default), -1 for max,)
452 virtual void setObjSense(double s);
453
454 /** Set the primal solution column values
455
456 colsol[numcols()] is an array of values of the problem column
457 variables. These values are copied to memory owned by the
458 solver object or the solver. They will be returned as the
459 result of colsol() until changed by another call to
460 setColsol() or by a call to any solver routine. Whether the
461 solver makes use of the solution in any way is
462 solver-dependent.
463 */
464 virtual void setColSolution(const double* colsol);
465
466 /** Set dual solution vector
467
468 rowprice[numrows()] is an array of values of the problem row
469 dual variables. These values are copied to memory owned by the
470 solver object or the solver. They will be returned as the
471 result of rowprice() until changed by another call to
472 setRowprice() or by a call to any solver routine. Whether the
473 solver makes use of the solution in any way is
474 solver-dependent.
475 */
476 virtual void setRowPrice(const double* rowprice);
477
478 //-------------------------------------------------------------------------
479 /**@name Methods to expand a problem.<br>
480 Note that if a column is added then by default it will correspond to a
481 continuous variable. */
482 //@{
483 using OsiSolverInterface::addCol;
484 /** */
485 virtual void addCol(const CoinPackedVectorBase& vec, const double collb,
486 const double colub, const double obj);
487 /** Add a column (primal variable) to the problem. */
488 virtual void addCol(int numberElements, const int* rows,
489 const double* elements, const double collb,
490 const double colub, const double obj);
491
492 using OsiSolverInterface::addCols;
493 /** */
494 virtual void addCols(const int numcols,
495 const CoinPackedVectorBase* const* cols,
496 const double* collb, const double* colub,
497 const double* obj);
498 /** */
499 virtual void deleteCols(const int num, const int* colIndices);
500
501 using OsiSolverInterface::addRow;
502 /** */
503 virtual void addRow(const CoinPackedVectorBase& vec, const double rowlb,
504 const double rowub);
505 /** */
506 virtual void addRow(const CoinPackedVectorBase& vec, const char rowsen,
507 const double rowrhs, const double rowrng);
508
509 using OsiSolverInterface::addRows;
510 /** */
511 virtual void addRows(const int numrows,
512 const CoinPackedVectorBase* const* rows,
513 const double* rowlb, const double* rowub);
514 /** */
515 virtual void addRows(const int numrows,
516 const CoinPackedVectorBase* const* rows,
517 const char* rowsen, const double* rowrhs,
518 const double* rowrng);
519 /** */
520 virtual void deleteRows(const int num, const int* rowIndices);
521
522 //-----------------------------------------------------------------------
523 /** Apply a collection of row cuts which are all effective.
524 applyCuts seems to do one at a time which seems inefficient.
525 */
526 virtual void applyRowCuts(int numberCuts, const OsiRowCut* cuts);
527 /** Apply a collection of row cuts which are all effective.
528 applyCuts seems to do one at a time which seems inefficient.
529 This uses array of pointers
530 */
531 virtual void applyRowCuts(int numberCuts, const OsiRowCut** cuts);
532 //@}
533 //@}
534
535 //---------------------------------------------------------------------------
536
537 public:
538 /**@name Methods to input a problem */
539 //@{
540 /** Load in an problem by copying the arguments (the constraints on the
541 rows are given by lower and upper bounds). If a pointer is 0 then the
542 following values are the default:
543 <ul>
544 <li> <code>colub</code>: all columns have upper bound infinity
545 <li> <code>collb</code>: all columns have lower bound 0
546 <li> <code>rowub</code>: all rows have upper bound infinity
547 <li> <code>rowlb</code>: all rows have lower bound -infinity
548 <li> <code>obj</code>: all variables have 0 objective coefficient
549 </ul>
550 */
551 virtual void loadProblem(const CoinPackedMatrix& matrix, const double* collb,
552 const double* colub, const double* obj,
553 const double* rowlb, const double* rowub);
554
555 /** Load in an problem by assuming ownership of the arguments (the
556 constraints on the rows are given by lower and upper bounds). For
557 default values see the previous method. <br>
558 <strong>WARNING</strong>: The arguments passed to this method will be
559 freed using the C++ <code>delete</code> and <code>delete[]</code>
560 functions.
561 */
562 virtual void assignProblem(CoinPackedMatrix*& matrix, double*& collb,
563 double*& colub, double*& obj, double*& rowlb,
564 double*& rowub);
565
566 /** Load in an problem by copying the arguments (the constraints on the
567 rows are given by sense/rhs/range triplets). If a pointer is 0 then the
568 following values are the default:
569 <ul>
570 <li> <code>colub</code>: all columns have upper bound infinity
571 <li> <code>collb</code>: all columns have lower bound 0
572 <li> <code>obj</code>: all variables have 0 objective coefficient
573 <li> <code>rowsen</code>: all rows are >=
574 <li> <code>rowrhs</code>: all right hand sides are 0
575 <li> <code>rowrng</code>: 0 for the ranged rows
576 </ul>
577 */
578 virtual void loadProblem(const CoinPackedMatrix& matrix, const double* collb,
579 const double* colub, const double* obj,
580 const char* rowsen, const double* rowrhs,
581 const double* rowrng);
582
583 /** Load in an problem by assuming ownership of the arguments (the
584 constraints on the rows are given by sense/rhs/range triplets). For
585 default values see the previous method. <br>
586 <strong>WARNING</strong>: The arguments passed to this method will be
587 freed using the C++ <code>delete</code> and <code>delete[]</code>
588 functions.
589 */
590 virtual void assignProblem(CoinPackedMatrix*& matrix, double*& collb,
591 double*& colub, double*& obj, char*& rowsen,
592 double*& rowrhs, double*& rowrng);
593
594 /** Just like the other loadProblem() methods except that the matrix is
595 given in a standard column major ordered format (without gaps). */
596 virtual void loadProblem(const int numcols, const int numrows,
597 const CoinBigIndex* start, const int* index,
598 const double* value, const double* collb,
599 const double* colub, const double* obj,
600 const double* rowlb, const double* rowub);
601
602 /** Just like the other loadProblem() methods except that the matrix is
603 given in a standard column major ordered format (without gaps). */
604 virtual void loadProblem(const int numcols, const int numrows,
605 const CoinBigIndex* start, const int* index,
606 const double* value, const double* collb,
607 const double* colub, const double* obj,
608 const char* rowsen, const double* rowrhs,
609 const double* rowrng);
610
611 using OsiSolverInterface::readMps;
612 /** Read an mps file from the given filename (defaults to Osi reader) -
613 returns number of errors (see OsiMpsReader class) */
614 virtual int readMps(const char* filename, const char* extension = "mps");
615
616 /** Write the problem into an mps file of the given filename.
617 If objSense is non zero then -1.0 forces the code to write a
618 maximization objective and +1.0 to write a minimization one.
619 If 0.0 then solver can do what it wants */
620 virtual void writeMps(const char* filename,
621 const char* extension = "mps",
622 double objSense = 0.0) const;
623 /** Write the problem into an mps file of the given filename,
624 names may be null. formatType is
625 0 - normal
626 1 - extra accuracy
627 2 - IEEE hex (later)
628
629 Returns non-zero on I/O error
630 */
631 virtual int writeMpsNative(const char* filename, const char** rowNames,
632 const char** columnNames, int formatType = 0,
633 int numberAcross = 2, double objSense = 0.0) const;
634 //@}
635
636 /**@name Message handling (extra for Cbc messages).
637 Normally I presume you would want the same language.
638 If not then you could use underlying model pointer */
639 //@{
640 /// Set language
641 void newLanguage(CoinMessages::Language language);
642 void setLanguage(CoinMessages::Language language) { newLanguage(language); }
643 //@}
644 //---------------------------------------------------------------------------
645
646 /**@name Cbc specific public interfaces */
647 //@{
648 /// Get pointer to Cbc model
649 inline CbcModel* getModelPtr() const { return modelPtr_; }
650 /// Get pointer to underlying solver
651 inline OsiSolverInterface* getRealSolverPtr() const {
652 return modelPtr_->solver();
653 }
654 /// Set cutoff bound on the objective function.
655 inline void setCutoff(double value) { modelPtr_->setCutoff(value); }
656 /// Get the cutoff bound on the objective function - always as minimize
657 inline double getCutoff() const { return modelPtr_->getCutoff(); }
658 /// Set the CbcModel::CbcMaxNumNode maximum node limit
659 inline void setMaximumNodes(int value) { modelPtr_->setMaximumNodes(value); }
660 /// Get the CbcModel::CbcMaxNumNode maximum node limit
661 inline int getMaximumNodes() const { return modelPtr_->getMaximumNodes(); }
662 /// Set the CbcModel::CbcMaxNumSol maximum number of solutions
663 inline void setMaximumSolutions(int value) {
664 modelPtr_->setMaximumSolutions(value);
665 }
666 /// Get the CbcModel::CbcMaxNumSol maximum number of solutions
667 inline int getMaximumSolutions() const {
668 return modelPtr_->getMaximumSolutions();
669 }
670 /// Set the CbcModel::CbcMaximumSeconds maximum number of seconds
671 inline void setMaximumSeconds(double value) {
672 modelPtr_->setMaximumSeconds(value);
673 }
674 /// Get the CbcModel::CbcMaximumSeconds maximum number of seconds
675 inline double getMaximumSeconds() const {
676 return modelPtr_->getMaximumSeconds();
677 }
678 /// Node limit reached?
679 inline bool isNodeLimitReached() const {
680 return modelPtr_->isNodeLimitReached();
681 }
682 /// Solution limit reached?
683 inline bool isSolutionLimitReached() const {
684 return modelPtr_->isSolutionLimitReached();
685 }
686 /// Get how many Nodes it took to solve the problem.
687 inline int getNodeCount() const { return modelPtr_->getNodeCount(); }
688 /// Final status of problem - 0 finished, 1 stopped, 2 difficulties
689 inline int status() const { return modelPtr_->status(); }
690 /** Pass in a message handler
691
692 It is the client's responsibility to destroy a message handler installed
693 by this routine; it will not be destroyed when the solver interface is
694 destroyed.
695 */
696 virtual void passInMessageHandler(CoinMessageHandler* handler);
697 //@}
698
699 //---------------------------------------------------------------------------
700
701 /**@name Constructors and destructors */
702 //@{
703 /// Default Constructor
704 OsiCbcSolverInterface(OsiSolverInterface* solver = NULL,
705 CbcStrategy* strategy = NULL);
706
707 /// Clone
708 virtual OsiSolverInterface* clone(bool copyData = true) const;
709
710 /// Copy constructor
712#if 0
713 /// Borrow constructor - only delete one copy
714 OsiCbcSolverInterface (CbcModel * rhs, bool reallyOwn=false);
715
716 /// Releases so won't error
717 void releaseCbc();
718#endif
719 /// Assignment operator
721
722 /// Destructor
723 virtual ~OsiCbcSolverInterface();
724
725 //@}
726 //---------------------------------------------------------------------------
727
728 protected:
729 ///@name Protected methods
730 //@{
731 /** Apply a row cut (append to constraint matrix). */
732 virtual void applyRowCut(const OsiRowCut& rc);
733
734 /** Apply a column cut (adjust one or more bounds). */
735 virtual void applyColCut(const OsiColCut& cc);
736 //@}
737 /**@name Protected member data */
738 //@{
739 /// Cbc model represented by this class instance
740 mutable CbcModel* modelPtr_;
741 //@}
742};
743// So unit test can find out if NDEBUG set
744bool OsiCbcHasNDEBUG();
745
746// #############################################################################
747/** A function that tests the methods in the OsiCbcSolverInterface class. */
748void OsiCbcSolverInterfaceUnitTest(const std::string& mpsDir,
749 const std::string& netlibDir);
750
751#endif
void OsiCbcSolverInterfaceUnitTest(const std::string &mpsDir, const std::string &netlibDir)
A function that tests the methods in the OsiCbcSolverInterface class.
bool OsiCbcHasNDEBUG()
static const double OsiCbcInfinity
virtual void setInteger(int index)
Set the index-th variable to be an integer variable.
virtual bool isIterationLimitReached() const
Iteration limit reached?
virtual const double * getRowRange() const
Get pointer to array[getNumRows()] of row ranges.
CbcModel * getModelPtr() const
Get pointer to Cbc model.
int getMaximumSolutions() const
Get the CbcModel::CbcMaxNumSol maximum number of solutions.
virtual double getObjValue() const
Get objective function value.
void setMaximumSeconds(double value)
Set the CbcModel::CbcMaximumSeconds maximum number of seconds.
virtual const char * getRowSense() const
Get pointer to array[getNumRows()] of row constraint senses.
virtual int getNumElements() const
Get number of nonzero elements.
virtual std::string getObjName(unsigned maxLen=std::string::npos) const
Return the name of the objective function.
virtual bool setWarmStart(const CoinWarmStart *warmstart)
Set warmstarting information.
double getCutoff() const
Get the cutoff bound on the objective function - always as minimize.
virtual const double * getRowUpper() const
Get pointer to array[getNumRows()] of row upper bounds.
virtual void initialSolve()
Solve initial LP relaxation.
virtual const CoinPackedMatrix * getMatrixByCol() const
Get pointer to column-wise copy of matrix.
virtual void deleteRows(const int num, const int *rowIndices)
virtual void deleteCols(const int num, const int *colIndices)
virtual void setContinuous(int index)
Set the index-th variable to be a continuous variable.
virtual void setRowSetTypes(const int *indexFirst, const int *indexLast, const char *senseList, const double *rhsList, const double *rangeList)
Set the type of a number of rows simultaneously The default implementation just invokes setRowType()...
virtual void setObjName(std::string name)
Set the name of the objective function.
virtual void resolve()
Resolve an LP relaxation after problem modification.
virtual bool isDualObjectiveLimitReached() const
Is the given dual objective limit reached?
virtual int writeMpsNative(const char *filename, const char **rowNames, const char **columnNames, int formatType=0, int numberAcross=2, double objSense=0.0) const
Write the problem into an mps file of the given filename, names may be null.
virtual const CoinPackedMatrix * getMatrixByRow() const
Get pointer to row-wise copy of matrix.
virtual bool setHintParam(OsiHintParam key, bool yesNo=true, OsiHintStrength strength=OsiHintTry, void *otherInformation=NULL)
virtual bool getHintParam(OsiHintParam key, bool &yesNo, OsiHintStrength &strength, void *&otherInformation) const
Get a hint parameter.
virtual void addCols(const int numcols, const CoinPackedVectorBase *const *cols, const double *collb, const double *colub, const double *obj)
virtual void loadProblem(const CoinPackedMatrix &matrix, const double *collb, const double *colub, const double *obj, const double *rowlb, const double *rowub)
Load in an problem by copying the arguments (the constraints on the rows are given by lower and upper...
int getNodeCount() const
Get how many Nodes it took to solve the problem.
virtual ~OsiCbcSolverInterface()
Destructor.
bool getIntParam(OsiIntParam key, int &value) const
virtual void branchAndBound()
Invoke solver's built-in enumeration algorithm.
bool isSolutionLimitReached() const
Solution limit reached?
virtual int getNumRows() const
Get number of rows.
friend void OsiCbcSolverInterfaceUnitTest(const std::string &mpsDir, const std::string &netlibDir)
A function that tests the methods in the OsiCbcSolverInterface class.
virtual bool isContinuous(int colNumber) const
Return true if column is continuous.
virtual std::vector< double * > getPrimalRays(int maxNumRays) const
Get as many primal rays as the solver can provide.
int getMaximumNodes() const
Get the CbcModel::CbcMaxNumNode maximum node limit.
virtual void setColLower(int elementIndex, double elementValue)
Set a single column lower bound Use -DBL_MAX for -infinity.
virtual const double * getObjCoefficients() const
Get pointer to array[getNumCols()] of objective function coefficients.
virtual void setRowNames(OsiNameVec &srcNames, int srcStart, int len, int tgtStart)
Set multiple row names.
void setCutoff(double value)
Set cutoff bound on the objective function.
virtual bool isProvenOptimal() const
Is optimality proven?
virtual int getIterationCount() const
Get how many iterations it took to solve the problem (whatever "iteration" mean to the solver.
virtual const double * getRowLower() const
Get pointer to array[getNumRows()] of row lower bounds.
double getMaximumSeconds() const
Get the CbcModel::CbcMaximumSeconds maximum number of seconds.
virtual void applyRowCuts(int numberCuts, const OsiRowCut *cuts)
Apply a collection of row cuts which are all effective.
bool getStrParam(OsiStrParam key, std::string &value) const
virtual void applyRowCut(const OsiRowCut &rc)
Apply a row cut (append to constraint matrix).
virtual const double * getRightHandSide() const
Get pointer to array[getNumRows()] of rows right-hand sides.
virtual std::string getRowName(int rowIndex, unsigned maxLen=std::string::npos) const
Return the name of the row.
virtual void setColName(int ndx, std::string name)
Set a column name.
virtual const double * getReducedCost() const
Get a pointer to array[getNumCols()] of reduced costs.
virtual void setColSetBounds(const int *indexFirst, const int *indexLast, const double *boundList)
Set the bounds on a number of columns simultaneously The default implementation just invokes setColL...
bool setIntParam(OsiIntParam key, int value)
virtual void setObjSense(double s)
Set objective function sense (1 for min (default), -1 for max,)
virtual bool isPrimalObjectiveLimitReached() const
Is the given primal objective limit reached?
virtual const double * getColSolution() const
Get pointer to array[getNumCols()] of primal solution vector.
virtual int readMps(const char *filename, const char *extension="mps")
Read an mps file from the given filename (defaults to Osi reader) - returns number of errors (see Osi...
virtual void setRowUpper(int elementIndex, double elementValue)
Set a single row upper bound Use DBL_MAX for infinity.
virtual void setRowPrice(const double *rowprice)
Set dual solution vector.
OsiCbcSolverInterface(OsiSolverInterface *solver=NULL, CbcStrategy *strategy=NULL)
Default Constructor.
virtual void unmarkHotStart()
Delete the snapshot.
virtual const double * getColLower() const
Get pointer to array[getNumCols()] of column lower bounds.
virtual void deleteRowNames(int tgtStart, int len)
Delete len row names starting at index tgtStart.
bool setStrParam(OsiStrParam key, const std::string &value)
virtual void applyColCut(const OsiColCut &cc)
Apply a column cut (adjust one or more bounds).
virtual OsiSolverInterface * clone(bool copyData=true) const
Clone.
virtual void setObjCoeff(int elementIndex, double elementValue)
Set an objective function coefficient.
virtual void passInMessageHandler(CoinMessageHandler *handler)
Pass in a message handler.
virtual CoinWarmStart * getWarmStart() const
Get warmstarting information.
virtual void solveFromHotStart()
Optimize starting from the hotstart.
virtual void setColUpper(int elementIndex, double elementValue)
Set a single column upper bound Use DBL_MAX for infinity.
virtual std::vector< double * > getDualRays(int maxNumRays, bool fullRay=false) const
Get as many dual rays as the solver can provide.
virtual const double * getRowActivity() const
Get pointer to array[getNumRows()] of row activity levels (constraint matrix times the solution vecto...
void newLanguage(CoinMessages::Language language)
Set language.
virtual bool isProvenDualInfeasible() const
Is dual infeasiblity proven?
void setMaximumSolutions(int value)
Set the CbcModel::CbcMaxNumSol maximum number of solutions.
virtual void setColNames(OsiNameVec &srcNames, int srcStart, int len, int tgtStart)
Set multiple column names.
virtual void writeMps(const char *filename, const char *extension="mps", double objSense=0.0) const
Write the problem into an mps file of the given filename.
virtual CoinWarmStart * getEmptyWarmStart() const
Get an empty warm start object.
int status() const
Final status of problem - 0 finished, 1 stopped, 2 difficulties.
virtual void setRowBounds(int elementIndex, double lower, double upper)
Set a single row lower and upper bound.
OsiCbcSolverInterface & operator=(const OsiCbcSolverInterface &rhs)
Assignment operator.
virtual bool isAbandoned() const
Are there a numerical difficulties?
bool isNodeLimitReached() const
Node limit reached?
virtual void markHotStart()
Create a hotstart point of the optimization process.
virtual int getNumCols() const
Get number of columns.
virtual double getInfinity() const
Get solver's value for infinity.
OsiSolverInterface * getRealSolverPtr() const
Get pointer to underlying solver.
bool setDblParam(OsiDblParam key, double value)
virtual void setRowName(int ndx, std::string name)
Set a row name.
virtual double getObjSense() const
Get objective function sense (1 for min (default), -1 for max)
virtual void addRow(const CoinPackedVectorBase &vec, const double rowlb, const double rowub)
void setLanguage(CoinMessages::Language language)
virtual void setRowLower(int elementIndex, double elementValue)
Set a single row lower bound Use -DBL_MAX for -infinity.
virtual const double * getColUpper() const
Get pointer to array[getNumCols()] of column upper bounds.
virtual bool isProvenPrimalInfeasible() const
Is primal infeasiblity proven?
CbcModel * modelPtr_
Cbc model represented by this class instance.
virtual void addRows(const int numrows, const CoinPackedVectorBase *const *rows, const double *rowlb, const double *rowub)
virtual std::string getColName(int colIndex, unsigned maxLen=std::string::npos) const
Return the name of the column.
virtual void assignProblem(CoinPackedMatrix *&matrix, double *&collb, double *&colub, double *&obj, double *&rowlb, double *&rowub)
Load in an problem by assuming ownership of the arguments (the constraints on the rows are given by l...
virtual const OsiNameVec & getColNames()
Return a pointer to a vector of column names.
virtual void setRowType(int index, char sense, double rightHandSide, double range)
Set the type of a single row
virtual const OsiNameVec & getRowNames()
Return a pointer to a vector of row names.
virtual void addCol(const CoinPackedVectorBase &vec, const double collb, const double colub, const double obj)
virtual const double * getRowPrice() const
Get pointer to array[getNumRows()] of dual prices.
virtual void setColSolution(const double *colsol)
Set the primal solution column values.
virtual std::string dfltRowColName(char rc, int ndx, unsigned digits=7) const
Generate a standard name of the form Rnnnnnnn or Cnnnnnnn.
bool getDblParam(OsiDblParam key, double &value) const
void setMaximumNodes(int value)
Set the CbcModel::CbcMaxNumNode maximum node limit.
virtual void setRowSetBounds(const int *indexFirst, const int *indexLast, const double *boundList)
Set the bounds on a number of rows simultaneously The default implementation just invokes setRowLowe...
virtual void setColBounds(int elementIndex, double lower, double upper)
Set a single column lower and upper bound.
virtual void deleteColNames(int tgtStart, int len)
Delete len column names starting at index tgtStart.