azin rashidi pour
azin rashidi pour

Reputation: 1

How to access the attributes of a feasible solution in Gurobi Python model?

I have solved a Gurobi- Python model. Consider that for example during the optimization, this text is printed in the Run part: "Solution count 5: 131320 135861 179634 ... 192440" For each of these feasible and optimal objective values, there are too many solutions. for each of these 5 values, I want to access the variables of only one solution. (one solution with obj value=131320, one solution with obj value=135861 and so on).

I used this code: " nSolutions = model.SolCount for e in range(nSolutions):

    model.setParam(GRB.Param.SolutionNumber, e)
    Obj = model.PoolObjVal
    y_value = model.getAttr('X', y)

"

the problem is that for every e, the y_value is the values of variable y of the Optimal solution not the solution which objective value is equal to Obj.

I want the y_value of that feasible solution not the optimal one.

Upvotes: 0

Views: 68

Answers (1)

Riley
Riley

Reputation: 2261

Use the Xn attribute. Eg, for Python

model.params.SolutionNumber=2
y_value = y.Xn

Upvotes: 0

Related Questions