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 
The xpress.problem object this function is referring to. If problem is not None, then solution is either None (in which case the current solution is used) or it is to be intended referred to the indices of variables in problem. If problem is None, solution must provide this information directly, i.e. it must be a dictionary mapping variable objects to their value
solution 
Either a list or NumPy array of values (in which case problem must not be None) or a dictionary mapping variable objects to their value. As mentioned above, if it is None then problem must be passed and the assignment for the function is assumed to be the solution as retrieved via problem.getSolution
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. Note that the dictionary is necessary as no problem is
# defined. 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 this x=2,
# 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},
                 problem=p, solution=[2,3])

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

p.optimize()

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

# 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, because the objects in *args contain variables, and all variables could be used in zero or more problems. Only the following cases are allowed:
  • problem=None and solution is a dictionary mapping variables to values; the dictionary must have a key for each variable appearing in *args;
  • problem is not None but solution=None; then solution is taken as the result of problem.getSolution; this call is equivalent to p.getSolution(*args);
  • problem is not None and solution is either a list or a NumPy array; then the size of solution must match the number of variables of problem and the order of values in the list/array is the same order in which the variables were added to problem.
3. Variables assignment do not have to correspond to a feasible solution.
4.

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-2024 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.