xpress.user
xpress.user |
Purpose
Creates an expression that is computed by means of a user-specified function.
Synopsis
def f (a1, a2, ..., an):
[...]
a = xpress.user (f, t1, t2, ..., tn)
Arguments
f
|
User function; must be a Python function with as many (possibly optional) arguments as specified in the declaration.
|
t1,...,tn
|
Arguments of the user function.
|
Example
The following code shows how to define user functions:
import math def mynorm (v): return math.sqrt (sum (v[i] for i in range (len (v))) def weighted_sum (t1, t2, t3 = 0): return 2*t1 + 3*t2 + 4*t3 x = [xp.var() for i in range (20)] f1 = xp.user (mynorm, x) f2 = xp.user (weighted_sum, x[0], x[1], x[2]) # doesn't use optional arg f3 = xp.user (weighted_sum, x[0], x[1])
Further information
User functions must return a Float, as the behaviour is otherwise undefined.