jijmodeling 0.13.2__cp310-cp310-win_amd64.whl → 1.12.0__cp310-cp310-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.cp310-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-310.opt-1.pyc +0 -0
- jijmodeling/__pycache__/__init__.cpython-310.pyc +0 -0
- jijmodeling/__pycache__/_version.cpython-310.opt-1.pyc +0 -0
- jijmodeling/__pycache__/_version.cpython-310.pyc +0 -0
- jijmodeling/_version.py +0 -4
- jijmodeling/deprecation/__init__.py +0 -11
- jijmodeling/deprecation/__pycache__/__init__.cpython-310.opt-1.pyc +0 -0
- jijmodeling/deprecation/__pycache__/__init__.cpython-310.pyc +0 -0
- jijmodeling/deprecation/__pycache__/deprecation.cpython-310.opt-1.pyc +0 -0
- jijmodeling/deprecation/__pycache__/deprecation.cpython-310.pyc +0 -0
- jijmodeling/deprecation/deprecation.py +0 -108
- jijmodeling/exceptions/__init__.py +0 -26
- jijmodeling/exceptions/__pycache__/__init__.cpython-310.opt-1.pyc +0 -0
- jijmodeling/exceptions/__pycache__/__init__.cpython-310.pyc +0 -0
- jijmodeling/exceptions/__pycache__/exceptions.cpython-310.opt-1.pyc +0 -0
- jijmodeling/exceptions/__pycache__/exceptions.cpython-310.pyc +0 -0
- jijmodeling/exceptions/exceptions.py +0 -37
- jijmodeling/expression/__init__.py +0 -76
- jijmodeling/expression/__pycache__/__init__.cpython-310.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/__init__.cpython-310.pyc +0 -0
- jijmodeling/expression/__pycache__/condition.cpython-310.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/condition.cpython-310.pyc +0 -0
- jijmodeling/expression/__pycache__/constraint.cpython-310.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/constraint.cpython-310.pyc +0 -0
- jijmodeling/expression/__pycache__/expression.cpython-310.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/expression.cpython-310.pyc +0 -0
- jijmodeling/expression/__pycache__/extract.cpython-310.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/extract.cpython-310.pyc +0 -0
- jijmodeling/expression/__pycache__/from_old_serializable.cpython-310.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/from_old_serializable.cpython-310.pyc +0 -0
- jijmodeling/expression/__pycache__/mathfunc.cpython-310.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/mathfunc.cpython-310.pyc +0 -0
- jijmodeling/expression/__pycache__/prod.cpython-310.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/prod.cpython-310.pyc +0 -0
- jijmodeling/expression/__pycache__/serializable.cpython-310.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/serializable.cpython-310.pyc +0 -0
- jijmodeling/expression/__pycache__/sum.cpython-310.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/sum.cpython-310.pyc +0 -0
- jijmodeling/expression/__pycache__/type_annotations.cpython-310.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/type_annotations.cpython-310.pyc +0 -0
- jijmodeling/expression/__pycache__/utils.cpython-310.opt-1.pyc +0 -0
- jijmodeling/expression/__pycache__/utils.cpython-310.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-310.opt-1.pyc +0 -0
- jijmodeling/expression/variables/__pycache__/__init__.cpython-310.pyc +0 -0
- jijmodeling/expression/variables/__pycache__/deci_vars.cpython-310.opt-1.pyc +0 -0
- jijmodeling/expression/variables/__pycache__/deci_vars.cpython-310.pyc +0 -0
- jijmodeling/expression/variables/__pycache__/jagged_array.cpython-310.opt-1.pyc +0 -0
- jijmodeling/expression/variables/__pycache__/jagged_array.cpython-310.pyc +0 -0
- jijmodeling/expression/variables/__pycache__/placeholders.cpython-310.opt-1.pyc +0 -0
- jijmodeling/expression/variables/__pycache__/placeholders.cpython-310.pyc +0 -0
- jijmodeling/expression/variables/__pycache__/variable.cpython-310.opt-1.pyc +0 -0
- jijmodeling/expression/variables/__pycache__/variable.cpython-310.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-310.opt-1.pyc +0 -0
- jijmodeling/latex_repr/__pycache__/__init__.cpython-310.pyc +0 -0
- jijmodeling/latex_repr/__pycache__/latex_repr.cpython-310.opt-1.pyc +0 -0
- jijmodeling/latex_repr/__pycache__/latex_repr.cpython-310.pyc +0 -0
- jijmodeling/latex_repr/__pycache__/problem_latex_repr.cpython-310.opt-1.pyc +0 -0
- jijmodeling/latex_repr/__pycache__/problem_latex_repr.cpython-310.pyc +0 -0
- jijmodeling/latex_repr/latex_repr.py +0 -243
- jijmodeling/latex_repr/problem_latex_repr.py +0 -210
- jijmodeling/marker/__marker__.cp310-win_amd64.pyd +0 -0
- jijmodeling/match/__init__.py +0 -19
- jijmodeling/match/__pycache__/__init__.cpython-310.opt-1.pyc +0 -0
- jijmodeling/match/__pycache__/__init__.cpython-310.pyc +0 -0
- jijmodeling/match/__pycache__/condition_same.cpython-310.opt-1.pyc +0 -0
- jijmodeling/match/__pycache__/condition_same.cpython-310.pyc +0 -0
- jijmodeling/match/__pycache__/constraint_same.cpython-310.opt-1.pyc +0 -0
- jijmodeling/match/__pycache__/constraint_same.cpython-310.pyc +0 -0
- jijmodeling/match/__pycache__/expand.cpython-310.opt-1.pyc +0 -0
- jijmodeling/match/__pycache__/expand.cpython-310.pyc +0 -0
- jijmodeling/match/__pycache__/expr_same.cpython-310.opt-1.pyc +0 -0
- jijmodeling/match/__pycache__/expr_same.cpython-310.pyc +0 -0
- jijmodeling/match/__pycache__/is_same_expr.cpython-310.opt-1.pyc +0 -0
- jijmodeling/match/__pycache__/is_same_expr.cpython-310.pyc +0 -0
- jijmodeling/match/__pycache__/penalty_same.cpython-310.opt-1.pyc +0 -0
- jijmodeling/match/__pycache__/penalty_same.cpython-310.pyc +0 -0
- jijmodeling/match/__pycache__/problem_same.cpython-310.opt-1.pyc +0 -0
- jijmodeling/match/__pycache__/problem_same.cpython-310.pyc +0 -0
- jijmodeling/match/__pycache__/replace.cpython-310.opt-1.pyc +0 -0
- jijmodeling/match/__pycache__/replace.cpython-310.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-310.opt-1.pyc +0 -0
- jijmodeling/problem/__pycache__/__init__.cpython-310.pyc +0 -0
- jijmodeling/problem/__pycache__/problem.cpython-310.opt-1.pyc +0 -0
- jijmodeling/problem/__pycache__/problem.cpython-310.pyc +0 -0
- jijmodeling/problem/problem.py +0 -186
- jijmodeling/protobuf/__init__.py +0 -8
- jijmodeling/protobuf/__pycache__/__init__.cpython-310.opt-1.pyc +0 -0
- jijmodeling/protobuf/__pycache__/__init__.cpython-310.pyc +0 -0
- jijmodeling/protobuf/__pycache__/from_protobuf.cpython-310.opt-1.pyc +0 -0
- jijmodeling/protobuf/__pycache__/from_protobuf.cpython-310.pyc +0 -0
- jijmodeling/protobuf/__pycache__/to_protobuf.cpython-310.opt-1.pyc +0 -0
- jijmodeling/protobuf/__pycache__/to_protobuf.cpython-310.pyc +0 -0
- jijmodeling/protobuf/__pycache__/type_annotations.cpython-310.opt-1.pyc +0 -0
- jijmodeling/protobuf/__pycache__/type_annotations.cpython-310.pyc +0 -0
- jijmodeling/protobuf/from_protobuf.py +0 -336
- jijmodeling/protobuf/pb2/__init__.py +0 -42
- jijmodeling/protobuf/pb2/__pycache__/__init__.cpython-310.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/__init__.cpython-310.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/array_length_pb2.cpython-310.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/array_length_pb2.cpython-310.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/binary_op_pb2.cpython-310.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/binary_op_pb2.cpython-310.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/commutative_op_pb2.cpython-310.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/commutative_op_pb2.cpython-310.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/constraint_pb2.cpython-310.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/constraint_pb2.cpython-310.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/custom_penalty_term_pb2.cpython-310.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/custom_penalty_term_pb2.cpython-310.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/decision_var_pb2.cpython-310.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/decision_var_pb2.cpython-310.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/element_pb2.cpython-310.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/element_pb2.cpython-310.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/expression_pb2.cpython-310.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/expression_pb2.cpython-310.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/forall_pb2.cpython-310.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/forall_pb2.cpython-310.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/header_pb2.cpython-310.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/header_pb2.cpython-310.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/index_pb2.cpython-310.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/index_pb2.cpython-310.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/number_lit_pb2.cpython-310.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/number_lit_pb2.cpython-310.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/placeholder_pb2.cpython-310.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/placeholder_pb2.cpython-310.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/problem_pb2.cpython-310.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/problem_pb2.cpython-310.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/reduction_op_pb2.cpython-310.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/reduction_op_pb2.cpython-310.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/subscript_pb2.cpython-310.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/subscript_pb2.cpython-310.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/unary_op_pb2.cpython-310.opt-1.pyc +0 -0
- jijmodeling/protobuf/pb2/__pycache__/unary_op_pb2.cpython-310.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-310.opt-1.pyc +0 -0
- jijmodeling/sampleset/__pycache__/__init__.cpython-310.pyc +0 -0
- jijmodeling/sampleset/__pycache__/evaluation.cpython-310.opt-1.pyc +0 -0
- jijmodeling/sampleset/__pycache__/evaluation.cpython-310.pyc +0 -0
- jijmodeling/sampleset/__pycache__/measuring_time.cpython-310.opt-1.pyc +0 -0
- jijmodeling/sampleset/__pycache__/measuring_time.cpython-310.pyc +0 -0
- jijmodeling/sampleset/__pycache__/record.cpython-310.opt-1.pyc +0 -0
- jijmodeling/sampleset/__pycache__/record.cpython-310.pyc +0 -0
- jijmodeling/sampleset/__pycache__/sampleset.cpython-310.opt-1.pyc +0 -0
- jijmodeling/sampleset/__pycache__/sampleset.cpython-310.pyc +0 -0
- jijmodeling/sampleset/__pycache__/solving_time.cpython-310.opt-1.pyc +0 -0
- jijmodeling/sampleset/__pycache__/solving_time.cpython-310.pyc +0 -0
- jijmodeling/sampleset/__pycache__/system_time.cpython-310.opt-1.pyc +0 -0
- jijmodeling/sampleset/__pycache__/system_time.cpython-310.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-310.opt-1.pyc +0 -0
- jijmodeling/type_annotations/__pycache__/__init__.cpython-310.pyc +0 -0
- jijmodeling/type_annotations/__pycache__/type_annotations.cpython-310.opt-1.pyc +0 -0
- jijmodeling/type_annotations/__pycache__/type_annotations.cpython-310.pyc +0 -0
- jijmodeling/type_annotations/type_annotations.py +0 -54
- jijmodeling/utils/__init__.py +0 -28
- jijmodeling/utils/__pycache__/__init__.cpython-310.opt-1.pyc +0 -0
- jijmodeling/utils/__pycache__/__init__.cpython-310.pyc +0 -0
- jijmodeling/utils/__pycache__/deprecated.cpython-310.opt-1.pyc +0 -0
- jijmodeling/utils/__pycache__/deprecated.cpython-310.pyc +0 -0
- jijmodeling/utils/__pycache__/utils.cpython-310.opt-1.pyc +0 -0
- jijmodeling/utils/__pycache__/utils.cpython-310.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,428 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import typing as typ
|
|
4
|
-
from typing import List, Optional, Tuple, Union, overload
|
|
5
|
-
import warnings
|
|
6
|
-
|
|
7
|
-
from typeguard import check_type, typechecked
|
|
8
|
-
|
|
9
|
-
from jijmodeling.deprecation.deprecation import (
|
|
10
|
-
deprecated_kwargs,
|
|
11
|
-
deprecated_name,
|
|
12
|
-
JijFutureWarning
|
|
13
|
-
)
|
|
14
|
-
import jijmodeling.exceptions.exceptions as _exceptions
|
|
15
|
-
import jijmodeling.expression.condition as _condition
|
|
16
|
-
import jijmodeling.expression.expression as _expression
|
|
17
|
-
import jijmodeling.expression.serializable as _serializable
|
|
18
|
-
import jijmodeling.expression.sum as _sum
|
|
19
|
-
import jijmodeling.expression.variables.variable as _variable
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class Penalty(metaclass=_serializable.Serializable):
|
|
23
|
-
"""
|
|
24
|
-
Penalty term without constraint.
|
|
25
|
-
|
|
26
|
-
Incorporate it into the model as a penalty term. It is not evaluated
|
|
27
|
-
as a constraint, so it is not used to determine if a solution is
|
|
28
|
-
feasible. However, it is evaluated separately from the objective
|
|
29
|
-
function. It is mainly used to include conditions that you want to
|
|
30
|
-
treat as soft constraints as penalty terms. The penalty class can
|
|
31
|
-
also be used when you would like to express the constraint as a
|
|
32
|
-
penalty that you define, rather than one that is automatically
|
|
33
|
-
changed by QUBO.
|
|
34
|
-
"""
|
|
35
|
-
|
|
36
|
-
@deprecated_name("Penalty", "CustomPenaltyTerm", kind="class")
|
|
37
|
-
def __init__(
|
|
38
|
-
self,
|
|
39
|
-
label: str,
|
|
40
|
-
penalty_term: _expression.Expression,
|
|
41
|
-
forall: Union[
|
|
42
|
-
_variable.Element,
|
|
43
|
-
Tuple[_variable.Element, Optional[_condition.Condition]],
|
|
44
|
-
List[
|
|
45
|
-
Union[
|
|
46
|
-
_variable.Element,
|
|
47
|
-
Tuple[_variable.Element, Optional[_condition.Condition]],
|
|
48
|
-
]
|
|
49
|
-
],
|
|
50
|
-
] = [],
|
|
51
|
-
with_multiplier: typ.Optional[bool] = None,
|
|
52
|
-
):
|
|
53
|
-
"""
|
|
54
|
-
Initializes a Penalty object without constraint.
|
|
55
|
-
|
|
56
|
-
Args:
|
|
57
|
-
label (str): A unique identifier for the penalty term.
|
|
58
|
-
penalty_term (_expression.Expression): The expression representing the penalty term.
|
|
59
|
-
forall (tuple, optional): A list of elements and optional conditions that the penalty term applies to. Default is an empty list.
|
|
60
|
-
with_multiplier (typ.Optional[bool], deprecated): A flag indicating whether to use a multiplier in the penalty term. This argument is deprecated and will be removed in the next version. Default is None.
|
|
61
|
-
|
|
62
|
-
Example:
|
|
63
|
-
```python
|
|
64
|
-
import jijmodeling as jm
|
|
65
|
-
n = jm.Placeholder('n')
|
|
66
|
-
x = jm.BinaryVar('x', shape=n)
|
|
67
|
-
pe = jm.Penalty('p', (x[:]-1)**2) # one-hot constraint
|
|
68
|
-
```
|
|
69
|
-
"""
|
|
70
|
-
self._label = label
|
|
71
|
-
self._penalty_term = penalty_term
|
|
72
|
-
|
|
73
|
-
if with_multiplier is None:
|
|
74
|
-
self._with_multiplier = True
|
|
75
|
-
else:
|
|
76
|
-
self._with_multiplier = with_multiplier
|
|
77
|
-
|
|
78
|
-
# convert forall to list-type object
|
|
79
|
-
forall_list = forall if isinstance(forall, list) else [forall]
|
|
80
|
-
|
|
81
|
-
@typechecked
|
|
82
|
-
def convert_to_element(
|
|
83
|
-
index: Union[
|
|
84
|
-
_variable.Element, Tuple[_variable.Element, Optional[_condition.Condition]]
|
|
85
|
-
]
|
|
86
|
-
) -> Tuple[_variable.Element, _condition.Condition]:
|
|
87
|
-
if isinstance(index, tuple): # Tuple[ElementType, Condition]
|
|
88
|
-
elem, cond = index
|
|
89
|
-
if cond is not None:
|
|
90
|
-
return (elem, cond)
|
|
91
|
-
else:
|
|
92
|
-
return (elem, _condition.NoneCondition())
|
|
93
|
-
else: # ElementType
|
|
94
|
-
return (index, _condition.NoneCondition())
|
|
95
|
-
|
|
96
|
-
ForallType = List[Tuple[_variable.Element, _condition.Condition]]
|
|
97
|
-
self._forall: ForallType = [convert_to_element(elem) for elem in forall_list]
|
|
98
|
-
|
|
99
|
-
# type validation
|
|
100
|
-
check_type(self.label, str)
|
|
101
|
-
check_type(self._penalty_term, _expression.Expression)
|
|
102
|
-
check_type(self._with_multiplier, bool)
|
|
103
|
-
|
|
104
|
-
@property
|
|
105
|
-
def label(self) -> str:
|
|
106
|
-
return self._label
|
|
107
|
-
|
|
108
|
-
@property
|
|
109
|
-
def name(self) -> str:
|
|
110
|
-
return self._label
|
|
111
|
-
|
|
112
|
-
@property
|
|
113
|
-
def penalty_term(self) -> _expression.Expression:
|
|
114
|
-
"""Penalty term (without multiplier)."""
|
|
115
|
-
return self._penalty_term
|
|
116
|
-
|
|
117
|
-
@property
|
|
118
|
-
def expression(self) -> _expression.Expression:
|
|
119
|
-
"""Penalty term (without multiplier)."""
|
|
120
|
-
return self._penalty_term
|
|
121
|
-
|
|
122
|
-
@property
|
|
123
|
-
def with_multiplier(self) -> bool:
|
|
124
|
-
"""Penalty term has lagrange muliplier or not."""
|
|
125
|
-
return self._with_multiplier
|
|
126
|
-
|
|
127
|
-
@property
|
|
128
|
-
def forall(self):
|
|
129
|
-
return self._forall
|
|
130
|
-
|
|
131
|
-
def children(self):
|
|
132
|
-
return [self.penalty_term]
|
|
133
|
-
|
|
134
|
-
def __repr__(self) -> str:
|
|
135
|
-
return f"Pena({self.label}: {self.penalty_term})"
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
@deprecated_kwargs(removes=["with_multiplier"])
|
|
139
|
-
def CustomPenaltyTerm(
|
|
140
|
-
name: str,
|
|
141
|
-
expression: _expression.Expression,
|
|
142
|
-
*,
|
|
143
|
-
forall: Union[
|
|
144
|
-
_variable.Element,
|
|
145
|
-
Tuple[_variable.Element, Optional[_condition.Condition]],
|
|
146
|
-
List[
|
|
147
|
-
Union[
|
|
148
|
-
_variable.Element,
|
|
149
|
-
Tuple[_variable.Element, Optional[_condition.Condition]],
|
|
150
|
-
]
|
|
151
|
-
],
|
|
152
|
-
] = [],
|
|
153
|
-
with_multiplier: typ.Optional[bool] = None,
|
|
154
|
-
) -> Penalty:
|
|
155
|
-
"""
|
|
156
|
-
Initializes a Penalty object without constraint.
|
|
157
|
-
|
|
158
|
-
Args:
|
|
159
|
-
name (str): A unique identifier for the penalty term.
|
|
160
|
-
expression (_expression.Expression): The expression representing the penalty term.
|
|
161
|
-
forall (Element | Tuple[Element, Optional[Condition]] | List[Element | Tuple[Element, Optional[Condition]]], optional): A list of elements and optional conditions that the penalty term applies to. Default is an empty list.
|
|
162
|
-
with_multiplier (typ.Optional[bool], deprecated): A flag indicating whether to use a multiplier in the penalty term. This argument is deprecated and will be removed in the next version. Default is None.
|
|
163
|
-
|
|
164
|
-
Example:
|
|
165
|
-
```python
|
|
166
|
-
import jijmodeling as jm
|
|
167
|
-
n = jm.Placeholder('n')
|
|
168
|
-
x = jm.BinaryVar('x', shape=n)
|
|
169
|
-
pe = jm.CustomPenaltyTerm('p', (x[:]-1)**2) # one-hot constraint
|
|
170
|
-
```
|
|
171
|
-
"""
|
|
172
|
-
with warnings.catch_warnings():
|
|
173
|
-
warnings.simplefilter("ignore", category=JijFutureWarning)
|
|
174
|
-
return Penalty(name, expression, forall, with_multiplier)
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
ConstraintConditionType = Union[_condition.Equal, _condition.LessThanEqual]
|
|
178
|
-
ConstraintCondTypeValue = (_condition.Equal, _condition.LessThanEqual)
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
class Constraint(metaclass=_serializable.Serializable):
|
|
182
|
-
"""Constraint of optimization model."""
|
|
183
|
-
@overload
|
|
184
|
-
def __init__(
|
|
185
|
-
self,
|
|
186
|
-
name: str,
|
|
187
|
-
expression: Union[_expression.Expression, ConstraintConditionType],
|
|
188
|
-
*,
|
|
189
|
-
forall: Union[
|
|
190
|
-
_variable.Element,
|
|
191
|
-
Tuple[_variable.Element, Optional[_condition.Condition]],
|
|
192
|
-
List[
|
|
193
|
-
Union[
|
|
194
|
-
_variable.Element,
|
|
195
|
-
Tuple[_variable.Element, Optional[_condition.Condition]],
|
|
196
|
-
]
|
|
197
|
-
],
|
|
198
|
-
] = [],
|
|
199
|
-
): ...
|
|
200
|
-
|
|
201
|
-
@deprecated_kwargs(
|
|
202
|
-
name="Constraint",
|
|
203
|
-
pos_len=2,
|
|
204
|
-
changes={"label":"name", "condition":"expression"},
|
|
205
|
-
removes=["with_penalty", "with_multiplier", "left_lower", "auto_qubo"]
|
|
206
|
-
)
|
|
207
|
-
def __init__(
|
|
208
|
-
self,
|
|
209
|
-
label: str,
|
|
210
|
-
condition: Union[_expression.Expression, ConstraintConditionType],
|
|
211
|
-
forall: Union[
|
|
212
|
-
_variable.Element,
|
|
213
|
-
Tuple[_variable.Element, Optional[_condition.Condition]],
|
|
214
|
-
List[
|
|
215
|
-
Union[
|
|
216
|
-
_variable.Element,
|
|
217
|
-
Tuple[_variable.Element, Optional[_condition.Condition]],
|
|
218
|
-
]
|
|
219
|
-
],
|
|
220
|
-
] = [],
|
|
221
|
-
with_penalty: typ.Optional[bool] = None,
|
|
222
|
-
with_multiplier: typ.Optional[bool] = None,
|
|
223
|
-
left_lower: Union[
|
|
224
|
-
_expression.NumericValue, _expression.Expression, None
|
|
225
|
-
] = None,
|
|
226
|
-
auto_qubo: Optional[bool] = None,
|
|
227
|
-
):
|
|
228
|
-
"""
|
|
229
|
-
Constraint of optimization model.
|
|
230
|
-
|
|
231
|
-
Args:
|
|
232
|
-
name (str): A unique identifier for the penalty term.
|
|
233
|
-
expression (Union[CompareCondition, Expression]): constraint condition.
|
|
234
|
-
forall (Element | Tuple[Element, Optional[Condition]] | List[Element | Tuple[Element, Optional[Condition]]], optional): A list of elements and optional conditions that the penalty term applies to. Default is an empty list.
|
|
235
|
-
with_penalty (bool, optional): Add constraints as penalty. This argument is deprecated and will be removed in the next version. Defaults to True.
|
|
236
|
-
with_multiplier (bool, optional): prod a multiplier on the penalty term. This argument is deprecated and will be removed in the next version. Defaults to True.
|
|
237
|
-
left_lower: left hand side lower value. usually used for slack variables. This argument is deprecated and will be removed in the next version. Defaults to None.
|
|
238
|
-
auto_qubo (bool, optional): auto qubo convert. This argument is deprecated and will be removed in the next version. Defaults to True.
|
|
239
|
-
|
|
240
|
-
Examples:
|
|
241
|
-
```python
|
|
242
|
-
import jijmodeling as jm
|
|
243
|
-
n = jm.Placeholder("n")
|
|
244
|
-
x = jm.BinaryVar("x", shape=(n, ))
|
|
245
|
-
term = jm.Constraint("const", x[:] == 1)
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
constraint with forall
|
|
249
|
-
|
|
250
|
-
```python
|
|
251
|
-
import jijmodeling as jm
|
|
252
|
-
d = jm.Placeholder("d", ndim=1)
|
|
253
|
-
n = d.shape[0]
|
|
254
|
-
x = jm.BinaryVar("x", shape=(n, n))
|
|
255
|
-
i = jm.Element("i", n)
|
|
256
|
-
term = jm.Constraint("const2", x[i, :] == 1, forall=(i, d[i] > 0))
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
Raises:
|
|
260
|
-
TypeError: condition is not `CompareCondition` or `Experssion`.
|
|
261
|
-
ExpressionValiddteError: right hand side has a desicision variable.
|
|
262
|
-
TypeError: `left_lower` is not `numbers.Number` or `Expression`.
|
|
263
|
-
TypeError: forall is not `Element`, `dict`, `tuple` or `list`.
|
|
264
|
-
ExpressionIndexError: The indices have not been reduced and remains. Ex: `Sum(i, x[i,j,k]) == 1, forall=[j]`, In this case "k" is needed in forall.
|
|
265
|
-
ExpressionIndexError: The conditions of indices have inconsistency.
|
|
266
|
-
"""
|
|
267
|
-
|
|
268
|
-
self._label = label
|
|
269
|
-
|
|
270
|
-
self._with_penalty = with_penalty if with_penalty is not None else True
|
|
271
|
-
self._with_multiplier = with_multiplier if with_multiplier is not None else True
|
|
272
|
-
|
|
273
|
-
# auto_qubo setting (automatically disabled if order >= 2 or term is
|
|
274
|
-
# not a Condition)
|
|
275
|
-
import jijmodeling.expression.utils as _utils
|
|
276
|
-
|
|
277
|
-
if isinstance(condition, ConstraintCondTypeValue):
|
|
278
|
-
order = max(
|
|
279
|
-
_utils.get_order(condition.left), _utils.get_order(condition.right)
|
|
280
|
-
)
|
|
281
|
-
if order >= 2 and auto_qubo is None:
|
|
282
|
-
auto_qubo = False
|
|
283
|
-
elif isinstance(condition, _expression.Expression):
|
|
284
|
-
if auto_qubo is None:
|
|
285
|
-
auto_qubo = False
|
|
286
|
-
else:
|
|
287
|
-
raise TypeError(
|
|
288
|
-
"condition of Constraint is <=, == or Expression, not {}.".format(
|
|
289
|
-
condition.__class__.__name__
|
|
290
|
-
)
|
|
291
|
-
)
|
|
292
|
-
|
|
293
|
-
self._auto_qubo: bool = auto_qubo if auto_qubo is not None else True
|
|
294
|
-
|
|
295
|
-
# convert Expression to Condition object
|
|
296
|
-
self._condition: ConstraintConditionType = (
|
|
297
|
-
condition
|
|
298
|
-
if isinstance(condition, _condition.CompareCondition)
|
|
299
|
-
else _condition.Equal(condition, _expression.Number(0))
|
|
300
|
-
)
|
|
301
|
-
|
|
302
|
-
# convert number object to Number object
|
|
303
|
-
self._left_lower: Optional[_expression.Expression] = (
|
|
304
|
-
_expression.Number(left_lower)
|
|
305
|
-
if isinstance(left_lower, (int, float))
|
|
306
|
-
else left_lower
|
|
307
|
-
)
|
|
308
|
-
|
|
309
|
-
# convert forall to list-type object
|
|
310
|
-
forall_list = forall if isinstance(forall, list) else [forall]
|
|
311
|
-
|
|
312
|
-
@typechecked
|
|
313
|
-
def convert_to_element(
|
|
314
|
-
index: Union[
|
|
315
|
-
_variable.Element, Tuple[_variable.Element, Optional[_condition.Condition]]
|
|
316
|
-
]
|
|
317
|
-
) -> Tuple[_variable.Element, _condition.Condition]:
|
|
318
|
-
if isinstance(index, tuple): # Tuple[ElementType, Condition]
|
|
319
|
-
elem, cond = index
|
|
320
|
-
if cond is not None:
|
|
321
|
-
return (elem, cond)
|
|
322
|
-
else:
|
|
323
|
-
return (elem, _condition.NoneCondition())
|
|
324
|
-
else: # ElementType
|
|
325
|
-
return (index, _condition.NoneCondition())
|
|
326
|
-
|
|
327
|
-
ForallType = List[Tuple[_variable.Element, _condition.Condition]]
|
|
328
|
-
self._forall: ForallType = [convert_to_element(elem) for elem in forall_list]
|
|
329
|
-
|
|
330
|
-
# type validation
|
|
331
|
-
LeftLowerType = Optional[_expression.Expression]
|
|
332
|
-
check_type(self.label, str)
|
|
333
|
-
check_type(self._condition, _condition.CompareCondition)
|
|
334
|
-
check_type(self._forall, ForallType)
|
|
335
|
-
check_type(self._with_penalty, bool)
|
|
336
|
-
check_type(self._with_multiplier, bool)
|
|
337
|
-
check_type(self._left_lower, LeftLowerType)
|
|
338
|
-
check_type(self._auto_qubo, bool)
|
|
339
|
-
|
|
340
|
-
import jijmodeling.expression.extract as _extract
|
|
341
|
-
|
|
342
|
-
if isinstance(self._left_lower, _expression.Expression):
|
|
343
|
-
if _extract.has_decivar(self._left_lower):
|
|
344
|
-
raise _exceptions.CannotContainDecisionVarError(
|
|
345
|
-
"You cannot include decision variables in left_lower."
|
|
346
|
-
)
|
|
347
|
-
|
|
348
|
-
# check forall index reduction
|
|
349
|
-
indices = _utils.condition_indices(self._condition)
|
|
350
|
-
forall_labels = [index[0].label for index in self._forall]
|
|
351
|
-
for index in indices:
|
|
352
|
-
if index.label not in forall_labels:
|
|
353
|
-
raise _exceptions.ExpressionIndexError(
|
|
354
|
-
"Constraint cannot have unreducted subscripts."
|
|
355
|
-
+ " Please check your formulation or"
|
|
356
|
-
+ f" use forall to reduct index '{index.label}'."
|
|
357
|
-
)
|
|
358
|
-
# condition index check
|
|
359
|
-
# Ensure there are no contradictions in the dependency between indices entering the condition
|
|
360
|
-
# For example, [(i, i < j), j] is fine because j is processed in the outer loop,
|
|
361
|
-
# but [j, (i, i < j)] is not good because j is processed in the inner loop.
|
|
362
|
-
for i, (_, cond) in enumerate(self._forall):
|
|
363
|
-
if isinstance(cond, _condition.NoneCondition):
|
|
364
|
-
continue
|
|
365
|
-
cond_indices = _utils.condition_indices(cond)
|
|
366
|
-
for ind in cond_indices:
|
|
367
|
-
# but [j, (i, i < j)] is not good because j is processed in the inner loop.
|
|
368
|
-
if not (ind.label in forall_labels[: i + 1]):
|
|
369
|
-
raise _exceptions.ExpressionIndexError(
|
|
370
|
-
"Check the conditions you are including in forall. There is a discrepancy in the subscript dependency."
|
|
371
|
-
)
|
|
372
|
-
|
|
373
|
-
@property
|
|
374
|
-
def label(self) -> str:
|
|
375
|
-
return self._label
|
|
376
|
-
|
|
377
|
-
@property
|
|
378
|
-
def name(self) -> str:
|
|
379
|
-
return self._label
|
|
380
|
-
|
|
381
|
-
@property
|
|
382
|
-
def condition(self) -> ConstraintConditionType:
|
|
383
|
-
return self._condition
|
|
384
|
-
|
|
385
|
-
@property
|
|
386
|
-
def expression(self) -> ConstraintConditionType:
|
|
387
|
-
return self._condition
|
|
388
|
-
|
|
389
|
-
@property
|
|
390
|
-
def term(
|
|
391
|
-
self,
|
|
392
|
-
) -> Union[_condition.Equal, _condition.LessThanEqual, _condition.LessThan]:
|
|
393
|
-
return self.condition
|
|
394
|
-
|
|
395
|
-
@property
|
|
396
|
-
def with_penalty(self) -> bool:
|
|
397
|
-
return self._with_penalty
|
|
398
|
-
|
|
399
|
-
@property
|
|
400
|
-
def with_multiplier(self) -> bool:
|
|
401
|
-
return self._with_multiplier
|
|
402
|
-
|
|
403
|
-
@property
|
|
404
|
-
def forall(self) -> List[Tuple[_variable.Element, _condition.Condition]]:
|
|
405
|
-
return self._forall
|
|
406
|
-
|
|
407
|
-
@property
|
|
408
|
-
def left_lower(self) -> Optional[_expression.Expression]:
|
|
409
|
-
return self._left_lower
|
|
410
|
-
|
|
411
|
-
@property
|
|
412
|
-
def auto_qubo(self):
|
|
413
|
-
return self._auto_qubo
|
|
414
|
-
|
|
415
|
-
def _forall_to_sum(self, expression):
|
|
416
|
-
indices = self.forall[::-1]
|
|
417
|
-
if indices is None:
|
|
418
|
-
return expression
|
|
419
|
-
term = expression
|
|
420
|
-
for i, index in enumerate(indices):
|
|
421
|
-
if index is None:
|
|
422
|
-
return expression
|
|
423
|
-
cond = indices[i][1]
|
|
424
|
-
term = _sum.sum((index[0], cond), term)
|
|
425
|
-
return term
|
|
426
|
-
|
|
427
|
-
def __repr__(self):
|
|
428
|
-
return "Cons(" + self.label + ")[" + str(self.condition) + "]"
|