GRBColumn#

GRBColumn#

Gurobi column object. A column consists of a list of coefficient, constraint pairs. Columns are used to represent the set of constraints in which a variable participates, and the associated coefficients. They are temporary objects that typically have short lifespans.

You generally build columns by starting with an empty column (using the GRBColumn constructor), and then adding terms. Terms can be added individually, using addTerm, or in groups, using addTerms. Terms can also be removed from a column, using remove.

Individual terms in a column can be queried using the getConstr, and getCoeff methods. You can query the number of terms in the column using the size method.

GRBColumn GRBColumn()#

Column constructor that creates an empty column.

Return value:

An empty column object.

Example:
// Create an empty column object
GRBColumn col = new GRBColumn();
GRBColumn GRBColumn(GRBColumn col)#

Column constructor that copies an existing column.

Arguments:

col – Existing column object.

Return value:

A copy of the input column object.

Example:
// Copy an existing column object
GRBColumn colCopy = new GRBColumn(col);
void addTerm(double coeff, GRBConstr constr)#

Add a single term into a column.

Arguments:
  • coeff – Coefficient for new term.

  • constr – Constraint for new term.

Example:
// Add coefficient-constraint pair (2.0, constr1) to a column object
col.addTerm(2.0, constr1);
void addTerms(double[] coeffs, GRBConstr[] constrs)#

Add a list of terms into a column. Note that the lengths of the two argument arrays must be equal.

Arguments:
  • coeffs – Coefficients for added constraints.

  • constrs – Constraints to add to column.

Example:
// Add 3 trivial linear constraints to the model
GRBConstr[] constrs = model.addConstrs(3);
// Coefficients for the new column
double[] coeffs = {1.0, 2.0, 3.0};
// Create and fill GRBColumn object
GRBColumn col = new GRBColumn();
col.addTerms(coeffs, constrs);
void addTerms(double[] coeffs, GRBConstr[] constrs, int start, int len)#

Add new terms into a column. This signature allows you to use arrays to hold the coefficients and constraints that describe the terms in an array without being forced to add an term for each member in the array. The start and len arguments allow you to specify which terms to add.

Arguments:
  • coeffs – Coefficients for added constraints.

  • constrs – Constraints to add to column.

  • start – The first term in the list to add.

  • len – The number of terms to add.

Example:
// Add 3 trivial linear constraints to the model
GRBConstr[] constrs = model.addConstrs(3);
// Coefficients for the new column
double[] coeffs = {1.0, 2.0, 3.0};
// Create and fill GRBColumn object, but use only first 2 pairs
GRBColumn col = new GRBColumn();
col.addTerms(coeffs, constrs, 0, 2);
void clear()#

Remove all terms from a column.

Example:
// Clear all terms from the column
col.clear();
double getCoeff(int i)#

Retrieve the coefficient from a single term in the column.

Arguments:

i – Index for coefficient of interest.

Return value:

Coefficient for the term at index i in the column.

Example:
// Get the coefficient of the first coefficient-constraint pair
double coeff = col.getCoeff(0);
GRBConstr getConstr(int i)#

Retrieve the constraint object from a single term in the column.

Arguments:

i – Index for term of interest.

Return value:

Constraint for the term at index i in the column.

Example:
// Get the constraint of the first coefficient-constraint pair
GRBConstr constr = col.getConstr(0);
void remove(int i)#

Remove the term stored at index i of the column.

Arguments:

i – The index of the term to be removed.

Example:
// Remove the first coefficient-constraint pair from the column
col.remove(0);
boolean remove(GRBConstr constr)#

Remove the term associated with constraint constr from the column.

Arguments:

constr – The constraint whose term should be removed.

Return value:

Returns true if the constraint appeared in the column (and was removed).

Example:
// Remove the pair associated with constr1
boolean removed = col.remove(constr1);
int size()#

Retrieve the number of terms in the column.

Return value:

Number of terms in the column.

Example:
// Get the number of terms in the column
int size = col.size();