Solvers & settings#
An external solver is required to solve the optimization problem formulated by the model. This section provides an overview of the supported solvers and how to configure them. The module oM_ProblemSolving manages the process of calling the selected solver.
Supported solvers#
The model supports the following solvers:
Gurobi#
Gurobi is a commercial solver that requires a license. It is not installed automatically and must be installed separately by the user. You can find installation instructions on the official Gurobi website.
Example installation commands:
# Using pip
pip install gurobipy
# Using conda
conda config --add channels http://conda.anaconda.org/gurobi
conda install gurobi
HiGHS & CBC#
HiGHS and CBC are open-source solvers. They are downloaded and installed automatically by functions within the oM_SolverSetup module if they are not already present in your environment. No manual installation is typically required.
Configuration#
The solver configuration is managed by the oM_SolverSetup module, which is responsible for detecting available solvers and preparing them for use by the oM_ProblemSolving module.
- el1xr_opt.Modules.oM_SolverSetup.ensure_ampl_solvers(targets=('highs',), quiet=False)[source]
Check for and automatically install a list of AMPL solver modules if missing.
- Parameters:
targets (
Iterable[str]) – An iterable of solver names to check/install (e.g., [“highs”, “cbc”]).quiet (
bool) – If True, suppress warnings about failed installations.
- Return type:
Dict[str,bool]- Returns:
A dictionary mapping each solver name to a boolean indicating its availability after the check/installation process.
- el1xr_opt.Modules.oM_SolverSetup.pick_solver(preferred, *, allow_fallback=False)[source]
Select and configure a solver, prioritizing AMPL modules for performance.
This function provides a standardized way to select a solver. It checks for the availability of a high-performance AMPL module first. If the preferred solver’s module is found, it configures Pyomo to use it via the ‘nl’ interface.
The selection is strict by default: if the AMPL module is not available, the function will raise a
RuntimeErrorunlessallow_fallbackis True.- Parameters:
preferred (
Optional[str]) – The desired solver’s name (e.g., “highs”). Defaults to “highs” if None.allow_fallback (
bool) – If True, the function can be extended to support other solver configurations (e.g., Pyomo’s built-in appsi solvers) when the AMPL module is unavailable. Currently, this will still result in an error if the module is not found.
- Returns:
A dictionary containing the solver configuration for Pyomo’s
SolverFactory, including the factory name, I/O method, and executable path.- Raises:
ValueError – If the
preferredsolver is not in the supported list.RuntimeError – If the corresponding AMPL module is not found and
allow_fallbackis False.