Skip to main content

Warning: max constraint violation (9.2015e-06) exceeds tolerance



1 comment

  • Riley Clement
    Gurobi Staff Gurobi Staff

    Hi Sudheer,

    The following code snippet should help:

    def get_constr_from_index(model, index):

        constr_boundaries_and_get = (
            (model.NumConstrs, model.getConstrs),
            (model.NumQConstrs, model.getQConstrs),
            (model.NumSOS, model.getSOSs),
            (model.NumGenConstrs, model.getGenConstrs),
        for boundary, get_func in constr_boundaries_and_get:
            if index < boundary:
                return get_func()[index]
            index -= boundary
        raise ValueError(f"Constraint with index {index} not found in model")

    def get_max_violated_constr(model):
        constr = get_constr_from_index(model, model.ConstrVioIndex)
        return constr

    max_violated_constr = get_max_violated_constr(model)

    The max_violated_constr will then be the constraint you're looking for.

    - Riley


Please sign in to leave a comment.