Initializing help system before first use

Creating a problem

Create an empty optimization problem myproblem 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. The synopsis of the xpress.problem method is as follows:

xpress.problem(*args, name='noname', sense=xpress.minimize)

The only two named arguments are name and sense and they denote the problem name and the optimization sense, respectively. The argument args is a list composed as follows:

  • zero or more variables declared with xpress.var or xpress.vars;
  • zero or more constraints created from functions of the variables;
  • at most one function in the variables;
  • at most one string.
The variables and constraints will be added to the problem as if they were with the problem.addVariable and problem.addConstraint functions, respectively, while the function is treated as the objective function and added to the problem as if with the problem.setObjective function. If the sense parameter is also added, this becomes the optimization sense. Because the arguments are scanned in the order they are received, the user ought to ensure that a constraint or the objective function are passed only after all of the variables containing them are passed.

Note that indicator constraints (see Section Indicator constraints) cannot be added directly in the problem declaration but need to be added using problem.addIndicator.

The following is an example of the compact declaration: variables x and y are declared first, then the problem declaration is passed these variables and followed by two constraints and a function to be used as objective function. Note that because no optimization sense is given, minimization is assumed.

import xpress as xp
x = xp.var()
y = xp.var(lb=-1, ub=1)
prob = xp.problem(x, y, 2*x + y >= 1, x + 2*y >= 1, x + y, name='myproblem')

All operations for adding/deleting variables, constraint, SOS and others are allowed on problems declared this way; note that setting a new objective function with problem.setObjective resets the optimization sense, and sets it to xpress.minimize if none is given.