Skip to content

Utils

extract_nodes(tree, cls)

Extract specified class object from Expression tree.

Parameters:

Name Type Description Default
tree Expression

Target expression tree.

required
cls Type

Target class.

required

Returns:

Name Type Description
List tp.List[T]

cls object list are included in tree.

Examples:

import jijmodeling as jm
d = jm.Placheolder("d", dim=1)
n = d.shape[0]
x = jm.Binary("x", shape=(n, ))
i = jm.Element("i", n)
term = jm.Sum(i, d[i]*x[i])
jm.extract_nodes(term, jm.DecisionVariable)
# [x]

get_order(expression)

Get an order of polynomial.

For example, x_i * y_i + x_i -> 2 if x and y is a decision variable.

Parameters:

Name Type Description Default
expression Expression

expression

required

Returns:

Name Type Description
int int

Integer

expression_indices(expression)

Extract all indices from the expression.

Parameters:

Name Type Description Default
expression Expression

expression

required

Returns:

Type Description
tp.List[_variable.Element]

List[Element]:

check_non_decision_variable(exp_list, error_msg)

Check if list has decision variable or not.

Parameters:

Name Type Description Default
exp_list Iterable[Expression]

target iterator.

required
error_msg str

error message.

required

Raises:

Type Description
CannotContainDecisionVarError

if list has decision variable.

flatten_binary_operator(expression, op_type=_expression.Add)

Flatten op_type binary operator to list.

This function flattens a given node to the following

node1 <> node2 <> node3 <> ... <> nodeN -> [node1, node2, node3, ..., nodeN]

where <> is a specified binary operator by op_type.

Parameters:

Name Type Description Default
expression Expression

target expression.

required
op_type Type[BinaryOperator]

target binary operator.

_expression.Add

Returns:

Type Description
tp.List[_expression.Expression]

List[Expression]: list of expression. Each element is not binary operator.


Last update: 2023年7月5日