Initializing help system before first use

xpress.problem

Purpose
Class for all optimization problems solved by the Xpress Optimizer.
Synopsis
p = xpress.problem(*elements=None, name='', sense=xpress.minimize)
Arguments
elements 
Variables, constraints, SOSs, or objective function of the problem. These can be specified as single objects or lists and arrays thereof. They can be listed in the same order as would be added to the problem through problem.addVariable, problem.addConstraint, problem.addSOS, problem.setObjective, i.e. by making sure that the variables appearing in a constraint or objective function appear beforehand in the list.
name 
Name of the problem, displayed on solve log or saved in the .lp or .mps file when saved with problem.write.
sense 
Optimization sense. Can be xpress.minimize (default) or xpress.maximize.
Example 1
An object of class xpress.problem can be created from scratch or read from a file. It contains a set of variables and constraints, and may have an objective function. An empty optimization problem is created as follows:
myproblem = xp.problem()
A name can be assigned to a problem upon creation:
myproblem = xp.problem(name='My first problem')
The problem has no variables or constraint at this point.
Example 2
Simply call optimize() to solve an optimization problem that was either built or read from a file. The type of solver is determined based on the type of problem: if at least one integer variable was declared, then the problem will be solved as a mixed integer (linear or quadratically constrained) problem, while if all variables are continuous the problem is solved as a linear or quadratic optimization problem.
m.optimize()
The status of a problem after solution can be found via the solvestatus and solstatus attributes, and also in the return value of the optimize function, as follows:
import xpress as xp

m = xp.problem()
m.read("example3.lp")
solvestatus, solstatus = m.optimize()

print("solve status:", solvestatus)
print("solution status:", solstatus)

print("solution:", m.getSolution())
Example 3
It is useful, after solving a problem, to obtain the value of an optimal solution. After solving a continuous or mixed integer problem, the two methods problem.getSolution and problem.getSlacks return the vector (of portions thereof) of an optimal solution or the slack of the constraints. If an optimal solution was not found but a feasible solution is available, these methods will return data based on this solution. They can be used in multiple ways as shown in the following examples:
import xpress as xp

m  = xp.problem()

v1 = m.addVariable()
x  = [m.addVariable(lb=-1, ub=1, vartype=xp.integer) for i in range(10)]

[...] # add constraints and objective

m.optimize()

print(m.getSolution ())            # prints a list with an optimal solution
print("v1 is", m.getSolution(v1))  # only prints the value of v1
a = m.getSolution(x)               # gets the values of all variables in the vector x
b = m.getSolution(0:4)             # gets the value of v1 and x[0], x[1], x[2]
After creating an empty problem, one can read a problem from a file via the read method, which only takes the file name as its argument. An already-built problem can be written to a file with the write method. Its arguments are similar to those in the Xpress-Optimizer API function XPRSwriteprob, to which we refer.

© 2001-2025 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.