Skip to content

Summation

ReductionOperator

Bases: _expression.Expression

Super class of reduction operators. Subclass examples: SumOperator, ProdOperator

sum_index: _variable.Element property

Summation index.

operand: _expression.Expression property

Summation operand.

condition: _conditions.Condition property

Summation condition.

children()

[sum_index, operand, condition].

SumOperator

Bases: ReductionOperator

Class that represents the sum.

Example

Create i=0ndixi\sum_{i=0}^n d_i x_i

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])

Sum(indices, term)

Sum function.

Parameters:

Name Type Description Default
indices tp.Union[INDEXWITHCOND, tp.List[INDEXWITHCOND]]

summation index dict or list of index.

required
term Expression

operand of summation

required

Returns:

Name Type Description
SumOperator SumOperator

SumOperator object.

Example

Create i=0ndixi\sum_{i=0}^n d_i x_i

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 ijdijxixj\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])

sum(index, operand)

Sum function.

Parameters:

Name Type Description Default
indices

summation index dict or list of index.

required
operand Expression

operand of summation

required

Returns:

Name Type Description
SumOperator SumOperator

SumOperator object.

Example

Create i=0ndixi\sum_{i=0}^n d_i x_i

import jijmodeling as jm
d = jm.Placeholder('d', ndim=1)
n = d.shape[0]
x = jm.BinaryVar('x', shape=n)
i = jm.Element('i', n)
jm.sum(i, d[i]*x[i])
# Σ_{i}(d[i]x[i])

Create ijdijxixj\sum_{i}\sum_j d_{ij}x_i x_j

import jijmodeling as jm
d = jm.Placeholder('d', ndim=2)
n = d.shape[0]
x = jm.BinaryVar('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', ndim=2)
n = d.shape[0]
i, j = jm.Element("i", n), jm.Element("j", n)
x = jm.BinaryVar('x', shape=n)
jm.sum([i, (j, i < j)], d[i, j]*x[i]*x[j])


Last update: 2023年7月5日