Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
235b702
Added num_solution checks to balas
viens-code Aug 18, 2025
d1668b5
Added num_solution checks to lp_enum
viens-code Aug 18, 2025
9548607
Add num_solution checks to lp_enum_solnpool
viens-code Aug 18, 2025
ac9f517
Updated gurobi_solnpool to check num_solutions and allow PoolSearchMo…
viens-code Aug 18, 2025
1a83132
Added checks to SolutionPool where max_pool_size exists
viens-code Aug 18, 2025
fe41db1
Added tests for invalid policies in SolutionPool
viens-code Aug 18, 2025
706c8db
Added pool name methods to PoolManager
viens-code Aug 18, 2025
14a33bd
Added policy type to SolutionPoolBase
viens-code Aug 18, 2025
0942029
Added methods to get pool/pools policy and max_pool_sizes
viens-code Aug 18, 2025
2430679
Added get_pool_sizes method
viens-code Aug 18, 2025
de7db76
Changed to .items in dict comprehensions where keys and values needed
viens-code Aug 18, 2025
221be05
Readability tweaks to emphasize active pool and set of pools
viens-code Aug 18, 2025
73fd086
Documentation adds for SolutionPool methods
viens-code Aug 19, 2025
249188e
Documentation Updates
viens-code Sep 2, 2025
09b4d66
Updates sense information in KeepBest pool
viens-code Sep 2, 2025
ec110a0
Enforce pass through behavior with PoolManager to_dict method
viens-code Sep 2, 2025
3e12b37
Added PoolManager to_dict pass through test
viens-code Sep 2, 2025
217bdc6
SolutionPool Updates
viens-code Sep 2, 2025
6262edc
Fixed issues caused by absence of to_dict method in Bunch/MyMunch
viens-code Sep 4, 2025
5f4cdbd
Merge branch 'or-fusion:solnpool' into solnpool
viens-code Sep 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pyomo/contrib/alternative_solutions/aos_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,9 @@ def get_model_variables(


class MyMunch(Munch):

to_dict = Munch.toDict
#WEH, MPV needed to add a to_dict since Bunch did not have one
def to_dict(self):
return _to_dict(self)


def _to_dict(x):
Expand All @@ -319,4 +320,5 @@ def _to_dict(x):
elif xtype in [dict, Munch, MyMunch]:
return {k: _to_dict(v) for k, v in x.items()}
else:
print(f'Here: {x=} {type(x)}')
return x.to_dict()
6 changes: 5 additions & 1 deletion pyomo/contrib/alternative_solutions/balas.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def enumerate_binary_solutions(
model : ConcreteModel
A concrete Pyomo model
num_solutions : int
The maximum number of solutions to generate.
The maximum number of solutions to generate. Must be positive
variables: None or a collection of Pyomo _GeneralVarData variables
The variables for which bounds will be generated. None indicates
that all variables will be included. Alternatively, a collection of
Expand Down Expand Up @@ -83,6 +83,10 @@ def enumerate_binary_solutions(
"""
logger.info("STARTING NO-GOOD CUT ANALYSIS")

assert num_solutions >= 1, "num_solutions must be positive integer"
if num_solutions == 1:
logger.warning("Running alternative_solutions method to find only 1 solution!")

assert search_mode in [
"optimal",
"random",
Expand Down
20 changes: 18 additions & 2 deletions pyomo/contrib/alternative_solutions/gurobi_solnpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def gurobi_generate_solutions(
solver_options={},
tee=False,
poolmanager=None,
pool_search_mode=2,
):
"""
Finds alternative optimal solutions for discrete variables using Gurobi's
Expand All @@ -42,7 +43,7 @@ def gurobi_generate_solutions(
A concrete Pyomo model.
num_solutions : int
The maximum number of solutions to generate. This parameter maps to
the PoolSolutions parameter in Gurobi.
the PoolSolutions parameter in Gurobi. Must be positive.
rel_opt_gap : non-negative float or None
The relative optimality gap for allowable alternative solutions.
None implies that there is no limit on the relative optimality gap
Expand All @@ -59,12 +60,27 @@ def gurobi_generate_solutions(
Boolean indicating that the solver output should be displayed.
poolmanager : None
Optional pool manager that will be used to collect solution
pool_search_mode : 1 or 2
The generation method for filling the pool.
This parameter maps to the PoolSearchMode in gurobi.
Method designed to work with value 2 as optimality ordered.

Returns
-------
poolmanager
A PyomoPoolManager object
"""

assert num_solutions >= 1, "num_solutions must be positive integer"
if num_solutions == 1:
logger.warning("Running alternative_solutions method to find only 1 solution!")

assert pool_search_mode in [1, 2], "pool_search_mode must be 1 or 2"
if pool_search_mode == 1:
logger.warning(
"Running gurobi_solnpool with PoolSearchMode=1, best effort search may lead to unexpected behavior"
)

if poolmanager is None:
poolmanager = PyomoPoolManager()
poolmanager.add_pool("gurobi_generate_solutions", policy="keep_all")
Expand All @@ -78,7 +94,7 @@ def gurobi_generate_solutions(
opt.config.stream_solver = tee
opt.config.load_solution = False
opt.gurobi_options["PoolSolutions"] = num_solutions
opt.gurobi_options["PoolSearchMode"] = 2
opt.gurobi_options["PoolSearchMode"] = pool_search_mode
if rel_opt_gap is not None:
opt.gurobi_options["PoolGap"] = rel_opt_gap
if abs_opt_gap is not None:
Expand Down
6 changes: 5 additions & 1 deletion pyomo/contrib/alternative_solutions/lp_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def enumerate_linear_solutions(
model : ConcreteModel
A concrete Pyomo model
num_solutions : int
The maximum number of solutions to generate.
The maximum number of solutions to generate. Must be positive
rel_opt_gap : float or None
The relative optimality gap for the original objective for which
variable bounds will be found. None indicates that a relative gap
Expand Down Expand Up @@ -83,6 +83,10 @@ def enumerate_linear_solutions(
"""
logger.info("STARTING LP ENUMERATION ANALYSIS")

assert num_solutions >= 1, "num_solutions must be positive integer"
if num_solutions == 1:
logger.warning("Running alternative_solutions method to find only 1 solution!")

assert search_mode in [
"optimal",
"random",
Expand Down
6 changes: 5 additions & 1 deletion pyomo/contrib/alternative_solutions/lp_enum_solnpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def enumerate_linear_solutions_soln_pool(
model : ConcreteModel
A concrete Pyomo model
num_solutions : int
The maximum number of solutions to generate.
The maximum number of solutions to generate. Must be positive.
variables: None or a collection of Pyomo _GeneralVarData variables
The variables for which bounds will be generated. None indicates
that all variables will be included. Alternatively, a collection of
Expand Down Expand Up @@ -134,6 +134,10 @@ def enumerate_linear_solutions_soln_pool(
"""
logger.info("STARTING LP ENUMERATION ANALYSIS USING GUROBI SOLUTION POOL")

assert num_solutions >= 1, "num_solutions must be positive integer"
if num_solutions == 1:
logger.warning("Running alternative_solutions method to find only 1 solution!")

if poolmanager is None:
poolmanager = PyomoPoolManager()
poolmanager.add_pool("enumerate_binary_solutions", policy="keep_all")
Expand Down
Loading