jijzepttools.modeling.algorithm.series_decomposition.extract#
Functions#
|
Get separable indices from constraint. |
Module Contents#
- get_separable_indices(constraint: jijmodeling.Constraint, *, separable_exprs: List[jijzepttools.modeling.utils.type.Expr] = None, separable_pattern: List[Callable[[jijzepttools.modeling.utils.type.Expr], bool]] = None) List[jijmodeling.Element] #
Get separable indices from constraint. “separable” means that the constraint does not share the same decision variable with the index. The strategy is as follows:
if there is DecisionVariable without subscript, the constraint is not separable
get forall indices from constraint
- for each forall index,
- get list of jm.SubscriptOp whose variable is decision variable and whose subscript has at least one of the following property:
each element of subscript is the same as index
each element of subscript contains only index and the subscript expr is included in additional_separable_sub_list
if there is no duplicated variable, the forall index is separable index
if there is duplicated variable and the forall index is located in the same subscript, the forall index is separable index
otherwise, the forall index is not separable index
- Parameters:
constraint (jm.Constraint) – constraint
separable_exprs (tp.List[object], optional) – additional separable expressions. Defaults to [].
separable_pattern (tp.List[tp.Callable[[Expr], bool]], optional) – additional separable patterns. Defaults to [].
- Returns:
separable indices
- Return type:
tp.List[jm.Element]
Example
>>> x = jm.BinaryVar("x", shape=(10, 10, 10)) >>> y = jm.IntegerVar("y", shape=(10,), lower_bound=0, upper_bound=10) >>> A = jm.Placeholder("A", ndim=1) >>> I = jm.Placeholder("I", ndim=1) >>> i = jm.Element("i", belong_to=I) >>> j = jm.Element("j", belong_to=(0, 10)) >>> k = jm.Element("k", belong_to=(0, 10)) >>> z = jm.Placeholder("z", ndim=1) >>> constraint = jm.Constraint("constraint", jm.sum(i, x[i, j, k]) <= z[k], forall=[j, k]) >>> sorted(get_separable_indices(constraint), key=lambda x: x.name) [Element(name='j', belong_to=(NumberLit(value=0), NumberLit(value=10))), Element(name='k', belong_to=(NumberLit(value=0), NumberLit(value=10)))] >>> constraint = jm.Constraint("constraint", jm.sum(i, x[i, j, k]) <= y[k], forall=[j, k]) >>> sorted(get_separable_indices(constraint), key=lambda x: x.name) [Element(name='k', belong_to=(NumberLit(value=0), NumberLit(value=10)))]