Concepts
Features
Reference
Gurobi column object. A column consists of a list of coefficient,constraint pairs. Columns are used to represent the set of constraintsin which a variable participates, and the associated coefficients. Theyare temporary objects that typically have short lifespans.
You generally build columns by starting with an empty column (using theGRBColumn constructor), and then adding terms. Terms canbe added individually, usingaddTerm,or in groups, usingaddTerms. Termscan also be removed from a column, usingremove.
Individual terms in a column can be queried using thegetConstr, andgetCoeff methods. You can query thenumber of terms in the column using thesize method.
Column constructor that creates an empty column.
An empty column object.
// Create an empty column objectGRBColumncol=newGRBColumn();
Column constructor that copies an existing column.
col – Existing column object.
A copy of the input column object.
// Copy an existing column objectGRBColumncolCopy=newGRBColumn(col);
Add a single term into a column.
coeff – Coefficient for new term.
constr – Constraint for new term.
// Add coefficient-constraint pair (2.0, constr1) to a column objectcol.addTerm(2.0,constr1);
Add a list of terms into a column. Note that the lengths of the twoargument arrays must be equal.
coeffs – Coefficients for added constraints.
constrs – Constraints to add to column.
// Add 3 trivial linear constraints to the modelGRBConstr[]constrs=model.addConstrs(3);// Coefficients for the new columndouble[]coeffs={1.0,2.0,3.0};// Create and fill GRBColumn objectGRBColumncol=newGRBColumn();col.addTerms(coeffs,constrs);
Add new terms into a column. This signature allows you to use arrays tohold the coefficients and constraints that describe the terms in anarray without being forced to add an term for each member in the array.Thestart andlen arguments allow you to specify which terms toadd.
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.
// Add 3 trivial linear constraints to the modelGRBConstr[]constrs=model.addConstrs(3);// Coefficients for the new columndouble[]coeffs={1.0,2.0,3.0};// Create and fill GRBColumn object, but use only first 2 pairsGRBColumncol=newGRBColumn();col.addTerms(coeffs,constrs,0,2);
Remove all terms from a column.
// Clear all terms from the columncol.clear();
Retrieve the coefficient from a single term in the column.
i – Index for coefficient of interest.
Coefficient for the term at indexi in the column.
// Get the coefficient of the first coefficient-constraint pairdoublecoeff=col.getCoeff(0);
Retrieve the constraint object from a single term in the column.
i – Index for term of interest.
Constraint for the term at indexi in the column.
// Get the constraint of the first coefficient-constraint pairGRBConstrconstr=col.getConstr(0);
Remove the term stored at indexi of the column.
i – The index of the term to be removed.
// Remove the first coefficient-constraint pair from the columncol.remove(0);
Remove the term associated with constraintconstr from the column.
constr – The constraint whose term should be removed.
Returnstrue if the constraint appeared in the column (and was removed).
// Remove the pair associated with constr1booleanremoved=col.remove(constr1);
Retrieve the number of terms in the column.
Number of terms in the column.
// Get the number of terms in the columnintsize=col.size();
Help and Feedback