Movatterモバイル変換


[0]ホーム

URL:


ContentsMenuExpandLight modeDark modeAuto light/dark mode
Gurobi Optimizer Reference Manual
Light LogoDark Logo

Concepts

Features

Reference

Gurobi
Back to top

GRBColumn#

GRBColumn#

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 property.

GRBColumnGRBColumn()#

Column constructor that creates an empty column.

Returns:

An empty column object.

Example:
// Create empty column objectGRBColumncol=newGRBColumn();
GRBColumnGRBColumn(GRBColumnorig)#

Column constructor that copies an existing column.

Returns:

A copy of the input column object.

Example:
// Copy an existing columnGRBColumncol=newGRBColumn(col2);
voidAddTerm(doublecoeff,GRBConstrconstr)#

Add a single term into a column.

Parameters:
  • coeff – Coefficient for new term.

  • constr – Constraint for new term.

Example:
// Add a pair (2.0, constr1) to column objectcol.AddTerm(2.0,constr1);
voidAddTerms(double[]coeffs,GRBConstr[]constrs)#

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

Parameters:
  • coeffs – Coefficients for added constraints.

  • constrs – Constraints to add to column.

Example:
// Add 3 trivial linear constraints to modelGRBConstr[]constrs=model.AddConstrs(3);// Constraint coefficients for variable xdouble[]coeffs={1.0,2.0,3.0};// Create and fill GRBColumn objectGRBColumncol=newGRBColumn();col.AddTerms(coeffs,constrs);
voidAddTerms(double[]coeffs,GRBConstr[]constrs,intstart,intlen)#

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.

Parameters:
  • 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 modelGRBConstr[]constrs=model.AddConstrs(3);// Constraint coefficients for variable xdouble[]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);
voidClear()#

Remove all terms from a column.

Example:
col.Clear();
doubleGetCoeff(inti)#

Retrieve the coefficient from a single term in the column.

Returns:

Coefficient for the term at indexi in the column.

Example:
// Get the coefficient of first coefficient constraint pairdoublecoeff=col.GetCoeff(0);
GRBConstrGetConstr(inti)#

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

Returns:

Constraint for the term at indexi in the column.

Example:
// Get the constraint of first coefficient constraint pairGRBConstrconstr=col.GetConstr(0);
GRBConstrRemove(inti)#

Remove the term stored at indexi of the column.

Parameters:

i – The index of the term to be removed.

Returns:

The constraint whose term was removed from the column. Returnsnull if the specified index is out of range.

Example:
// Remove first coefficient constraint paircol.Remove(0);
booleanRemove(GRBConstrconstr)#

Remove the term associated with constraintconstr from the column.

Parameters:

constr – The constraint whose term should be removed.

Returns:

Returnstrue if the constraint appeared in the column (andwas removed).

Example:
// Remove pair associated with constr1boolremoved=col.Remove(constr1);
intSize#

(Property) The number of terms in the column.

Example:
ints=col.Size;

Help and Feedback

On this page

[8]ページ先頭

©2009-2025 Movatter.jp