CYCLUS
OsiCbcSolverInterface_2_5.hpp
Go to the documentation of this file.
1 // $Id: OsiCbcSolverInterface.hpp 1902 2013-04-10 16:58:16Z 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_5_HPP
7 #define OsiCbcSolverInterface_2_5_HPP
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 
18 class OsiRowCut;
19 class OsiClpSolverInterface;
20 static const double OsiCbcInfinity = COIN_DBL_MAX;
21 
22 //#############################################################################
23 
24 /** Cbc Solver Interface
25 
26 Instantiation of OsiCbcSolverInterface for the Agent Algorithm.
27 
28 */
29 
31  virtual public OsiSolverInterface {
32  friend void OsiCbcSolverInterfaceUnitTest(const std::string & mpsDir, 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 
222  /// Get pointer to row-wise copy of matrix
223  virtual const CoinPackedMatrix * getMatrixByRow() const;
224 
225  /// Get pointer to column-wise copy of matrix
226  virtual const CoinPackedMatrix * getMatrixByCol() const;
227 
228  /// Get solver's value for infinity
229  virtual double getInfinity() const;
230  //@}
231 
232  /**@name Methods related to querying the solution */
233  //@{
234  /// Get pointer to array[getNumCols()] of primal solution vector
235  virtual const double * getColSolution() const;
236 
237  /// Get pointer to array[getNumRows()] of dual prices
238  virtual const double * getRowPrice() const;
239 
240  /// Get a pointer to array[getNumCols()] of reduced costs
241  virtual const double * getReducedCost() const;
242 
243  /** Get pointer to array[getNumRows()] of row activity levels (constraint
244  matrix times the solution vector */
245  virtual const double * getRowActivity() const;
246 
247  /// Get objective function value
248  virtual double getObjValue() const;
249 
250  /** Get how many iterations it took to solve the problem (whatever
251  "iteration" mean to the solver. */
252  virtual int getIterationCount() const ;
253 
254  /** Get as many dual rays as the solver can provide. (In case of proven
255  primal infeasibility there should be at least one.)
256 
257  The first getNumRows() ray components will always be associated with
258  the row duals (as returned by getRowPrice()). If \c fullRay is true,
259  the final getNumCols() entries will correspond to the ray components
260  associated with the nonbasic variables. If the full ray is requested
261  and the method cannot provide it, it will throw an exception.
262 
263  <strong>NOTE for implementers of solver interfaces:</strong> <br>
264  The double pointers in the vector should point to arrays of length
265  getNumRows() and they should be allocated via new[]. <br>
266 
267  <strong>NOTE for users of solver interfaces:</strong> <br>
268  It is the user's responsibility to free the double pointers in the
269  vector using delete[].
270  */
271  // virtual std::vector<double*> getDualRays(int maxNumRays,
272  // bool fullRay = false) const;
273  // signature change to be compatible with current apt-get version
274  virtual std::vector<double*> getDualRays(int maxNumRays) const;
275 
276  /** Get as many primal rays as the solver can provide. (In case of proven
277  dual infeasibility there should be at least one.)
278 
279  <strong>NOTE for implementers of solver interfaces:</strong> <br>
280  The double pointers in the vector should point to arrays of length
281  getNumCols() and they should be allocated via new[]. <br>
282 
283  <strong>NOTE for users of solver interfaces:</strong> <br>
284  It is the user's responsibility to free the double pointers in the
285  vector using delete[].
286  */
287  virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
288 
289  //@}
290 
291  /*! \name Methods for row and column names.
292 
293  Because OsiCbc is a pass-through class, it's necessary to override any
294  virtual method in order to be sure we catch an override by the underlying
295  solver. See the OsiSolverInterface class documentation for detailed
296  descriptions.
297  */
298  //@{
299 
300  /*! \brief Generate a standard name of the form Rnnnnnnn or Cnnnnnnn */
301 
302  virtual std::string dfltRowColName(char rc,
303  int ndx, unsigned digits = 7) const ;
304 
305  /*! \brief Return the name of the objective function */
306 
307  virtual std::string getObjName (unsigned maxLen = std::string::npos) const ;
308 
309  /*! \brief Set the name of the objective function */
310 
311  virtual void setObjName (std::string name) ;
312 
313  /*! \brief Return the name of the row. */
314 
315  virtual std::string getRowName(int rowIndex,
316  unsigned maxLen = std::string::npos) const ;
317 
318  /*! \brief Return a pointer to a vector of row names */
319 
320  virtual const OsiNameVec &getRowNames() ;
321 
322  /*! \brief Set a row name */
323 
324  virtual void setRowName(int ndx, std::string name) ;
325 
326  /*! \brief Set multiple row names */
327 
328  virtual void setRowNames(OsiNameVec &srcNames,
329  int srcStart, int len, int tgtStart) ;
330 
331  /*! \brief Delete len row names starting at index tgtStart */
332 
333  virtual void deleteRowNames(int tgtStart, int len) ;
334 
335  /*! \brief Return the name of the column */
336 
337  virtual std::string getColName(int colIndex,
338  unsigned maxLen = std::string::npos) const ;
339 
340  /*! \brief Return a pointer to a vector of column names */
341 
342  virtual const OsiNameVec &getColNames() ;
343 
344  /*! \brief Set a column name */
345 
346  virtual void setColName(int ndx, std::string name) ;
347 
348  /*! \brief Set multiple column names */
349 
350  virtual void setColNames(OsiNameVec &srcNames,
351  int srcStart, int len, int tgtStart) ;
352 
353  /*! \brief Delete len column names starting at index tgtStart */
354  virtual void deleteColNames(int tgtStart, int len) ;
355 
356  //@}
357 
358  //@}
359 
360  //---------------------------------------------------------------------------
361 
362  /**@name Problem modifying methods */
363  //@{
364  //-------------------------------------------------------------------------
365  /**@name Changing bounds on variables and constraints */
366  //@{
367  /** Set an objective function coefficient */
368  virtual void setObjCoeff( int elementIndex, double elementValue );
369 
370  using OsiSolverInterface::setColLower ;
371  /** Set a single column lower bound<br>
372  Use -DBL_MAX for -infinity. */
373  virtual void setColLower( int elementIndex, double elementValue );
374 
375  using OsiSolverInterface::setColUpper ;
376  /** Set a single column upper bound<br>
377  Use DBL_MAX for infinity. */
378  virtual void setColUpper( int elementIndex, double elementValue );
379 
380  /** Set a single column lower and upper bound */
381  virtual void setColBounds( int elementIndex,
382  double lower, double upper );
383 
384  /** Set the bounds on a number of columns simultaneously<br>
385  The default implementation just invokes setColLower() and
386  setColUpper() over and over again.
387  @param indexFirst,indexLast pointers to the beginning and after the
388  end of the array of the indices of the variables whose
389  <em>either</em> bound changes
390  @param boundList the new lower/upper bound pairs for the variables
391  */
392  virtual void setColSetBounds(const int* indexFirst,
393  const int* indexLast,
394  const double* boundList);
395 
396  /** Set a single row lower bound<br>
397  Use -DBL_MAX for -infinity. */
398  virtual void setRowLower( int elementIndex, double elementValue );
399 
400  /** Set a single row upper bound<br>
401  Use DBL_MAX for infinity. */
402  virtual void setRowUpper( int elementIndex, double elementValue ) ;
403 
404  /** Set a single row lower and upper bound */
405  virtual void setRowBounds( int elementIndex,
406  double lower, double upper ) ;
407 
408  /** Set the type of a single row<br> */
409  virtual void setRowType(int index, char sense, double rightHandSide,
410  double range);
411 
412  /** Set the bounds on a number of rows simultaneously<br>
413  The default implementation just invokes setRowLower() and
414  setRowUpper() over and over again.
415  @param indexFirst,indexLast pointers to the beginning and after the
416  end of the array of the indices of the constraints whose
417  <em>either</em> bound changes
418  @param boundList the new lower/upper bound pairs for the constraints
419  */
420  virtual void setRowSetBounds(const int* indexFirst,
421  const int* indexLast,
422  const double* boundList);
423 
424  /** Set the type of a number of rows simultaneously<br>
425  The default implementation just invokes setRowType()
426  over and over again.
427  @param indexFirst,indexLast pointers to the beginning and after the
428  end of the array of the indices of the constraints whose
429  <em>any</em> characteristics changes
430  @param senseList the new senses
431  @param rhsList the new right hand sides
432  @param rangeList the new ranges
433  */
434  virtual void setRowSetTypes(const int* indexFirst,
435  const int* indexLast,
436  const char* senseList,
437  const double* rhsList,
438  const double* rangeList);
439  //@}
440 
441  //-------------------------------------------------------------------------
442  /**@name Integrality related changing methods */
443  //@{
444  /** Set the index-th variable to be a continuous variable */
445  virtual void setContinuous(int index);
446  /** Set the index-th variable to be an integer variable */
447  virtual void setInteger(int index);
448  /** Set the variables listed in indices (which is of length len) to be
449  continuous variables */
450  virtual void setContinuous(const int* indices, int len);
451  /** Set the variables listed in indices (which is of length len) to be
452  integer variables */
453  virtual void setInteger(const int* indices, int len);
454  //@}
455 
456  //-------------------------------------------------------------------------
457  /// Set objective function sense (1 for min (default), -1 for max,)
458  virtual void setObjSense(double s );
459 
460  /** Set the primal solution column values
461 
462  colsol[numcols()] is an array of values of the problem column
463  variables. These values are copied to memory owned by the
464  solver object or the solver. They will be returned as the
465  result of colsol() until changed by another call to
466  setColsol() or by a call to any solver routine. Whether the
467  solver makes use of the solution in any way is
468  solver-dependent.
469  */
470  virtual void setColSolution(const double * colsol);
471 
472  /** Set dual solution vector
473 
474  rowprice[numrows()] is an array of values of the problem row
475  dual variables. These values are copied to memory owned by the
476  solver object or the solver. They will be returned as the
477  result of rowprice() until changed by another call to
478  setRowprice() or by a call to any solver routine. Whether the
479  solver makes use of the solution in any way is
480  solver-dependent.
481  */
482  virtual void setRowPrice(const double * rowprice);
483 
484  //-------------------------------------------------------------------------
485  /**@name Methods to expand a problem.<br>
486  Note that if a column is added then by default it will correspond to a
487  continuous variable. */
488  //@{
489  using OsiSolverInterface::addCol ;
490  /** */
491  virtual void addCol(const CoinPackedVectorBase& vec,
492  const double collb, const double colub,
493  const double obj);
494  /** Add a column (primal variable) to the problem. */
495  virtual void addCol(int numberElements, const int * rows, const double * elements,
496  const double collb, const double colub,
497  const double obj) ;
498 
499  using OsiSolverInterface::addCols ;
500  /** */
501  virtual void addCols(const int numcols,
502  const CoinPackedVectorBase * const * cols,
503  const double* collb, const double* colub,
504  const double* obj);
505  /** */
506  virtual void deleteCols(const int num, const int * colIndices);
507 
508  using OsiSolverInterface::addRow ;
509  /** */
510  virtual void addRow(const CoinPackedVectorBase& vec,
511  const double rowlb, const double rowub);
512  /** */
513  virtual void addRow(const CoinPackedVectorBase& vec,
514  const char rowsen, const double rowrhs,
515  const double rowrng);
516 
517  using OsiSolverInterface::addRows ;
518  /** */
519  virtual void addRows(const int numrows,
520  const CoinPackedVectorBase * const * rows,
521  const double* rowlb, const double* rowub);
522  /** */
523  virtual void addRows(const int numrows,
524  const CoinPackedVectorBase * const * rows,
525  const char* rowsen, const double* rowrhs,
526  const double* rowrng);
527  /** */
528  virtual void deleteRows(const int num, const int * rowIndices);
529 
530  //-----------------------------------------------------------------------
531  /** Apply a collection of row cuts which are all effective.
532  applyCuts seems to do one at a time which seems inefficient.
533  */
534  virtual void applyRowCuts(int numberCuts, const OsiRowCut * cuts);
535  /** Apply a collection of row cuts which are all effective.
536  applyCuts seems to do one at a time which seems inefficient.
537  This uses array of pointers
538  */
539  virtual void applyRowCuts(int numberCuts, const OsiRowCut ** cuts);
540  //@}
541  //@}
542 
543  //---------------------------------------------------------------------------
544 
545 public:
546 
547  /**@name Methods to input a problem */
548  //@{
549  /** Load in an problem by copying the arguments (the constraints on the
550  rows are given by lower and upper bounds). If a pointer is 0 then the
551  following values are the default:
552  <ul>
553  <li> <code>colub</code>: all columns have upper bound infinity
554  <li> <code>collb</code>: all columns have lower bound 0
555  <li> <code>rowub</code>: all rows have upper bound infinity
556  <li> <code>rowlb</code>: all rows have lower bound -infinity
557  <li> <code>obj</code>: all variables have 0 objective coefficient
558  </ul>
559  */
560  virtual void loadProblem(const CoinPackedMatrix& matrix,
561  const double* collb, const double* colub,
562  const double* obj,
563  const double* rowlb, const double* rowub);
564 
565  /** Load in an problem by assuming ownership of the arguments (the
566  constraints on the rows are given by lower and upper bounds). For
567  default values see the previous method. <br>
568  <strong>WARNING</strong>: The arguments passed to this method will be
569  freed using the C++ <code>delete</code> and <code>delete[]</code>
570  functions.
571  */
572  virtual void assignProblem(CoinPackedMatrix*& matrix,
573  double*& collb, double*& colub, double*& obj,
574  double*& rowlb, double*& rowub);
575 
576  /** Load in an problem by copying the arguments (the constraints on the
577  rows are given by sense/rhs/range triplets). If a pointer is 0 then the
578  following values are the default:
579  <ul>
580  <li> <code>colub</code>: all columns have upper bound infinity
581  <li> <code>collb</code>: all columns have lower bound 0
582  <li> <code>obj</code>: all variables have 0 objective coefficient
583  <li> <code>rowsen</code>: all rows are >=
584  <li> <code>rowrhs</code>: all right hand sides are 0
585  <li> <code>rowrng</code>: 0 for the ranged rows
586  </ul>
587  */
588  virtual void loadProblem(const CoinPackedMatrix& matrix,
589  const double* collb, const double* colub,
590  const double* obj,
591  const char* rowsen, const double* rowrhs,
592  const double* rowrng);
593 
594  /** Load in an problem by assuming ownership of the arguments (the
595  constraints on the rows are given by sense/rhs/range triplets). For
596  default values see the previous method. <br>
597  <strong>WARNING</strong>: The arguments passed to this method will be
598  freed using the C++ <code>delete</code> and <code>delete[]</code>
599  functions.
600  */
601  virtual void assignProblem(CoinPackedMatrix*& matrix,
602  double*& collb, double*& colub, double*& obj,
603  char*& rowsen, double*& rowrhs,
604  double*& rowrng);
605 
606  /** Just like the other loadProblem() methods except that the matrix is
607  given in a standard column major ordered format (without gaps). */
608  virtual void loadProblem(const int numcols, const int numrows,
609  const CoinBigIndex * start, const int* index,
610  const double* value,
611  const double* collb, const double* colub,
612  const double* obj,
613  const double* rowlb, const double* rowub);
614 
615  /** Just like the other loadProblem() methods except that the matrix is
616  given in a standard column major ordered format (without gaps). */
617  virtual void loadProblem(const int numcols, const int numrows,
618  const CoinBigIndex * start, const int* index,
619  const double* value,
620  const double* collb, const double* colub,
621  const double* obj,
622  const char* rowsen, const double* rowrhs,
623  const double* rowrng);
624 
625  using OsiSolverInterface::readMps ;
626  /** Read an mps file from the given filename (defaults to Osi reader) - returns
627  number of errors (see OsiMpsReader class) */
628  virtual int readMps(const char *filename,
629  const char *extension = "mps") ;
630 
631  /** Write the problem into an mps file of the given filename.
632  If objSense is non zero then -1.0 forces the code to write a
633  maximization objective and +1.0 to write a minimization one.
634  If 0.0 then solver can do what it wants */
635  virtual void writeMps(const char *filename,
636  const char *extension = "mps",
637  double objSense=0.0) const;
638  /** Write the problem into an mps file of the given filename,
639  names may be null. formatType is
640  0 - normal
641  1 - extra accuracy
642  2 - IEEE hex (later)
643 
644  Returns non-zero on I/O error
645  */
646  virtual int writeMpsNative(const char *filename,
647  const char ** rowNames, const char ** columnNames,
648  int formatType=0,int numberAcross=2,
649  double objSense=0.0) const ;
650  //@}
651 
652  /**@name Message handling (extra for Cbc messages).
653  Normally I presume you would want the same language.
654  If not then you could use underlying agent pointer */
655  //@{
656  /// Set language
657  void newLanguage(CoinMessages::Language language);
658  void setLanguage(CoinMessages::Language language)
659  {newLanguage(language);}
660  //@}
661  //---------------------------------------------------------------------------
662 
663  /**@name Cbc specific public interfaces */
664  //@{
665  /// Get pointer to Cbc agent
666  inline CbcModel * getAgentPtr() const
667  { return agentPtr_;}
668  /// Get pointer to underlying solver
669  inline OsiSolverInterface * getRealSolverPtr() const
670  { return agentPtr_->solver();}
671  /// Set cutoff bound on the objective function.
672  inline void setCutoff(double value)
673  { agentPtr_->setCutoff(value);}
674  /// Get the cutoff bound on the objective function - always as minimize
675  inline double getCutoff() const
676  { return agentPtr_->getCutoff();}
677  /// Set the CbcModel::CbcMaxNumNode maximum node limit
678  inline void setMaximumNodes( int value)
679  { agentPtr_->setMaximumNodes(value);}
680  /// Get the CbcModel::CbcMaxNumNode maximum node limit
681  inline int getMaximumNodes() const
682  { return agentPtr_->getMaximumNodes();}
683  /// Set the CbcModel::CbcMaxNumSol maximum number of solutions
684  inline void setMaximumSolutions( int value)
685  { agentPtr_->setMaximumSolutions(value);}
686  /// Get the CbcModel::CbcMaxNumSol maximum number of solutions
687  inline int getMaximumSolutions() const
688  { return agentPtr_->getMaximumSolutions();}
689  /// Set the CbcModel::CbcMaximumSeconds maximum number of seconds
690  inline void setMaximumSeconds( double value)
691  { agentPtr_->setMaximumSeconds(value);}
692  /// Get the CbcModel::CbcMaximumSeconds maximum number of seconds
693  inline double getMaximumSeconds() const
694  { return agentPtr_->getMaximumSeconds();}
695  /// Node limit reached?
696  inline bool isNodeLimitReached() const
697  { return agentPtr_->isNodeLimitReached();}
698  /// Solution limit reached?
699  inline bool isSolutionLimitReached() const
700  { return agentPtr_->isSolutionLimitReached();}
701  /// Get how many Nodes it took to solve the problem.
702  inline int getNodeCount() const
703  { return agentPtr_->getNodeCount();}
704  /// Final status of problem - 0 finished, 1 stopped, 2 difficulties
705  inline int status() const
706  { return agentPtr_->status();}
707  /** Pass in a message handler
708 
709  It is the client's responsibility to destroy a message handler installed
710  by this routine; it will not be destroyed when the solver interface is
711  destroyed.
712  */
713  virtual void passInMessageHandler(CoinMessageHandler * handler);
714  //@}
715 
716  //---------------------------------------------------------------------------
717 
718  /**@name Constructors and destructors */
719  //@{
720  /// Default Constructor
721  OsiCbcSolverInterface (OsiSolverInterface * solver=NULL,
722  CbcStrategy * strategy=NULL);
723 
724  /// Clone
725  virtual OsiSolverInterface * clone(bool copyData = true) const;
726 
727  /// Copy constructor
729 #if 0
730  /// Borrow constructor - only delete one copy
731  OsiCbcSolverInterface (CbcModel * rhs, bool reallyOwn=false);
732 
733  /// Releases so won't error
734  void releaseCbc();
735 #endif
736  /// Assignment operator
738 
739  /// Destructor
740  virtual ~OsiCbcSolverInterface ();
741 
742  //@}
743  //---------------------------------------------------------------------------
744 
745 protected:
746  ///@name Protected methods
747  //@{
748  /** Apply a row cut (append to constraint matrix). */
749  virtual void applyRowCut(const OsiRowCut& rc);
750 
751  /** Apply a column cut (adjust one or more bounds). */
752  virtual void applyColCut(const OsiColCut& cc);
753  //@}
754  /**@name Protected member data */
755  //@{
756  /// Cbc agent represented by this class instance
757  mutable CbcModel * agentPtr_;
758  //@}
759 };
760 // So unit test can find out if NDEBUG set
761 bool OsiCbcHasNDEBUG();
762 
763 //#############################################################################
764 /** A function that tests the methods in the OsiCbcSolverInterface class. */
765 void OsiCbcSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
766 
767 #endif
void setMaximumNodes(int value)
Set the CbcModel::CbcMaxNumNode maximum node limit.
virtual bool isProvenDualInfeasible() const
Is dual infeasiblity proven?
virtual void setObjName(std::string name)
Set the name of the objective function.
virtual void applyRowCuts(int numberCuts, const OsiRowCut *cuts)
Apply a collection of row cuts which are all effective.
virtual void setColUpper(int elementIndex, double elementValue)
Set a single column upper bound Use DBL_MAX for infinity.
friend void OsiCbcSolverInterfaceUnitTest(const std::string &mpsDir, const std::string &netlibDir)
A function that tests the methods in the OsiCbcSolverInterface class.
virtual int getIterationCount() const
Get how many iterations it took to solve the problem (whatever "iteration" mean to the solver...
virtual void resolve()
Resolve an LP relaxation after problem modification.
CbcModel * agentPtr_
Cbc agent represented by this class instance.
bool isNodeLimitReached() const
Node limit reached?
virtual void setRowLower(int elementIndex, double elementValue)
Set a single row lower bound Use -DBL_MAX for -infinity.
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 addRows(const int numrows, const CoinPackedVectorBase *const *rows, const double *rowlb, const double *rowub)
virtual const CoinPackedMatrix * getMatrixByCol() const
Get pointer to column-wise copy of matrix.
virtual void addCol(const CoinPackedVectorBase &vec, const double collb, const double colub, const double obj)
virtual const double * getColSolution() const
Get pointer to array[getNumCols()] of primal solution vector.
virtual void deleteCols(const int num, const int *colIndices)
virtual void markHotStart()
Create a hotstart point of the optimization process.
virtual const double * getRowUpper() const
Get pointer to array[getNumRows()] of row upper bounds.
virtual bool setHintParam(OsiHintParam key, bool yesNo=true, OsiHintStrength strength=OsiHintTry, void *otherInformation=NULL)
bool getIntParam(OsiIntParam key, int &value) const
virtual void initialSolve()
Solve initial LP relaxation.
void setLanguage(CoinMessages::Language language)
virtual void setColBounds(int elementIndex, double lower, double upper)
Set a single column lower and upper bound.
virtual const CoinPackedMatrix * getMatrixByRow() const
Get pointer to row-wise copy of matrix.
virtual const double * getColUpper() const
Get pointer to array[getNumCols()] of column upper bounds.
int status() const
Final status of problem - 0 finished, 1 stopped, 2 difficulties.
virtual void passInMessageHandler(CoinMessageHandler *handler)
Pass in a message handler.
virtual void setRowPrice(const double *rowprice)
Set dual solution vector.
virtual std::string getRowName(int rowIndex, unsigned maxLen=std::string::npos) const
Return the name of the row.
virtual const double * getReducedCost() const
Get a pointer to array[getNumCols()] of reduced costs.
virtual OsiSolverInterface * clone(bool copyData=true) const
Clone.
virtual void setRowType(int index, char sense, double rightHandSide, double range)
Set the type of a single row
virtual std::vector< double * > getDualRays(int maxNumRays) const
Get as many dual rays as the solver can provide.
std::string name(int nuc)
Definition: pyne.cc:2940
virtual const double * getRowLower() const
Get pointer to array[getNumRows()] of row lower bounds.
virtual const double * getObjCoefficients() const
Get pointer to array[getNumCols()] of objective function coefficients.
virtual bool isPrimalObjectiveLimitReached() const
Is the given primal objective limit reached?
virtual bool getHintParam(OsiHintParam key, bool &yesNo, OsiHintStrength &strength, void *&otherInformation) const
Get a hint parameter.
virtual void setObjSense(double s)
Set objective function sense (1 for min (default), -1 for max,)
virtual void addRow(const CoinPackedVectorBase &vec, const double rowlb, const double rowub)
virtual double getInfinity() const
Get solver&#39;s value for infinity.
virtual std::string getObjName(unsigned maxLen=std::string::npos) const
Return the name of the objective function.
bool isSolutionLimitReached() const
Solution limit reached?
virtual const OsiNameVec & getRowNames()
Return a pointer to a vector of row names.
double getMaximumSeconds() const
Get the CbcModel::CbcMaximumSeconds maximum number of seconds.
void setMaximumSeconds(double value)
Set the CbcModel::CbcMaximumSeconds maximum number of seconds.
virtual void deleteRowNames(int tgtStart, int len)
Delete len row names starting at index tgtStart.
CbcModel * getAgentPtr() const
Get pointer to Cbc agent.
bool getDblParam(OsiDblParam key, double &value) const
bool getStrParam(OsiStrParam key, std::string &value) const
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...
int getNodeCount() const
Get how many Nodes it took to solve the problem.
virtual int getNumElements() const
Get number of nonzero elements.
double getCutoff() const
Get the cutoff bound on the objective function - always as minimize.
static const double OsiCbcInfinity
virtual void applyRowCut(const OsiRowCut &rc)
Apply a row cut (append to constraint matrix).
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 setColNames(OsiNameVec &srcNames, int srcStart, int len, int tgtStart)
Set multiple column names.
virtual int getNumRows() const
Get number of rows.
virtual void applyColCut(const OsiColCut &cc)
Apply a column cut (adjust one or more bounds).
virtual const double * getRowActivity() const
Get pointer to array[getNumRows()] of row activity levels (constraint matrix times the solution vecto...
virtual bool isProvenPrimalInfeasible() const
Is primal infeasiblity proven?
virtual ~OsiCbcSolverInterface()
Destructor.
int getMaximumSolutions() const
Get the CbcModel::CbcMaxNumSol maximum number of solutions.
OsiSolverInterface * getRealSolverPtr() const
Get pointer to underlying solver.
bool setStrParam(OsiStrParam key, const std::string &value)
virtual void solveFromHotStart()
Optimize starting from the hotstart.
virtual bool isAbandoned() const
Are there a numerical difficulties?
virtual void deleteColNames(int tgtStart, int len)
Delete len column names starting at index tgtStart.
int getMaximumNodes() const
Get the CbcModel::CbcMaxNumNode maximum node limit.
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...
bool OsiCbcHasNDEBUG()
OsiCbcSolverInterface(OsiSolverInterface *solver=NULL, CbcStrategy *strategy=NULL)
Default Constructor.
virtual double getObjValue() const
Get objective function value.
virtual bool setWarmStart(const CoinWarmStart *warmstart)
Set warmstarting information.
virtual void branchAndBound()
Invoke solver&#39;s built-in enumeration algorithm.
virtual double getObjSense() const
Get objective function sense (1 for min (default), -1 for max)
virtual void setColSolution(const double *colsol)
Set the primal solution column values.
static std::string digits
string of digit characters
Definition: pyne.h:124
virtual const OsiNameVec & getColNames()
Return a pointer to a vector of column names.
virtual void setColLower(int elementIndex, double elementValue)
Set a single column lower bound Use -DBL_MAX for -infinity.
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 setRowBounds(int elementIndex, double lower, double upper)
Set a single row lower and upper bound.
virtual void deleteRows(const int num, const int *rowIndices)
virtual bool isDualObjectiveLimitReached() const
Is the given dual objective limit reached?
virtual CoinWarmStart * getWarmStart() const
Get warmstarting information.
virtual bool isProvenOptimal() const
Is optimality proven?
virtual void addCols(const int numcols, const CoinPackedVectorBase *const *cols, const double *collb, const double *colub, const double *obj)
virtual std::string dfltRowColName(char rc, int ndx, unsigned digits=7) const
Generate a standard name of the form Rnnnnnnn or Cnnnnnnn.
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...
virtual void setRowNames(OsiNameVec &srcNames, int srcStart, int len, int tgtStart)
Set multiple row names.
virtual void setRowName(int ndx, std::string name)
Set a row name.
virtual const double * getRightHandSide() const
Get pointer to array[getNumRows()] of rows right-hand sides.
virtual void setRowUpper(int elementIndex, double elementValue)
Set a single row upper bound Use DBL_MAX for infinity.
virtual int getNumCols() const
Get number of columns.
bool setIntParam(OsiIntParam key, int value)
virtual void unmarkHotStart()
Delete the snapshot.
virtual void setObjCoeff(int elementIndex, double elementValue)
Set an objective function coefficient.
virtual const double * getRowPrice() const
Get pointer to array[getNumRows()] of dual prices.
virtual bool isContinuous(int colNumber) const
Return true if column is continuous.
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.
void setMaximumSolutions(int value)
Set the CbcModel::CbcMaxNumSol maximum number of solutions.
virtual void setColName(int ndx, std::string name)
Set a column name.
virtual bool isIterationLimitReached() const
Iteration limit reached?
virtual void setInteger(int index)
Set the index-th variable to be an integer variable.
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.
void newLanguage(CoinMessages::Language language)
Set language.
virtual const char * getRowSense() const
Get pointer to array[getNumRows()] of row constraint senses.
virtual CoinWarmStart * getEmptyWarmStart() const
Get an empty warm start object.
OsiCbcSolverInterface & operator=(const OsiCbcSolverInterface &rhs)
Assignment operator.
void setCutoff(double value)
Set cutoff bound on the objective function.
virtual const double * getColLower() const
Get pointer to array[getNumCols()] of column lower bounds.
bool setDblParam(OsiDblParam key, double value)
virtual void setContinuous(int index)
Set the index-th variable to be a continuous variable.
virtual std::vector< double * > getPrimalRays(int maxNumRays) const
Get as many primal rays as the solver can provide.
virtual const double * getRowRange() const
Get pointer to array[getNumRows()] of row ranges.