jijmodeling 0.10.15__cp38-cp38-win_amd64.whl → 0.10.16__cp38-cp38-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 +2 -0
- jijmodeling/__pycache__/__init__.cpython-38.opt-1.pyc +0 -0
- jijmodeling/__pycache__/__init__.cpython-38.pyc +0 -0
- jijmodeling/__pycache__/_version.cpython-38.opt-1.pyc +0 -0
- jijmodeling/__pycache__/_version.cpython-38.pyc +0 -0
- jijmodeling/_version.py +2 -2
- jijmodeling/exceptions/__pycache__/__init__.cpython-38.opt-1.pyc +0 -0
- jijmodeling/exceptions/__pycache__/__init__.cpython-38.pyc +0 -0
- jijmodeling/exceptions/__pycache__/exceptions.cpython-38.opt-1.pyc +0 -0
- jijmodeling/exceptions/__pycache__/exceptions.cpython-38.pyc +0 -0
- jijmodeling/expression/__pycache__/__init__.cpython-38.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/__init__.cpython-38.pyc +0 -0
- jijmodeling/expression/__pycache__/condition.cpython-38.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/condition.cpython-38.pyc +0 -0
- jijmodeling/expression/__pycache__/constraint.cpython-38.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/constraint.cpython-38.pyc +0 -0
- jijmodeling/expression/__pycache__/expression.cpython-38.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/expression.cpython-38.pyc +0 -0
- jijmodeling/expression/__pycache__/extract.cpython-38.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/extract.cpython-38.pyc +0 -0
- jijmodeling/expression/__pycache__/from_old_serializable.cpython-38.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/from_old_serializable.cpython-38.pyc +0 -0
- jijmodeling/expression/__pycache__/mathfunc.cpython-38.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/mathfunc.cpython-38.pyc +0 -0
- jijmodeling/expression/__pycache__/prod.cpython-38.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/prod.cpython-38.pyc +0 -0
- jijmodeling/expression/__pycache__/serializable.cpython-38.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/serializable.cpython-38.pyc +0 -0
- jijmodeling/expression/__pycache__/sum.cpython-38.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/sum.cpython-38.pyc +0 -0
- jijmodeling/expression/__pycache__/type_annotations.cpython-38.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/type_annotations.cpython-38.pyc +0 -0
- jijmodeling/expression/__pycache__/utils.cpython-38.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/utils.cpython-38.pyc +0 -0
- jijmodeling/expression/utils.py +26 -0
- jijmodeling/expression/variables/__pycache__/__init__.cpython-38.opt-1.pyc +0 -0
- jijmodeling/expression/variables/__pycache__/__init__.cpython-38.pyc +0 -0
- jijmodeling/expression/variables/__pycache__/deci_vars.cpython-38.opt-1.pyc +0 -0
- jijmodeling/expression/variables/__pycache__/deci_vars.cpython-38.pyc +0 -0
- jijmodeling/expression/variables/__pycache__/jagged_array.cpython-38.opt-1.pyc +0 -0
- jijmodeling/expression/variables/__pycache__/jagged_array.cpython-38.pyc +0 -0
- jijmodeling/expression/variables/__pycache__/placeholders.cpython-38.opt-1.pyc +0 -0
- jijmodeling/expression/variables/__pycache__/placeholders.cpython-38.pyc +0 -0
- jijmodeling/expression/variables/__pycache__/variable.cpython-38.opt-1.pyc +0 -0
- jijmodeling/expression/variables/__pycache__/variable.cpython-38.pyc +0 -0
- jijmodeling/latex_repr/__pycache__/__init__.cpython-38.opt-1.pyc +0 -0
- jijmodeling/latex_repr/__pycache__/__init__.cpython-38.pyc +0 -0
- jijmodeling/latex_repr/__pycache__/latex_repr.cpython-38.opt-1.pyc +0 -0
- jijmodeling/latex_repr/__pycache__/latex_repr.cpython-38.pyc +0 -0
- jijmodeling/latex_repr/__pycache__/problem_latex_repr.cpython-38.opt-1.pyc +0 -0
- jijmodeling/latex_repr/__pycache__/problem_latex_repr.cpython-38.pyc +0 -0
- jijmodeling/marker/__marker__.cp38-win_amd64.pyd +0 -0
- jijmodeling/match/__pycache__/__init__.cpython-38.opt-1.pyc +0 -0
- jijmodeling/match/__pycache__/__init__.cpython-38.pyc +0 -0
- jijmodeling/match/__pycache__/condition_same.cpython-38.opt-1.pyc +0 -0
- jijmodeling/match/__pycache__/condition_same.cpython-38.pyc +0 -0
- jijmodeling/match/__pycache__/constraint_same.cpython-38.opt-1.pyc +0 -0
- jijmodeling/match/__pycache__/constraint_same.cpython-38.pyc +0 -0
- jijmodeling/match/__pycache__/expr_same.cpython-38.opt-1.pyc +0 -0
- jijmodeling/match/__pycache__/expr_same.cpython-38.pyc +0 -0
- jijmodeling/match/__pycache__/is_same_expr.cpython-38.opt-1.pyc +0 -0
- jijmodeling/match/__pycache__/is_same_expr.cpython-38.pyc +0 -0
- jijmodeling/match/__pycache__/penalty_same.cpython-38.opt-1.pyc +0 -0
- jijmodeling/match/__pycache__/penalty_same.cpython-38.pyc +0 -0
- jijmodeling/match/__pycache__/problem_same.cpython-38.opt-1.pyc +0 -0
- jijmodeling/match/__pycache__/problem_same.cpython-38.pyc +0 -0
- jijmodeling/match/__pycache__/replace.cpython-38.opt-1.pyc +0 -0
- jijmodeling/match/__pycache__/replace.cpython-38.pyc +0 -0
- jijmodeling/match/expr_same.py +9 -0
- jijmodeling/match/is_same_expr.py +17 -1
- jijmodeling/match/replace.py +210 -0
- jijmodeling/problem/__pycache__/__init__.cpython-38.opt-1.pyc +0 -0
- jijmodeling/problem/__pycache__/__init__.cpython-38.pyc +0 -0
- jijmodeling/problem/__pycache__/problem.cpython-38.opt-1.pyc +0 -0
- jijmodeling/problem/__pycache__/problem.cpython-38.pyc +0 -0
- jijmodeling/protobuf/__pycache__/__init__.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/__pycache__/__init__.cpython-38.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/__init__.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/__init__.cpython-38.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/extract_attribute_value_from_header.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/extract_attribute_value_from_header.cpython-38.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/from_protobuf.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/from_protobuf.cpython-38.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_array_shape.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_array_shape.cpython-38.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_binary_op.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_binary_op.cpython-38.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_binary_var.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_binary_var.cpython-38.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_constraint.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_constraint.cpython-38.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_element.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_element.cpython-38.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_expression.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_expression.cpython-38.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_forall.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_forall.cpython-38.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_integer_var.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_integer_var.cpython-38.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_jagged_array.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_jagged_array.cpython-38.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_number_lit.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_number_lit.cpython-38.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_penalty.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_penalty.cpython-38.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_placeholder.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_placeholder.cpython-38.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_problem.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_problem.cpython-38.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_reduction_op.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_reduction_op.cpython-38.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_subscript_op.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_subscript_op.cpython-38.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_unary_op.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/from_protobuf/__pycache__/message_to_unary_op.cpython-38.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/__init__.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/__init__.cpython-38.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/add_header_to_message.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/add_header_to_message.cpython-38.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/array_shape_to_message.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/array_shape_to_message.cpython-38.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/binary_op_to_message.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/binary_op_to_message.cpython-38.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/binary_var_to_message.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/binary_var_to_message.cpython-38.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/constraint_to_message.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/constraint_to_message.cpython-38.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/element_to_message.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/element_to_message.cpython-38.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/expression_to_message.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/expression_to_message.cpython-38.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/forall_to_message.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/forall_to_message.cpython-38.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/integer_var_to_message.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/integer_var_to_message.cpython-38.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/jagged_array_to_message.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/jagged_array_to_message.cpython-38.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/number_lit_to_message.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/number_lit_to_message.cpython-38.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/penalty_to_message.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/penalty_to_message.cpython-38.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/placeholder_to_message.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/placeholder_to_message.cpython-38.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/problem_to_message.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/problem_to_message.cpython-38.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/reduction_op_to_message.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/reduction_op_to_message.cpython-38.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/subscript_op_to_message.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/subscript_op_to_message.cpython-38.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/to_protobuf.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/to_protobuf.cpython-38.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/unary_op_to_message.cpython-38.opt-1.pyc +0 -0
- jijmodeling/protobuf/to_protobuf/__pycache__/unary_op_to_message.cpython-38.pyc +0 -0
- jijmodeling/sampleset/__pycache__/__init__.cpython-38.opt-1.pyc +0 -0
- jijmodeling/sampleset/__pycache__/__init__.cpython-38.pyc +0 -0
- jijmodeling/sampleset/__pycache__/evaluation.cpython-38.opt-1.pyc +0 -0
- jijmodeling/sampleset/__pycache__/evaluation.cpython-38.pyc +0 -0
- jijmodeling/sampleset/__pycache__/measuring_time.cpython-38.opt-1.pyc +0 -0
- jijmodeling/sampleset/__pycache__/measuring_time.cpython-38.pyc +0 -0
- jijmodeling/sampleset/__pycache__/record.cpython-38.opt-1.pyc +0 -0
- jijmodeling/sampleset/__pycache__/record.cpython-38.pyc +0 -0
- jijmodeling/sampleset/__pycache__/sampleset.cpython-38.opt-1.pyc +0 -0
- jijmodeling/sampleset/__pycache__/sampleset.cpython-38.pyc +0 -0
- jijmodeling/sampleset/__pycache__/solving_time.cpython-38.opt-1.pyc +0 -0
- jijmodeling/sampleset/__pycache__/solving_time.cpython-38.pyc +0 -0
- jijmodeling/sampleset/__pycache__/system_time.cpython-38.opt-1.pyc +0 -0
- jijmodeling/sampleset/__pycache__/system_time.cpython-38.pyc +0 -0
- jijmodeling/type_annotations/__pycache__/__init__.cpython-38.opt-1.pyc +0 -0
- jijmodeling/type_annotations/__pycache__/__init__.cpython-38.pyc +0 -0
- jijmodeling/type_annotations/__pycache__/type_annotations.cpython-38.opt-1.pyc +0 -0
- jijmodeling/type_annotations/__pycache__/type_annotations.cpython-38.pyc +0 -0
- jijmodeling/utils/__pycache__/__init__.cpython-38.opt-1.pyc +0 -0
- jijmodeling/utils/__pycache__/__init__.cpython-38.pyc +0 -0
- jijmodeling/utils/__pycache__/utils.cpython-38.opt-1.pyc +0 -0
- jijmodeling/utils/__pycache__/utils.cpython-38.pyc +0 -0
- {jijmodeling-0.10.15.dist-info → jijmodeling-0.10.16.dist-info}/METADATA +1 -1
- {jijmodeling-0.10.15.dist-info → jijmodeling-0.10.16.dist-info}/RECORD +180 -177
- {jijmodeling-0.10.15.dist-info → jijmodeling-0.10.16.dist-info}/LICENSE.txt +0 -0
- {jijmodeling-0.10.15.dist-info → jijmodeling-0.10.16.dist-info}/WHEEL +0 -0
- {jijmodeling-0.10.15.dist-info → jijmodeling-0.10.16.dist-info}/top_level.txt +0 -0
jijmodeling/__init__.py
CHANGED
|
@@ -41,6 +41,7 @@ from jijmodeling.match.expr_same import expr_same
|
|
|
41
41
|
from jijmodeling.match.is_same_expr import is_same_cond, is_same_expr
|
|
42
42
|
from jijmodeling.match.penalty_same import penalty_same
|
|
43
43
|
from jijmodeling.match.problem_same import problem_same
|
|
44
|
+
from jijmodeling.match.replace import replace
|
|
44
45
|
from jijmodeling.problem.problem import Problem, ProblemSense
|
|
45
46
|
from jijmodeling.protobuf.from_protobuf.from_protobuf import from_protobuf
|
|
46
47
|
from jijmodeling.protobuf.to_protobuf.to_protobuf import to_protobuf
|
|
@@ -89,6 +90,7 @@ __all__ = [
|
|
|
89
90
|
"is_same_expr",
|
|
90
91
|
"penalty_same",
|
|
91
92
|
"problem_same",
|
|
93
|
+
"replace",
|
|
92
94
|
"Binary",
|
|
93
95
|
"DecisionVariable",
|
|
94
96
|
"Element",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
jijmodeling/_version.py
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
jijmodeling/expression/utils.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
import itertools as it
|
|
3
4
|
import typing as tp
|
|
4
5
|
|
|
5
6
|
import typeguard as _typeguard
|
|
@@ -173,3 +174,28 @@ def check_non_decision_variable(
|
|
|
173
174
|
for v in variables:
|
|
174
175
|
if isinstance(v, _deci_vars.DecisionVariable):
|
|
175
176
|
raise _exceptions.CannotContainDecisionVarError(error_msg)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def flatten_binary_operator(
|
|
180
|
+
expression: _expression.Expression,
|
|
181
|
+
op_type: tp.Type[_expression.BinaryOperator] = _expression.Add,
|
|
182
|
+
) -> tp.List[_expression.Expression]:
|
|
183
|
+
"""
|
|
184
|
+
Flatten `op_type` binary operator to list.
|
|
185
|
+
This function flattens a given node to the following:
|
|
186
|
+
node1 <> node2 <> node3 <> ... <> nodeN -> [node1, node2, node3, ..., nodeN]
|
|
187
|
+
where <> is a specified binary operator by `op_type`.
|
|
188
|
+
|
|
189
|
+
Args:
|
|
190
|
+
expression (Expression): target expression.
|
|
191
|
+
op_type (Type[BinaryOperator]): target binary operator.
|
|
192
|
+
|
|
193
|
+
Returns:
|
|
194
|
+
List[Expression]: list of expression. Each element is not binary operator.
|
|
195
|
+
"""
|
|
196
|
+
if isinstance(expression, op_type):
|
|
197
|
+
left = flatten_binary_operator(expression.left, op_type)
|
|
198
|
+
right = flatten_binary_operator(expression.right, op_type)
|
|
199
|
+
return list(it.chain.from_iterable([left, right]))
|
|
200
|
+
else:
|
|
201
|
+
return [expression]
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
jijmodeling/match/expr_same.py
CHANGED
|
@@ -13,6 +13,15 @@ def expr_same(
|
|
|
13
13
|
pattern: Union[ExpressionType, Condition],
|
|
14
14
|
check_id: bool = True,
|
|
15
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
|
+
"""
|
|
16
25
|
if isinstance(target, (Expression, Range)) and isinstance(
|
|
17
26
|
pattern, (Expression, Range)
|
|
18
27
|
):
|
|
@@ -31,6 +31,8 @@ def is_same_expr(
|
|
|
31
31
|
# Check if the type of `target` is a subclass of the type of `pattern`
|
|
32
32
|
if not isinstance(target, type(pattern)):
|
|
33
33
|
return False
|
|
34
|
+
if type(target) != type(pattern):
|
|
35
|
+
return False
|
|
34
36
|
|
|
35
37
|
# Case: Number
|
|
36
38
|
if type(target) is Number and type(pattern) is Number:
|
|
@@ -70,9 +72,11 @@ def is_same_expr(
|
|
|
70
72
|
pattern, ReductionOperator
|
|
71
73
|
):
|
|
72
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)
|
|
73
77
|
# Case: No match
|
|
74
78
|
else:
|
|
75
|
-
raise TypeError(f"{target.__class__.__name__} is not supported
|
|
79
|
+
raise TypeError(f"{target.__class__.__name__} is not supported in `is_same_expr`.")
|
|
76
80
|
|
|
77
81
|
|
|
78
82
|
def is_same_cond(target: Condition, pattern: Condition, check_id) -> bool:
|
|
@@ -112,6 +116,18 @@ def is_same_number(target: Number, pattern: Number) -> bool:
|
|
|
112
116
|
return True
|
|
113
117
|
|
|
114
118
|
|
|
119
|
+
def is_same_arrayshape(target: ArrayShape, pattern: ArrayShape, check_id: bool) -> bool:
|
|
120
|
+
# Compare the following attributes:
|
|
121
|
+
# - array
|
|
122
|
+
# - dim
|
|
123
|
+
if is_same_expr(target.array, pattern.array, check_id):
|
|
124
|
+
return False
|
|
125
|
+
elif target.dimension != pattern.dimension:
|
|
126
|
+
return False
|
|
127
|
+
else:
|
|
128
|
+
return True
|
|
129
|
+
|
|
130
|
+
|
|
115
131
|
def is_same_shape(target: ShapeType, pattern: ShapeType, check_id: bool) -> bool:
|
|
116
132
|
if len(target) != len(pattern):
|
|
117
133
|
return False
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import typing as tp
|
|
2
|
+
|
|
3
|
+
from functools import singledispatch
|
|
4
|
+
|
|
5
|
+
import jijmodeling as jm
|
|
6
|
+
from jijmodeling.exceptions.exceptions import JijModelingError
|
|
7
|
+
import jijmodeling.expression.condition as jc
|
|
8
|
+
|
|
9
|
+
from jijmodeling.match.expr_same import expr_same
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def replace(
|
|
13
|
+
expr: jm.Expression, target: jm.Expression, source: jm.Expression, check_id: bool
|
|
14
|
+
) -> jm.Expression:
|
|
15
|
+
"""
|
|
16
|
+
replace expression (from `target` element to `source` one)
|
|
17
|
+
This function selects the target element from the expression and replaces it with the source element.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
expr (jm.Expression): expression
|
|
21
|
+
target (jm.Expression): target sub tree
|
|
22
|
+
source (jm.Expression): new sub tree
|
|
23
|
+
check_id (bool): replace only if the uuid is the same, default is True
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
jm.Expression: replaced sub tree
|
|
27
|
+
|
|
28
|
+
Examples:
|
|
29
|
+
>>> import jijmodeling as jm
|
|
30
|
+
>>> n = jm.Placeholder("n")
|
|
31
|
+
>>> i = jm.Element("i", n)
|
|
32
|
+
>>> x = jm.Binary("x", shape=(n, n))
|
|
33
|
+
>>> x_i = x[i] # [i] は xi を生成するたびにuuidが変わるので replaceで使うには一度だけ生成したオブジェクトを使い回す必要がある
|
|
34
|
+
>>> expr = jm.Sum(i, x_i)
|
|
35
|
+
>>> u = jm.Integer("u", shape=(n,), lower=0, upper=10)
|
|
36
|
+
>>> k = jm.Placeholder("k")
|
|
37
|
+
>>> j = jm.Element("j", k)
|
|
38
|
+
>>> y = jm.Placeholder("y", shape=(n, k))
|
|
39
|
+
>>> replaced = replace(expr, x_i, jm.Sum(j, u[i]*y[i,j]), check_id=True)
|
|
40
|
+
>>> print(replaced)
|
|
41
|
+
>>> Sum_{i=0}^{n}(Sum_{j=0}^{k}(u[i]*y[i,j]))
|
|
42
|
+
|
|
43
|
+
>>> import jijmodeling as jm
|
|
44
|
+
>>> n = jm.Placeholder("n")
|
|
45
|
+
>>> i = jm.Element("i", n)
|
|
46
|
+
>>> x = jm.Binary("x", shape=(n, n))
|
|
47
|
+
>>> expr = jm.Sum(i, x[i])
|
|
48
|
+
>>> u = jm.Integer("u", shape=(n,), lower=0, upper=10)
|
|
49
|
+
>>> k = jm.Placeholder("k")
|
|
50
|
+
>>> j = jm.Element("j", k)
|
|
51
|
+
>>> y = jm.Placeholder("y", shape=(n, k))
|
|
52
|
+
>>> replaced = replace(expr, x[i], jm.Sum(j, u[i]*y[i,j]), check_id=False) # check_id=False にすると、uuidが異なっていても置換できる
|
|
53
|
+
>>> print(replaced)
|
|
54
|
+
>>> Sum_{i=0}^{n}(Sum_{j=0}^{k}(u[i]*y[i,j]))
|
|
55
|
+
"""
|
|
56
|
+
if expr_same(expr, target, check_id):
|
|
57
|
+
return source
|
|
58
|
+
|
|
59
|
+
return _replace(expr, target, source, check_id)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@singledispatch
|
|
63
|
+
def _replace(
|
|
64
|
+
expr: jm.Expression, target: jm.Expression, source: jm.Expression, check_id: bool
|
|
65
|
+
) -> jm.Expression:
|
|
66
|
+
raise TypeError(f"{type(expr)} is not supported in `replace`.")
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# List all the types that are inherited from `jm.Expression` and register them to `_replace` function.
|
|
70
|
+
@_replace.register
|
|
71
|
+
def _(expr: jm.ArrayShape, target: jm.Expression, source: jm.Expression, check_id: bool) -> jm.Expression:
|
|
72
|
+
if expr_same(expr, target, check_id):
|
|
73
|
+
return source
|
|
74
|
+
if isinstance(source, (jm.Variable, jm.Subscripts)) and expr_same(expr.array, target, check_id):
|
|
75
|
+
return source.shape[expr.dim]
|
|
76
|
+
return expr
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@_replace.register
|
|
80
|
+
def _(
|
|
81
|
+
expr: jm.expression.Number,
|
|
82
|
+
target: jm.Expression,
|
|
83
|
+
source: jm.Expression,
|
|
84
|
+
check_id: bool,
|
|
85
|
+
) -> jm.Expression:
|
|
86
|
+
if expr_same(expr, target, check_id):
|
|
87
|
+
return source
|
|
88
|
+
return expr
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@_replace.register
|
|
92
|
+
def _(
|
|
93
|
+
expr: jm.expression.BinaryOperator,
|
|
94
|
+
target: jm.Expression,
|
|
95
|
+
source: jm.Expression,
|
|
96
|
+
check_id: bool,
|
|
97
|
+
) -> jm.Expression:
|
|
98
|
+
if expr_same(expr, target, check_id):
|
|
99
|
+
return source
|
|
100
|
+
|
|
101
|
+
cls = type(expr)
|
|
102
|
+
replaced_left = _replace(expr.left, target, source, check_id)
|
|
103
|
+
replaced_right = _replace(expr.right, target, source, check_id)
|
|
104
|
+
return cls(replaced_left, replaced_right)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
@_replace.register
|
|
108
|
+
def _(
|
|
109
|
+
expr: jm.expression.UnaryOperator,
|
|
110
|
+
target: jm.Expression,
|
|
111
|
+
source: jm.Expression,
|
|
112
|
+
check_id: bool,
|
|
113
|
+
) -> jm.Expression:
|
|
114
|
+
if expr_same(expr, target, check_id):
|
|
115
|
+
return source
|
|
116
|
+
|
|
117
|
+
cls = type(expr)
|
|
118
|
+
replaced = _replace(expr, target, source, check_id)
|
|
119
|
+
return cls(replaced)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
@_replace.register
|
|
123
|
+
def _(
|
|
124
|
+
expr: jm.expression.sum.ReductionOperator,
|
|
125
|
+
target: jm.Expression,
|
|
126
|
+
source: jm.Expression,
|
|
127
|
+
check_id: bool,
|
|
128
|
+
) -> jm.Expression:
|
|
129
|
+
if expr_same(expr, target, check_id):
|
|
130
|
+
return source
|
|
131
|
+
|
|
132
|
+
replaced_sum_index = tp.cast(
|
|
133
|
+
jm.Element, _replace(expr.sum_index, target, source, check_id)
|
|
134
|
+
)
|
|
135
|
+
replaced_operand = _replace(expr.operand, target, source, check_id)
|
|
136
|
+
replaced_condition = _replace_condition(expr.condition, target, source, check_id)
|
|
137
|
+
cls = type(expr)
|
|
138
|
+
return cls(replaced_sum_index, replaced_operand, replaced_condition)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
@_replace.register
|
|
142
|
+
def _(
|
|
143
|
+
expr: jm.Variable, target: jm.Expression, source: jm.Expression, check_id: bool
|
|
144
|
+
) -> jm.Expression:
|
|
145
|
+
if expr_same(expr, target, check_id):
|
|
146
|
+
return source
|
|
147
|
+
return expr
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
@_replace.register
|
|
152
|
+
def _(
|
|
153
|
+
expr: jm.Subscripts, target: jm.Expression, source: jm.Expression, check_id: bool
|
|
154
|
+
) -> jm.Expression:
|
|
155
|
+
if expr_same(expr, target, check_id):
|
|
156
|
+
return source
|
|
157
|
+
replaced_variable = tp.cast(
|
|
158
|
+
jm.Variable, _replace(expr.variable, target, source, check_id)
|
|
159
|
+
)
|
|
160
|
+
replaced_subscripts = [
|
|
161
|
+
_replace(s, target, source, check_id) for s in expr.subscripts
|
|
162
|
+
]
|
|
163
|
+
cls = type(expr)
|
|
164
|
+
return cls(replaced_variable, replaced_subscripts)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
@singledispatch
|
|
168
|
+
def _replace_condition(
|
|
169
|
+
condition: jc.Condition,
|
|
170
|
+
target: jm.Expression,
|
|
171
|
+
source: jm.Expression,
|
|
172
|
+
check_id: bool,
|
|
173
|
+
) -> jc.Condition:
|
|
174
|
+
raise TypeError(f"{type(condition)} is not supported in `replace`.")
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
@_replace_condition.register
|
|
178
|
+
def _(
|
|
179
|
+
condition: jc.NoneCondition,
|
|
180
|
+
target: jm.Expression,
|
|
181
|
+
source: jm.Expression,
|
|
182
|
+
check_id: bool,
|
|
183
|
+
) -> jc.Condition:
|
|
184
|
+
return condition
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
@_replace_condition.register
|
|
188
|
+
def _(
|
|
189
|
+
condition: jc.CompareCondition,
|
|
190
|
+
target: jm.Expression,
|
|
191
|
+
source: jm.Expression,
|
|
192
|
+
check_id: bool,
|
|
193
|
+
) -> jc.Condition:
|
|
194
|
+
replaced_left = _replace(condition.left, target, source, check_id)
|
|
195
|
+
replaced_right = _replace(condition.right, target, source, check_id)
|
|
196
|
+
cls = type(condition)
|
|
197
|
+
return cls(replaced_left, replaced_right)
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
@_replace_condition.register
|
|
201
|
+
def _(
|
|
202
|
+
condition: jc.ConditionOperator,
|
|
203
|
+
target: jm.Expression,
|
|
204
|
+
source: jm.Expression,
|
|
205
|
+
check_id: bool,
|
|
206
|
+
) -> jc.Condition:
|
|
207
|
+
replaced_left = _replace_condition(condition.left, target, source, check_id)
|
|
208
|
+
replaced_right = _replace_condition(condition.right, target, source, check_id)
|
|
209
|
+
cls = type(condition)
|
|
210
|
+
return cls(replaced_left, replaced_right)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
jijmodeling/protobuf/from_protobuf/__pycache__/extract_attribute_value_from_header.cpython-38.pyc
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|