Expression#
- class gamspy.Expression(left: OperableType | ImplicitEquation | None, data: str, right: OperableType | str | None)[source]#
Bases:
Operable
Expression of two operands and an operation.
- Parameters:
- left: str | int | float | Parameter | Variable | None
Left operand
- data: str
Operation
- right: str | int | float | Parameter | Variable | None
Right operand
- Attributes:
records
Evaluates the expression and returns the resulting records.
- representation
Methods
gamsRepr
()Representation of this Expression in GAMS language.
Declaration of the Expression in GAMS
Representation of this Expression in Latex.
toList
()Convenience method to return the records of the expression as a list.
toValue
()Convenience method to return expression records as a Python float.
Examples
>>> import gamspy as gp >>> m = gp.Container() >>> a = gp.Parameter(m, name="a") >>> b = gp.Parameter(m, name="b") >>> expression = a * b >>> expression.gamsRepr() '(a * b)'
- gamsRepr() str [source]#
Representation of this Expression in GAMS language.
- Returns:
- str
Examples
>>> import gamspy as gp >>> m = gp.Container() >>> a = gp.Parameter(m, name="a") >>> b = gp.Parameter(m, name="b") >>> expression = a * b >>> expression.gamsRepr() '(a * b)'
- getDeclaration() str [source]#
Declaration of the Expression in GAMS
- Returns:
- str
Examples
>>> import gamspy as gp >>> m = gp.Container() >>> a = gp.Parameter(m, name="a") >>> b = gp.Parameter(m, name="b") >>> expression = a * b >>> expression.getDeclaration() '(a * b)'
- toList() list | None [source]#
Convenience method to return the records of the expression as a list.
- Returns:
- list | None
Examples
>>> import numpy as np >>> import gamspy as gp >>> m = gp.Container() >>> i = gp.Set(m, records=range(3)) >>> a = gp.Parameter(m, domain=i, records=np.array([1,2,3])) >>> b = gp.Parameter(m, domain=i, records=np.array([4,5,6])) >>> (a + b).toList() [['0', 5.0], ['1', 7.0], ['2', 9.0]]
- toValue() float | None [source]#
Convenience method to return expression records as a Python float. Only possible if there is a single record as a result of the expression evaluation.
- Returns:
- float | None
- Raises:
- TypeError
In case the dimension of the expression is not zero.
Examples
>>> import gamspy as gp >>> m = gp.Container() >>> a = gp.Parameter(m, records=5) >>> b = gp.Parameter(m, records=6) >>> (a + b).toValue() np.float64(11.0)
- property records: pd.DataFrame | None#
Evaluates the expression and returns the resulting records.
- Returns:
- pd.DataFrame | None
Examples
>>> import gamspy as gp >>> m = gp.Container() >>> a = gp.Parameter(m, records=5) >>> b = gp.Parameter(m, records=6) >>> (a + b).records value 0 11.0
- property representation: str#
!! processed by numpydoc !!