Skip to content

Commit

Permalink
improve mindtpy logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ZedongPeng committed Dec 1, 2023
1 parent 65e58f5 commit c8eead9
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions pyomo/contrib/mindtpy/algorithm_base_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ def __init__(self, **kwds):
self.log_formatter = (
' {:>9} {:>15} {:>15g} {:>12g} {:>12g} {:>7.2%} {:>7.2f}'
)
self.termination_condition_log_formatter = (
' {:>9} {:>15} {:>15} {:>12g} {:>12g} {:>7.2%} {:>7.2f}'
)
self.fixed_nlp_log_formatter = (
'{:1}{:>9} {:>15} {:>15g} {:>12g} {:>12g} {:>7.2%} {:>7.2f}'
)
Expand Down Expand Up @@ -1919,11 +1922,6 @@ def handle_main_max_timelimit(self, main_mip, main_mip_results):
"""
# If we have found a valid feasible solution, we take that. If not, we can at least use the dual bound.
MindtPy = main_mip.MindtPy_utils
self.config.logger.info(
'Unable to optimize MILP main problem '
'within time limit. '
'Using current solver feasible solution.'
)
copy_var_list_values(
main_mip.MindtPy_utils.variable_list,
self.fixed_nlp.MindtPy_utils.variable_list,
Expand All @@ -1932,10 +1930,10 @@ def handle_main_max_timelimit(self, main_mip, main_mip_results):
)
self.update_suboptimal_dual_bound(main_mip_results)
self.config.logger.info(
self.log_formatter.format(
self.termination_condition_log_formatter.format(
self.mip_iter,
'MILP',
value(MindtPy.mip_obj.expr),
'maxTimeLimit',
self.primal_bound,
self.dual_bound,
self.rel_gap,
Expand All @@ -1962,8 +1960,18 @@ def handle_main_unbounded(self, main_mip):
# to the constraints, and deactivated for the linear main problem.
config = self.config
MindtPy = main_mip.MindtPy_utils
config.logger.info(
self.termination_condition_log_formatter.format(
self.mip_iter,
'MILP',
'Unbounded',
self.primal_bound,
self.dual_bound,
self.rel_gap,
get_main_elapsed_time(self.timing),
)
)
config.logger.warning(
'main MILP was unbounded. '
'Resolving with arbitrary bound values of (-{0:.10g}, {0:.10g}) on the objective. '
'You can change this bound with the option obj_bound.'.format(
config.obj_bound
Expand Down

0 comments on commit c8eead9

Please sign in to comment.