Expression#

class gamspy.Expression(left: OperableType | ImplicitEquation | None, operator: str, right: OperableType | str | None)[source]#

Bases: Operable

Represents an expression involving two operands and an operator.

This class constructs a binary expression tree that can be evaluated or translated into GAMS syntax.

Parameters:
leftOperableType | ImplicitEquation | None

Left operand.

operatorstr

The operator symbol (e.g., ‘+’, ‘-’, ‘*’, ‘=’, ‘eq’).

rightOperableType | str | None

Right operand.

Attributes:
records

Evaluates the expression and returns the resulting records.

representation

Methods

gamsRepr()

Representation of this Expression in GAMS language.

getDeclaration()

Declaration of the Expression in GAMS

latexRepr()

Returns the LaTeX representation of this Expression.

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'
latexRepr() str[source]#

Returns the LaTeX representation of this Expression.

Returns:
str

The LaTeX string.

Examples

>>> import gamspy as gp
>>> m = gp.Container()
>>> a = gp.Parameter(m, name="a")
>>> b = gp.Parameter(m, name="b")
>>> (a + b).latexRepr()
'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 !!