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
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import typing as tp
|
|
4
|
-
|
|
5
|
-
import jijmodeling.exceptions.exceptions as _exceptions
|
|
6
|
-
import jijmodeling.expression.condition as _condition
|
|
7
|
-
import jijmodeling.expression.expression as _expression
|
|
8
|
-
import jijmodeling.expression.variables.deci_vars as _deci_vars
|
|
9
|
-
import jijmodeling.expression.variables.variable as _variable
|
|
10
|
-
import jijmodeling.problem.problem as _problem
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def extract_variables(
|
|
14
|
-
expression: _expression.Expression,
|
|
15
|
-
) -> tp.List[_variable.Variable]:
|
|
16
|
-
"""
|
|
17
|
-
Extract variables.
|
|
18
|
-
|
|
19
|
-
Args:
|
|
20
|
-
expression (Expression): target expression
|
|
21
|
-
|
|
22
|
-
Returns:
|
|
23
|
-
List[Variable]: A list of variables included in the expression.
|
|
24
|
-
|
|
25
|
-
Examples:
|
|
26
|
-
```python
|
|
27
|
-
import jijmodeling as jm
|
|
28
|
-
from jijmodeling.expression.extract import extract_variables
|
|
29
|
-
a = jm.Placeholder("d", dim=2)
|
|
30
|
-
n = a.shape[0]
|
|
31
|
-
x = jm.Binary("x", shape=(n, ))
|
|
32
|
-
i, j = jm.Element("i", n), jm.Element("j", n)
|
|
33
|
-
term = jm.Sum([i, j], x[i] - s[i, j])
|
|
34
|
-
extract_variables(term)
|
|
35
|
-
# >>> [j, i, s, x, a, a_shape_0]
|
|
36
|
-
```
|
|
37
|
-
"""
|
|
38
|
-
return list(_extract_var_dict(expression).values())
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
def extract_expressions(
|
|
42
|
-
expression: _expression.Expression,
|
|
43
|
-
pattern: tp.Callable[[_expression.Expression], bool],
|
|
44
|
-
) -> tp.List[_expression.Expression]:
|
|
45
|
-
"""
|
|
46
|
-
Extract expressions.
|
|
47
|
-
|
|
48
|
-
Args:
|
|
49
|
-
expression (Expression): target expression
|
|
50
|
-
pattern (Callable[Expression, bool]): pattern to extract
|
|
51
|
-
|
|
52
|
-
Returns:
|
|
53
|
-
List[Expression]: A list of expressions included in the expression.
|
|
54
|
-
|
|
55
|
-
Examples:
|
|
56
|
-
```python
|
|
57
|
-
import jijmodeling as jm
|
|
58
|
-
from jijmodeling.expression.extract import extract_expressions
|
|
59
|
-
a = jm.Placeholder("d", dim=2)
|
|
60
|
-
n = a.shape[0]
|
|
61
|
-
x = jm.Binary("x", shape=(n, ))
|
|
62
|
-
i, j = jm.Element("i", n), jm.Element("j", n)
|
|
63
|
-
s = jm.Binary("s", shape=(n, n))
|
|
64
|
-
term = jm.Sum([i, j], x[i] - s[i, j])
|
|
65
|
-
extract_expressions(term, lambda x: isinstance(x, jm.Element))
|
|
66
|
-
# >>> [i, j]
|
|
67
|
-
extract_expressions(term, lambda x: isinstance(x, jm.Binary))
|
|
68
|
-
# >>> [x, s]
|
|
69
|
-
extract_expressions(term, lambda x: isinstance(x, jm.Subscripts) and x.variable.label == "s")
|
|
70
|
-
# >>> [s[i, j]]
|
|
71
|
-
```
|
|
72
|
-
"""
|
|
73
|
-
return list(_extract_node_dict(expression, pattern).values())
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
def _extract_node_dict(
|
|
77
|
-
expression: _expression.Expression,
|
|
78
|
-
condition: tp.Callable[[_expression.Expression], bool],
|
|
79
|
-
) -> tp.Dict[str, _expression.Expression]:
|
|
80
|
-
var_set = {}
|
|
81
|
-
for child in expression.children():
|
|
82
|
-
var_set.update(_extract_node_dict(child, condition))
|
|
83
|
-
if condition(expression):
|
|
84
|
-
var_set[expression.uuid] = expression
|
|
85
|
-
return var_set
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
def _extract_var_dict(
|
|
89
|
-
expression: _expression.Expression,
|
|
90
|
-
) -> tp.Dict[str, _variable.Variable]:
|
|
91
|
-
return tp.cast(
|
|
92
|
-
tp.Dict[str, _variable.Variable],
|
|
93
|
-
_extract_node_dict(expression, lambda x: isinstance(x, _variable.Variable)),
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
def extract_vars_from_cond(
|
|
98
|
-
condition: _condition.Condition,
|
|
99
|
-
) -> tp.List[_variable.Variable]:
|
|
100
|
-
return list(_extract_vars_from_cond_dict(condition).values())
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
def _extract_vars_from_cond_dict(
|
|
104
|
-
condition: _condition.Condition,
|
|
105
|
-
) -> tp.Dict[str, _variable.Variable]:
|
|
106
|
-
if isinstance(condition, _condition.CompareCondition):
|
|
107
|
-
var_dict = _extract_var_dict(condition.left)
|
|
108
|
-
var_dict.update(_extract_var_dict(condition.right))
|
|
109
|
-
return var_dict
|
|
110
|
-
|
|
111
|
-
elif isinstance(condition, _condition.ConditionOperator):
|
|
112
|
-
var_dict = _extract_vars_from_cond_dict(condition.left)
|
|
113
|
-
var_dict.update(_extract_vars_from_cond_dict(condition.right))
|
|
114
|
-
return var_dict
|
|
115
|
-
else:
|
|
116
|
-
return {}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
def extract_vars_from_problem(problem: _problem.Problem) -> tp.List[_variable.Variable]:
|
|
120
|
-
return list(_extract_vars_from_problem_dict(problem).values())
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
def _extract_vars_from_problem_dict(
|
|
124
|
-
problem: _problem.Problem,
|
|
125
|
-
) -> tp.Dict[str, _variable.Variable]:
|
|
126
|
-
# Extracts all variables from the objective function
|
|
127
|
-
variables = _extract_var_dict(problem.objective)
|
|
128
|
-
|
|
129
|
-
# Extracts all variables from all the constraints
|
|
130
|
-
for constraint in problem.constraints.values():
|
|
131
|
-
variables.update(_extract_vars_from_cond_dict(constraint.condition))
|
|
132
|
-
for index, condition in constraint.forall:
|
|
133
|
-
variables.update(_extract_var_dict(index))
|
|
134
|
-
variables.update(_extract_vars_from_cond_dict(condition))
|
|
135
|
-
if constraint.left_lower is not None:
|
|
136
|
-
variables.update(_extract_var_dict(constraint.left_lower))
|
|
137
|
-
|
|
138
|
-
# Extracts all variables from all the user-defined penalty
|
|
139
|
-
for penalty in problem.penalties.values():
|
|
140
|
-
variables.update(_extract_var_dict(penalty.penalty_term))
|
|
141
|
-
for index, condition in penalty.forall:
|
|
142
|
-
variables.update(_extract_var_dict(index))
|
|
143
|
-
variables.update(_extract_vars_from_cond_dict(condition))
|
|
144
|
-
|
|
145
|
-
return variables
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
def check_unique_variable_label(expression: _expression.Expression):
|
|
149
|
-
"""
|
|
150
|
-
Check unique variable label.
|
|
151
|
-
|
|
152
|
-
Args:
|
|
153
|
-
expression (Expression): target expression
|
|
154
|
-
|
|
155
|
-
Returns:
|
|
156
|
-
None: If the every variable label is unique.
|
|
157
|
-
|
|
158
|
-
Raises:
|
|
159
|
-
ModelingError: If label is not unique.
|
|
160
|
-
"""
|
|
161
|
-
variables = extract_variables(expression)
|
|
162
|
-
var_labels = []
|
|
163
|
-
for v in variables:
|
|
164
|
-
if v.label not in var_labels:
|
|
165
|
-
var_labels.append(v.label)
|
|
166
|
-
else:
|
|
167
|
-
raise _exceptions.ModelingError(
|
|
168
|
-
f"It seems that the variable {v.label} is defined twice. "
|
|
169
|
-
+ "Please check the label when defining the variable."
|
|
170
|
-
)
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
def has_decivar(expression: _expression.Expression) -> bool:
|
|
174
|
-
variables = extract_variables(expression)
|
|
175
|
-
for v in variables:
|
|
176
|
-
if isinstance(v, _deci_vars.DecisionVariable):
|
|
177
|
-
return True
|
|
178
|
-
return False
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
def condition_has_decivar(condition: _condition.Condition) -> bool:
|
|
182
|
-
variables = extract_vars_from_cond(condition)
|
|
183
|
-
for v in variables:
|
|
184
|
-
if isinstance(v, _deci_vars.DecisionVariable):
|
|
185
|
-
return True
|
|
186
|
-
return False
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
import warnings
|
|
3
|
-
|
|
4
|
-
from jijmodeling.expression.condition import (
|
|
5
|
-
AndOperator,
|
|
6
|
-
Equal,
|
|
7
|
-
LessThan,
|
|
8
|
-
LessThanEqual,
|
|
9
|
-
NoneCondition,
|
|
10
|
-
OrOperator,
|
|
11
|
-
XorOperator,
|
|
12
|
-
)
|
|
13
|
-
from jijmodeling.expression.constraint import Constraint, Penalty
|
|
14
|
-
from jijmodeling.deprecation.deprecation import JijFutureWarning
|
|
15
|
-
from jijmodeling.expression.expression import (
|
|
16
|
-
Add,
|
|
17
|
-
Div,
|
|
18
|
-
Expression,
|
|
19
|
-
Mod,
|
|
20
|
-
Mul,
|
|
21
|
-
Number,
|
|
22
|
-
Power,
|
|
23
|
-
)
|
|
24
|
-
from jijmodeling.expression.mathfunc import AbsoluteValue, Ceil, Floor, Log2, Max, Min
|
|
25
|
-
from jijmodeling.expression.prod import ProdOperator
|
|
26
|
-
from jijmodeling.expression.sum import SumOperator
|
|
27
|
-
from jijmodeling.expression.variables.deci_vars import Binary, Integer
|
|
28
|
-
from jijmodeling.expression.variables.jagged_array import JaggedArray
|
|
29
|
-
from jijmodeling.expression.variables.placeholders import ArrayShape, Placeholder
|
|
30
|
-
from jijmodeling.expression.variables.variable import Element, Range, Subscripts
|
|
31
|
-
from jijmodeling.problem import Problem, ProblemSense
|
|
32
|
-
|
|
33
|
-
_OLD_NAME_TO_CLASS = {
|
|
34
|
-
"jijmodeling.expression.variables.placeholders.Placeholder": Placeholder,
|
|
35
|
-
"jijmodleing.expression.variables.jagged_array.JaggedArray": JaggedArray,
|
|
36
|
-
"jijmodeling.expression.variables.variable.Subscripts": Subscripts,
|
|
37
|
-
"jijmodeling.expression.variables.variable.Element": Element,
|
|
38
|
-
"jijmodeling.expression.variables.variable.Range": Range,
|
|
39
|
-
"jijmodeling.expression.variables.placeholders.ArrayShape": ArrayShape,
|
|
40
|
-
"jijmodeling.expression.expression.Number": Number,
|
|
41
|
-
"jijmodeling.expression.expression.Add": Add,
|
|
42
|
-
"jijmodeling.expression.expression.Mul": Mul,
|
|
43
|
-
"jijmodeling.expression.expression.Div": Div,
|
|
44
|
-
"jijmodeling.expression.expression.Power": Power,
|
|
45
|
-
"jijmodeling.expression.expression.Mod": Mod,
|
|
46
|
-
"jijmodeling.expression.mathfunc.AbsoluteValue": AbsoluteValue,
|
|
47
|
-
"jijmodeling.expression.mathfunc.Max": Max,
|
|
48
|
-
"jijmodeling.expression.mathfunc.Min": Min,
|
|
49
|
-
"jijmodeling.expression.mathfunc.Ceil": Ceil,
|
|
50
|
-
"jijmodeling.expression.mathfunc.Floor": Floor,
|
|
51
|
-
"jijmodeling.expression.mathfunc.Log2": Log2,
|
|
52
|
-
"jijmodeling.expression.prod.ProdOperator": ProdOperator,
|
|
53
|
-
"jijmodeling.expression.sum.SumOperator": SumOperator,
|
|
54
|
-
"jijmodeling.expression.variables.deci_vars.Binary": Binary,
|
|
55
|
-
"jijmodeling.expression.variables.deci_vars.LogEncInteger": Integer,
|
|
56
|
-
"jijmodeling.expression.condition.NoneCondition": NoneCondition,
|
|
57
|
-
"jijmodeling.expression.condition.AndOperator": AndOperator,
|
|
58
|
-
"jijmodeling.expression.condition.OrOperator": OrOperator,
|
|
59
|
-
"jijmodeling.expression.condition.XorOperator": XorOperator,
|
|
60
|
-
"jijmodeling.expression.condition.Equal": Equal,
|
|
61
|
-
"jijmodeling.expression.condition.LessEqual": LessThan,
|
|
62
|
-
"jijmodeling.expression.condition.LessThanEqual": LessThanEqual,
|
|
63
|
-
"jijmodeling.expression.constraint.Constraint": Constraint,
|
|
64
|
-
"jijmodeling.expression.constraint.Penalty": Penalty,
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
def from_0_10_0_serializable(serializable: dict) -> Problem:
|
|
69
|
-
if not serializable["version"] == "0.10.0":
|
|
70
|
-
raise ValueError(
|
|
71
|
-
f"In 'from_0_10_0_serializable', support only 0.10.0, not {serializable['version']}."
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
object_schema = serializable["object"]
|
|
75
|
-
if not object_schema["class"] == "jijmodeling.problem.Problem":
|
|
76
|
-
raise ValueError(
|
|
77
|
-
f"{object_schema['class']} is not supported in 'from_0_10_0_serializable'."
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
attributes = object_schema["attributes"]
|
|
81
|
-
name = attributes["name"]
|
|
82
|
-
_kind_map = {"Minimum": ProblemSense.MINIMUM, "Maximum": ProblemSense.MAXIMUM}
|
|
83
|
-
kind = _kind_map[attributes["kind"]]
|
|
84
|
-
objective = _class_0100_from_serializable(attributes["objective"])
|
|
85
|
-
constraints = [
|
|
86
|
-
_class_0100_from_serializable(c) for c in attributes["constraints"].values()
|
|
87
|
-
]
|
|
88
|
-
penalties = [
|
|
89
|
-
_class_0100_from_serializable(c) for c in attributes["penalties"].values()
|
|
90
|
-
]
|
|
91
|
-
|
|
92
|
-
problem = Problem(name, sense=kind)
|
|
93
|
-
problem += objective
|
|
94
|
-
for c in constraints:
|
|
95
|
-
problem += c
|
|
96
|
-
for p in penalties:
|
|
97
|
-
problem += p
|
|
98
|
-
|
|
99
|
-
return problem
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
def old_0_10_0_to_new_from_serializable(serializable: dict) -> Expression:
|
|
103
|
-
"""Deserialize from old schema to new JijModeling Expression."""
|
|
104
|
-
object_schema = serializable["object"]
|
|
105
|
-
return _class_0100_from_serializable(object_schema)
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
def _0100_from_serializable(object_schema: dict | int | float | None):
|
|
109
|
-
if not isinstance(object_schema, dict):
|
|
110
|
-
return object_schema
|
|
111
|
-
if "class" in object_schema:
|
|
112
|
-
return _class_0100_from_serializable(object_schema)
|
|
113
|
-
elif "iteratable" in object_schema:
|
|
114
|
-
return _iteratable_0100_from_serializable(object_schema)
|
|
115
|
-
else:
|
|
116
|
-
raise ValueError(
|
|
117
|
-
f"'{object_schema.keys()}' is not supported in 0_10_0 deserializer."
|
|
118
|
-
)
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
def _iteratable_0100_from_serializable(object_schema: dict):
|
|
122
|
-
value = [_0100_from_serializable(v) for v in object_schema["value"]]
|
|
123
|
-
if object_schema["iteratable"] == "tuple":
|
|
124
|
-
return tuple(value)
|
|
125
|
-
else:
|
|
126
|
-
return value
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
def _class_0100_from_serializable(object_schema: dict):
|
|
130
|
-
jm_cls = _OLD_NAME_TO_CLASS[object_schema["class"]]
|
|
131
|
-
attributes = object_schema["attributes"]
|
|
132
|
-
|
|
133
|
-
attr_values = {k: _0100_from_serializable(v) for k, v in attributes.items()}
|
|
134
|
-
|
|
135
|
-
with warnings.catch_warnings():
|
|
136
|
-
warnings.simplefilter("ignore", category=JijFutureWarning)
|
|
137
|
-
return jm_cls(**attr_values)
|
|
@@ -1,335 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import abc as _abc
|
|
4
|
-
import builtins as _builtins
|
|
5
|
-
import numbers as _numbers
|
|
6
|
-
import typing as tp
|
|
7
|
-
|
|
8
|
-
from abc import abstractmethod
|
|
9
|
-
|
|
10
|
-
import numpy as np
|
|
11
|
-
import typeguard as _typeguard
|
|
12
|
-
|
|
13
|
-
import jijmodeling.exceptions.exceptions as _exceptions
|
|
14
|
-
import jijmodeling.expression.expression as _expression
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class UnaryOperator(_expression.Expression, metaclass=_abc.ABCMeta):
|
|
18
|
-
"""
|
|
19
|
-
Binary Operator class represents each operation (ex. +,*,&,...) on `_expression.Expression`.
|
|
20
|
-
"""
|
|
21
|
-
|
|
22
|
-
_mark = " "
|
|
23
|
-
|
|
24
|
-
def __init__(
|
|
25
|
-
self,
|
|
26
|
-
operand: tp.Union[_expression.Expression, _expression.NumericValue],
|
|
27
|
-
uuid: tp.Optional[str] = None,
|
|
28
|
-
):
|
|
29
|
-
super().__init__()
|
|
30
|
-
|
|
31
|
-
_typeguard.check_type(
|
|
32
|
-
operand,
|
|
33
|
-
tp.Union[_expression.Expression, _expression.NumericValue],
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
# convert int float to Number
|
|
37
|
-
self._operand: _expression.Expression = (
|
|
38
|
-
operand
|
|
39
|
-
if isinstance(operand, _expression.Expression)
|
|
40
|
-
else _expression.Number(operand)
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
import jijmodeling.utils.utils as _utils
|
|
44
|
-
|
|
45
|
-
_utils.validate_value("operand.is_operatable()", self._operand.is_operatable())
|
|
46
|
-
|
|
47
|
-
import jijmodeling.expression.extract as _extract
|
|
48
|
-
|
|
49
|
-
if _extract.has_decivar(self._operand):
|
|
50
|
-
raise _exceptions.CannotContainDecisionVarError(
|
|
51
|
-
"An unary operator operand cannot contain a decision variable."
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
if uuid is not None:
|
|
55
|
-
self._uuid = uuid
|
|
56
|
-
|
|
57
|
-
@property
|
|
58
|
-
def operand(self) -> _expression.Expression:
|
|
59
|
-
return self._operand
|
|
60
|
-
|
|
61
|
-
@classmethod
|
|
62
|
-
@abstractmethod
|
|
63
|
-
def operation(
|
|
64
|
-
cls: tp.Type[UnaryOperator], operand: _expression.NumericValue
|
|
65
|
-
) -> _expression.NumericValue:
|
|
66
|
-
"""
|
|
67
|
-
Execute operation.
|
|
68
|
-
|
|
69
|
-
Examples:
|
|
70
|
-
```python
|
|
71
|
-
Ceil.operation(4.3)
|
|
72
|
-
# >>> 5
|
|
73
|
-
Floor.operation(3.9)
|
|
74
|
-
# >>> 3
|
|
75
|
-
Log2.operation(4)
|
|
76
|
-
# >>> 2.0
|
|
77
|
-
```
|
|
78
|
-
"""
|
|
79
|
-
|
|
80
|
-
@classmethod
|
|
81
|
-
def create(
|
|
82
|
-
cls: tp.Type[UnaryOperator],
|
|
83
|
-
operand: tp.Union[_expression.Expression, _expression.NumericValue],
|
|
84
|
-
) -> _expression.Expression:
|
|
85
|
-
if isinstance(operand, (int, float, _numbers.Real)):
|
|
86
|
-
return _expression.Number(cls.operation(operand))
|
|
87
|
-
elif isinstance(operand, _expression.Number):
|
|
88
|
-
return _expression.Number(cls.operation(operand.value))
|
|
89
|
-
elif isinstance(operand, _expression.Expression):
|
|
90
|
-
return cls(operand)
|
|
91
|
-
else:
|
|
92
|
-
raise _exceptions.ModelingError(
|
|
93
|
-
"The operand of {} is support only number or_expression.Expression, not {}.".format(
|
|
94
|
-
cls.__name__, operand.__class__.__name__
|
|
95
|
-
)
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
def is_operatable(self) -> bool:
|
|
99
|
-
"""
|
|
100
|
-
Unary operator is operatable.
|
|
101
|
-
|
|
102
|
-
Returns:
|
|
103
|
-
bool: True
|
|
104
|
-
"""
|
|
105
|
-
return True
|
|
106
|
-
|
|
107
|
-
def children(self) -> tp.List[_expression.Expression]:
|
|
108
|
-
return [self.operand]
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
class AbsoluteValue(UnaryOperator):
|
|
112
|
-
"""Absolute value operator."""
|
|
113
|
-
|
|
114
|
-
def __repr__(self) -> str:
|
|
115
|
-
return "|" + str(self.operand) + "|"
|
|
116
|
-
|
|
117
|
-
@classmethod
|
|
118
|
-
def operation(cls, operand: _expression.NumericValue) -> _expression.NumericValue:
|
|
119
|
-
"""operation of absolute value.
|
|
120
|
-
Args:
|
|
121
|
-
operand (_expression.NumericValue): operand of absolute value.
|
|
122
|
-
|
|
123
|
-
Returns:
|
|
124
|
-
_expression.NumericValue: absolute value of operand.
|
|
125
|
-
"""
|
|
126
|
-
abs_value: _expression.NumericValue = np.abs(operand)
|
|
127
|
-
return abs_value
|
|
128
|
-
|
|
129
|
-
def _default_repr_latex_(self) -> str:
|
|
130
|
-
return r"\left|" + self.operand._make_latex() + r"\right|"
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
class Max(_expression.BinaryOperator):
|
|
134
|
-
"""Max operator."""
|
|
135
|
-
|
|
136
|
-
def __init__(
|
|
137
|
-
self,
|
|
138
|
-
left: _expression.Expression,
|
|
139
|
-
right: _expression.Expression,
|
|
140
|
-
uuid: tp.Optional[str] = None,
|
|
141
|
-
):
|
|
142
|
-
super().__init__(left, right, uuid)
|
|
143
|
-
|
|
144
|
-
import jijmodeling.expression.extract as _extract
|
|
145
|
-
|
|
146
|
-
if _extract.has_decivar(self.left) or _extract.has_decivar(self.right):
|
|
147
|
-
raise _exceptions.CannotContainDecisionVarError(
|
|
148
|
-
"operands of Max function cannot contain a decision variable."
|
|
149
|
-
)
|
|
150
|
-
|
|
151
|
-
def __repr__(self) -> str:
|
|
152
|
-
return "max(" + ",".join(map(str, [self.left, self.right])) + ")"
|
|
153
|
-
|
|
154
|
-
@classmethod
|
|
155
|
-
def operation(cls, left, right) -> tp.Any:
|
|
156
|
-
"""operation of max.
|
|
157
|
-
|
|
158
|
-
Args:
|
|
159
|
-
left (_expression.Expression): left operand of max.
|
|
160
|
-
right (_expression.Expression): right operand of max.
|
|
161
|
-
|
|
162
|
-
Returns:
|
|
163
|
-
tp.Any: max value of left and right.
|
|
164
|
-
"""
|
|
165
|
-
return _builtins.max(left, right)
|
|
166
|
-
|
|
167
|
-
def _default_repr_latex_(self) -> str:
|
|
168
|
-
left = self.left._make_latex()
|
|
169
|
-
right = self.right._make_latex()
|
|
170
|
-
return r"\max(" + f"{left}, {right})"
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
class Min(_expression.BinaryOperator):
|
|
174
|
-
"""Min operator."""
|
|
175
|
-
|
|
176
|
-
def __init__(
|
|
177
|
-
self,
|
|
178
|
-
left: _expression.Expression,
|
|
179
|
-
right: _expression.Expression,
|
|
180
|
-
uuid: tp.Optional[str] = None,
|
|
181
|
-
):
|
|
182
|
-
super().__init__(left, right, uuid)
|
|
183
|
-
|
|
184
|
-
import jijmodeling.expression.extract as _extract
|
|
185
|
-
|
|
186
|
-
if _extract.has_decivar(self.left) or _extract.has_decivar(self.right):
|
|
187
|
-
raise _exceptions.CannotContainDecisionVarError(
|
|
188
|
-
"operands of Max function cannot contain a decision variable."
|
|
189
|
-
)
|
|
190
|
-
|
|
191
|
-
def __repr__(self) -> str:
|
|
192
|
-
return "min(" + ",".join(map(str, [self.left, self.right])) + ")"
|
|
193
|
-
|
|
194
|
-
@classmethod
|
|
195
|
-
def operation(cls, left, right) -> tp.Any:
|
|
196
|
-
"""operation of min.
|
|
197
|
-
|
|
198
|
-
Args:
|
|
199
|
-
left (_expression.Expression): left operand of min.
|
|
200
|
-
right (_expression.Expression): right operand of min.
|
|
201
|
-
|
|
202
|
-
Returns:
|
|
203
|
-
tp.Any: min value of left and right.
|
|
204
|
-
"""
|
|
205
|
-
return _builtins.min(left, right)
|
|
206
|
-
|
|
207
|
-
def _default_repr_latex_(self) -> str:
|
|
208
|
-
left = self.left._make_latex()
|
|
209
|
-
right = self.right._make_latex()
|
|
210
|
-
return r"\min(" + f"{left}, {right})"
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
class Ceil(UnaryOperator):
|
|
214
|
-
"""Ceil operator."""
|
|
215
|
-
|
|
216
|
-
def __repr__(self):
|
|
217
|
-
return "[" + str(self.operand) + "]"
|
|
218
|
-
|
|
219
|
-
@classmethod
|
|
220
|
-
def operation(cls, operand: _expression.NumericValue) -> _expression.NumericValue:
|
|
221
|
-
ceil_value: _expression.NumericValue = np.ceil(operand)
|
|
222
|
-
return ceil_value
|
|
223
|
-
|
|
224
|
-
def _default_repr_latex_(self) -> str:
|
|
225
|
-
term_str = (
|
|
226
|
-
self.operand._make_latex()
|
|
227
|
-
if isinstance(self.operand, _expression.Expression)
|
|
228
|
-
else str(self.operand)
|
|
229
|
-
)
|
|
230
|
-
return r"\left\lceil " + term_str + r"\right\rceil"
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
class Floor(UnaryOperator):
|
|
234
|
-
def __repr__(self) -> str:
|
|
235
|
-
return "|_" + str(self.operand) + "_|"
|
|
236
|
-
|
|
237
|
-
@classmethod
|
|
238
|
-
def operation(cls, operand: _expression.NumericValue) -> _expression.NumericValue:
|
|
239
|
-
floor_value: _expression.NumericValue = np.floor(operand)
|
|
240
|
-
return floor_value
|
|
241
|
-
|
|
242
|
-
def _default_repr_latex_(self) -> str:
|
|
243
|
-
term_str = (
|
|
244
|
-
self.operand._make_latex()
|
|
245
|
-
if isinstance(self.operand, _expression.Expression)
|
|
246
|
-
else str(self._operand)
|
|
247
|
-
)
|
|
248
|
-
return r"\left\lfloor " + term_str + r"\right\floor "
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
class Log2(UnaryOperator):
|
|
252
|
-
def __repr__(self) -> str:
|
|
253
|
-
return f"log2({str(self.operand)})"
|
|
254
|
-
|
|
255
|
-
@classmethod
|
|
256
|
-
def operation(cls, operand: _expression.NumericValue) -> tp.Any:
|
|
257
|
-
return np.log2(operand)
|
|
258
|
-
|
|
259
|
-
def _default_repr_latex_(self) -> str:
|
|
260
|
-
return r"\log_2" + f"({self.operand._make_latex()})"
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
def abs(term) -> _expression.Expression:
|
|
264
|
-
"""Absolute function.
|
|
265
|
-
Args:
|
|
266
|
-
term (int | float | Expression): term of absolute value.
|
|
267
|
-
Returns:
|
|
268
|
-
Union[AbsoluteValue, Expression]: absolute value of term.
|
|
269
|
-
"""
|
|
270
|
-
return AbsoluteValue.create(term)
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
def ceil(term) -> _expression.Expression:
|
|
274
|
-
"""Ceiling function.
|
|
275
|
-
Args:
|
|
276
|
-
term (int | float | Expression): term of ceiling function.
|
|
277
|
-
|
|
278
|
-
Returns:
|
|
279
|
-
Union[Ceil, Expression]: ceiling value of term.
|
|
280
|
-
"""
|
|
281
|
-
return Ceil.create(term)
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
def floor(term) -> _expression.Expression:
|
|
285
|
-
"""Floor function.
|
|
286
|
-
|
|
287
|
-
Args:
|
|
288
|
-
term (int | float | Expression): term of floor function.
|
|
289
|
-
|
|
290
|
-
Returns:
|
|
291
|
-
Union[Floor, Expression]: floor value of term.
|
|
292
|
-
"""
|
|
293
|
-
return Floor.create(term)
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
def log2(antilog) -> _expression.Expression:
|
|
297
|
-
"""
|
|
298
|
-
Log function.
|
|
299
|
-
|
|
300
|
-
Args:
|
|
301
|
-
antilog (int | float |_expression.Expression): antilog
|
|
302
|
-
|
|
303
|
-
$$\\log_{2}\\mathrm{antilog}$$
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
Returns:
|
|
307
|
-
: Log2 value
|
|
308
|
-
"""
|
|
309
|
-
return Log2.create(antilog)
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
def max(left, right) -> _expression.Expression:
|
|
313
|
-
"""Max function.
|
|
314
|
-
|
|
315
|
-
Args:
|
|
316
|
-
left (int | float | _expression.Expression): left operand of max.
|
|
317
|
-
right (int | float | _expression.Expression): right operand of max.
|
|
318
|
-
|
|
319
|
-
Returns:
|
|
320
|
-
Union[Max, Expression]: max value of left and right.
|
|
321
|
-
"""
|
|
322
|
-
return Max.create(left, right)
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
def min(left, right) -> _expression.Expression:
|
|
326
|
-
"""Min function.
|
|
327
|
-
|
|
328
|
-
Args:
|
|
329
|
-
left (int | float | _expression.Expression): left operand of min.
|
|
330
|
-
right (int | float | _expression.Expression): right operand of min.
|
|
331
|
-
|
|
332
|
-
Returns:
|
|
333
|
-
Union[Min, Expression]: min value of left and right.
|
|
334
|
-
"""
|
|
335
|
-
return Min.create(left, right)
|