Hi,
I am trying to select some of the variables returned by the solver, but I keep getting errors.
As shown below, the model returns 2 w variables (w_0 and w_1), 6 Z variables (Z_0,...,Z_5), and an intercept 'b'.
(In red, the values I would like to retrieve).
print(model.getVars())
Optimal objective 1.127659574e+01
[<gurobi.Var w_0 (value 0.19148936170212763)>, <gurobi.Var w_1 (value -0.148936170212766)>, <gurobi.Var Z_0 (value 5.787234042553191)>, <gurobi.Var Z_1 (value 0.0)>, <gurobi.Var Z_2 (value 0.0)>, <gurobi.Var Z_3 (value 2.723404255319149)>, <gurobi.Var Z_4 (value 0.0)>, <gurobi.Var Z_5 (value 2.76595744680851)>, <gurobi.Var b (value 3.4255319148936176)>]
In order to retrieve the intercept, I type:
b = b.X
print(b)
And I successfully get the value 3.4255319148936176
But I haven't managed to get the coefficients w[0] and w[1] ("w" being a list and n = 2).
I have tried:
for i in range(n):
w = [x for x in model.getVars() if x.VarName.find('w_%d' %i)]
for i in range(n):
w = [v.x for v in m.getVars()]
and other countless things, but none of them print 0.19148936170212763 and -0.148936170212766. The second one prints me the values of all the variables in getVars(), even if the range is only n=2.
Any hint on how to do it?
Thank you!