Skip to content
Open
18 changes: 8 additions & 10 deletions pyomo/devel/initialization/global_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ def _initialize_with_global_solver(
'interfaces, so the global solvers are limited to ScipDirect, '
'ScipPersistent, and GurobiDirectMINLP.'
)
# Check if time limit is provided for global solver
if global_solver.config.time_limit is None:
logger.warning(
'No time limit set for global optimizer. '
'For a large model, this may take a long time. '
'Consider setting a time limit using global_solver.config.time_limit.'
)

res = global_solver.solve(
nlp,
load_solutions=True,
Expand All @@ -40,15 +48,5 @@ def _initialize_with_global_solver(
logger.info(
f'solved NLP with {global_solver.name}: {res.solution_status}, {res.termination_condition}'
)
res = nlp_solver.solve(
nlp, load_solutions=False, raise_exception_on_nonoptimal_result=False
)
logger.info(
f'solved NLP with {nlp_solver.name}: {res.solution_status}, {res.termination_condition}'
)
if res.solution_status in {SolutionStatus.feasible, SolutionStatus.optimal}:
res.solution_loader.load_vars()
else:
logger.warning('initialization was not successful via global optimization')

return res
45 changes: 43 additions & 2 deletions pyomo/devel/initialization/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,23 @@ def initialize_with_piecewise_linear_approximation(
finally:
_cleanup(orig_var_data)

# Commented out while I fix testing
Comment thread
stephenscini marked this conversation as resolved.
Outdated
# # Try final nlp solve

# # solve the original problem from the initialized solution
# nlp_res = nlp_solver.solve(
# nlp, load_solutions=False, raise_exception_on_nonoptimal_result=False
# )
# logger.info(
# f'solved NLP: {nlp_res.solution_status}, {nlp_res.termination_condition}'
# )

# if nlp_res.solution_status in {SolutionStatus.feasible, SolutionStatus.optimal}:
# nlp_res.solution_loader.load_vars()
# else:
# logger.warning('initialization was not successful via LP approximation')

# return nlp_res
return res


Expand Down Expand Up @@ -239,7 +256,20 @@ def initialize_with_LP_approximation(
finally:
_cleanup(orig_var_data)

return res
# solve the original problem from the initialized solution
nlp_res = nlp_solver.solve(
nlp, load_solutions=False, raise_exception_on_nonoptimal_result=False
)
logger.info(
f'solved NLP: {nlp_res.solution_status}, {nlp_res.termination_condition}'
)

if nlp_res.solution_status in {SolutionStatus.feasible, SolutionStatus.optimal}:
nlp_res.solution_loader.load_vars()
else:
logger.warning('initialization was not successful via LP approximation')
Comment thread
stephenscini marked this conversation as resolved.
Outdated

return nlp_res


def initialize_with_global_opt(
Expand Down Expand Up @@ -293,4 +323,15 @@ def initialize_with_global_opt(
finally:
_cleanup(orig_var_data)

return res
nlp_res = nlp_solver.solve(
nlp, load_solutions=False, raise_exception_on_nonoptimal_result=False
)
logger.info(
f'solved NLP with {nlp_solver.name}: {nlp_res.solution_status}, {nlp_res.termination_condition}'
)
if nlp_res.solution_status in {SolutionStatus.feasible, SolutionStatus.optimal}:
nlp_res.solution_loader.load_vars()
else:
logger.warning('initialization was not successful via global optimization')

return nlp_res
Comment thread
stephenscini marked this conversation as resolved.
Outdated
15 changes: 1 addition & 14 deletions pyomo/devel/initialization/lp_approx_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,4 @@ def _initialize_with_LP_approximation(
)
logger.info(f'solved LP: {lp_res.solution_status}, {lp_res.termination_condition}')

# try solving the NLP
nlp_res = nlp_solver.solve(
orig_nlp, load_solutions=False, raise_exception_on_nonoptimal_result=False
)
logger.info(
f'solved NLP: {nlp_res.solution_status}, {nlp_res.termination_condition}'
)

if nlp_res.solution_status in {SolutionStatus.feasible, SolutionStatus.optimal}:
nlp_res.solution_loader.load_vars()
else:
logger.warning('initialization was not successful via LP approximation')

return nlp_res
return lp_res