Hide navigation sidebar
Hide table of contents sidebar
Back to top
Toggle table of contents sidebar

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

  GRBColumn GRBColumn()

    Column constructor that creates an empty column.

    Returns:

      An empty column object.

    Example:

          // Create empty column object
          GRBColumn col = new GRBColumn();

          ' Create empty column object
          Dim col As GRBColumn = New GRBColumn()

  GRBColumn GRBColumn(GRBColumn orig)

    Column constructor that copies an existing column.

    Returns:

      A copy of the input column object.

    Example:

          // Copy an existing column
          GRBColumn col = new GRBColumn(col2);

          ' Copy an existing column
          Dim col As GRBColumn = New GRBColumn(col2)

  void AddTerm(double coeff, GRBConstr constr)

    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 object
          col.AddTerm(2.0, constr1);

          ' Add a pair (2.0, constr1) to 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.

    Parameters:

      - coeffs – Coefficients for added constraints.

      - constrs – Constraints to add to column.

    Example:

          // Add 3 trivial linear constraints to model
          GRBConstr[] constrs = model.AddConstrs(3);
          // Constraint coefficients for variable x
          double[] coeffs = {1.0, 2.0, 3.0};
          // Create and fill GRBColumn object
          GRBColumn col = new GRBColumn();
          col.AddTerms(coeffs, constrs);

          ' Add 3 trivial linear constraints to model
          Dim constrs As GRBConstr() = model.AddConstrs(3)
          ' Constraint coefficients for variable x
          Dim coeffs As Double() = New Double() {1.0, 2.0, 3.0}
          ' Create and fill GRBColumn object
          Dim col As GRBColumn = 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.

    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 model
          GRBConstr[] constrs = model.AddConstrs(3);
          // Constraint coefficients for variable x
          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);

          ' Add 3 trivial linear constraints to model
          Dim constrs As GRBConstr() = model.AddConstrs(3)
          ' Constraint coefficients for variable x
          Dim coeffs As Double() = New Double() {1.0, 2.0, 3.0}
          ' Create and fill GRBColumn object, but use only first 2 pairs
          Dim col As GRBColumn = New GRBColumn()
          col.AddTerms(coeffs, constrs, 0, 2)

  void Clear()

    Remove all terms from a column.

    Example:

          col.Clear();

          col.Clear()

  double GetCoeff(int i)

    Retrieve the coefficient from a single term in the column.

    Returns:

      Coefficient for the term at index `i` in the column.

    Example:

          // Get the coefficient of first coefficient constraint pair
          double coeff = col.GetCoeff(0);

          ' Get the coefficient of first coefficient constraint pair
          Dim coeff As Double = col.GetCoeff(0)

  GRBConstr GetConstr(int i)

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

    Returns:

      Constraint for the term at index `i` in the column.

    Example:

          // Get the constraint of first coefficient constraint pair
          GRBConstr constr = col.GetConstr(0);

          ' Get the constraint of first coefficient constraint pair
          Dim constr As GRBConstr = col.GetConstr(0)

  GRBConstr Remove(int i)

    Remove the term stored at index `i` of the column.

    Parameters:

      i – The index of the term to be removed.

    Returns:

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

    Example:

          // Remove first coefficient constraint pair
          col.Remove(0);

          ' Remove first coefficient constraint pair
          col.Remove(0)

  boolean Remove(GRBConstr constr)

    Remove the term associated with constraint `constr` from the column.

    Parameters:

      constr – The constraint whose term should be removed.

    Returns:

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

    Example:

          // Remove pair associated with constr1
          bool removed = col.Remove(constr1);

          ' Remove pair associated with constr1
          Dim removed As Boolean = col.Remove(constr1)

  int Size

    (Property) The number of terms in the column.

    Example:

          int s = col.Size;

          Dim s As Integer = col.Size

Help and Feedback

Press `/` or click to search this documentation | Gurobi website | Gurobi community forum
Go to other Gurobi documentation | Gurobi download | Contact support