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

# GRBGenConstr

GRBGenConstr

  Gurobi general constraint object. General constraints are always associated with a particular model. You create a general constraint object by adding a general constraint to a model (using one of the `GRBModel.addGenConstr*` methods), rather than by using a `GRBGenConstr` constructor.

  The methods on general constraint objects are used to get and set constraint attributes. For example, general constraint types can be queried by calling `get` (`GRB.IntAttr.GenConstrType`). 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.

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

    Query the value of a general constraint attribute.

    Arguments:

      attr – The attribute being queried.

    Return value:

      The current value of the requested attribute.

    Example:

          // Get PWL approximation error
          double funcpieceerror = gc.get(GRB.DoubleAttr.FuncPieceError);
          // Get general constraint type
          int type = gc.get(GRB.IntAttr.GenConstrType);
          // Get general constraint name
          String name = gc.get(GRB.StringAttr.GenConstrName);

  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 a general constraint attribute.

    Arguments:

      - attr – The attribute being modified.

      - newval – The desired new value of the attribute.

    Example:

          // Set PWL approximation error
          gc.set(GRB.DoubleAttr.FuncPieceError, 1e-4);
          // Set number of PWL pieces
          gc.set(GRB.IntAttr.FuncPieces, 100);
          // Set name of general constraint
          gc.set(GRB.StringAttr.GenConstrName, "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