Skip to main content

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

Answered

Comments

2 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support.
  • Riley Clement
    • 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

    0

Post is closed for comments.