Product#
- class gamspy.Product(domain: OperationIndexType, expression: OperationRhsType)[source]#
Bases:
OperationRepresents a product operation over a domain.
- Parameters:
- domainSet | Alias | ImplicitSet | Sequence[Set | Alias], Domain, Condition
- rhsOperation
- ExpressionMathOpImplicitVariableImplicitParameterintboolVariableParameter
- Attributes:
recordsEvaluates the operation and returns the resulting records.
Methods
gamsRepr()Representation of the Product operation in GAMS language.
Representation of this operation in Latex.
toGraph()Return a
graphviz.Digraphof 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']) >>> v = gp.Variable(m, "v") >>> e = gp.Equation(m, "e", type="eq") >>> p = gp.Parameter(m, "p", domain=[i], records=[("i1", 1), ("i2", 2), ("i3", 4)]) >>> e[...] = gp.Product(i, p[i]) <= v
- gamsRepr()[source]#
Representation of the Product operation in GAMS language.
- Returns:
- str
Examples
>>> from gamspy import Container, Set, Parameter, Variable, Product >>> m = Container() >>> i = Set(m, "i", records=['i1','i2', 'i3']) >>> c = Parameter(m, "c", domain=i) >>> v = Variable(m, "v", domain=i) >>> Product(i, c[i]*v[i]).gamsRepr() 'prod(i,c(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.Digraphof this operation’s tree.The operation (e.g.
sum) is drawn as a box with an edge to each index of its domain (labeledindex) and an edge to its body. Requires the optionalgraphvizdependency (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