Modifying values of variables-Python
AnsweredHi,
I am trying to update the values of the variables of my model, but the message error "Attribute 'X' cannot be set" keeps popping up. In the code, I read the model from a .mps file, update it, and optimize it. A_C and B are a panda dataframe and an array, respectively. Soluzioni_da_testare is another array, whose length is the same as the length of the variables array. What I am doing incorrectly?
The code is the following:
m = Model()
m = gb.read(filepath)
m.update()
variables = m.getVars()
m.optimize()
A_C,B = create_data() #this is a function
results,soluzioni_da_testare =algorithm(A_C,B) #this is a function
for i in soluzioni_da_testare:
for var, value in zip(variables, i):
var.setAttr(GRB.Attr.X, value)
-
Official comment
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. -
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 -
I forgot to update the model. Now it works
0
Post is closed for comments.
Comments
4 comments