Sor#

class gamspy.Sor(domain: OperationIndexType, expression: OperationRhsType)[source]#

Bases: Operation

Represents a sor operation over a domain.

Parameters:
domainSet | Alias | ImplicitSet | Sequence[Set | Alias], Domain, Condition
rhsOperation
Expression
MathOp
ImplicitVariable
ImplicitParameter
int
bool
Variable
Parameter
Attributes:
records

Evaluates the operation and returns the resulting records.

Methods

gamsRepr()

Representation of the Sor operation in GAMS language.

latexRepr()

Representation of this operation in Latex.

toGraph()

Return a graphviz.Digraph of this operation's tree.

toList()

Convenience method to return the records of the operation as a list.

toValue()

Convenience method to return the records of the operation as a Python float.

Examples

>>> import gamspy as gp
>>> m = gp.Container()
>>> i = gp.Set(m, "i", records=['i1','i2', 'i3'])
>>> p = gp.Parameter(m, domain=i)
>>> p[i] = gp.math.uniformInt(0,1)
>>> result = gp.Parameter(m)
>>> result[:] = gp.Sor(i, p[i])
gamsRepr() str[source]#

Representation of the Sor operation in GAMS language.

Returns:
str

Examples

>>> from gamspy import Container, Set, Parameter, Variable, Sor
>>> m = Container()
>>> i = Set(m, "i", records=['i1','i2', 'i3'])
>>> v = Variable(m, "v", domain=i, type="binary")
>>> Sor(i, v[i]).gamsRepr()
'sor(i,v(i))'
latexRepr() str#

Representation of this operation in Latex.

Returns:
str

Examples

>>> import numpy as np
>>> import gamspy as gp
>>> m = gp.Container()
>>> i = gp.Set(m, "i", records=range(3))
>>> a = gp.Parameter(m, "a", domain=i, records=np.array([3,5,7]))
>>> print(gp.Sum(i, a[i]).latexRepr())
toGraph()#

Return a graphviz.Digraph of this operation’s tree.

The operation (e.g. sum) is drawn as a box with an edge to each index of its domain (labeled index) and an edge to its body. Requires the optional graphviz dependency (pip install gamspy[graph]).

Returns:
graphviz.Digraph

Examples

>>> import gamspy as gp
>>> m = gp.Container()
>>> i = gp.Set(m, "i", records=range(3))
>>> a = gp.Parameter(m, "a", domain=i)
>>> graph = gp.Sum(i, a[i]).toGraph()
toList() list#

Convenience method to return the records of the operation as a list.

Returns:
list | None

Examples

>>> import numpy as np
>>> import gamspy as gp
>>> m = gp.Container()
>>> i = gp.Set(m, "i", records=["i1", "i2"])
>>> j = gp.Set(m, "j", records=["j1", "j2"])
>>> a = gp.Parameter(m, "a", domain=[i, j], records=np.array([(1,2), (3,4)]))
>>> gp.Sum(i, a[i, j]).toList()
[['j1', 4.0], ['j2', 6.0]]
toValue() float#

Convenience method to return the records of the operation as a Python float. Only possible if there is a single record as a result of the operation.

Returns:
float | None

Examples

>>> import numpy as np
>>> import gamspy as gp
>>> m = gp.Container()
>>> i = gp.Set(m, "i", records=["i1", "i2"])
>>> a = gp.Parameter(m, "a", domain=i, records=np.array([1,2]))
>>> gp.Sum(i, a[i]).toValue()
np.float64(3.0)
property records: pd.DataFrame | None#

Evaluates the operation and returns the resulting records.

Returns:
pd.DataFrame | None

Examples

>>> import numpy as np
>>> import gamspy as gp
>>> m = gp.Container()
>>> i = gp.Set(m, "i", records=["i1", "i2"])
>>> a = gp.Parameter(m, "a", domain=i, records=np.array([1,2]))
>>> gp.Sum(i, a[i]).records
   value
0    3.0