Skip to main content

Warning: max constraint violation exceeds tolerance

Ongoing

Comments

4 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than three 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.
  • Huilin Feng
    • Gurobi-versary
    • First Comment
    • First Question

    I have found that the problem exists in the log function in the objective. Why addGenConstrLogA brings constraint violation warnings? 

    0
  • Eli Towle
    • Gurobi Staff

    The code you posted is not self-contained, because \( \texttt{R} \), \( \texttt{D} \), \( \texttt{T} \), and other Python variables are not defined. However, I do have a guess about where the constraint violations come from.

    As is the case for all function constraints, Model.addGenConstrLogA() adds a piecewise-linear approximation of the specified function to the model. In your example, Gurobi builds a piecewise-linear approximation of \( y = \log_{10}(x) \), where \( x \) is the variable \( \texttt{tp[d]} \) and \( y \) is the variable \( \texttt{z[d]} \). However, your \( \texttt{tp} \) variables are defined to be nonnegative with no upper bounds. As a result, Gurobi picks a satisfactorily large upper bound \( u, \) then constructs the piecewise approximation of \( y = \log_{10}(x) \) over the domain \( x \in [0, u] \). Even though Gurobi uses a large number of points to construct the piecewise-linear approximation, it can be a poor approximation because these points are thinly stretched across this large domain.

    Can you please try defining the tightest possible bounds on your \( \texttt{tp} \) variables? Note that you can control how Gurobi constructs this piecewise-linear approximation using the FuncPieces, FuncPieceError, FuncPieceLength, and FuncPieceRatio attributes (or the parameters with the same names).

    If you are feeling especially ambitious, you could define your own piecewise-linear constraint using the Model.addGenConstrPWL() method. In particular, because \( \texttt{tp[d]} \) (\(x\)) is integer-valued, you could construct an exact piecewise-linear representation of \( y = \log_{10}(x) \) by building the approximation from the finite set of points \( \{ (x, \log_{10}(x)) : x \in \{\ell, \ell+1, ..., u-1, u\} \} \), where \( [\ell, u] \) defines the domain of \( x \).

    0
  • Huilin Feng
    • Gurobi-versary
    • First Comment
    • First Question

    Hi, Eli. Thank you for your help. I have tried defining the bounds on tp variables, and changed the value of the FuncPieces, FuncPieceError, FuncPieceLength, and FuncPieceRatio attributes. The max constraint violation decreases; however, it drops to 1.9367e-06 and then cannot decrease further no matter how I construct this piecewise-linear approximation using these attributes. So, I still got the warnings: max constraint violation (1.9367e-06) exceeds tolerance & max general constraint violation (1.9367e-06) exceeds tolerance. 

    I was wondering if there is any method to avoid the warnings?

    Thank you very much.

    0

Post is closed for comments.