Solvers used in this book#
To get started in a Jupyter or Colab notebook, run this magic command in a code cell:
%pip install pyomo highspy
%pip installs into the current notebook kernel’s environment. If you are installing from a terminal instead, use:
python -m pip install pyomo highspy
This provides the solver setup for most examples in chapters 1–4, 7, 9 and 10, and the linear parts of chapters 5 and 8. Specific examples need additional solvers, as shown below; their preambles also identify other Python packages they use. The choice follows the mathematical formulation: changing a solver name cannot make an incompatible formulation solvable.
Use Run all to execute the setup and integer-solution check below. This notebook needs no commercial solver license.
A guide to the solvers#
LO means linear optimization, and MILO means mixed-integer linear optimization: some decisions must be integer or binary. Solver documentation commonly calls these LP and MILP. The table lists the problem classes relevant to this book.
Solver |
Problem classes |
Where used in the book |
|---|---|---|
LO and MILO |
Most linear examples; linear subproblems throughout the book |
|
Smooth continuous nonlinear optimization |
Milk pooling and the dynamic-model appendix example; continuous Colab alternatives to MOSEK |
|
Convex quadratic and conic optimization, including mixed-integer conic models |
§§5.2–5.4, chapter 6 except §6.4, and §9.1 when run locally; their Colab preambles substitute Ipopt. Optional comparisons in §§6.4 and 8.1 |
|
Linear and nonlinear optimization, including mixed-integer and nonconvex models |
Building insulation (§6.4), robust BIM (§8.1), cutting stock and the global worst-case subproblem in §10.2 |
|
LO, MILO and quadratic optimization, including nonconvex quadratic models |
Facility location, dinner seating and traveling salesman |
|
LO and MILO |
Facility location, dinner seating and the functional-programming appendix |
|
LO and MILO in the examples here |
Facility-location comparisons |
HiGHS, Ipopt, SCIP and CBC are open-source solvers. MOSEK, Gurobi, CPLEX and Xpress are commercial, proprietary products, even when a particular license is free of charge. The licensing section below explains the distinction.
What about GLPK? The GNU Linear Programming Kit is another open-source LO/MILO solver, mentioned among the alternatives in §1.2. The examples here generally select HiGHS. For a compatible linear model, Pyomo can use pyo.SolverFactory("glpk") after the separate glpsol executable is installed and available on PATH. This changes the solver interface, so check any solver-specific options too.
Modeling tools, solvers and interfaces#
Pyomo describes the variables, objective and constraints; a solver computes a solution. For setup instructions, see the Pyomo installation guide. The package highspy supplies HiGHS’s Python interface.
CVXPY is another modeling tool, used in the refinery example. It also calls a solver underneath. Its solver guide shows how to select that solver and inspect the results.
Names such as appsi_highs, mosek_direct and gurobi_persistent identify Pyomo interfaces: the connections through which Pyomo sends a model to a solver and retrieves its results. An interface determines which solver features are accessible from that code.
Why can a nonlinear solver solve a convex model?#
“Nonlinear” describes the expressions; “convex” describes the geometry. A model can be both. For example, minimizing a positive-semidefinite quadratic objective over linear constraints is convex nonlinear optimization. As the Ipopt documentation explains, Ipopt works with smooth continuous expressions. For a convex problem, a local minimum is also global.
A conic solver such as MOSEK instead receives the cone structure explicitly. Expressing a model in conic form lets its algorithms use that structure. This is why chapter 6 revisits problems that can also be written as nonlinear models.
Integer decisions need a solver that enforces them. A binary variable represents a yes/no choice; allowing a value such as 0.3 produces a continuous relaxation with different feasible decisions. Ipopt solves continuous problems, so integer choices require a mixed-integer solver.
How the book uses these choices#
HiGHS supports the progression from production planning to scheduling, networks and uncertainty. It also solves the binary scenario-selection model in §9.4 economic dispatch. In the chapter-3 disjunctive examples, Pyomo first transforms the model into MILO form for HiGHS.
Ipopt introduces local nonlinear optimization in milk pooling. Different starting points can lead to different solutions, illustrating the role of nonconvexity. It also handles the dynamic example in the appendix and serves as the Colab alternative for the continuous quadratic and conic examples described below.
MOSEK handles the quadratic and conic formulations used for regression, portfolios, classifiers and insulation. Chapter 6 often uses Pyomo’s kernel interface, which provides explicit components for cones. The preambles for the continuous examples substitute Ipopt on Colab. In §6.4 building insulation, SCIP solves the main examples both locally and on Colab, including the binary layer choices. An optional MOSEK comparison solves the same models in explicit conic form. §8.1 robust BIM also offers an optional MOSEK comparison. Ipopt cannot enforce integer choices.
SCIP solves the nonlinear models in building insulation and robust BIM, and the bilinear mixed-integer models in the cutting-stock extra, through Pyomo’s scip_direct interface and PySCIPOpt. In §10.2, PySCIPOpt is used directly to obtain global bounds for the nonconvex worst-case subproblem. HiGHS handles that example’s linear master and fixed-scenario models, and the linear parts of cutting stock.
Gurobi supports solver comparisons and the persistent-interface and callback techniques in the traveling-salesman extra material. CBC, CPLEX and Xpress provide alternative solvers for selected comparisons; CBC also appears in the functional-programming appendix.
CVXPY offers a second way to formulate the refinery problem. After problem.solve(), problem.solver_stats.solver_name identifies the backend chosen by CVXPY. Recording it makes comparisons easier to reproduce.
Licenses and academic access#
“Open source”, “free of charge” and “academic use” describe different things. Open-source licenses grant rights to inspect, modify and redistribute software under stated conditions. A free community edition or academic license of a commercial solver grants the rights in the vendor’s agreement; it does not make that solver open source.
Open-source terms#
HiGHS uses MIT and SCIP uses Apache 2.0, both permissive licenses. Ipopt, CBC, Couenne and Bonmin use the Eclipse Public License (EPL). These licenses allow commercial use, subject to their conditions. Keep the applicable notices and license texts when redistributing; copyleft licenses can also require providing source for covered software or modifications. Check the license shipped with your installed release and its dependencies: an open-source solver can include separately licensed numerical libraries, such as HSL in some Ipopt builds.
GLPK uses GNU GPL, a copyleft license. Using it does not automatically require publishing your model, data or all your application code. GLPK’s author explicitly distinguishes a user’s model from the solver in this licensing explanation. Running glpsol as a separate program on your model differs from distributing an application linked with the GLPK library. Redistribution of GLPK, modifications or a combined work can trigger source-code obligations to recipients; private use alone does not require public release. See the GNU GPL FAQ. For a distributed product, ask your organization’s licensing specialist to review the actual integration and distribution plan.
Commercial solvers: community, trial and academic access#
The main no-cost routes are compared below. Size limits apply to the model sent to the solver, including auxiliary variables and constraints introduced by reformulations. Consult the linked vendor terms for current limits and permitted uses.
Solver |
Community or trial access |
Academic access |
|---|---|---|
Gurobi |
The bundled restricted license is for non-production use: up to 2,000 variables and 2,000 linear constraints, reduced to 200 variables when quadratic terms are present. See limits. |
Free licenses without model-size limits for eligible students, faculty and staff; named-user, WLS and institutional options. See academic licenses. |
CPLEX |
Community Edition allows up to 1,000 variables and 1,000 constraints. |
IBM’s academic program provides eligible students and faculty access without functional or model-size limits. See IBM’s licensing comparison. |
MOSEK |
A 30-day trial has no model-size restrictions. |
The free personal academic license has no size limit, lasts 365 days and is renewable; institutional floating licenses are also available. |
Xpress |
The bundled Community License allows 5,000 variables and constraints combined for linear, quadratic and conic models. For general nonlinear models, FICO specifies a limit of “200 variables and constraints”. See FICO’s limits and the combined counting rule. |
Consult FICO’s academic programs or your institution for the applicable access and terms. |
An academic license is permission for eligible educational or research work, not a general commercial entitlement. For example, Gurobi and MOSEK restrict academic use to education and non-commercial research. An institutional email helps establish eligibility; it does not by itself authorize consulting, company deployment or every industry-funded project. Check the intended use with the vendor or your institution, along with renewal, machine/cloud access and concurrent-user rules. Keep personal license files and credentials private; a shared notebook should contain setup instructions, not somebody else’s key.
Installing and checking your setup#
The next cell installs Pyomo and HiGHS on Colab. When running locally, install them first in the Python environment associated with your notebook using the command at the top of this page.
import sys
if "google.colab" in sys.modules:
%pip install pyomo highspy
This example follows the book’s SolverFactory pattern and checks an actual integer solution. It maximizes a nonnegative integer subject to twice its value being at most five.
import pyomo.environ as pyo
solver = "appsi_highs"
SOLVER = pyo.SolverFactory(solver)
assert SOLVER.available(), f"Solver {solver} is not available."
model = pyo.ConcreteModel()
model.x = pyo.Var(domain=pyo.NonNegativeIntegers)
model.capacity = pyo.Constraint(expr=2 * model.x <= 5)
model.profit = pyo.Objective(expr=model.x, sense=pyo.maximize)
results = SOLVER.solve(model)
pyo.assert_optimal_termination(results)
print(pyo.value(model.x)) # 2.0
2.0
The result is 2.0: the best integer value is 2, whereas the continuous relaxation would allow 2.5.
The remaining installation commands and option snippets are reference instructions for other solvers and their notebooks. They are not needed to run this check; in particular, the MA57 option belongs to an Ipopt solver, not the HiGHS solver above.
For the additional solvers:
Ipopt and CBC: the book often obtains executables through IDAES. Install with
python -m pip install pyomo idaes-pse, then runidaes get-extensions. With the default installation location,import idaesconfigures the solver paths. The IDAES guide covers supported platforms and the included Bonmin and Couenne binaries. For preambles that download binaries with--to ./bin, useos.environ["PATH"] += os.pathsep + os.path.abspath("bin")afterimport os, replacing the Unix-only":bin"update so it also works on Windows.Ipopt options. Pyomo’s shell-based solver interfaces set options through
SOLVER.options[...]; option names and values depend on the solver. Ipopt/MA57 means Ipopt using HSL’s MA57 routine for its internal linear equations. If Ipopt reports insufficient memory with MA27, select MA57 on the IpoptSOLVERbefore solving, provided your build includes it (see Ipopt options). The HSL-enabled IDAES binaries include the required license; availability varies by platform, and"mumps"is another choice where included.SOLVER.options["linear_solver"] = "ma57"
HSL, a collection of Fortran codes for large-scale scientific computation. See www.hsl.rl.ac.uk.
MOSEK: install with
python -m pip install pyomo mosekand follow the license setup instructions. Eligible readers can request a personal academic license using their institutional email. Keep the license private. On each fresh Colab runtime, upload your.licfile and, afterimport os, setos.environ["MOSEKLM_LICENSE_FILE"] = "/content/mosek.lic"(adjust the path) before importing MOSEK, as explained in the Colab guidance.SCIP: for the Pyomo examples, install
python -m pip install "pyomo>=6.10.1" "pyscipopt>=6.2.1"and usepyo.SolverFactory("scip_direct"). Supported binary packages include SCIP, as described in the PySCIPOpt installation guide; this interface does not need a separate SCIP executable. §10.2 also uses PySCIPOpt directly. On Windows, installpywin32in the notebook environment (%pip install pywin32) and restart the kernel so Pyomo can use its Windows pipe support when capturing SCIP output. This prevents output-capture stalls that can occur even withtee=False.Gurobi: on Colab, run
%pip install pyomo gurobipy. The bundled license handles small examples; larger models need a full license. WLS (Web License Service) supports hosted Colab, including academic WLS access for eligible readers. The Web License Manager is the portal where you create its API key and download the privategurobi.licfile; follow the WLS setup guide. WLS needs an internet connection to obtain license tokens.Upload
gurobi.licthrough Colab’s Files pane on each fresh runtime. Then this optional example solves the integermodelabove with Gurobi; adjust the path if needed. Keep the file and its credentials out of shared notebook cells, outputs and repositories.import os os.environ["GRB_LICENSE_FILE"] = "/content/gurobi.lic" with pyo.SolverFactory( "gurobi_direct", manage_env=True, options={"OutputFlag": 0} ) as SOLVER: results = SOLVER.solve(model) pyo.assert_optimal_termination(results) print(pyo.value(model.x)) # 2.0
gurobi_directuses the installed Python package. Withmanage_env=True, leaving thewithblock closes its models and environment.OutputFlagis set before startup to suppress license details as well as solver logs. When finished, remove the uploaded file and choose Runtime → Disconnect and delete runtime; merely closing a browser tab can leave a WLS session active.Alternatively, use a Colab local runtime on a suitably licensed machine. A laptop license does not automatically license hosted Colab. The table links to setup and licensing information for CPLEX and Xpress.
CVXPY: install with
python -m pip install cvxpy; its installation guide explains additional solver options.
Before you trust a result#
Check solver termination before interpreting values. For MILO and global nonlinear optimization, report the feasible incumbent together with the bound or optimality gap when the solve stops early. For nonconvex problems, a successful local solve does not establish global optimality. Recording the solver version, settings and data helps others reproduce and interpret your results.
We thank @leonlan for suggesting this overview in issue #73.