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

Logarithm with parameterized variables on Python

回答済み

コメント

2件のコメント

  • 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

サインインしてコメントを残してください。