Initializing help system before first use

xpress.evaluate

Purpose

Returns the evaluation of one or more expressions for a given assignment of values to optimization variables.


Synopsis
v = xpress.evaluate(*args, problem=None, solution=None)
Arguments
args 
One or more objects to be evaluated. These can be variables, linear or nonlinear expressions; they can also be tuples, lists, dictionaries, or NumPy arrays of variables and expressions.
problem 
If this argument is provided and solution is None, the current solution from the problem is used when evaluating the variables, and the result will be the same as problem.getSolution(*args).
solution 
A list, NumPy array, or dictionary of values, to be used when evaluating the variables. If a dictionary is provided, it can be keyed by xpress.variable objects or by variable indices.
Example
The following examples are valid uses of xpress.evaluate:
import xpress as xp

p = xp.problem()  # Create a problem

x = p.addVariable()
y = p.addVariable(vartype=xp.binary)

# Uses evaluate without a problem but by assigning the variables
# explicitly. The result should be [5.4, 124.71633781453677].

v1 = xp.evaluate([x + y, x**3 - xp.cos(x)], solution={x:5, y:0.4})


# Similar to the computation of v1 but with a vector of numbers; the
# order in which the variables were added to p means that x=2 and
# y=3 here. The result should be {'exp1':11, 'exp2':6, 'exp3':9}.

v2 = xp.evaluate({'exp1':x + 3*y, 'exp2':x*y, 'exp3':y**2},
                 solution=[2,3])

p.addConstraint(x + y >= 3)
p.setObjective(x + 2*y)

p.optimize()

l = xp.array([x**2 * y, x * y**2, x**3])

# No solution is passed, so the solution of p as computed with optimize()
# above is used. It is easy to show that the solution is x=3, y=0, so
# the result is np.array([0, 0, 27]).

v3 = xp.evaluate(l, problem=p)
Further information
1. Variable assignments do not have to correspond to a feasible solution.
2. At least one of the arguments problem and solution must be specified. For unlinked problems, both arguments must be provided whenever the indices of the variables are needed (i.e., if the solution is provided as a list, NumPy array, or dictionary keyed by variable index). This is because unlinked variables can belong to multiple problems, and they can have a different index in each one, so the problem argument is needed to resolve ambiguity.
3. When using evaluate with piecewise linear functions that have a step discontinuity, for example with the constraint y == xp.pwl({(0,3): x, (3,5): 10*x}), if at an optimal solution x=3the Optimizer library will compute a value for y that is anywhere between 3 and 30, because of numerical issues associated with discontinuities.

In such cases, evaluate is unaware of the link between the function and y and, by convention, will return a value of the function that correspond to the second interval, i.e., the function will be evaluated at 30. In order to obtain the value of the piecewise linear function, evaluate should be run on y instead.


Related topics

© 2001-2026 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.