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

Using the value of a decision variable as an argument in Python function

回答済み

コメント

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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • Jonasz Staszek
    • Community Moderator
    • Gurobi-versary
    • Thought Leader
    • First Question

    Hi Niklas,

    the thing you want to achieve can be done, although it won't be easy.

    First of all, rounding can be achieved, although it will require scaling and additional variables.

    Further, I am afraid you won't be able to use constants the way you wish. I would suggest coming up with a (linear) function that will convert the value of a_LTL into the desired value (which would replace looking up the value in alpha_truck dict).

    In terms of pseudocode, this would look something like this:

    aux1 = m.addVar(vtype="C")
    m.addConstr(aux1 == a * a_LTL + b) # it would be up to you to figure out the appropriate a and b

    You would obviously need to include aux1 in the objective function.

    Hope this helps.

    Best regards
    Jonasz

    0
  • Niklas Heidingsfelder
    • Gurobi-versary
    • First Comment
    • First Question

    Hi Jonasz,

    Thank you very much for your helpful feedback! I think I understood your approach.

    Just to make sure that I got it right: Basically, your suggestion would be to determine a function in dependency of "a_LTL" that will give me the corresponding values that I am currently trying to retrieve from the dictionary, right?

    Kind regards,

    Niklas

    0
  • Jonasz Staszek
    • Community Moderator
    • Gurobi-versary
    • Thought Leader
    • First Question

    Hi Niklas,

    Just to make sure that I got it right: Basically, your suggestion would be to determine a function in dependency of "a_LTL" that will give me the corresponding values that I am currently trying to retrieve from the dictionary, right?

    That's correct.
    Best regards
    Jonasz
    0
  • Niklas Heidingsfelder
    • Gurobi-versary
    • First Comment
    • First Question

    Hi Jonasz,

    Ok, thanks for the confirmation!

    Best regards,

    Niklas

    0

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