Useful Set and Get Methods in CbcModel

Most of the parameter setting in CBC is done through CbcModel methods. The most commonly used set and get methods are listed in Table 2.2.

Table 2.2. Useful Set and Get Methods in CbcModel

Method(s) Description
bool setMaximumNodes(int value)
int getMaximumNodes() const
bool setMaximumSeconds(double value)
double getMaximumSeconds()
bool setMaximumSolutions(double value)
double getMaximumSolutions() const
These set methods tell CBC to stop after a given number of nodes, seconds, or solutions is reached. The get methods return the corresponding values.
bool setIntegerTolerance(double value) const
double getIntegerTolerance() const
An integer variable is deemed to be at an integral value if it is no further than this value (tolerance) away.
bool setAllowableGap(double value)
double getAllowableGap() const
bool setAllowablePercentageGap(double value)
double getAllowablePercentageGap() const
bool setAllowableFractionGap(double value)
double getAllowableFractionGap() const
CbcModel returns if the gap between the best known solution and the best possible solution is less than this value, or as a percentage, or a fraction.
void setNumberStrong(double value)
int numberStrong() [a] const
These methods set or get the maximum number of candidates at a node to be evaluated for strong branching.
void setPrintFrequency(int value)
int printFrequency() const
Controls the number of nodes evaluated between status prints. Print frequency has a very slight overhead, if value is small.
int getNodeCount() const Returns number of nodes evaluated in the search.
int numberRowsAtContinuous() const Returns number of rows in the problem when handed to the solver (i.e., before cuts where added). Commonly used in implementing heuristics.
int  numberIntegers() const
const int * integerVariable() const
Returns number of integer variables and an array specifying them.
bool isBinary(int colIndex) const
bool isContinuous(int colIndex) const
bool isInteger(int colIndex) const
Returns information on variable colIndex. OSI methods can be used to set these attributes (before handing the model to CbcModel).
double getObjValue() const This method returns the best objective value so far.
double getCurrentObjValue() const This method returns the current objective value.
const double * getObjCoefficients() const
This method return the objective coefficients.
const double * getRowLower() const
const double * getRowUpper() const
const double * getColLower() const
const double * getColUpper() const
These methods return the lower and upper bounds on row and column activities.
const CoinPackedMatrix * getMatrixByRow() const This method returns a pointer to a row copy of matrix stored as a CoinPackedMatrix which can be further examined.
const CoinPackedMatrix * getMatrixByCol() const This method returns a pointer to a column copy of matrix stored as a CoinPackedMatrix which can be further examined.
CoinBigIndex getNumElements() const[b] Returns the number of nonzero elements in the problem matrix.
void setObjSense(double value)
double getObjSense() const
These methods set and get the objective sense. The parameter value should be +1 to minimize and -1 to maximize.

[a] This methods (and some of the other) do not follow the "get" convention. The convention has changed over time and there are still some inconsistencies to be cleaned up.

[b] CoinBigIndex is a typedef which in most cases is the same as int.