# Find multiple solutions in Pyomo with Gurobi

I am fairly new to Pyomo and Gurobi. I'd like to find 20 sets of different solutions that meet the following constraints.

constraints：
10<=x1<=20
12<=x2<=32
5<=x3<=15
5<=x4<=52
x1+x2+x3+x4=100.


From here I learned Gurobi has PoolSolutions, so I decided to have a try.

from gurobipy import GRB
import numpy as np
from pyomo.environ import *
import matplotlib.pyplot as plt

generator={
1 :{'down':10,  'up':20,},
2 :{'down':12,  'up':32,},
3 :{'down':5,   'up':15,},
4 :{'down':5,   'up':52,},
}
G = generator.keys()

# create a new model
m = ConcreteModel()

# create variables
m.P = Var(G, domain=NonNegativeReals)

# set objective
m.OBJ = Objective(expr = 0)

m.c = ConstraintList()
m.c.add(sum(m.P[g] for g in G)== 100)
for g in G:

# try to get 20 sets of different solutions
n_of_s = 20
opt = SolverFactory('gurobi_persistent')
opt.set_instance(m)
opt.set_gurobi_param('PoolSolutions', n_of_s)
opt.set_gurobi_param('PoolSearchMode', 2)
opt.solve()


But it doesn't work properly. Hope somebody could teach me how to modify this and how to show the results of 20 solutions. Any suggestions are welcomed. THX

• The solution pool is only for integer problems. It does not generate multiple solutions for a continuous problem. Of course, you can generate 20 different solutions for your continuous problem by just perturbing the solution by some epsilon. So, maybe you want 20 different corner points (basis solutions). – Erwin Kalvelagen Jan 19 at 9:43
• Thank you @ Erwin Kalvelagen！After I replace NonNegativeReals with NonNegativeIntegers, opt.get_model_attr('SolCount') returns 20, so I think 20 basis solutions are found. Do you know how to show all solutions? In Gurobi I can use xn, but how can I do that with pyomo,thanks! – ssswokao Jan 20 at 3:58
• (1) Changing your continuous variables into integer variables is not the same as finding basis solutions of the original continuous problem. That is a bit more complicated, I am afraid. Here is an approach to find all optimal basis solutions of an LP: yetanothermathprogrammingconsultant.blogspot.com/2016/01/…. (A constant objective will find all feasible basis solutions). (2) You set the pool capacity to 20 so Gurobi will not find more than 20. Just increase the capacity to a large number. – Erwin Kalvelagen Jan 20 at 5:38