Initializing help system before first use

object.extractLinear

object.extractLinear


Purpose

Returns the variables and coefficients of the linear part of any expression.


Synopsis
vars, coef = a.extractLinear()
Arguments
An expression or variable.
vars 
A list containing the variable objects composing the linear expression in a.
coef 
A list containing the corresponding coefficients in the linear expression.
Example
The following code snippets show what is the expected result of applying extractLinear:
import xpress as xp

x = xp.var()
y = xp.var(name='myvar')

a = x + 2*y
b = 3*x
c = y**2 + x**2 - 6*x
d = x**5 - 7*x  # nonlinear expression

print (a.extractLinear())  # will print "([C1, myvar], [1, 2])"
assert (a.extractLinear() == ([x, y], [1, 2]))

print (b.extractLinear())  # will print "([C1], [3])"
print (c.extractLinear())  # will print "([C1], [-6])"
print (d.extractLinear())  # will print "([C1], [-7])"
Further information
1. Note that this operator returns variable objects, not indices, in the vars portion of the output tuple. To obtain indices, use the problem.getIndex function. Printing these lists will show the name of the associated variables, as determined by the user when creating the variable with the name argument or, if name was not provided, it will show the name as determined by the Optimizer's library (default variable names are "C"+index). See also Subsection Variable names and Python objects.
2. This operator is most useful only for linear expressions with more than one element. For nonlinear expressions, the function attempts to extract as much linear information it can, but will not be able to infer linearity apart from the most obvious cases. For example, for the expression x**4 + xp.log(xp.exp(y)), which contains the linear term y, the function will return ([],[]).

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