FICO Xpress Optimizer Python Interface

9.8.1 · active · verified Thu Apr 16

The FICO Xpress Optimizer Python interface (xpress) enables users to formulate, manage, and solve a comprehensive range of mathematical optimization problems including Linear Programming (LP), Quadratic Programming (QP), Second-Order Conic Programming (SOCP), and their mixed-integer counterparts (MILP, MIQP, MIQCQP, MISOCP), along with general nonlinear and mixed-integer nonlinear problems. It offers seamless integration with numerical libraries like NumPy and supports advanced features such as callbacks for solver control. The library is currently at version 9.8.1, with frequent updates including patches and minor versions released multiple times a year.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart defines and solves a simple Linear Programming (LP) problem using the FICO Xpress Python interface. It initializes a problem, adds variables and constraints, sets an objective, and then optimizes the problem, printing the solution if optimal.

import xpress as xp

p = xp.problem(name='my_first_lp')

x1 = p.addVariable(name='x1', lb=0, ub=xp.infinity)
x2 = p.addVariable(name='x2', lb=0, ub=xp.infinity)

p.setObjective(3*x1 + 2*x2, sense=xp.minimize)

p.addConstraint(4*x1 + 2*x2 >= 10, name='c1')
p.addConstraint(x1 + x2 >= 3, name='c2')

p.optimize()

if p.getProbStatus() == xp.lp_optimal:
    print(f"Solution Status: Optimal")
    print(f"Objective Value: {p.getObjVal()}")
    print(f"x1 = {p.getSolution(x1)}")
    print(f"x2 = {p.getSolution(x2)}")
else:
    print(f"Solution Status: {p.getProbStatusString()}")

view raw JSON →