Module sum
Classes
SumOperator
class SumOperator(
self,
sum_index: Element,
operand: Expression,
condition: Optional[Condition] = None,
uuid: Optional[str] = None,)
Class that represents the sum.
Example: Create
>>> from jijmodeling import Placeholder, Binary, SumOperator
>>> from jijmodeling import Element
>>> d = Placeholder('d', dim=1)
>>> n = d.shape[0]
>>> x = Binary('x', shape=n)
>>> i = Element("i", n)
>>> SumOperator(sum_index=i, \
operand=d[i]*x[i], condition=None)
Σ_{i}(d[i]x[i])
Initialize self. See help(type(self)) for accurate signature.
Base classes
jijmodeling.Expression
Instance attributes
- condition summation condition
- operand summation operand
- sum_index summation index
- uuid
Methods
def children(self) -> list
[sum_index, operand, condition]
def is_operatable(self) -> bool
specify whether the operators (+, -, *, /,...) can be applied to the expression. For example, "a[3]" is true, whereas "a" is not.
Returns: bool: defaults False.
Functions
Sum
def Sum(
indices: Union[INDEXWITHCOND, List[INDEXWITHCOND]],
term: Expression,
condition: Optional[Union[Condition, List[Optional[Condition]]]] = None
) -> SumOperator
Sum function
Args: indices: summation index dict or list of index. term (Expression): operand of summation condition: [deprecated] summation conditions. Defaults to None.
Returns: SumOperator: SumOperator object.
Example: Create
>>> import jijmodeling as jm
>>> d = jm.Placeholder('d', dim=1)
>>> n = d.shape[0]
>>> x = jm.Binary('x', shape=n)
>>> i = jm.Element('i', n)
>>> jm.Sum(i, d[i]*x[i])
Σ_{i}(d[i]x[i])
Create $`\sum_{i}\sum_j d_{ij}x_i x_j`$
>>> import jijmodeling as jm
>>> d = jm.Placeholder('d', dim = 2)
>>> n = d.shape[0]
>>> x = jm.Binary('x', shape=n)
>>> i = jm.Element('i', n)
>>> j = jm.Element('j', n)
>>> jm.Sum([i, j], d[i, j]*x[i]*x[j])
Conditional sum
>>> import jijmodeling as jm
>>> d = jm.Placeholder('d', dim = 2)
>>> n = d.shape[0]
>>> i, j = jm.Element("i", n), jm.Element("j", n)
>>> x = jm.Binary('x', shape=n)
>>> jm.Sum([i, (j, i < j)], d[i, j]*x[i]*x[j])