Skip to main content

Logarithm with parameterized variables on Python

Answered

Comments

3 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.
  • Eli Towle
    • Gurobi Staff

    Given Var objects \(\texttt{x}\) and \(\texttt{y}\), you can add the constraint \( y = \textrm{ln}(x) \) using Model.addGenConstrLog() as follows:

    x = model.addVar(name="x")
    y = model.addVar(name="y")

    model.addGenConstrLog(x, y)

    To add multiple general constraints, you can iterate over your indices and add the constraints one by one. Here is another example that models the \(n\) constraints \( y_i = \textrm{ln}(x_i) \) for \(i = 0, \ldots, n-1\):

    n = 5
    x = model.addVars(n, name="x")
    y = model.addVars(n, name="y")

    for i in range(n):
        model.addGenConstrLog(x[i], y[i])

    The two arguments to Model.addGenConstrLog() should both be Var objects. What exactly are you trying to model, and how do you define \(\texttt{x}\) and \(\texttt{y}\)?

    0
  • Iason Liagkas
    • Gurobi-versary
    • Detective
    • Thought Leader

    No I know how to define x, and y. They are multi-parameter variables and from what you say I have to put the for outside of the logarithm function. That was something I was not aware of. You have answered my question Eli. 

    Kind regards
    Iason

    0

Post is closed for comments.