Skip to content

Commit

Permalink
run black
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbynum committed Feb 11, 2024
1 parent 3ca70d1 commit 4471b7c
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 113 deletions.
25 changes: 17 additions & 8 deletions pyomo/contrib/solver/gurobi.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ def __init__(
visibility=visibility,
)
self.use_mipstart: bool = self.declare(
'use_mipstart',
'use_mipstart',
ConfigValue(
default=False,
domain=bool,
default=False,
domain=bool,
description="If True, the values of the integer variables will be passed to Gurobi.",
)
),
)


Expand Down Expand Up @@ -339,9 +339,12 @@ def _solve(self):
self._solver_model.setParam('MIPGap', config.rel_gap)
if config.abs_gap is not None:
self._solver_model.setParam('MIPGapAbs', config.abs_gap)

if config.use_mipstart:
for pyomo_var_id, gurobi_var in self._pyomo_var_to_solver_var_map.items():
for (
pyomo_var_id,
gurobi_var,
) in self._pyomo_var_to_solver_var_map.items():
pyomo_var = self._vars[pyomo_var_id][0]
if pyomo_var.is_integer() and pyomo_var.value is not None:
self.set_var_attr(pyomo_var, 'Start', pyomo_var.value)
Expand Down Expand Up @@ -866,7 +869,9 @@ def _postsolve(self, timer: HierarchicalTimer):
if status == grb.LOADED: # problem is loaded, but no solution
results.termination_condition = TerminationCondition.unknown
elif status == grb.OPTIMAL: # optimal
results.termination_condition = TerminationCondition.convergenceCriteriaSatisfied
results.termination_condition = (
TerminationCondition.convergenceCriteriaSatisfied
)
elif status == grb.INFEASIBLE:
results.termination_condition = TerminationCondition.provenInfeasible
elif status == grb.INF_OR_UNBD:
Expand Down Expand Up @@ -894,7 +899,11 @@ def _postsolve(self, timer: HierarchicalTimer):
else:
results.termination_condition = TerminationCondition.unknown

if results.termination_condition != TerminationCondition.convergenceCriteriaSatisfied and config.raise_exception_on_nonoptimal_result:
if (
results.termination_condition
!= TerminationCondition.convergenceCriteriaSatisfied
and config.raise_exception_on_nonoptimal_result
):
raise RuntimeError(
'Solver did not find the optimal solution. Set opt.config.raise_exception_on_nonoptimal_result = False to bypass this error.'
)
Expand Down
16 changes: 8 additions & 8 deletions pyomo/contrib/solver/ipopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ def __init__(
implicit_domain=implicit_domain,
visibility=visibility,
)
self.timing_info.no_function_solve_time: Optional[float] = (
self.timing_info.declare(
'no_function_solve_time', ConfigValue(domain=NonNegativeFloat)
)
self.timing_info.no_function_solve_time: Optional[
float
] = self.timing_info.declare(
'no_function_solve_time', ConfigValue(domain=NonNegativeFloat)
)
self.timing_info.function_solve_time: Optional[float] = (
self.timing_info.declare(
'function_solve_time', ConfigValue(domain=NonNegativeFloat)
)
self.timing_info.function_solve_time: Optional[
float
] = self.timing_info.declare(
'function_solve_time', ConfigValue(domain=NonNegativeFloat)
)


Expand Down
4 changes: 3 additions & 1 deletion pyomo/contrib/solver/sol_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ def parse_sol_file(
# TODO: this is solver dependent
# But this was the way in the previous version - and has been fine thus far?
result.solution_status = SolutionStatus.infeasible
result.termination_condition = TerminationCondition.iterationLimit # this is not always correct
result.termination_condition = (
TerminationCondition.iterationLimit
) # this is not always correct
elif (exit_code[1] >= 500) and (exit_code[1] <= 599):
exit_code_message = (
"FAILURE: the solver stopped by an error condition "
Expand Down
Loading

0 comments on commit 4471b7c

Please sign in to comment.