sasoptpy.Expression

class Expression(exp=None, name=None)[source]

Bases: object

Creates a mathematical expression to represent model components

Parameters
expExpression, optional

An existing expression where arguments are being passed

namestring, optional

A local name for the expression

Notes

  • Two other classes (Variable and Constraint) are subclasses of this class.

  • Expressions are created automatically after linear math operations with variables.

  • An expression object can be called when defining constraints and other expressions.

Examples

>>> x = so.Variable(name='x')
>>> y = so.VariableGroup(3, name='y')
>>> e = so.Expression(exp=x + 3 * y[0] - 5 * y[1], name='exp1')
>>> print(e)
 -  5.0 * y[1]  +  3.0 * y[0]  +  x
>>> print(repr(e))
sasoptpy.Expression(exp =  -  5.0 * y[1]  +  3.0 * y[0]  +  x ,
                    name='exp1')
>>> sales = so.Variable(name='sales')
>>> material = so.Variable(name='material')
>>> profit = 5 * sales - 3 * material
>>> print(profit)
 5.0 * sales  -  3.0 * material
>>> print(repr(profit))
sasoptpy.Expression(exp =  5.0 * sales  -  3.0 * material , name=None)
>>> import sasoptpy.abstract.math as sm
>>> f = sm.sin(x) + sm.min(y[1],1) ** 2
>>> print(type(f))
<class 'sasoptpy.core.Expression'>
>>> print(f)
sin(x) + (min(y[1] , 1)) ** (2)