The FICO® Xpress Python interface is a powerful tool for optimization modeling and solving. It allows users to leverage the capabilities of the FICO® Xpress Solver directly within Python. Here are some key features:
- Modeling: You can create and manipulate optimization models using Python objects. This includes defining variables, constraints, and objective functions. It allows creating constraints and objectives using expressions with operator overloading.
- Integration with NumPy and SciPy: The interface supports the use of NumPy and SciPy sparse arrays, making it easier and more efficient to handle large datasets and perform numerical operations.
- Solving: It provides functions to solve various types of optimization problems, including linear programming (LP), mixed-integer programming (MIP), quadratic programming (QP) and (general) nonlinear programming (NLP), and access to the full set of solver features available with Xpress.
- Callbacks: Users can implement custom callbacks to interact with the optimization process, such as monitoring progress or modifying the solver's behavior.
- Examples and Documentation: The interface comes with extensive examples and documentation to help users get started and explore advanced features.
- XpressPythonAPI: A slide deck with descriptions, examples and links for the most relevant API methods.
- A Youtube playlist with several videos containing slides readouts and demos using Python notebooks is available. Links to individual videos are provided below.
| Example name | Description | Notes | Video |
|---|---|---|---|
| callback_newnode | Using a callback function during the branch and bound search | Link | |
| indicators | Using indicator constraints | Link | |
| load_problem | Comparison of model building performance between low-level and high-level methods | Link | |
| loadlp | Using the low-level API function loadLP() | ||
| logic_cons | Using general constraints for logical expressions | Link | |
| modeling | Modeling a basic MIP problem | Link | |
| multiobj_knapsack.ipynb | Multi-objective knapsack problem with blended and lexicographic approaches | ||
| numpy_arrays | Using the numerical library NumPy | Link | |
| piecewise_linear | Using piecewise linear functions | Link | |
| sos | Defining Special Ordered Set (SOS) constraints | Link | |
| write_read | Writing and reading a problem file | Link |
| Example name | Description | Notes | Video |
|---|---|---|---|
| assignment | One-to-one assignment of projects to persons to maximize the overall preference level | ||
| bin_packing | Pack items into bins to minimize the number of bins used | Showcases the use of the xp.Dot operator |
|
| campaign_polars | Campaign conversion optimization to maximize expected value subject to budget and channel capacity constraints | Showcases the use of Polars dataframes to generate aggregate expressions | |
| circle_packing | Place |
||
| facility_location | A basic facility location problem | ||
| firestation_scipy | Using a SciPy sparse matrix formulation to model the fire station location problem | ||
| inscribed_square | Inscribed square problem solved with Xpress NonLinear or Xpress Global | To run Xpress NonLinear with Knitro, a Knitro license is required. | Link |
| markowitz_multiobj | Multi-objective formulation of Markowitz portfolio optimization problem | Link | |
| max_flow | Finding the maximum number of vertex-disjoint paths between two nodes in a telecommunications network | ||
| n_queens | The problem of placing |
||
| pairwise_distance | Determine the positions of |
Interactive 3D visualization | |
| portfolio_pandas | Showcases the use of Pandas operations to generate expressions and constraints for a portfolio selection problem | Requires Xpress version 9.8 or later | |
| sudoku | Solving a Sudoku problem | ||
| tsp_callbacks | Solving a TSP problem using callbacks | This example requires a full license of the FICO® Xpress Optimizer. | |
| unitcommitment_indicators | Unit commitment problem formulation with indicator constraints |
-
Open Codespaces and create a codespace:
- Click on the "Code" (green) button on this repository page.
- On the "Codespaces" tab, select "Create a Codespace on main". This will set up a cloud-based development environment for you.
-
Open Python Notebook:
- Once the Codespace is created and the environment is ready (wait for the README preview to appear), you can open a Python notebook.
- Navigate to a notebook file (with a
.ipynbextension) within the Codespace. - Click on the notebook file to open it in the Jupyter interface.
-
Run the Notebook:
- Run a code cell in the Python notebook as you would normally do in a local environment.
- When running for the first time, select "Install/Enable suggested extensions: Python + Jupyter" as suggested in the pop-up window at the top of the screen.
- After installation, select the installed Python environment and wait for the code cell to be executed. You are all set to run all the code cells.
See source code files for copyright notices.
The examples in this repository are licensed under the Apache License, Version 2.0. See LICENSE for the full license text. The examples use FICO® Xpress software. By running it, you agree to the Community License terms of the Xpress Shrinkwrap License Agreement with respect to the FICO® Xpress software. See the licensing options overview for additional details and information about obtaining a paid license.