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

# gurobipy.GenConstr

class GenConstr

  Gurobi general constraint object. General constraints are always associated with a particular model. You add a general constraint to a model either by using one of the `Model.addGenConstr*` methods, or by using `Model.addConstr` or `Model.addConstrs` plus a general constraint helper function).

  General constraint objects have a number of attributes, which can be queried with the `GenConstr.getAttr` method.

  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.

  getAttr(attrname)

    Query the value of a general constraint attribute.

    Raises an `AttributeError` if the requested attribute doesn’t exist or can’t be queried. Raises a `GurobiError` if there is a problem with the `GenConstr` object (e.g., it was removed from the model).

    Parameters:

      attrname – The attribute being queried.

    Returns:

      The current value of the requested attribute.

    Example:

          print(genconstr.getAttr(GRB.Attr.GenConstrType))
          print(genconstr.getAttr("GenConstrType"))

  setAttr(attrname, newvalue)

    Set the value of a general constraint attribute. Note that, due to our lazy update approach, the change won’t actually take effect until you update the model (using `Model.update`), optimize the model (using `Model.optimize`), or write the model to disk (using `Model.write`).

    Raises an `AttributeError` if the specified attribute doesn’t exist or can’t be set. Raises a `GurobiError` if there is a problem with the `GenConstr` object (e.g., it was removed from the model).

    Parameters:

      - attrname – The attribute being modified.

      - newvalue – The desired new value of the attribute.

Help and Feedback

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