メインコンテンツへスキップ

General constraint for difference between two log functions

回答済み

コメント

5件のコメント

  • 正式なコメント
    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 why not try our AI Gurobot?.
  • Jaromił Najman
    • Gurobi Staff

    Hi Peyman,

    In your case, you don't have to use the addGenConstrPWL function as you don't want to model a custom nonlinear function. For the \(\log\) function, Gurobi already has the addGenConstrLog function which you can use. You can then just use the addGenConstrLog twice to model the two \(\log\) terms in Eq. 39.

    Best regards,
    Jaromił

    0
  • Peyman Noursalehi
    • Gurobi-versary
    • First Comment
    • First Question

    Hi Jaromił,

    Thank you for your help. If I may, can I ask for a short snippet of how that would work? I've spent a good chunk of time on it and am still struggling with it. 

    Let's say Z is an M by N variable:

    z = m.addVars(M, N , name = "weights", vtype=GRB.CONTINUOUS)

    As I understand it, I need to use addGenConstrLog  to add a new variable y = log(z). 

    y = m.addVars(M, N , name = "y", vtype=GRB.CONTINUOUS)
    gc1 = [m.addGenConstrLog(z[m,n], y[m,n]) for m in M for n in N]

    where I guess gc1 is the error code. now for the modeling the difference in logs, it should be something along the lines of 

    for m in M:
    for n in N:
    z[m,n] - z[M[0],n] = B \\some number

    Is this approach correct?

    Best,
    Peyman

    0
  • Jaromił Najman
    • Gurobi Staff

    Hi Peyman,

    The approach is correct. Please note that

    gc1 = [m.addGenConstrLog(z[m,n], y[m,n]) for m in M for n in N]

    may provide an Attribute Error since your model object is called \(\texttt{m}\) and you use \(\texttt{m}\) to iterate over \(\texttt{M}\). Additionally the final constraints should read

    for i in M:
    for n in N:
    m.addConstr(y[i,n] - y[M[0],n] == B, name="logConstr")

    because \(\texttt{y}\) are the actual values of the \(\log(z)\) function, see the documentation of addGenConstrLog.

    Best regards,
    Jaromił

    1
  • Peyman Noursalehi
    • Gurobi-versary
    • First Comment
    • First Question

    Thank you very much Jaromił!

    Best,
    Peyman

    0

投稿コメントは受け付けていません。