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

Modifying values of variables-Python

回答済み

コメント

3件のコメント

  • Marika Karbstein
    • Gurobi Staff

    Hi Emanuele,

    The X attribute is the solution value and is not modifiable. If you want to define a start solution, you need to set the Start attribute.

    Hope this helps,
    Marika

    0
  • Emanuele Pizzari
    • Gurobi-versary
    • First Question
    • First Comment

    Hi Marika,

    I modified the code. However, when I ask to print the Start attribute, the value is the same, i.e. 1e+101. I also tried to not optimize before, but I am not sure it matters. For reference, I have 4 continuous variables, lb=0 ub=inf. The first array I am trying to use is [1.66666667 0.3333333 0. 0.]. What I am trying to do is to give values to certain variables and then check if the body of some constraints is equal to the constant term (this last part is not written yet, I will take care of it later, but I think it helps understand the general scope of the code)

    m = Model()
    m = gb.read(filepath)
    m.optimize()
    m.update()
    variables = m.getVars()
    A_C,B = create_data()
    results,soluzioni_da_testare =algorithm(A_C,B)
    for i in soluzioni_da_testare:
    for var, value in zip(variables, i):
    var.setAttr(GRB.Attr.Start, value)
    print(var.Start)
    0
  • Emanuele Pizzari
    • Gurobi-versary
    • First Question
    • First Comment

    I forgot to update the model. Now it works

     

    0

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