jijmodeling 0.13.2__cp39-cp39-win_amd64.whl → 1.12.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.12.0.dist-info/METADATA +235 -0
- jijmodeling-1.12.0.dist-info/RECORD +18 -0
- {jijmodeling-0.13.2.dist-info → jijmodeling-1.12.0.dist-info}/WHEEL +1 -2
- {jijmodeling-0.13.2.dist-info → jijmodeling-1.12.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.2.dist-info/METADATA +0 -60
- jijmodeling-0.13.2.dist-info/RECORD +0 -219
- jijmodeling-0.13.2.dist-info/top_level.txt +0 -1
jijmodeling/match/expand.py
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import typing as tp
|
|
2
|
-
|
|
3
|
-
import jijmodeling as jm
|
|
4
|
-
|
|
5
|
-
from jijmodeling.match.replace import replace_if
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def expand_add(expr: jm.Expression) -> jm.Expression:
|
|
9
|
-
"""
|
|
10
|
-
recursively replace the jm.Expression following the rules below:
|
|
11
|
-
$$
|
|
12
|
-
a (c + d) \\rightarrow a c + a d
|
|
13
|
-
$$
|
|
14
|
-
$$
|
|
15
|
-
(c + d) a \\rightarrow c a + d a
|
|
16
|
-
$$
|
|
17
|
-
$$
|
|
18
|
-
\sum_{...}^{...}(a + b) \\rightarrow \sum_{...}^{...}(a) + \sum_{...}^{...}(b)
|
|
19
|
-
c * \sum_{...}^{...}(a) \\rightarrow \sum_{...}^{...}(c * a)
|
|
20
|
-
\sum_{...}^{...}(a) * c \\rightarrow \sum_{...}^{...}(a * c)
|
|
21
|
-
$$
|
|
22
|
-
Args:
|
|
23
|
-
expr (jm.Expression): target expression
|
|
24
|
-
|
|
25
|
-
Returns:
|
|
26
|
-
jm.Expression: expanded expression
|
|
27
|
-
"""
|
|
28
|
-
|
|
29
|
-
# extract & replace
|
|
30
|
-
def pattern_expand_add(expr: jm.Expression) -> tp.Optional[jm.Expression]:
|
|
31
|
-
"""pattern 1
|
|
32
|
-
a * (c + d) -> a * c + a * d
|
|
33
|
-
(c + d) * a -> c * a + d * a
|
|
34
|
-
\sum_{...}^{...}(a + b) -> \sum_{...}^{...}(a) + \sum_{...}^{...}(b)
|
|
35
|
-
c * \sum_{...}^{...}(a) -> \sum_{...}^{...}(c * a)
|
|
36
|
-
\sum_{...}^{...}(a) * c -> \sum_{...}^{...}(a * c)
|
|
37
|
-
"""
|
|
38
|
-
if isinstance(expr, jm.expression.expression.Mul):
|
|
39
|
-
if isinstance(expr.right, jm.expression.expression.Add):
|
|
40
|
-
a = expr.left
|
|
41
|
-
c = expr.right.left
|
|
42
|
-
d = expr.right.right
|
|
43
|
-
return a * c + a * d
|
|
44
|
-
|
|
45
|
-
elif isinstance(expr.left, jm.expression.expression.Add):
|
|
46
|
-
a = expr.right
|
|
47
|
-
c = expr.left.left
|
|
48
|
-
d = expr.left.right
|
|
49
|
-
return c * a + d * a
|
|
50
|
-
elif isinstance(expr.right, jm.expression.sum.SumOperator):
|
|
51
|
-
c = expr.left
|
|
52
|
-
sum_expr = expr.right
|
|
53
|
-
return jm.expression.sum.SumOperator(
|
|
54
|
-
sum_expr.sum_index, c * sum_expr.operand, sum_expr.condition
|
|
55
|
-
)
|
|
56
|
-
elif isinstance(expr.left, jm.expression.sum.SumOperator):
|
|
57
|
-
c = expr.right
|
|
58
|
-
sum_expr = expr.left
|
|
59
|
-
return jm.expression.sum.SumOperator(
|
|
60
|
-
sum_expr.sum_index, sum_expr.operand * c, sum_expr.condition
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
if isinstance(expr, jm.expression.sum.SumOperator):
|
|
64
|
-
if isinstance(expr.operand, jm.expression.expression.Add):
|
|
65
|
-
operand_left = expr.operand.left
|
|
66
|
-
operand_right = expr.operand.right
|
|
67
|
-
return jm.expression.sum.SumOperator(
|
|
68
|
-
expr.sum_index, operand_left, expr.condition
|
|
69
|
-
) + jm.expression.sum.SumOperator(
|
|
70
|
-
expr.sum_index, operand_right, expr.condition
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
return None
|
|
74
|
-
|
|
75
|
-
replaced_expr = expr
|
|
76
|
-
|
|
77
|
-
# repeat until no more replacement
|
|
78
|
-
while True:
|
|
79
|
-
new_replaced_expr = replace_if(replaced_expr, pattern_expand_add)
|
|
80
|
-
if jm.expr_same(replaced_expr, new_replaced_expr, check_id=False):
|
|
81
|
-
break
|
|
82
|
-
replaced_expr = new_replaced_expr
|
|
83
|
-
|
|
84
|
-
return replaced_expr
|
jijmodeling/match/expr_same.py
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from typing import Union
|
|
4
|
-
|
|
5
|
-
from jijmodeling.expression.condition import Condition
|
|
6
|
-
from jijmodeling.expression.expression import Expression
|
|
7
|
-
from jijmodeling.expression.variables.variable import Range
|
|
8
|
-
from jijmodeling.match.is_same_expr import ExpressionType, is_same_cond, is_same_expr
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def expr_same(
|
|
12
|
-
target: Union[ExpressionType, Condition],
|
|
13
|
-
pattern: Union[ExpressionType, Condition],
|
|
14
|
-
check_id: bool = True,
|
|
15
|
-
) -> bool:
|
|
16
|
-
"""
|
|
17
|
-
Check if two expressions are the same.
|
|
18
|
-
Args:
|
|
19
|
-
target (Union[ExpressionType, Condition]): target expression
|
|
20
|
-
pattern (Union[ExpressionType, Condition]): pattern expression
|
|
21
|
-
check_id (bool): check if the uuid is the same, default is True
|
|
22
|
-
Returns:
|
|
23
|
-
bool: True if the expressions are the same
|
|
24
|
-
"""
|
|
25
|
-
if isinstance(target, (Expression, Range)) and isinstance(
|
|
26
|
-
pattern, (Expression, Range)
|
|
27
|
-
):
|
|
28
|
-
return is_same_expr(target, pattern, check_id)
|
|
29
|
-
elif isinstance(target, Condition) and isinstance(pattern, Condition):
|
|
30
|
-
return is_same_cond(target, pattern, check_id)
|
|
31
|
-
else:
|
|
32
|
-
return False
|
|
@@ -1,306 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from typing import Tuple, Union
|
|
4
|
-
|
|
5
|
-
from jijmodeling.expression.condition import (
|
|
6
|
-
CompareCondition,
|
|
7
|
-
Condition,
|
|
8
|
-
ConditionOperator,
|
|
9
|
-
NoneCondition,
|
|
10
|
-
)
|
|
11
|
-
from jijmodeling.expression.expression import BinaryOperator, Expression, Number
|
|
12
|
-
from jijmodeling.expression.mathfunc import UnaryOperator
|
|
13
|
-
from jijmodeling.expression.sum import ReductionOperator
|
|
14
|
-
from jijmodeling.expression.type_annotations import ShapeElementType
|
|
15
|
-
from jijmodeling.expression.variables.deci_vars import Binary, Integer
|
|
16
|
-
from jijmodeling.expression.variables.jagged_array import JaggedArray
|
|
17
|
-
from jijmodeling.expression.variables.placeholders import ArrayShape, Placeholder
|
|
18
|
-
from jijmodeling.expression.variables.variable import Element, Range, Subscripts
|
|
19
|
-
|
|
20
|
-
ExpressionType = Union[Expression, Range]
|
|
21
|
-
ShapeType = Tuple[ShapeElementType, ...]
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
def is_same_expr(
|
|
25
|
-
target: ExpressionType, pattern: ExpressionType, check_id: bool = True
|
|
26
|
-
) -> bool:
|
|
27
|
-
# Check if the IDs are the same
|
|
28
|
-
if check_id == True and target.uuid != pattern.uuid:
|
|
29
|
-
return False
|
|
30
|
-
|
|
31
|
-
# Check if the type of `target` is a subclass of the type of `pattern`
|
|
32
|
-
if not isinstance(target, type(pattern)):
|
|
33
|
-
return False
|
|
34
|
-
if type(target) != type(pattern):
|
|
35
|
-
return False
|
|
36
|
-
|
|
37
|
-
# Case: Number
|
|
38
|
-
if type(target) is Number and type(pattern) is Number:
|
|
39
|
-
return is_same_number(target, pattern)
|
|
40
|
-
# Case: Placeholder
|
|
41
|
-
elif type(target) is Placeholder and type(pattern) is Placeholder:
|
|
42
|
-
return is_same_placeholder(target, pattern, check_id)
|
|
43
|
-
# Case: JaggedArray
|
|
44
|
-
elif type(target) is JaggedArray and type(pattern) is JaggedArray:
|
|
45
|
-
return is_same_jagged_array(target, pattern)
|
|
46
|
-
# Case: ArrayShape
|
|
47
|
-
elif type(target) is ArrayShape and type(pattern) is ArrayShape:
|
|
48
|
-
return is_same_array_shape(target, pattern, check_id)
|
|
49
|
-
# Case: Range
|
|
50
|
-
elif type(target) is Range and type(pattern) is Range:
|
|
51
|
-
return is_same_range(target, pattern, check_id)
|
|
52
|
-
# Case: Element
|
|
53
|
-
elif type(target) is Element and type(pattern) is Element:
|
|
54
|
-
return is_same_element(target, pattern, check_id)
|
|
55
|
-
# Case: Subscripts
|
|
56
|
-
elif type(target) is Subscripts and type(pattern) is Subscripts:
|
|
57
|
-
return is_same_subscripts(target, pattern, check_id)
|
|
58
|
-
# Case: Binary
|
|
59
|
-
elif type(target) is Binary and type(pattern) is Binary:
|
|
60
|
-
return is_same_binary(target, pattern, check_id)
|
|
61
|
-
# Case: Integer
|
|
62
|
-
elif type(target) is Integer and type(pattern) is Integer:
|
|
63
|
-
return is_same_integer(target, pattern, check_id)
|
|
64
|
-
# Case: UnaryOperator
|
|
65
|
-
elif isinstance(target, UnaryOperator) and isinstance(pattern, UnaryOperator):
|
|
66
|
-
return is_same_unary_op(target, pattern, check_id)
|
|
67
|
-
# Case: BinaryOperator
|
|
68
|
-
elif isinstance(target, BinaryOperator) and isinstance(pattern, BinaryOperator):
|
|
69
|
-
return is_same_binary_op(target, pattern, check_id)
|
|
70
|
-
# Case: ReductionOperator
|
|
71
|
-
elif isinstance(target, ReductionOperator) and isinstance(
|
|
72
|
-
pattern, ReductionOperator
|
|
73
|
-
):
|
|
74
|
-
return is_same_reduction_op(target, pattern, check_id)
|
|
75
|
-
elif type(target) is ArrayShape and type(pattern) is ArrayShape:
|
|
76
|
-
return is_same_arrayshape(target, pattern, check_id)
|
|
77
|
-
# Case: No match
|
|
78
|
-
else:
|
|
79
|
-
raise TypeError(
|
|
80
|
-
f"{target.__class__.__name__} is not supported in `is_same_expr`."
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
def is_same_cond(target: Condition, pattern: Condition, check_id) -> bool:
|
|
85
|
-
# Check if the IDs are the same
|
|
86
|
-
if check_id == True and target.uuid != pattern.uuid:
|
|
87
|
-
return False
|
|
88
|
-
|
|
89
|
-
# Check if the type of `target` is a subclass of the type of `pattern`
|
|
90
|
-
if not isinstance(target, type(pattern)):
|
|
91
|
-
return False
|
|
92
|
-
|
|
93
|
-
# Case: NonCondition
|
|
94
|
-
if type(target) is NoneCondition and type(pattern) is NoneCondition:
|
|
95
|
-
return True
|
|
96
|
-
# Case: CompareCondition
|
|
97
|
-
elif isinstance(target, CompareCondition) and isinstance(pattern, CompareCondition):
|
|
98
|
-
return is_same_comparison_op(target, pattern, check_id)
|
|
99
|
-
# Case: ConditionOperator
|
|
100
|
-
elif isinstance(target, ConditionOperator) and isinstance(
|
|
101
|
-
pattern, ConditionOperator
|
|
102
|
-
):
|
|
103
|
-
return is_same_logical_op(target, pattern, check_id)
|
|
104
|
-
# Case: No match
|
|
105
|
-
else:
|
|
106
|
-
raise TypeError(f"{target.__class__.__name__} is not supported.")
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
def is_same_number(target: Number, pattern: Number) -> bool:
|
|
110
|
-
# Compare the following attributes:
|
|
111
|
-
# - value
|
|
112
|
-
# - dtype
|
|
113
|
-
if target.value != pattern.value:
|
|
114
|
-
return False
|
|
115
|
-
elif target.dtype != pattern.dtype:
|
|
116
|
-
return False
|
|
117
|
-
else:
|
|
118
|
-
return True
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
def is_same_arrayshape(target: ArrayShape, pattern: ArrayShape, check_id: bool) -> bool:
|
|
122
|
-
# Compare the following attributes:
|
|
123
|
-
# - array
|
|
124
|
-
# - dim
|
|
125
|
-
if is_same_expr(target.array, pattern.array, check_id):
|
|
126
|
-
return False
|
|
127
|
-
elif target.dimension != pattern.dimension:
|
|
128
|
-
return False
|
|
129
|
-
else:
|
|
130
|
-
return True
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
def is_same_shape(target: ShapeType, pattern: ShapeType, check_id: bool) -> bool:
|
|
134
|
-
if len(target) != len(pattern):
|
|
135
|
-
return False
|
|
136
|
-
|
|
137
|
-
for target_shape_elt, pattern_shape_elt in zip(target, pattern):
|
|
138
|
-
# Check if the type of the element of `target` is different from the type of the element of `pattern`
|
|
139
|
-
if type(target_shape_elt) is not type(pattern_shape_elt):
|
|
140
|
-
return False
|
|
141
|
-
# Case: the types of the elements of `target` and `pattern` are not equal to `ArrayShape`
|
|
142
|
-
elif (
|
|
143
|
-
type(target_shape_elt) is not ArrayShape
|
|
144
|
-
and type(pattern_shape_elt) is not ArrayShape
|
|
145
|
-
):
|
|
146
|
-
if not is_same_expr(target_shape_elt, pattern_shape_elt, check_id=check_id):
|
|
147
|
-
return False
|
|
148
|
-
# Case: the types of the elements of `target` and `pattern` are equal to `ArrayShape`
|
|
149
|
-
elif check_id == True and target_shape_elt.uuid != pattern_shape_elt.uuid:
|
|
150
|
-
return False
|
|
151
|
-
return True
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
def is_same_placeholder(
|
|
155
|
-
target: Placeholder, pattern: Placeholder, check_id: bool
|
|
156
|
-
) -> bool:
|
|
157
|
-
# Compare the following attributes:
|
|
158
|
-
# - label
|
|
159
|
-
# - dim
|
|
160
|
-
# - shape
|
|
161
|
-
if target.label != pattern.label:
|
|
162
|
-
return False
|
|
163
|
-
elif target.dim != pattern.dim:
|
|
164
|
-
return False
|
|
165
|
-
else:
|
|
166
|
-
return is_same_shape(target.shape, pattern.shape, check_id)
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
def is_same_jagged_array(target: JaggedArray, pattern: JaggedArray) -> bool:
|
|
170
|
-
# Compare the following attributes:
|
|
171
|
-
# - label
|
|
172
|
-
# - dim
|
|
173
|
-
if target.label != pattern.label:
|
|
174
|
-
return False
|
|
175
|
-
elif target.dim != pattern.dim:
|
|
176
|
-
return False
|
|
177
|
-
else:
|
|
178
|
-
return True
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
def is_same_array_shape(
|
|
182
|
-
target: ArrayShape, pattern: ArrayShape, check_id: bool
|
|
183
|
-
) -> bool:
|
|
184
|
-
# Compare the following attributes:
|
|
185
|
-
# - dimension
|
|
186
|
-
# - array
|
|
187
|
-
if target.dimension != pattern.dimension:
|
|
188
|
-
return False
|
|
189
|
-
else:
|
|
190
|
-
return is_same_expr(target.array, pattern.array, check_id=check_id)
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
def is_same_range(target: Range, pattern: Range, check_id: bool) -> bool:
|
|
194
|
-
# Compare the following attributes:
|
|
195
|
-
# - start
|
|
196
|
-
# - last
|
|
197
|
-
return is_same_expr(target.start, pattern.start, check_id) and is_same_expr(
|
|
198
|
-
target.last, pattern.last, check_id
|
|
199
|
-
)
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
def is_same_element(target: Element, pattern: Element, check_id: bool) -> bool:
|
|
203
|
-
# Comare the following attributes:
|
|
204
|
-
# - label
|
|
205
|
-
# - parent
|
|
206
|
-
if target.label != pattern.label:
|
|
207
|
-
return False
|
|
208
|
-
else:
|
|
209
|
-
return is_same_expr(target.parent, pattern.parent, check_id)
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
def is_same_subscripts(target: Subscripts, pattern: Subscripts, check_id: bool) -> bool:
|
|
213
|
-
# Comare the following attributes:
|
|
214
|
-
# - variable
|
|
215
|
-
# - subscripts
|
|
216
|
-
if not is_same_expr(target.variable, pattern.variable, check_id):
|
|
217
|
-
return False
|
|
218
|
-
elif len(target.subscripts) != len(pattern.subscripts):
|
|
219
|
-
return False
|
|
220
|
-
else:
|
|
221
|
-
for target_subs, pattern_subs in zip(target.subscripts, pattern.subscripts):
|
|
222
|
-
if not is_same_expr(target_subs, pattern_subs, check_id):
|
|
223
|
-
return False
|
|
224
|
-
return True
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
def is_same_binary(target: Binary, pattern: Binary, check_id: bool) -> bool:
|
|
228
|
-
# Compare the following attributes:
|
|
229
|
-
# - label
|
|
230
|
-
# - shape
|
|
231
|
-
if target.label != pattern.label:
|
|
232
|
-
return False
|
|
233
|
-
else:
|
|
234
|
-
return is_same_shape(target.shape, pattern.shape, check_id)
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
def is_same_integer(target: Integer, pattern: Integer, check_id: bool) -> bool:
|
|
238
|
-
# Compare the following attributes:
|
|
239
|
-
# - label
|
|
240
|
-
# - lower
|
|
241
|
-
# - upper
|
|
242
|
-
# - shape
|
|
243
|
-
if target.label != pattern.label:
|
|
244
|
-
return False
|
|
245
|
-
elif not is_same_expr(target.lower, pattern.lower, check_id):
|
|
246
|
-
return False
|
|
247
|
-
elif not is_same_expr(target.upper, pattern.upper, check_id):
|
|
248
|
-
return False
|
|
249
|
-
else:
|
|
250
|
-
return is_same_shape(target.shape, pattern.shape, check_id)
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
def is_same_unary_op(
|
|
254
|
-
target: UnaryOperator, pattern: UnaryOperator, check_id: bool
|
|
255
|
-
) -> bool:
|
|
256
|
-
# Compare the following attribute:
|
|
257
|
-
# - operand
|
|
258
|
-
return is_same_expr(target.operand, pattern.operand, check_id)
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
def is_same_binary_op(
|
|
262
|
-
target: BinaryOperator, pattern: BinaryOperator, check_id: bool
|
|
263
|
-
) -> bool:
|
|
264
|
-
# Compare the following attributes:
|
|
265
|
-
# - left
|
|
266
|
-
# - right
|
|
267
|
-
return is_same_expr(target.left, pattern.left, check_id) and is_same_expr(
|
|
268
|
-
target.right, pattern.right, check_id
|
|
269
|
-
)
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
def is_same_reduction_op(
|
|
273
|
-
target: ReductionOperator, pattern: ReductionOperator, check_id: bool
|
|
274
|
-
) -> bool:
|
|
275
|
-
# Compare the following attributes:
|
|
276
|
-
# - sum_index
|
|
277
|
-
# - condition
|
|
278
|
-
# - operand
|
|
279
|
-
if not is_same_element(target.sum_index, pattern.sum_index, check_id):
|
|
280
|
-
return False
|
|
281
|
-
elif not is_same_cond(target.condition, pattern.condition, check_id):
|
|
282
|
-
return False
|
|
283
|
-
else:
|
|
284
|
-
return is_same_expr(target.operand, pattern.operand, check_id)
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
def is_same_comparison_op(
|
|
288
|
-
target: CompareCondition, pattern: CompareCondition, check_id: bool
|
|
289
|
-
) -> bool:
|
|
290
|
-
# Compare the following attributes:
|
|
291
|
-
# - left
|
|
292
|
-
# - right
|
|
293
|
-
return is_same_expr(target.left, pattern.left, check_id) and is_same_expr(
|
|
294
|
-
target.right, pattern.right, check_id
|
|
295
|
-
)
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
def is_same_logical_op(
|
|
299
|
-
target: ConditionOperator, pattern: ConditionOperator, check_id: bool
|
|
300
|
-
) -> bool:
|
|
301
|
-
# Compare the following attributes:
|
|
302
|
-
# - left
|
|
303
|
-
# - right
|
|
304
|
-
return is_same_cond(target.left, pattern.left, check_id) and is_same_cond(
|
|
305
|
-
target.right, pattern.right, check_id
|
|
306
|
-
)
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import jijmodeling.expression.constraint as _constraint
|
|
4
|
-
|
|
5
|
-
from jijmodeling.match.condition_same import condition_same
|
|
6
|
-
from jijmodeling.match.expr_same import expr_same
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
def penalty_same(
|
|
10
|
-
target: _constraint.Penalty, pattern: _constraint.Penalty, check_id: bool = True
|
|
11
|
-
) -> bool:
|
|
12
|
-
# Is the same label?
|
|
13
|
-
if target.label != pattern.label:
|
|
14
|
-
return False
|
|
15
|
-
# Is the same `with_multiplier`?
|
|
16
|
-
if target.with_multiplier is not pattern.with_multiplier:
|
|
17
|
-
return False
|
|
18
|
-
# Is the same `forall`?
|
|
19
|
-
if len(target.forall) != len(pattern.forall):
|
|
20
|
-
return False
|
|
21
|
-
for target_forall, pattern_forall in zip(target.forall, pattern.forall):
|
|
22
|
-
target_element, target_condition = target_forall
|
|
23
|
-
pattern_element, pattern_condition = pattern_forall
|
|
24
|
-
is_same_forall = expr_same(
|
|
25
|
-
target_element, pattern_element, check_id
|
|
26
|
-
) and condition_same(target_condition, pattern_condition, check_id)
|
|
27
|
-
|
|
28
|
-
if is_same_forall is False:
|
|
29
|
-
return False
|
|
30
|
-
# Is the same `penalty_term`?
|
|
31
|
-
return expr_same(target.penalty_term, pattern.penalty_term, check_id)
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from jijmodeling.match.constraint_same import constraint_same
|
|
4
|
-
from jijmodeling.match.expr_same import expr_same
|
|
5
|
-
from jijmodeling.match.penalty_same import penalty_same
|
|
6
|
-
from jijmodeling.problem.problem import Problem
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
def problem_same(target: Problem, pattern: Problem, check_id: bool = True) -> bool:
|
|
10
|
-
# Is the same `name`?
|
|
11
|
-
if target.name != pattern.name:
|
|
12
|
-
return False
|
|
13
|
-
# Is the same `sense`?
|
|
14
|
-
if target.sense != pattern.sense:
|
|
15
|
-
return False
|
|
16
|
-
# Is the same `objective`?
|
|
17
|
-
if expr_same(target.objective, pattern.objective, check_id) is False:
|
|
18
|
-
return False
|
|
19
|
-
# Is the same `constraints`?
|
|
20
|
-
if len(target.constraints.items()) != len(pattern.constraints.items()):
|
|
21
|
-
return False
|
|
22
|
-
for target_key, target_constraint in target.constraints.items():
|
|
23
|
-
if target_key not in pattern.constraints.keys():
|
|
24
|
-
return False
|
|
25
|
-
if (
|
|
26
|
-
constraint_same(
|
|
27
|
-
target_constraint, pattern.constraints[target_key], check_id
|
|
28
|
-
)
|
|
29
|
-
is False
|
|
30
|
-
):
|
|
31
|
-
return False
|
|
32
|
-
# Is the same `penalty`?
|
|
33
|
-
if len(target.penalties.items()) != len(pattern.penalties.items()):
|
|
34
|
-
return False
|
|
35
|
-
for target_key, target_penalty in target.penalties.items():
|
|
36
|
-
if target_key not in pattern.penalties.keys():
|
|
37
|
-
return False
|
|
38
|
-
if (
|
|
39
|
-
penalty_same(target_penalty, pattern.penalties[target_key], check_id)
|
|
40
|
-
is False
|
|
41
|
-
):
|
|
42
|
-
return False
|
|
43
|
-
|
|
44
|
-
return True
|