get the variable value from list
AnsweredI am using call back to solve an LP , when the where value is simplex I am saving the values of a variable in a list called "variables" and send it to a function as follows:
if where == GRB.Callback.SIMPLEX:
# Simplex callback
obj = model.cbGet(GRB.Callback.SPX_OBJVAL)
variables = model.getVars()
getSubSolution(variables)
then I am trying to read the value of the variables as follows:
def getSubSolution(variables):
y = variables
for i in range(1, n):
print(y[i].X)
but I got the following error message :
in gurobipy.__getattr
AttributeError: Unable to retrieve attribute 'X'
moreover, the variables are not ordered in the list :
[<gurobi.Var y10>, <gurobi.Var y15>, <gurobi.Var y19>, <gurobi.Var y35>, <gurobi.Var y1>, <gurobi.Var y2>, <gurobi.Var y3>, <gurobi.Var y4>, <gurobi.Var y5>, <gurobi.Var y6>, <gurobi.Var y7>, <gurobi.Var y8>, <gurobi.Var y9>, <gurobi.Var y11>, <gurobi.Var y12>, <gurobi.Var y13>, <gurobi.Var y14>, <gurobi.Var y16>, <gurobi.Var y17>, <gurobi.Var y18>, <gurobi.Var y20>, <gurobi.Var y21>, <gurobi.Var y22>, <gurobi.Var y23>, <gurobi.Var y24>, <gurobi.Var y25>, <gurobi.Var y26>, <gurobi.Var y27>, <gurobi.Var y28>, <gurobi.Var y29>, <gurobi.Var y30>, <gurobi.Var y31>, <gurobi.Var y32>, <gurobi.Var y33>, <gurobi.Var y34>]
-
Official comment
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?. -
There unfortunately isn't a way to query intermediate solution values from the simplex algorithm while it is running. See the Callback Codes section of the documentation for a full list of what can be queried when \( \texttt{where == GRB.Callback.SIMPLEX} \).
Note that the X variable attribute only assumes a value once the optimization is complete. It can't be queried while the optimization is in progress.
0
Post is closed for comments.
Comments
2 comments