-2

so I have a problem when it process for printing variables, it can get a result but can not print the variables

I is months, J is productsname so my setting variables

w_permanent = M.addVars (J , I , lb=0 , vtype=GRB.INTEGER, obj=salary)
w_temporary = M.addVars (J , I , lb=0 , vtype=GRB.INTEGER ,     obj=salary )
w_hire      = M.addVars (    I , lb=0 , vtype=GRB.INTEGER ,     obj=cost_hire[j])
w_fire      = M.addVars (    I , lb=0 , vtype=GRB.INTEGER ,     obj=cost_fire[j])
Stock       = M.addVars (J , I , lb=0 , vtype=GRB.CONTINUOUS ,  obj=b)

if M.status == GRB.Status.OPTIMAL: 
    print ('Total cost : %10.2f euro' % M.objVal)
    print ('')
    print ('All decision variables:\n')
    print ('Stock per month per product:\n')
    for i in I:
        for j in J:
            print('x1 = %f' % w_permanent[i,j].w_permanent)
joni
  • 6,840
  • 2
  • 13
  • 20
Ruomei
  • 1
  • 1
  • 1

1 Answers1

0

Use the .X attribute to get the value of a variable in the current solution:

print('x1 = %f' % w_permanent[i,j].X)
joni
  • 6,840
  • 2
  • 13
  • 20