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


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

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)

# add constraints
m.c = ConstraintList()
m.c.add(sum(m.P[g] for g in G)== 100)
for g in G:   
     m.c.add(m.P[g] <= generator[g]['up'])
     m.c.add(m.P[g] >= generator[g]['down'])

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

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

  • $\begingroup$ 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). $\endgroup$ – Erwin Kalvelagen Jan 19 at 9:43
  • $\begingroup$ 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! $\endgroup$ – ssswokao Jan 20 at 3:58
  • $\begingroup$ (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. $\endgroup$ – Erwin Kalvelagen Jan 20 at 5:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.