xpress.evaluate
Returns the evaluation of one or more expressions for a given assignment of values to optimization variables.
v = xpress.evaluate(*args, problem=None, solution=None)
|
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.
|
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)
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.
© 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.
