unfeasible_tools#

Module containing functions to diagnose unfeasible LP problems.

This module contains the following functions:

  • find_iis: finds a set of constraints that when removed make the problem solvable.

  • handle_unsolved_problem: fixes common issues that might be making the optimization problem unsolvable (like variables without bounds, or with upper-bound smaller than its lower-bound).

  • fix_variables_limits: Fixes issues caused when variables lower- and upper-bounds are wrongfully set.

wip.model_diagnostics.unfeasible_tools.analyze_unfeasible_problems(outputs_folder_path: Path | str | None = None) Dict[str, List[pulp.LpConstraint]][source]#

Analyze unfeasible problems in the outputs folder.

Parameters

outputs_folder_path (Path | str | None) – Path to the outputs’ folder. If None, the default outputs folder is used :param:`wip.constants.OTM_OUTPUTS_FOLDER_PATH`. The parameter :param:`outputs_folder_path` must contain the ‘.mps’ files that correspond to the optimization problems to analyze.

Returns

Returns a dictionary with the name of the problem as the key and a list of the infeasible constraints as value.

Return type

Dict[str, List[pulp.LpConstraint]]

wip.model_diagnostics.unfeasible_tools.find_iis(infeasible_model: LpProblem, **solver_kwargs) Tuple[LpProblem, set][source]#

Compute the Irreducible Infeasible Set (IIS) of an infeasible LP problem.

An IIS is a minimal set of constraints that makes the problem infeasible. This function computes the IIS of a given infeasible LP problem using the PuLP library.

The function deactivates each constraint and checks if the problem is still infeasible. Then the function iterates over the deactivated constraints, adding them back to the problem and checking whether it makes the problem infeasible. If the problem becomes infeasible, then the constraint is added to the IIS set and removed once more from the LP problem.

Parameters
  • infeasible_model (pulp.LpProblem) – An infeasible LP problem defined using the PuLP library.

  • **solver_kwargs (Any) – Optional keyword arguments to pass to the solver. Either specify an input parameter named solver that’s an instance of a valid PuLP solver, or specify the solver’s parameters as keyword arguments.

Returns

  • Tuple[pulp.LpProblem, set] – The unfeasible relaxed problem and a set containing the names of the constraints that form an IIS.

  • hint:: – Because this function solves many iterations of the optimization problem, a considerable number of logs are generated. You can suppress these logs by including a parameter msg=False to the function’s input parameters.

Return type

Tuple[LpProblem, set]

wip.model_diagnostics.unfeasible_tools.fix_variables_limits(prob: LpProblem, verbose: bool = True) LpProblem[source]#

Fix the limits of the variables in the optimization problem.

This function fixes the following problems with the variables limits:

  • Sets the lower-bound to -10,000 if it is not defined.

  • Sets the upper-bound to 10,000 if it is not defined.

  • Inverts the upper and lower bounds if the upper-bound is smaller than the lower-bound.

The function only executes the fixes if the optimization problem status is equal to ‘Undefined’ (-3), ‘Unbounded’ (-2) or ‘Not Solved’ (0).

Parameters
  • prob (pulp.LpProblem) – Optimization problem to fix the variables’ limits.

  • verbose (bool, default True) – Whether to print the name of the variables that had their limits fixed.

Returns

Optimization problem with the variables’ limits fixed.

Return type

pulp.LpProblem

wip.model_diagnostics.unfeasible_tools.handle_unsolved_problem(problem: LpProblem, errors: str = 'raise', **solver_kwargs) LpProblem[source]#

Handle an unsolved problem.

This function handles an unsolved problem by fixing the variables’ limits and trying to solve the problem again.

Parameters
  • problem (pulp.LpProblem) – An unsolved LP problem defined using the PuLP library.

  • errors (str {'raise', 'ignore'}, default 'raise') – How to handle errors. If ‘raise’, then an exception is raised. If ‘ignore’, then the original problem is returned.

  • **solver_kwargs (Any) – Optional keyword arguments to pass to the solver. Either specify an input parameter named solver that’s an instance of a valid PuLP solver, or specify the solver’s parameters as keyword arguments.

Returns

The fixed LP problem.

Return type

pulp.LpProblem

Raises

ValueError – If resolve is set to False and problem status is ‘not solved’. If errors is set to 'ignore', and the problem fails to be solved.

See also

fix_variables_limits

Fix the limits of the variables in the optimization problem.