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

# GRBConstr

GRBConstr

  Gurobi constraint object. Constraints are always associated with a particular model. You create a constraint object by adding a constraint to a model (using `GRBModel.addConstr`), rather than by using a `GRBConstr` constructor.

  The methods on constraint objects are used to get and set constraint attributes. For example, constraint right-hand sides can be queried by calling `get` (`GRB.DoubleAttr.RHS`). Note, however, that it is generally more efficient to query attributes for a set of constraints at once. This is done using the attribute query method on the `GRBModel` object (`GRBModel.get`).

  The full list of attributes can be found in the Attributes section of this document. Examples of how to query and set attributes can also be found in this section.

  char get(GRB.CharAttr attr)
  double get(GRB.DoubleAttr attr)
  int get(GRB.IntAttr attr)
  String get(GRB.StringAttr attr)

    Query the value of an attribute.

    Arguments:

      attr – The attribute being queried.

    Return value:

      The current value of the requested attribute.

    Example:

          // Get constraint sense
          char sense = constr.get(GRB.CharAttr.Sense);
          // Get RHS of the constraint
          double rhs = constr.get(GRB.DoubleAttr.RHS);
          // Get CBasis value
          int cbasis = constr.get(GRB.IntAttr.CBasis);
          // Get constraint name
          String name = constr.get(GRB.StringAttr.ConstrName);

  int index()

    This method returns the current index, or order, of the constraint in the underlying constraint matrix.

    Note that the index of a constraint may change after subsequent model modifications.

    Return value:

      -2: removed, -1: not in model, otherwise: index of the constraint in the model

    Example:

          // Get the index of the constraint in the model
          int index = constr.index();

  boolean sameAs(GRBConstr otherConstr)

    Check whether two constraint objects refer to the same constraint.

    Arguments:

      otherConstr – The other constraint.

    Return value:

      Boolean result indicates whether the two constraint objects refer to the same model constraint.

    Example:

          // Compare the constraint with another constraint
          boolean isSame = constr.sameAs(otherConstr);

  void set(GRB.CharAttr attr, char newval)
  void set(GRB.DoubleAttr attr, double newval)
  void set(GRB.IntAttr attr, int newval)
  void set(GRB.StringAttr attr, String newval)

    Set the value of an attribute.

    Arguments:

      - attr – The attribute being modified.

      - newval – The desired new value of the attribute.

    Example:

          // Set constraint sense
          constr.set(GRB.CharAttr.Sense, '>');
          // Set RHS of the constraint
          constr.set(GRB.DoubleAttr.RHS, 2.0);
          // Set CBasis value
          constr.set(GRB.IntAttr.CBasis, 0);
          // Set constraint name
          constr.set(GRB.StringAttr.ConstrName, "newName");

Help and Feedback

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