xpress.evaluate
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
|
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
|
import xpress as xp x = xp.var() y = xp.var(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}) p = xp.problem(x, y) # Create a problem and add variables x and y # 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.solve() 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 solve() # 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)
© 2001-2020 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.