I cant see variable notations in printint results
AnsweredHello,
When I write to see variable values i cant see the variable notations in the results.
My variable definition:
x = {}
for j in range (1,3):
for o in range (1,3):
for m in range(1,3):
x[j,o,m] = model.addVar(vtype=GRB.BINARY,name='x')
#Printing Results
for v in model.getVars():
print('%s %g' % (v.varName, v.x))
#My results:
x 1
x 0
x 0
x 1
x 1
x 0
x 0
x 1
why cant I see the results like:
x[1,1,1] 1
x[1,1,2] 0
..
thanks in advance
-
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?. -
Hi Mustafa,
This is because you name all of your variables "x". The addVar uses the provided name since it creates exactly 1 optimization variable. There are multiple ways of how to get the variable names you want. You can either set them manually via
for j in range (1,3):
for o in range (1,3):
for m in range(1,3):
x[j,o,m] = model.addVar(vtype=GRB.BINARY,name="x[%d,%d,%d]"%(j,o,m))or use the addVars method, which will generate these names automatically
J = [1,2]
O = [1,2]
M = [1,2]
x = model.addVars(J, O, M, vtype=GRB.BINARY, name="x")
# access variables via x[j,o,m]Best regards,
Jaromił0
Post is closed for comments.
Comments
2 comments