jijmodeling 0.13.1__cp39-cp39-win_amd64.whl → 1.11.0__cp39-cp39-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of jijmodeling might be problematic. Click here for more details.
- jijmodeling/__init__.py +1 -154
- jijmodeling/__init__.pyi +5152 -0
- jijmodeling/_jijmodeling.cp39-win_amd64.pyd +0 -0
- jijmodeling/dataset.py +5 -0
- jijmodeling/dataset.pyi +106 -0
- jijmodeling/experimental.py +13 -0
- jijmodeling/experimental.pyi +302 -0
- jijmodeling/py.typed +0 -0
- jijmodeling/range/__init__.py +14 -0
- jijmodeling/range/__init__.pyi +56 -0
- jijmodeling/range/size.py +14 -0
- jijmodeling/range/size.pyi +54 -0
- jijmodeling/range/value.py +14 -0
- jijmodeling/range/value.pyi +54 -0
- jijmodeling-1.11.0.dist-info/METADATA +235 -0
- jijmodeling-1.11.0.dist-info/RECORD +18 -0
- {jijmodeling-0.13.1.dist-info → jijmodeling-1.11.0.dist-info}/WHEEL +1 -2
- {jijmodeling-0.13.1.dist-info → jijmodeling-1.11.0.dist-info/licenses}/LICENSE.txt +1 -1
- jijmodeling/__pycache__/__init__.cpython-39.opt-1.pyc +0 -0
- jijmodeling/__pycache__/__init__.cpython-39.pyc +0 -0
- jijmodeling/__pycache__/_version.cpython-39.opt-1.pyc +0 -0
- jijmodeling/__pycache__/_version.cpython-39.pyc +0 -0
- jijmodeling/_version.py +0 -4
- jijmodeling/deprecation/__init__.py +0 -11
- jijmodeling/deprecation/__pycache__/__init__.cpython-39.opt-1.pyc +0 -0
- jijmodeling/deprecation/__pycache__/__init__.cpython-39.pyc +0 -0
- jijmodeling/deprecation/__pycache__/deprecation.cpython-39.opt-1.pyc +0 -0
- jijmodeling/deprecation/__pycache__/deprecation.cpython-39.pyc +0 -0
- jijmodeling/deprecation/deprecation.py +0 -108
- jijmodeling/exceptions/__init__.py +0 -26
- jijmodeling/exceptions/__pycache__/__init__.cpython-39.opt-1.pyc +0 -0
- jijmodeling/exceptions/__pycache__/__init__.cpython-39.pyc +0 -0
- jijmodeling/exceptions/__pycache__/exceptions.cpython-39.opt-1.pyc +0 -0
- jijmodeling/exceptions/__pycache__/exceptions.cpython-39.pyc +0 -0
- jijmodeling/exceptions/exceptions.py +0 -37
- jijmodeling/expression/__init__.py +0 -76
- jijmodeling/expression/__pycache__/__init__.cpython-39.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/__init__.cpython-39.pyc +0 -0
- jijmodeling/expression/__pycache__/condition.cpython-39.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/condition.cpython-39.pyc +0 -0
- jijmodeling/expression/__pycache__/constraint.cpython-39.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/constraint.cpython-39.pyc +0 -0
- jijmodeling/expression/__pycache__/expression.cpython-39.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/expression.cpython-39.pyc +0 -0
- jijmodeling/expression/__pycache__/extract.cpython-39.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/extract.cpython-39.pyc +0 -0
- jijmodeling/expression/__pycache__/from_old_serializable.cpython-39.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/from_old_serializable.cpython-39.pyc +0 -0
- jijmodeling/expression/__pycache__/mathfunc.cpython-39.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/mathfunc.cpython-39.pyc +0 -0
- jijmodeling/expression/__pycache__/prod.cpython-39.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/prod.cpython-39.pyc +0 -0
- jijmodeling/expression/__pycache__/serializable.cpython-39.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/serializable.cpython-39.pyc +0 -0
- jijmodeling/expression/__pycache__/sum.cpython-39.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/sum.cpython-39.pyc +0 -0
- jijmodeling/expression/__pycache__/type_annotations.cpython-39.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/type_annotations.cpython-39.pyc +0 -0
- jijmodeling/expression/__pycache__/utils.cpython-39.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/utils.cpython-39.pyc +0 -0
- jijmodeling/expression/condition.py +0 -378
- jijmodeling/expression/constraint.py +0 -428
- jijmodeling/expression/expression.py +0 -768
- jijmodeling/expression/extract.py +0 -186
- jijmodeling/expression/from_old_serializable.py +0 -137
- jijmodeling/expression/mathfunc.py +0 -335
- jijmodeling/expression/prod.py +0 -172
- jijmodeling/expression/serializable.py +0 -142
- jijmodeling/expression/sum.py +0 -261
- jijmodeling/expression/type_annotations.py +0 -50
- jijmodeling/expression/utils.py +0 -202
- jijmodeling/expression/variables/__init__.py +0 -39
- jijmodeling/expression/variables/__pycache__/__init__.cpython-39.opt-1.pyc +0 -0
- jijmodeling/expression/variables/__pycache__/__init__.cpython-39.pyc +0 -0
- jijmodeling/expression/variables/__pycache__/deci_vars.cpython-39.opt-1.pyc +0 -0
- jijmodeling/expression/variables/__pycache__/deci_vars.cpython-39.pyc +0 -0
- jijmodeling/expression/variables/__pycache__/jagged_array.cpython-39.opt-1.pyc +0 -0
- jijmodeling/expression/variables/__pycache__/jagged_array.cpython-39.pyc +0 -0
- jijmodeling/expression/variables/__pycache__/placeholders.cpython-39.opt-1.pyc +0 -0
- jijmodeling/expression/variables/__pycache__/placeholders.cpython-39.pyc +0 -0
- jijmodeling/expression/variables/__pycache__/variable.cpython-39.opt-1.pyc +0 -0
- jijmodeling/expression/variables/__pycache__/variable.cpython-39.pyc +0 -0
- jijmodeling/expression/variables/deci_vars.py +0 -212
- jijmodeling/expression/variables/jagged_array.py +0 -81
- jijmodeling/expression/variables/placeholders.py +0 -132
- jijmodeling/expression/variables/variable.py +0 -524
- jijmodeling/latex_repr/__init__.py +0 -11
- jijmodeling/latex_repr/__pycache__/__init__.cpython-39.opt-1.pyc +0 -0
- jijmodeling/latex_repr/__pycache__/__init__.cpython-39.pyc +0 -0
- jijmodeling/latex_repr/__pycache__/latex_repr.cpython-39.opt-1.pyc +0 -0
- jijmodeling/latex_repr/__pycache__/latex_repr.cpython-39.pyc +0 -0
- jijmodeling/latex_repr/__pycache__/problem_latex_repr.cpython-39.opt-1.pyc +0 -0
- jijmodeling/latex_repr/__pycache__/problem_latex_repr.cpython-39.pyc +0 -0
- jijmodeling/latex_repr/latex_repr.py +0 -243
- jijmodeling/latex_repr/problem_latex_repr.py +0 -210
- jijmodeling/marker/__marker__.cp39-win_amd64.pyd +0 -0
- jijmodeling/match/__init__.py +0 -19
- jijmodeling/match/__pycache__/__init__.cpython-39.opt-1.pyc +0 -0
- jijmodeling/match/__pycache__/__init__.cpython-39.pyc +0 -0
- jijmodeling/match/__pycache__/condition_same.cpython-39.opt-1.pyc +0 -0
- jijmodeling/match/__pycache__/condition_same.cpython-39.pyc +0 -0
- jijmodeling/match/__pycache__/constraint_same.cpython-39.opt-1.pyc +0 -0
- jijmodeling/match/__pycache__/constraint_same.cpython-39.pyc +0 -0
- jijmodeling/match/__pycache__/expand.cpython-39.opt-1.pyc +0 -0
- jijmodeling/match/__pycache__/expand.cpython-39.pyc +0 -0
- jijmodeling/match/__pycache__/expr_same.cpython-39.opt-1.pyc +0 -0
- jijmodeling/match/__pycache__/expr_same.cpython-39.pyc +0 -0
- jijmodeling/match/__pycache__/is_same_expr.cpython-39.opt-1.pyc +0 -0
- jijmodeling/match/__pycache__/is_same_expr.cpython-39.pyc +0 -0
- jijmodeling/match/__pycache__/penalty_same.cpython-39.opt-1.pyc +0 -0
- jijmodeling/match/__pycache__/penalty_same.cpython-39.pyc +0 -0
- jijmodeling/match/__pycache__/problem_same.cpython-39.opt-1.pyc +0 -0
- jijmodeling/match/__pycache__/problem_same.cpython-39.pyc +0 -0
- jijmodeling/match/__pycache__/replace.cpython-39.opt-1.pyc +0 -0
- jijmodeling/match/__pycache__/replace.cpython-39.pyc +0 -0
- jijmodeling/match/condition_same.py +0 -44
- jijmodeling/match/constraint_same.py +0 -53
- jijmodeling/match/expand.py +0 -84
- jijmodeling/match/expr_same.py +0 -32
- jijmodeling/match/is_same_expr.py +0 -306
- jijmodeling/match/penalty_same.py +0 -31
- jijmodeling/match/problem_same.py +0 -44
- jijmodeling/match/replace.py +0 -249
- jijmodeling/problem/__init__.py +0 -9
- jijmodeling/problem/__pycache__/__init__.cpython-39.opt-1.pyc +0 -0
- jijmodeling/problem/__pycache__/__init__.cpython-39.pyc +0 -0
- jijmodeling/problem/__pycache__/problem.cpython-39.opt-1.pyc +0 -0
- jijmodeling/problem/__pycache__/problem.cpython-39.pyc +0 -0
- jijmodeling/problem/problem.py +0 -186
- jijmodeling/protobuf/__init__.py +0 -8
- jijmodeling/protobuf/__pycache__/__init__.cpython-39.opt-1.pyc +0 -0
- jijmodeling/protobuf/__pycache__/__init__.cpython-39.pyc +0 -0
- jijmodeling/protobuf/__pycache__/from_protobuf.cpython-39.opt-1.pyc +0 -0
- jijmodeling/protobuf/__pycache__/from_protobuf.cpython-39.pyc +0 -0
- jijmodeling/protobuf/__pycache__/to_protobuf.cpython-39.opt-1.pyc +0 -0
- jijmodeling/protobuf/__pycache__/to_protobuf.cpython-39.pyc +0 -0
- jijmodeling/protobuf/__pycache__/type_annotations.cpython-39.opt-1.pyc +0 -0
- jijmodeling/protobuf/__pycache__/type_annotations.cpython-39.pyc +0 -0
- jijmodeling/protobuf/from_protobuf.py +0 -336
- jijmodeling/protobuf/pb2/__init__.py +0 -42
- jijmodeling/protobuf/pb2/__pycache__/__init__.cpython-39.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/__init__.cpython-39.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/array_length_pb2.cpython-39.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/array_length_pb2.cpython-39.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/binary_op_pb2.cpython-39.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/binary_op_pb2.cpython-39.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/commutative_op_pb2.cpython-39.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/commutative_op_pb2.cpython-39.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/constraint_pb2.cpython-39.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/constraint_pb2.cpython-39.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/custom_penalty_term_pb2.cpython-39.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/custom_penalty_term_pb2.cpython-39.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/decision_var_pb2.cpython-39.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/decision_var_pb2.cpython-39.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/element_pb2.cpython-39.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/element_pb2.cpython-39.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/expression_pb2.cpython-39.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/expression_pb2.cpython-39.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/forall_pb2.cpython-39.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/forall_pb2.cpython-39.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/header_pb2.cpython-39.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/header_pb2.cpython-39.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/index_pb2.cpython-39.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/index_pb2.cpython-39.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/number_lit_pb2.cpython-39.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/number_lit_pb2.cpython-39.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/placeholder_pb2.cpython-39.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/placeholder_pb2.cpython-39.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/problem_pb2.cpython-39.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/problem_pb2.cpython-39.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/reduction_op_pb2.cpython-39.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/reduction_op_pb2.cpython-39.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/subscript_pb2.cpython-39.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/subscript_pb2.cpython-39.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/unary_op_pb2.cpython-39.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/unary_op_pb2.cpython-39.pyc +0 -0
- jijmodeling/protobuf/pb2/array_length_pb2.py +0 -27
- jijmodeling/protobuf/pb2/binary_op_pb2.py +0 -27
- jijmodeling/protobuf/pb2/commutative_op_pb2.py +0 -27
- jijmodeling/protobuf/pb2/constraint_pb2.py +0 -31
- jijmodeling/protobuf/pb2/custom_penalty_term_pb2.py +0 -31
- jijmodeling/protobuf/pb2/decision_var_pb2.py +0 -31
- jijmodeling/protobuf/pb2/element_pb2.py +0 -31
- jijmodeling/protobuf/pb2/expression_pb2.py +0 -39
- jijmodeling/protobuf/pb2/forall_pb2.py +0 -29
- jijmodeling/protobuf/pb2/header_pb2.py +0 -31
- jijmodeling/protobuf/pb2/index_pb2.py +0 -25
- jijmodeling/protobuf/pb2/number_lit_pb2.py +0 -27
- jijmodeling/protobuf/pb2/placeholder_pb2.py +0 -25
- jijmodeling/protobuf/pb2/problem_pb2.py +0 -40
- jijmodeling/protobuf/pb2/reduction_op_pb2.py +0 -30
- jijmodeling/protobuf/pb2/subscript_pb2.py +0 -27
- jijmodeling/protobuf/pb2/unary_op_pb2.py +0 -27
- jijmodeling/protobuf/to_protobuf.py +0 -631
- jijmodeling/protobuf/type_annotations.py +0 -52
- jijmodeling/sampleset/__init__.py +0 -33
- jijmodeling/sampleset/__pycache__/__init__.cpython-39.opt-1.pyc +0 -0
- jijmodeling/sampleset/__pycache__/__init__.cpython-39.pyc +0 -0
- jijmodeling/sampleset/__pycache__/evaluation.cpython-39.opt-1.pyc +0 -0
- jijmodeling/sampleset/__pycache__/evaluation.cpython-39.pyc +0 -0
- jijmodeling/sampleset/__pycache__/measuring_time.cpython-39.opt-1.pyc +0 -0
- jijmodeling/sampleset/__pycache__/measuring_time.cpython-39.pyc +0 -0
- jijmodeling/sampleset/__pycache__/record.cpython-39.opt-1.pyc +0 -0
- jijmodeling/sampleset/__pycache__/record.cpython-39.pyc +0 -0
- jijmodeling/sampleset/__pycache__/sampleset.cpython-39.opt-1.pyc +0 -0
- jijmodeling/sampleset/__pycache__/sampleset.cpython-39.pyc +0 -0
- jijmodeling/sampleset/__pycache__/solving_time.cpython-39.opt-1.pyc +0 -0
- jijmodeling/sampleset/__pycache__/solving_time.cpython-39.pyc +0 -0
- jijmodeling/sampleset/__pycache__/system_time.cpython-39.opt-1.pyc +0 -0
- jijmodeling/sampleset/__pycache__/system_time.cpython-39.pyc +0 -0
- jijmodeling/sampleset/evaluation.py +0 -289
- jijmodeling/sampleset/measuring_time.py +0 -59
- jijmodeling/sampleset/record.py +0 -158
- jijmodeling/sampleset/sampleset.py +0 -389
- jijmodeling/sampleset/solving_time.py +0 -38
- jijmodeling/sampleset/system_time.py +0 -48
- jijmodeling/type_annotations/__init__.py +0 -44
- jijmodeling/type_annotations/__pycache__/__init__.cpython-39.opt-1.pyc +0 -0
- jijmodeling/type_annotations/__pycache__/__init__.cpython-39.pyc +0 -0
- jijmodeling/type_annotations/__pycache__/type_annotations.cpython-39.opt-1.pyc +0 -0
- jijmodeling/type_annotations/__pycache__/type_annotations.cpython-39.pyc +0 -0
- jijmodeling/type_annotations/type_annotations.py +0 -54
- jijmodeling/utils/__init__.py +0 -28
- jijmodeling/utils/__pycache__/__init__.cpython-39.opt-1.pyc +0 -0
- jijmodeling/utils/__pycache__/__init__.cpython-39.pyc +0 -0
- jijmodeling/utils/__pycache__/deprecated.cpython-39.opt-1.pyc +0 -0
- jijmodeling/utils/__pycache__/deprecated.cpython-39.pyc +0 -0
- jijmodeling/utils/__pycache__/utils.cpython-39.opt-1.pyc +0 -0
- jijmodeling/utils/__pycache__/utils.cpython-39.pyc +0 -0
- jijmodeling/utils/deprecated.py +0 -17
- jijmodeling/utils/utils.py +0 -146
- jijmodeling-0.13.1.dist-info/METADATA +0 -60
- jijmodeling-0.13.1.dist-info/RECORD +0 -219
- jijmodeling-0.13.1.dist-info/top_level.txt +0 -1
jijmodeling/expression/prod.py
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from typing import List, Optional, Tuple, Union
|
|
4
|
-
import warnings
|
|
5
|
-
|
|
6
|
-
from typeguard import typechecked
|
|
7
|
-
|
|
8
|
-
from jijmodeling.deprecation.deprecation import (
|
|
9
|
-
deprecated_name,
|
|
10
|
-
JijFutureWarning
|
|
11
|
-
)
|
|
12
|
-
import jijmodeling.expression.condition as _condition
|
|
13
|
-
import jijmodeling.expression.expression as _expression
|
|
14
|
-
import jijmodeling.expression.sum as _sum
|
|
15
|
-
|
|
16
|
-
# type validation
|
|
17
|
-
import jijmodeling.expression.variables.variable as _variable
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class ProdOperator(_sum.ReductionOperator):
|
|
21
|
-
pass
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
INDEXWITHCOND = Union[_variable.Element, Tuple[_variable.Element, _condition.Condition]]
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
@deprecated_name("Prod", "prod", kind="function")
|
|
28
|
-
def Prod(
|
|
29
|
-
indices: Union[INDEXWITHCOND, List[INDEXWITHCOND]],
|
|
30
|
-
term: _expression.Expression,
|
|
31
|
-
) -> ProdOperator:
|
|
32
|
-
"""
|
|
33
|
-
Prod function.
|
|
34
|
-
|
|
35
|
-
Args:
|
|
36
|
-
indices: product index dict or list of index.
|
|
37
|
-
term (Expression): operand
|
|
38
|
-
|
|
39
|
-
Returns:
|
|
40
|
-
ProdOperator: ProdOperator object.
|
|
41
|
-
|
|
42
|
-
Example:
|
|
43
|
-
Create $\\prod_{i=0}^n d_i x_i$
|
|
44
|
-
|
|
45
|
-
```python
|
|
46
|
-
import jijmodeling as jm
|
|
47
|
-
d = jm.Placeholder('d', dim=1)
|
|
48
|
-
n = d.shape[0]
|
|
49
|
-
x = jm.Binary('x', shape=n)
|
|
50
|
-
i = jm.Element('i', n)
|
|
51
|
-
jm.Prod(i, d[i]*x[i])
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
Create $\\prod_{i}\\sum_j d_{ij}x_i x_j$
|
|
55
|
-
|
|
56
|
-
```python
|
|
57
|
-
import jijmodeling as jm
|
|
58
|
-
d = jm.Placeholder('d', dim = 2)
|
|
59
|
-
n = d.shape[0]
|
|
60
|
-
x = jm.Binary('x', shape=n)
|
|
61
|
-
i = jm.Element('i', n)
|
|
62
|
-
j = jm.Element('j', n)
|
|
63
|
-
jm.Prod([i, j], d[i, j]*x[i]*x[j])
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
Conditional production
|
|
67
|
-
|
|
68
|
-
```python
|
|
69
|
-
import jijmodeling as jm
|
|
70
|
-
d = jm.Placeholder('d', dim = 2)
|
|
71
|
-
n = d.shape[0]
|
|
72
|
-
i, j = jm.Element("i", n), jm._variable.Element("j", n)
|
|
73
|
-
x = jm.Binary('x', shape=n)
|
|
74
|
-
jm.Prod([i, (j, i < j)], d[i, j]*x[i]*x[j])
|
|
75
|
-
```
|
|
76
|
-
"""
|
|
77
|
-
|
|
78
|
-
# convert indices and condition to list-type object
|
|
79
|
-
# ex. i -> [i]
|
|
80
|
-
indices_list = indices if isinstance(indices, list) else [indices] # type: ignore
|
|
81
|
-
|
|
82
|
-
@typechecked
|
|
83
|
-
def convert_to_element(
|
|
84
|
-
index: Union[
|
|
85
|
-
_variable.Element, Tuple[_variable.Element, Optional[_condition.Condition]]
|
|
86
|
-
],
|
|
87
|
-
) -> Tuple[_variable.Element, Optional[_condition.Condition]]:
|
|
88
|
-
if isinstance(
|
|
89
|
-
index, tuple
|
|
90
|
-
): # Tuple[_variable.ElementType, Optional[Condition]]
|
|
91
|
-
elem, cond = index
|
|
92
|
-
return (elem, cond)
|
|
93
|
-
else: # _variable.ElementType
|
|
94
|
-
return (index, None)
|
|
95
|
-
|
|
96
|
-
elems_and_conds: List[Tuple[_variable.Element, Optional[_condition.Condition]]] = [
|
|
97
|
-
convert_to_element(index) for index in indices_list
|
|
98
|
-
]
|
|
99
|
-
elements = [elem for elem, _ in elems_and_conds]
|
|
100
|
-
condition_list = [cond for _, cond in elems_and_conds]
|
|
101
|
-
|
|
102
|
-
# list length validation
|
|
103
|
-
import jijmodeling.utils.utils as _utils
|
|
104
|
-
|
|
105
|
-
_utils.validate_value("len(indices) > 0", len(elements) > 0)
|
|
106
|
-
_utils.validate_value("len(condition_list) > 0", len(condition_list) > 0)
|
|
107
|
-
_utils.validate_value(
|
|
108
|
-
"len(indices_list) == len(condition_list)",
|
|
109
|
-
len(indices_list) == len(condition_list),
|
|
110
|
-
)
|
|
111
|
-
sum_term = term
|
|
112
|
-
for sum_index, cond in zip(elements[::-1], condition_list[::-1]):
|
|
113
|
-
sum_term = ProdOperator(
|
|
114
|
-
sum_index=sum_index,
|
|
115
|
-
operand=sum_term,
|
|
116
|
-
condition=cond if cond is not None else _condition.NoneCondition(),
|
|
117
|
-
)
|
|
118
|
-
return sum_term # type: ignore
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
def prod(
|
|
122
|
-
index: Union[INDEXWITHCOND, List[INDEXWITHCOND]],
|
|
123
|
-
operand: _expression.Expression,
|
|
124
|
-
) -> ProdOperator:
|
|
125
|
-
"""
|
|
126
|
-
Prod function.
|
|
127
|
-
|
|
128
|
-
Args:
|
|
129
|
-
indices: product index dict or list of index.
|
|
130
|
-
operand (Expression): operand
|
|
131
|
-
|
|
132
|
-
Returns:
|
|
133
|
-
ProdOperator: ProdOperator object.
|
|
134
|
-
|
|
135
|
-
Example:
|
|
136
|
-
Create $\\prod_{i=0}^n d_i x_i$
|
|
137
|
-
|
|
138
|
-
```python
|
|
139
|
-
import jijmodeling as jm
|
|
140
|
-
d = jm.Placeholder('d', ndim=1)
|
|
141
|
-
n = d.shape[0]
|
|
142
|
-
x = jm.BinaryVar('x', shape=n)
|
|
143
|
-
i = jm.Element('i', n)
|
|
144
|
-
jm.prod(i, d[i]*x[i])
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
Create $\\prod_{i}\\sum_j d_{ij}x_i x_j$
|
|
148
|
-
|
|
149
|
-
```python
|
|
150
|
-
import jijmodeling as jm
|
|
151
|
-
d = jm.Placeholder('d', ndim=2)
|
|
152
|
-
n = d.shape[0]
|
|
153
|
-
x = jm.BinaryVar('x', shape=n)
|
|
154
|
-
i = jm.Element('i', n)
|
|
155
|
-
j = jm.Element('j', n)
|
|
156
|
-
jm.prod([i, j], d[i, j]*x[i]*x[j])
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
Conditional production
|
|
160
|
-
|
|
161
|
-
```python
|
|
162
|
-
import jijmodeling as jm
|
|
163
|
-
d = jm.Placeholder('d', ndim=2)
|
|
164
|
-
n = d.shape[0]
|
|
165
|
-
i, j = jm.Element("i", n), jm._variable.Element("j", n)
|
|
166
|
-
x = jm.BinaryVar('x', shape=n)
|
|
167
|
-
jm.prod([i, (j, i < j)], d[i, j]*x[i]*x[j])
|
|
168
|
-
```
|
|
169
|
-
"""
|
|
170
|
-
with warnings.catch_warnings():
|
|
171
|
-
warnings.simplefilter("ignore", category=JijFutureWarning)
|
|
172
|
-
return Prod(index, operand)
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import abc as _abc
|
|
4
|
-
import enum as _enum
|
|
5
|
-
import inspect as _inspect
|
|
6
|
-
import typing as tp
|
|
7
|
-
import uuid as _uuid
|
|
8
|
-
import warnings
|
|
9
|
-
|
|
10
|
-
from typeguard import typechecked
|
|
11
|
-
|
|
12
|
-
import jijmodeling
|
|
13
|
-
from jijmodeling.deprecation.deprecation import JijFutureWarning
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class Serializable(_abc.ABCMeta):
|
|
17
|
-
"""
|
|
18
|
-
Meta class that can call `to_serializable()` and `from_serializable()`.
|
|
19
|
-
"""
|
|
20
|
-
|
|
21
|
-
def __new__(cls, cls_name, cls_bases, cls_dict):
|
|
22
|
-
if "__init__" in cls_dict:
|
|
23
|
-
# serializeで用いるためExpressionクラスはコンストラクタの引数と対応する同じ名前の
|
|
24
|
-
# @property を持つ必要があるので, それが実装されているかをチェックする
|
|
25
|
-
init_func = _inspect.signature(cls_dict["__init__"])
|
|
26
|
-
params = [param for param in init_func.parameters if param != "self"]
|
|
27
|
-
for param in params:
|
|
28
|
-
if param not in cls_dict:
|
|
29
|
-
bases_has_property = False
|
|
30
|
-
for bases in cls_bases:
|
|
31
|
-
if param in dir(bases):
|
|
32
|
-
bases_has_property = True
|
|
33
|
-
if not bases_has_property:
|
|
34
|
-
raise NotImplementedError(
|
|
35
|
-
f"propety '{param}' must be" + f" define in {cls_name}."
|
|
36
|
-
)
|
|
37
|
-
return super().__new__(cls, cls_name, cls_bases, cls_dict)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def to_serializable(expression: Serializable) -> dict:
|
|
41
|
-
"""
|
|
42
|
-
Serialize an serializable object.
|
|
43
|
-
|
|
44
|
-
Args:
|
|
45
|
-
expression (Serializable): e.g. mathematical expression, problem, ...
|
|
46
|
-
|
|
47
|
-
Returns:
|
|
48
|
-
dict: serialized object
|
|
49
|
-
"""
|
|
50
|
-
seri = obj_to_seri(expression)
|
|
51
|
-
return {"version": "0.10.0", "object": seri}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
def obj_to_seri(obj):
|
|
55
|
-
if isinstance(obj.__class__, Serializable):
|
|
56
|
-
return expression_to_seri(obj)
|
|
57
|
-
elif isinstance(obj, (list, tuple)):
|
|
58
|
-
return {
|
|
59
|
-
"iteratable": "list" if isinstance(obj, list) else "tuple",
|
|
60
|
-
"value": [obj_to_seri(v) for v in obj],
|
|
61
|
-
}
|
|
62
|
-
elif isinstance(obj, dict):
|
|
63
|
-
return {k: obj_to_seri(v) for k, v in obj.items()}
|
|
64
|
-
elif isinstance(obj, _uuid.UUID):
|
|
65
|
-
return obj.hex
|
|
66
|
-
elif isinstance(obj, _enum.Enum):
|
|
67
|
-
if isinstance(obj, jijmodeling.expression.expression.DataType):
|
|
68
|
-
return obj.value.lower()
|
|
69
|
-
else:
|
|
70
|
-
return obj.value
|
|
71
|
-
else:
|
|
72
|
-
return obj
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
def expression_to_seri(expression: Serializable) -> dict:
|
|
76
|
-
exp_module = expression.__class__.__module__
|
|
77
|
-
exp_cls = expression.__class__.__name__
|
|
78
|
-
serializable: tp.Dict[str, tp.Any] = {"class": exp_module + "." + exp_cls}
|
|
79
|
-
|
|
80
|
-
init_args_keys = _inspect.signature(expression.__class__.__init__).parameters.keys()
|
|
81
|
-
init_params = {}
|
|
82
|
-
for key in init_args_keys:
|
|
83
|
-
# Ignore `self` because it is not used as a key for a serialized object
|
|
84
|
-
if key == "self":
|
|
85
|
-
continue
|
|
86
|
-
# Expression class の constructor の引数名と同じpropertyを必ず各クラスは持っているので
|
|
87
|
-
# それを情報としてserializeする
|
|
88
|
-
if f"_{key}" in dir(expression):
|
|
89
|
-
value = eval(f"expression._{key}")
|
|
90
|
-
else:
|
|
91
|
-
value = eval(f"expression.{key}")
|
|
92
|
-
init_params[key] = obj_to_seri(value)
|
|
93
|
-
serializable["attributes"] = init_params
|
|
94
|
-
return serializable
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
@typechecked
|
|
98
|
-
def from_serializable(serializable: tp.Union[dict, list]):
|
|
99
|
-
"""
|
|
100
|
-
Convert to Expression from serializable object (dict).
|
|
101
|
-
|
|
102
|
-
Args:
|
|
103
|
-
serializable (dict): serialized object
|
|
104
|
-
|
|
105
|
-
Returns:
|
|
106
|
-
Expression|Problem: e.g. mathematical expression, problem, ...
|
|
107
|
-
|
|
108
|
-
"""
|
|
109
|
-
if isinstance(serializable, dict) and "object" in serializable:
|
|
110
|
-
obj = serializable["object"]
|
|
111
|
-
else:
|
|
112
|
-
raise ValueError("version mismatch")
|
|
113
|
-
with warnings.catch_warnings():
|
|
114
|
-
warnings.simplefilter("ignore", category=JijFutureWarning)
|
|
115
|
-
return obj_from_seri(obj)
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
def obj_from_seri(obj):
|
|
119
|
-
if isinstance(obj, dict) and "class" in obj:
|
|
120
|
-
modulePath = obj["class"].split(".")[1:]
|
|
121
|
-
module = jijmodeling
|
|
122
|
-
for m in modulePath:
|
|
123
|
-
module = getattr(module, m)
|
|
124
|
-
# get name of arguments of __init__ of Expression object
|
|
125
|
-
init_args = _inspect.signature(module.__init__).parameters.keys()
|
|
126
|
-
init_arg_values = {
|
|
127
|
-
arg: obj_from_seri(obj["attributes"][arg])
|
|
128
|
-
for arg in init_args
|
|
129
|
-
if arg != "self"
|
|
130
|
-
}
|
|
131
|
-
return module(**init_arg_values)
|
|
132
|
-
elif isinstance(obj, dict) and "iteratable" in obj:
|
|
133
|
-
if obj["iteratable"] == "list":
|
|
134
|
-
return [obj_from_seri(s) for s in obj["value"]]
|
|
135
|
-
elif obj["iteratable"] == "tuple":
|
|
136
|
-
return tuple(obj_from_seri(s) for s in obj["value"])
|
|
137
|
-
elif isinstance(obj, list):
|
|
138
|
-
return [obj_from_seri(s) for s in obj]
|
|
139
|
-
elif isinstance(obj, dict):
|
|
140
|
-
return {k: obj_from_seri(v) for k, v in obj.items()}
|
|
141
|
-
|
|
142
|
-
return obj
|
jijmodeling/expression/sum.py
DELETED
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import typing as tp
|
|
4
|
-
import warnings
|
|
5
|
-
|
|
6
|
-
import typeguard as _typeguard
|
|
7
|
-
|
|
8
|
-
from typeguard import typechecked
|
|
9
|
-
|
|
10
|
-
from jijmodeling.deprecation.deprecation import (
|
|
11
|
-
deprecated_name,
|
|
12
|
-
JijFutureWarning
|
|
13
|
-
)
|
|
14
|
-
import jijmodeling.exceptions.exceptions as _exceptions
|
|
15
|
-
import jijmodeling.expression.condition as _conditions
|
|
16
|
-
import jijmodeling.expression.expression as _expression
|
|
17
|
-
import jijmodeling.expression.extract as _extract
|
|
18
|
-
|
|
19
|
-
# type validation
|
|
20
|
-
import jijmodeling.expression.type_annotations as _type_annotations
|
|
21
|
-
import jijmodeling.expression.variables.variable as _variable
|
|
22
|
-
import jijmodeling.utils.utils as _utils
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
class ReductionOperator(_expression.Expression):
|
|
26
|
-
"""Super class of reduction operators.
|
|
27
|
-
Subclass examples: SumOperator, ProdOperator
|
|
28
|
-
"""
|
|
29
|
-
|
|
30
|
-
def __init__(
|
|
31
|
-
self,
|
|
32
|
-
sum_index: _variable.Element,
|
|
33
|
-
operand: _expression.Expression,
|
|
34
|
-
condition: tp.Optional[_conditions.Condition] = None,
|
|
35
|
-
uuid: tp.Optional[str] = None,
|
|
36
|
-
) -> None:
|
|
37
|
-
super().__init__(uuid=uuid)
|
|
38
|
-
|
|
39
|
-
self._sum_index = sum_index
|
|
40
|
-
self._operand = operand
|
|
41
|
-
self._condition: _conditions.Condition = (
|
|
42
|
-
_conditions.NoneCondition() if condition is None else condition
|
|
43
|
-
)
|
|
44
|
-
if uuid is not None:
|
|
45
|
-
self._uuid = uuid
|
|
46
|
-
|
|
47
|
-
if _extract.condition_has_decivar(self._condition):
|
|
48
|
-
raise _exceptions.CannotContainDecisionVarError(
|
|
49
|
-
"condition for sum index cannot contain decision variable."
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
ConditionType = tp.Optional[_conditions.Condition]
|
|
53
|
-
_typeguard.check_type(self._sum_index, _type_annotations.SumIndexType)
|
|
54
|
-
_typeguard.check_type(self._operand, _type_annotations.OperandType)
|
|
55
|
-
_typeguard.check_type(self._condition, ConditionType)
|
|
56
|
-
|
|
57
|
-
@property
|
|
58
|
-
def sum_index(self) -> _variable.Element:
|
|
59
|
-
"""Summation index."""
|
|
60
|
-
return self._sum_index
|
|
61
|
-
|
|
62
|
-
@property
|
|
63
|
-
def operand(self) -> _expression.Expression:
|
|
64
|
-
"""Summation operand."""
|
|
65
|
-
return self._operand
|
|
66
|
-
|
|
67
|
-
@property
|
|
68
|
-
def condition(self) -> _conditions.Condition:
|
|
69
|
-
"""Summation condition."""
|
|
70
|
-
return self._condition
|
|
71
|
-
|
|
72
|
-
def children(self) -> list:
|
|
73
|
-
"""[sum_index, operand, condition]."""
|
|
74
|
-
return [self._sum_index, self._operand] + self.condition.expressions()
|
|
75
|
-
|
|
76
|
-
def is_operatable(self) -> bool:
|
|
77
|
-
return True
|
|
78
|
-
|
|
79
|
-
def __repr__(self) -> str:
|
|
80
|
-
sum_index = ""
|
|
81
|
-
if isinstance(self.sum_index.parent, _variable.Range):
|
|
82
|
-
sum_index = "{" + "{}={}".format(
|
|
83
|
-
self.sum_index, self.sum_index.parent.start
|
|
84
|
-
)
|
|
85
|
-
sum_index = sum_index + "}"
|
|
86
|
-
sum_index = sum_index + "^{" + str(self.sum_index.parent.last) + "}"
|
|
87
|
-
else:
|
|
88
|
-
sum_index = "{" + f"{self.sum_index} in {self.sum_index.parent}"
|
|
89
|
-
sum_index = sum_index + "}"
|
|
90
|
-
|
|
91
|
-
return "Sum_" + sum_index + "(" + str(self.operand) + ")"
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
class SumOperator(ReductionOperator):
|
|
95
|
-
"""
|
|
96
|
-
Class that represents the sum.
|
|
97
|
-
|
|
98
|
-
Example:
|
|
99
|
-
Create $`\\sum_{i=0}^n d_i x_i`$
|
|
100
|
-
|
|
101
|
-
```python
|
|
102
|
-
from jijmodeling import Placeholder, Binary, SumOperator
|
|
103
|
-
from jijmodeling import Element
|
|
104
|
-
d = Placeholder('d', dim=1)
|
|
105
|
-
n = d.shape[0]
|
|
106
|
-
x = Binary('x', shape=n)
|
|
107
|
-
i = Element("i", n)
|
|
108
|
-
SumOperator(sum_index=i, operand=d[i]*x[i], condition=None)
|
|
109
|
-
# Σ_{i}(d[i]x[i])
|
|
110
|
-
```
|
|
111
|
-
"""
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
INDEXWITHCOND = tp.Union[
|
|
115
|
-
_variable.Element, tp.Tuple[_variable.Element, _conditions.Condition]
|
|
116
|
-
]
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
@deprecated_name("Sum", "sum", kind="function")
|
|
120
|
-
def Sum(
|
|
121
|
-
indices: tp.Union[INDEXWITHCOND, tp.List[INDEXWITHCOND]],
|
|
122
|
-
term: _expression.Expression,
|
|
123
|
-
) -> SumOperator:
|
|
124
|
-
"""
|
|
125
|
-
Sum function.
|
|
126
|
-
|
|
127
|
-
Args:
|
|
128
|
-
indices: summation index dict or list of index.
|
|
129
|
-
term (Expression): operand of summation
|
|
130
|
-
|
|
131
|
-
Returns:
|
|
132
|
-
SumOperator: SumOperator object.
|
|
133
|
-
|
|
134
|
-
Example:
|
|
135
|
-
Create $`\\sum_{i=0}^n d_i x_i`$
|
|
136
|
-
|
|
137
|
-
```python
|
|
138
|
-
import jijmodeling as jm
|
|
139
|
-
d = jm.Placeholder('d', dim=1)
|
|
140
|
-
n = d.shape[0]
|
|
141
|
-
x = jm.Binary('x', shape=n)
|
|
142
|
-
i = jm.Element('i', n)
|
|
143
|
-
jm.Sum(i, d[i]*x[i])
|
|
144
|
-
# Σ_{i}(d[i]x[i])
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
Create $`\\sum_{i}\\sum_j d_{ij}x_i x_j`$
|
|
148
|
-
|
|
149
|
-
```python
|
|
150
|
-
import jijmodeling as jm
|
|
151
|
-
d = jm.Placeholder('d', dim = 2)
|
|
152
|
-
n = d.shape[0]
|
|
153
|
-
x = jm.Binary('x', shape=n)
|
|
154
|
-
i = jm.Element('i', n)
|
|
155
|
-
j = jm.Element('j', n)
|
|
156
|
-
jm.Sum([i, j], d[i, j]*x[i]*x[j])
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
Conditional sum
|
|
160
|
-
```python
|
|
161
|
-
import jijmodeling as jm
|
|
162
|
-
d = jm.Placeholder('d', dim = 2)
|
|
163
|
-
n = d.shape[0]
|
|
164
|
-
i, j = jm.Element("i", n), jm.Element("j", n)
|
|
165
|
-
x = jm.Binary('x', shape=n)
|
|
166
|
-
jm.Sum([i, (j, i < j)], d[i, j]*x[i]*x[j])
|
|
167
|
-
```
|
|
168
|
-
"""
|
|
169
|
-
|
|
170
|
-
# convert indices and condition to list-type object
|
|
171
|
-
# ex. i -> [i]
|
|
172
|
-
indices_list = indices if isinstance(indices, list) else [indices] # type: ignore
|
|
173
|
-
|
|
174
|
-
@typechecked
|
|
175
|
-
def convert_to_element(
|
|
176
|
-
index: tp.Union[
|
|
177
|
-
_variable.Element,
|
|
178
|
-
tp.Tuple[_variable.Element, tp.Optional[_conditions.Condition]],
|
|
179
|
-
]
|
|
180
|
-
) -> tp.Tuple[_variable.Element, tp.Optional[_conditions.Condition]]:
|
|
181
|
-
if isinstance(index, tuple): # Tuple[ElementType, Optional[Condition]]
|
|
182
|
-
elem, cond = index
|
|
183
|
-
return (elem, cond)
|
|
184
|
-
else: # ElementType
|
|
185
|
-
return (index, None)
|
|
186
|
-
|
|
187
|
-
elems_and_conds: tp.List[
|
|
188
|
-
tp.Tuple[_variable.Element, tp.Optional[_conditions.Condition]]
|
|
189
|
-
] = [convert_to_element(index) for index in indices_list]
|
|
190
|
-
elements = [elem for elem, _ in elems_and_conds]
|
|
191
|
-
condition_list = [cond for _, cond in elems_and_conds]
|
|
192
|
-
|
|
193
|
-
# list length validation
|
|
194
|
-
_utils.validate_value("len(indices) > 0", len(elements) > 0)
|
|
195
|
-
_utils.validate_value("len(condition_list) > 0", len(condition_list) > 0)
|
|
196
|
-
_utils.validate_value(
|
|
197
|
-
"len(indices_list) == len(condition_list)",
|
|
198
|
-
len(indices_list) == len(condition_list),
|
|
199
|
-
)
|
|
200
|
-
sum_term = term
|
|
201
|
-
for sum_index, cond in zip(elements[::-1], condition_list[::-1]):
|
|
202
|
-
sum_term = SumOperator(
|
|
203
|
-
sum_index=sum_index,
|
|
204
|
-
operand=sum_term,
|
|
205
|
-
condition=cond if cond is not None else _conditions.NoneCondition(),
|
|
206
|
-
)
|
|
207
|
-
return sum_term # type: ignore
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
def sum(
|
|
211
|
-
index: tp.Union[INDEXWITHCOND, tp.List[INDEXWITHCOND]],
|
|
212
|
-
operand: _expression.Expression,
|
|
213
|
-
) -> SumOperator:
|
|
214
|
-
"""
|
|
215
|
-
Sum function.
|
|
216
|
-
|
|
217
|
-
Args:
|
|
218
|
-
indices: summation index dict or list of index.
|
|
219
|
-
operand (Expression): operand of summation
|
|
220
|
-
|
|
221
|
-
Returns:
|
|
222
|
-
SumOperator: SumOperator object.
|
|
223
|
-
|
|
224
|
-
Example:
|
|
225
|
-
Create $`\\sum_{i=0}^n d_i x_i`$
|
|
226
|
-
|
|
227
|
-
```python
|
|
228
|
-
import jijmodeling as jm
|
|
229
|
-
d = jm.Placeholder('d', ndim=1)
|
|
230
|
-
n = d.shape[0]
|
|
231
|
-
x = jm.BinaryVar('x', shape=n)
|
|
232
|
-
i = jm.Element('i', n)
|
|
233
|
-
jm.sum(i, d[i]*x[i])
|
|
234
|
-
# Σ_{i}(d[i]x[i])
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
Create $`\\sum_{i}\\sum_j d_{ij}x_i x_j`$
|
|
238
|
-
|
|
239
|
-
```python
|
|
240
|
-
import jijmodeling as jm
|
|
241
|
-
d = jm.Placeholder('d', ndim=2)
|
|
242
|
-
n = d.shape[0]
|
|
243
|
-
x = jm.BinaryVar('x', shape=n)
|
|
244
|
-
i = jm.Element('i', n)
|
|
245
|
-
j = jm.Element('j', n)
|
|
246
|
-
jm.sum([i, j], d[i, j]*x[i]*x[j])
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
Conditional sum
|
|
250
|
-
```python
|
|
251
|
-
import jijmodeling as jm
|
|
252
|
-
d = jm.Placeholder('d', ndim=2)
|
|
253
|
-
n = d.shape[0]
|
|
254
|
-
i, j = jm.Element("i", n), jm.Element("j", n)
|
|
255
|
-
x = jm.BinaryVar('x', shape=n)
|
|
256
|
-
jm.sum([i, (j, i < j)], d[i, j]*x[i]*x[j])
|
|
257
|
-
```
|
|
258
|
-
"""
|
|
259
|
-
with warnings.catch_warnings():
|
|
260
|
-
warnings.simplefilter("ignore", category=JijFutureWarning)
|
|
261
|
-
return Sum(index, operand)
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import typing as tp
|
|
4
|
-
|
|
5
|
-
from jijmodeling.expression.expression import BinaryOperator, Expression, Number
|
|
6
|
-
from jijmodeling.expression.mathfunc import UnaryOperator
|
|
7
|
-
from jijmodeling.expression.variables.placeholders import ArrayShape, Placeholder
|
|
8
|
-
from jijmodeling.expression.variables.variable import (
|
|
9
|
-
Element,
|
|
10
|
-
Range,
|
|
11
|
-
Subscripts,
|
|
12
|
-
Variable,
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
# Type of subscript element
|
|
16
|
-
SubscriptElementType = (
|
|
17
|
-
Expression # tp.TypeVar("SubscriptElementType", bound=Expression)
|
|
18
|
-
)
|
|
19
|
-
# User Input type for subscript element
|
|
20
|
-
SubscriptElemInputType = tp.Union[slice, SubscriptElementType, int]
|
|
21
|
-
|
|
22
|
-
# Type of shape element
|
|
23
|
-
# tp.TypeVar("ShapeElementType", bound=Expression)
|
|
24
|
-
ShapeElementType = Expression
|
|
25
|
-
# User input type for shape element
|
|
26
|
-
ShapeElemInputType = tp.Union[ShapeElementType, int, None]
|
|
27
|
-
|
|
28
|
-
ElementParentType = tp.Union[Range, Variable, Subscripts]
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
NumericInt = int
|
|
32
|
-
ExprOrNum = tp.Union[Expression, int, float]
|
|
33
|
-
|
|
34
|
-
IntExpr = tp.Union[Expression, int]
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
ElementSetType = tp.Union[Range, Variable, Subscripts]
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
Operator = tp.Union[BinaryOperator, UnaryOperator]
|
|
41
|
-
|
|
42
|
-
StrictShapeElemType = tp.Union[
|
|
43
|
-
Number,
|
|
44
|
-
Placeholder,
|
|
45
|
-
Operator,
|
|
46
|
-
ArrayShape,
|
|
47
|
-
]
|
|
48
|
-
RangeBoundType = tp.TypeVar("RangeBoundType", bound=Expression)
|
|
49
|
-
SumIndexType = tp.TypeVar("SumIndexType", bound=Element)
|
|
50
|
-
OperandType = tp.TypeVar("OperandType", bound=Expression)
|