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

Define initial value of variable

回答済み

コメント

7件のコメント

  • 正式なコメント
    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 Sarah,

    Could you elaborate more on what exactly are you trying to achieve?

    Are you trying to add equality constraints forcing the values \(\texttt{f[i,k-1]}\) and \(\texttt{f[i,0]}\) to 0?

    This can be achieved via

    k_minus_one = len(operations)-1
    m.addConstrs(f[i, k_minus_one] == 0 for i in drones, name = "f_i_k-1_constraints")
    m.addConstrs(f[i, 0] == 0 for i in drones, name = "f_i_0_constraint")

    Or are you trying to provide a starting point? This can be achieved via setting of the variable Start attribute

    k_minus_one = len(operations)-1
    for i in drones:
    f[i,0].Start = 0
    f[i,k_minus_one].Start = 0

    Best regards,
    Jaromił

    0
  • Sarah Wendler
    • Gurobi-versary
    • First Comment
    • First Question

    Hi Jaromil, 

    thank you for your fast reply.

    So f[i, k] is supposed to be the battery charge after drone i finishes its kth operation. The initial battery charge is set to 0. 

    So i guess your second suggestion with the starting point is the right modeling for this case? Would this be correct? 

    Best regards, 

    Sarah 

    0
  • Sarah Wendler
    • Gurobi-versary
    • First Comment
    • First Question

    Hi Jaromil, 

    I just added it to my model and it gave me the following error: Do you know why this could happen? 

    Best regards, 

    Sarah

    0
  • Jaromił Najman
    • Gurobi Staff

    Hi Sarah,

    So f[i, k] is supposed to be the battery charge after drone i finishes its kth operation. The initial battery charge is set to 0.

    So i guess your second suggestion with the starting point is the right modeling for this case? Would this be correct?

    If you don't require \(\texttt{f[i,k-1]}\) to be 0 in the final solution but only want to provide a good first guess, then yes, it is the correct way.

    KeyError: (1,0)

    means that there is no entry \(\texttt{f[1,0]}\). Please note that I was only guessing the key entries due to missing variable creation information. Looking at your sets, maybe you meant that \(\texttt{f[1,1]}\) has to be 0?

    Best regards,
    Jaromił

    0
  • Sarah Wendler
    • Gurobi-versary
    • First Comment
    • First Question

    Hi Jaromil, 

    f[i, k-1] only has to be 0 if k = 1 

    After operation k > 1 k_minus_one is not supposed to be 0 anymore

    The range of k is supposed to be from 1 to 20: operations = [*range(1,21)]

    This is the variable information for f:

    f = m.addVars(drones, operations, vtype=GRB.CONTINUOUS, name='f')

    I'm still not sure so it would be nice if you could check again. 

    Best regards, 

    Sarah

     

    0
  • Jaromił Najman
    • Gurobi Staff

    Hi Sarah,

    f[i, k-1] only has to be 0 if k = 1

    This sounds to me like you want to enforce that \(\texttt{f[i, k-1] = 0}\). Thus, you should go with my first suggestion and add the corresponding equality constraints to your model.

    You will very likely have to adjust the keys to to fit your code.

    Best regards,
    Jaromił

    0

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