@@ -30,6 +30,7 @@ def gurobi_generate_solutions(
3030 solver_options = {},
3131 tee = False ,
3232 poolmanager = None ,
33+ pool_search_mode = 2 ,
3334):
3435 """
3536 Finds alternative optimal solutions for discrete variables using Gurobi's
@@ -42,7 +43,7 @@ def gurobi_generate_solutions(
4243 A concrete Pyomo model.
4344 num_solutions : int
4445 The maximum number of solutions to generate. This parameter maps to
45- the PoolSolutions parameter in Gurobi.
46+ the PoolSolutions parameter in Gurobi. Must be positive.
4647 rel_opt_gap : non-negative float or None
4748 The relative optimality gap for allowable alternative solutions.
4849 None implies that there is no limit on the relative optimality gap
@@ -59,12 +60,27 @@ def gurobi_generate_solutions(
5960 Boolean indicating that the solver output should be displayed.
6061 poolmanager : None
6162 Optional pool manager that will be used to collect solution
63+ pool_search_mode : 1 or 2
64+ The generation method for filling the pool.
65+ This parameter maps to the PoolSearchMode in gurobi.
66+ Method designed to work with value 2 as optimality ordered.
6267
6368 Returns
6469 -------
6570 poolmanager
6671 A PyomoPoolManager object
6772 """
73+
74+ assert num_solutions >= 1 , "num_solutions must be positive integer"
75+ if num_solutions == 1 :
76+ logger .warning ("Running alternative_solutions method to find only 1 solution!" )
77+
78+ assert pool_search_mode in [1 , 2 ], "pool_search_mode must be 1 or 2"
79+ if pool_search_mode == 1 :
80+ logger .warning (
81+ "Running gurobi_solnpool with PoolSearchMode=1, best effort search may lead to unexpected behavior"
82+ )
83+
6884 if poolmanager is None :
6985 poolmanager = PyomoPoolManager ()
7086 poolmanager .add_pool ("gurobi_generate_solutions" , policy = "keep_all" )
@@ -78,7 +94,7 @@ def gurobi_generate_solutions(
7894 opt .config .stream_solver = tee
7995 opt .config .load_solution = False
8096 opt .gurobi_options ["PoolSolutions" ] = num_solutions
81- opt .gurobi_options ["PoolSearchMode" ] = 2
97+ opt .gurobi_options ["PoolSearchMode" ] = pool_search_mode
8298 if rel_opt_gap is not None :
8399 opt .gurobi_options ["PoolGap" ] = rel_opt_gap
84100 if abs_opt_gap is not None :
0 commit comments