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.

Files changed (234) hide show
  1. jijmodeling/__init__.py +1 -154
  2. jijmodeling/__init__.pyi +5152 -0
  3. jijmodeling/_jijmodeling.cp39-win_amd64.pyd +0 -0
  4. jijmodeling/dataset.py +5 -0
  5. jijmodeling/dataset.pyi +106 -0
  6. jijmodeling/experimental.py +13 -0
  7. jijmodeling/experimental.pyi +302 -0
  8. jijmodeling/py.typed +0 -0
  9. jijmodeling/range/__init__.py +14 -0
  10. jijmodeling/range/__init__.pyi +56 -0
  11. jijmodeling/range/size.py +14 -0
  12. jijmodeling/range/size.pyi +54 -0
  13. jijmodeling/range/value.py +14 -0
  14. jijmodeling/range/value.pyi +54 -0
  15. jijmodeling-1.12.0.dist-info/METADATA +235 -0
  16. jijmodeling-1.12.0.dist-info/RECORD +18 -0
  17. {jijmodeling-0.13.2.dist-info → jijmodeling-1.12.0.dist-info}/WHEEL +1 -2
  18. {jijmodeling-0.13.2.dist-info → jijmodeling-1.12.0.dist-info/licenses}/LICENSE.txt +1 -1
  19. jijmodeling/__pycache__/__init__.cpython-39.opt-1.pyc +0 -0
  20. jijmodeling/__pycache__/__init__.cpython-39.pyc +0 -0
  21. jijmodeling/__pycache__/_version.cpython-39.opt-1.pyc +0 -0
  22. jijmodeling/__pycache__/_version.cpython-39.pyc +0 -0
  23. jijmodeling/_version.py +0 -4
  24. jijmodeling/deprecation/__init__.py +0 -11
  25. jijmodeling/deprecation/__pycache__/__init__.cpython-39.opt-1.pyc +0 -0
  26. jijmodeling/deprecation/__pycache__/__init__.cpython-39.pyc +0 -0
  27. jijmodeling/deprecation/__pycache__/deprecation.cpython-39.opt-1.pyc +0 -0
  28. jijmodeling/deprecation/__pycache__/deprecation.cpython-39.pyc +0 -0
  29. jijmodeling/deprecation/deprecation.py +0 -108
  30. jijmodeling/exceptions/__init__.py +0 -26
  31. jijmodeling/exceptions/__pycache__/__init__.cpython-39.opt-1.pyc +0 -0
  32. jijmodeling/exceptions/__pycache__/__init__.cpython-39.pyc +0 -0
  33. jijmodeling/exceptions/__pycache__/exceptions.cpython-39.opt-1.pyc +0 -0
  34. jijmodeling/exceptions/__pycache__/exceptions.cpython-39.pyc +0 -0
  35. jijmodeling/exceptions/exceptions.py +0 -37
  36. jijmodeling/expression/__init__.py +0 -76
  37. jijmodeling/expression/__pycache__/__init__.cpython-39.opt-1.pyc +0 -0
  38. jijmodeling/expression/__pycache__/__init__.cpython-39.pyc +0 -0
  39. jijmodeling/expression/__pycache__/condition.cpython-39.opt-1.pyc +0 -0
  40. jijmodeling/expression/__pycache__/condition.cpython-39.pyc +0 -0
  41. jijmodeling/expression/__pycache__/constraint.cpython-39.opt-1.pyc +0 -0
  42. jijmodeling/expression/__pycache__/constraint.cpython-39.pyc +0 -0
  43. jijmodeling/expression/__pycache__/expression.cpython-39.opt-1.pyc +0 -0
  44. jijmodeling/expression/__pycache__/expression.cpython-39.pyc +0 -0
  45. jijmodeling/expression/__pycache__/extract.cpython-39.opt-1.pyc +0 -0
  46. jijmodeling/expression/__pycache__/extract.cpython-39.pyc +0 -0
  47. jijmodeling/expression/__pycache__/from_old_serializable.cpython-39.opt-1.pyc +0 -0
  48. jijmodeling/expression/__pycache__/from_old_serializable.cpython-39.pyc +0 -0
  49. jijmodeling/expression/__pycache__/mathfunc.cpython-39.opt-1.pyc +0 -0
  50. jijmodeling/expression/__pycache__/mathfunc.cpython-39.pyc +0 -0
  51. jijmodeling/expression/__pycache__/prod.cpython-39.opt-1.pyc +0 -0
  52. jijmodeling/expression/__pycache__/prod.cpython-39.pyc +0 -0
  53. jijmodeling/expression/__pycache__/serializable.cpython-39.opt-1.pyc +0 -0
  54. jijmodeling/expression/__pycache__/serializable.cpython-39.pyc +0 -0
  55. jijmodeling/expression/__pycache__/sum.cpython-39.opt-1.pyc +0 -0
  56. jijmodeling/expression/__pycache__/sum.cpython-39.pyc +0 -0
  57. jijmodeling/expression/__pycache__/type_annotations.cpython-39.opt-1.pyc +0 -0
  58. jijmodeling/expression/__pycache__/type_annotations.cpython-39.pyc +0 -0
  59. jijmodeling/expression/__pycache__/utils.cpython-39.opt-1.pyc +0 -0
  60. jijmodeling/expression/__pycache__/utils.cpython-39.pyc +0 -0
  61. jijmodeling/expression/condition.py +0 -378
  62. jijmodeling/expression/constraint.py +0 -428
  63. jijmodeling/expression/expression.py +0 -768
  64. jijmodeling/expression/extract.py +0 -186
  65. jijmodeling/expression/from_old_serializable.py +0 -137
  66. jijmodeling/expression/mathfunc.py +0 -335
  67. jijmodeling/expression/prod.py +0 -172
  68. jijmodeling/expression/serializable.py +0 -142
  69. jijmodeling/expression/sum.py +0 -261
  70. jijmodeling/expression/type_annotations.py +0 -50
  71. jijmodeling/expression/utils.py +0 -202
  72. jijmodeling/expression/variables/__init__.py +0 -39
  73. jijmodeling/expression/variables/__pycache__/__init__.cpython-39.opt-1.pyc +0 -0
  74. jijmodeling/expression/variables/__pycache__/__init__.cpython-39.pyc +0 -0
  75. jijmodeling/expression/variables/__pycache__/deci_vars.cpython-39.opt-1.pyc +0 -0
  76. jijmodeling/expression/variables/__pycache__/deci_vars.cpython-39.pyc +0 -0
  77. jijmodeling/expression/variables/__pycache__/jagged_array.cpython-39.opt-1.pyc +0 -0
  78. jijmodeling/expression/variables/__pycache__/jagged_array.cpython-39.pyc +0 -0
  79. jijmodeling/expression/variables/__pycache__/placeholders.cpython-39.opt-1.pyc +0 -0
  80. jijmodeling/expression/variables/__pycache__/placeholders.cpython-39.pyc +0 -0
  81. jijmodeling/expression/variables/__pycache__/variable.cpython-39.opt-1.pyc +0 -0
  82. jijmodeling/expression/variables/__pycache__/variable.cpython-39.pyc +0 -0
  83. jijmodeling/expression/variables/deci_vars.py +0 -212
  84. jijmodeling/expression/variables/jagged_array.py +0 -81
  85. jijmodeling/expression/variables/placeholders.py +0 -132
  86. jijmodeling/expression/variables/variable.py +0 -524
  87. jijmodeling/latex_repr/__init__.py +0 -11
  88. jijmodeling/latex_repr/__pycache__/__init__.cpython-39.opt-1.pyc +0 -0
  89. jijmodeling/latex_repr/__pycache__/__init__.cpython-39.pyc +0 -0
  90. jijmodeling/latex_repr/__pycache__/latex_repr.cpython-39.opt-1.pyc +0 -0
  91. jijmodeling/latex_repr/__pycache__/latex_repr.cpython-39.pyc +0 -0
  92. jijmodeling/latex_repr/__pycache__/problem_latex_repr.cpython-39.opt-1.pyc +0 -0
  93. jijmodeling/latex_repr/__pycache__/problem_latex_repr.cpython-39.pyc +0 -0
  94. jijmodeling/latex_repr/latex_repr.py +0 -243
  95. jijmodeling/latex_repr/problem_latex_repr.py +0 -210
  96. jijmodeling/marker/__marker__.cp39-win_amd64.pyd +0 -0
  97. jijmodeling/match/__init__.py +0 -19
  98. jijmodeling/match/__pycache__/__init__.cpython-39.opt-1.pyc +0 -0
  99. jijmodeling/match/__pycache__/__init__.cpython-39.pyc +0 -0
  100. jijmodeling/match/__pycache__/condition_same.cpython-39.opt-1.pyc +0 -0
  101. jijmodeling/match/__pycache__/condition_same.cpython-39.pyc +0 -0
  102. jijmodeling/match/__pycache__/constraint_same.cpython-39.opt-1.pyc +0 -0
  103. jijmodeling/match/__pycache__/constraint_same.cpython-39.pyc +0 -0
  104. jijmodeling/match/__pycache__/expand.cpython-39.opt-1.pyc +0 -0
  105. jijmodeling/match/__pycache__/expand.cpython-39.pyc +0 -0
  106. jijmodeling/match/__pycache__/expr_same.cpython-39.opt-1.pyc +0 -0
  107. jijmodeling/match/__pycache__/expr_same.cpython-39.pyc +0 -0
  108. jijmodeling/match/__pycache__/is_same_expr.cpython-39.opt-1.pyc +0 -0
  109. jijmodeling/match/__pycache__/is_same_expr.cpython-39.pyc +0 -0
  110. jijmodeling/match/__pycache__/penalty_same.cpython-39.opt-1.pyc +0 -0
  111. jijmodeling/match/__pycache__/penalty_same.cpython-39.pyc +0 -0
  112. jijmodeling/match/__pycache__/problem_same.cpython-39.opt-1.pyc +0 -0
  113. jijmodeling/match/__pycache__/problem_same.cpython-39.pyc +0 -0
  114. jijmodeling/match/__pycache__/replace.cpython-39.opt-1.pyc +0 -0
  115. jijmodeling/match/__pycache__/replace.cpython-39.pyc +0 -0
  116. jijmodeling/match/condition_same.py +0 -44
  117. jijmodeling/match/constraint_same.py +0 -53
  118. jijmodeling/match/expand.py +0 -84
  119. jijmodeling/match/expr_same.py +0 -32
  120. jijmodeling/match/is_same_expr.py +0 -306
  121. jijmodeling/match/penalty_same.py +0 -31
  122. jijmodeling/match/problem_same.py +0 -44
  123. jijmodeling/match/replace.py +0 -249
  124. jijmodeling/problem/__init__.py +0 -9
  125. jijmodeling/problem/__pycache__/__init__.cpython-39.opt-1.pyc +0 -0
  126. jijmodeling/problem/__pycache__/__init__.cpython-39.pyc +0 -0
  127. jijmodeling/problem/__pycache__/problem.cpython-39.opt-1.pyc +0 -0
  128. jijmodeling/problem/__pycache__/problem.cpython-39.pyc +0 -0
  129. jijmodeling/problem/problem.py +0 -186
  130. jijmodeling/protobuf/__init__.py +0 -8
  131. jijmodeling/protobuf/__pycache__/__init__.cpython-39.opt-1.pyc +0 -0
  132. jijmodeling/protobuf/__pycache__/__init__.cpython-39.pyc +0 -0
  133. jijmodeling/protobuf/__pycache__/from_protobuf.cpython-39.opt-1.pyc +0 -0
  134. jijmodeling/protobuf/__pycache__/from_protobuf.cpython-39.pyc +0 -0
  135. jijmodeling/protobuf/__pycache__/to_protobuf.cpython-39.opt-1.pyc +0 -0
  136. jijmodeling/protobuf/__pycache__/to_protobuf.cpython-39.pyc +0 -0
  137. jijmodeling/protobuf/__pycache__/type_annotations.cpython-39.opt-1.pyc +0 -0
  138. jijmodeling/protobuf/__pycache__/type_annotations.cpython-39.pyc +0 -0
  139. jijmodeling/protobuf/from_protobuf.py +0 -336
  140. jijmodeling/protobuf/pb2/__init__.py +0 -42
  141. jijmodeling/protobuf/pb2/__pycache__/__init__.cpython-39.opt-1.pyc +0 -0
  142. jijmodeling/protobuf/pb2/__pycache__/__init__.cpython-39.pyc +0 -0
  143. jijmodeling/protobuf/pb2/__pycache__/array_length_pb2.cpython-39.opt-1.pyc +0 -0
  144. jijmodeling/protobuf/pb2/__pycache__/array_length_pb2.cpython-39.pyc +0 -0
  145. jijmodeling/protobuf/pb2/__pycache__/binary_op_pb2.cpython-39.opt-1.pyc +0 -0
  146. jijmodeling/protobuf/pb2/__pycache__/binary_op_pb2.cpython-39.pyc +0 -0
  147. jijmodeling/protobuf/pb2/__pycache__/commutative_op_pb2.cpython-39.opt-1.pyc +0 -0
  148. jijmodeling/protobuf/pb2/__pycache__/commutative_op_pb2.cpython-39.pyc +0 -0
  149. jijmodeling/protobuf/pb2/__pycache__/constraint_pb2.cpython-39.opt-1.pyc +0 -0
  150. jijmodeling/protobuf/pb2/__pycache__/constraint_pb2.cpython-39.pyc +0 -0
  151. jijmodeling/protobuf/pb2/__pycache__/custom_penalty_term_pb2.cpython-39.opt-1.pyc +0 -0
  152. jijmodeling/protobuf/pb2/__pycache__/custom_penalty_term_pb2.cpython-39.pyc +0 -0
  153. jijmodeling/protobuf/pb2/__pycache__/decision_var_pb2.cpython-39.opt-1.pyc +0 -0
  154. jijmodeling/protobuf/pb2/__pycache__/decision_var_pb2.cpython-39.pyc +0 -0
  155. jijmodeling/protobuf/pb2/__pycache__/element_pb2.cpython-39.opt-1.pyc +0 -0
  156. jijmodeling/protobuf/pb2/__pycache__/element_pb2.cpython-39.pyc +0 -0
  157. jijmodeling/protobuf/pb2/__pycache__/expression_pb2.cpython-39.opt-1.pyc +0 -0
  158. jijmodeling/protobuf/pb2/__pycache__/expression_pb2.cpython-39.pyc +0 -0
  159. jijmodeling/protobuf/pb2/__pycache__/forall_pb2.cpython-39.opt-1.pyc +0 -0
  160. jijmodeling/protobuf/pb2/__pycache__/forall_pb2.cpython-39.pyc +0 -0
  161. jijmodeling/protobuf/pb2/__pycache__/header_pb2.cpython-39.opt-1.pyc +0 -0
  162. jijmodeling/protobuf/pb2/__pycache__/header_pb2.cpython-39.pyc +0 -0
  163. jijmodeling/protobuf/pb2/__pycache__/index_pb2.cpython-39.opt-1.pyc +0 -0
  164. jijmodeling/protobuf/pb2/__pycache__/index_pb2.cpython-39.pyc +0 -0
  165. jijmodeling/protobuf/pb2/__pycache__/number_lit_pb2.cpython-39.opt-1.pyc +0 -0
  166. jijmodeling/protobuf/pb2/__pycache__/number_lit_pb2.cpython-39.pyc +0 -0
  167. jijmodeling/protobuf/pb2/__pycache__/placeholder_pb2.cpython-39.opt-1.pyc +0 -0
  168. jijmodeling/protobuf/pb2/__pycache__/placeholder_pb2.cpython-39.pyc +0 -0
  169. jijmodeling/protobuf/pb2/__pycache__/problem_pb2.cpython-39.opt-1.pyc +0 -0
  170. jijmodeling/protobuf/pb2/__pycache__/problem_pb2.cpython-39.pyc +0 -0
  171. jijmodeling/protobuf/pb2/__pycache__/reduction_op_pb2.cpython-39.opt-1.pyc +0 -0
  172. jijmodeling/protobuf/pb2/__pycache__/reduction_op_pb2.cpython-39.pyc +0 -0
  173. jijmodeling/protobuf/pb2/__pycache__/subscript_pb2.cpython-39.opt-1.pyc +0 -0
  174. jijmodeling/protobuf/pb2/__pycache__/subscript_pb2.cpython-39.pyc +0 -0
  175. jijmodeling/protobuf/pb2/__pycache__/unary_op_pb2.cpython-39.opt-1.pyc +0 -0
  176. jijmodeling/protobuf/pb2/__pycache__/unary_op_pb2.cpython-39.pyc +0 -0
  177. jijmodeling/protobuf/pb2/array_length_pb2.py +0 -27
  178. jijmodeling/protobuf/pb2/binary_op_pb2.py +0 -27
  179. jijmodeling/protobuf/pb2/commutative_op_pb2.py +0 -27
  180. jijmodeling/protobuf/pb2/constraint_pb2.py +0 -31
  181. jijmodeling/protobuf/pb2/custom_penalty_term_pb2.py +0 -31
  182. jijmodeling/protobuf/pb2/decision_var_pb2.py +0 -31
  183. jijmodeling/protobuf/pb2/element_pb2.py +0 -31
  184. jijmodeling/protobuf/pb2/expression_pb2.py +0 -39
  185. jijmodeling/protobuf/pb2/forall_pb2.py +0 -29
  186. jijmodeling/protobuf/pb2/header_pb2.py +0 -31
  187. jijmodeling/protobuf/pb2/index_pb2.py +0 -25
  188. jijmodeling/protobuf/pb2/number_lit_pb2.py +0 -27
  189. jijmodeling/protobuf/pb2/placeholder_pb2.py +0 -25
  190. jijmodeling/protobuf/pb2/problem_pb2.py +0 -40
  191. jijmodeling/protobuf/pb2/reduction_op_pb2.py +0 -30
  192. jijmodeling/protobuf/pb2/subscript_pb2.py +0 -27
  193. jijmodeling/protobuf/pb2/unary_op_pb2.py +0 -27
  194. jijmodeling/protobuf/to_protobuf.py +0 -631
  195. jijmodeling/protobuf/type_annotations.py +0 -52
  196. jijmodeling/sampleset/__init__.py +0 -33
  197. jijmodeling/sampleset/__pycache__/__init__.cpython-39.opt-1.pyc +0 -0
  198. jijmodeling/sampleset/__pycache__/__init__.cpython-39.pyc +0 -0
  199. jijmodeling/sampleset/__pycache__/evaluation.cpython-39.opt-1.pyc +0 -0
  200. jijmodeling/sampleset/__pycache__/evaluation.cpython-39.pyc +0 -0
  201. jijmodeling/sampleset/__pycache__/measuring_time.cpython-39.opt-1.pyc +0 -0
  202. jijmodeling/sampleset/__pycache__/measuring_time.cpython-39.pyc +0 -0
  203. jijmodeling/sampleset/__pycache__/record.cpython-39.opt-1.pyc +0 -0
  204. jijmodeling/sampleset/__pycache__/record.cpython-39.pyc +0 -0
  205. jijmodeling/sampleset/__pycache__/sampleset.cpython-39.opt-1.pyc +0 -0
  206. jijmodeling/sampleset/__pycache__/sampleset.cpython-39.pyc +0 -0
  207. jijmodeling/sampleset/__pycache__/solving_time.cpython-39.opt-1.pyc +0 -0
  208. jijmodeling/sampleset/__pycache__/solving_time.cpython-39.pyc +0 -0
  209. jijmodeling/sampleset/__pycache__/system_time.cpython-39.opt-1.pyc +0 -0
  210. jijmodeling/sampleset/__pycache__/system_time.cpython-39.pyc +0 -0
  211. jijmodeling/sampleset/evaluation.py +0 -289
  212. jijmodeling/sampleset/measuring_time.py +0 -59
  213. jijmodeling/sampleset/record.py +0 -158
  214. jijmodeling/sampleset/sampleset.py +0 -389
  215. jijmodeling/sampleset/solving_time.py +0 -38
  216. jijmodeling/sampleset/system_time.py +0 -48
  217. jijmodeling/type_annotations/__init__.py +0 -44
  218. jijmodeling/type_annotations/__pycache__/__init__.cpython-39.opt-1.pyc +0 -0
  219. jijmodeling/type_annotations/__pycache__/__init__.cpython-39.pyc +0 -0
  220. jijmodeling/type_annotations/__pycache__/type_annotations.cpython-39.opt-1.pyc +0 -0
  221. jijmodeling/type_annotations/__pycache__/type_annotations.cpython-39.pyc +0 -0
  222. jijmodeling/type_annotations/type_annotations.py +0 -54
  223. jijmodeling/utils/__init__.py +0 -28
  224. jijmodeling/utils/__pycache__/__init__.cpython-39.opt-1.pyc +0 -0
  225. jijmodeling/utils/__pycache__/__init__.cpython-39.pyc +0 -0
  226. jijmodeling/utils/__pycache__/deprecated.cpython-39.opt-1.pyc +0 -0
  227. jijmodeling/utils/__pycache__/deprecated.cpython-39.pyc +0 -0
  228. jijmodeling/utils/__pycache__/utils.cpython-39.opt-1.pyc +0 -0
  229. jijmodeling/utils/__pycache__/utils.cpython-39.pyc +0 -0
  230. jijmodeling/utils/deprecated.py +0 -17
  231. jijmodeling/utils/utils.py +0 -146
  232. jijmodeling-0.13.2.dist-info/METADATA +0 -60
  233. jijmodeling-0.13.2.dist-info/RECORD +0 -219
  234. jijmodeling-0.13.2.dist-info/top_level.txt +0 -1
@@ -1,202 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import itertools as it
4
- import typing as tp
5
-
6
- import typeguard as _typeguard
7
-
8
- import jijmodeling.exceptions.exceptions as _exceptions
9
- import jijmodeling.expression.condition as _condition
10
- import jijmodeling.expression.expression as _expression
11
- import jijmodeling.expression.extract as _extract
12
- import jijmodeling.expression.sum as _sum
13
- import jijmodeling.expression.variables.deci_vars as _deci_vars
14
- import jijmodeling.expression.variables.variable as _variable
15
-
16
- T = tp.TypeVar("T")
17
-
18
-
19
- def type_check_bool(value, cls) -> bool:
20
- try:
21
- _typeguard.check_type(value, cls)
22
- # NOTE: typeguard >= 3.0.0 raises typeguard.TypeCheckError instead of TypeError
23
- except _typeguard.TypeCheckError:
24
- return False
25
- else:
26
- return True
27
-
28
-
29
- def extract_nodes(tree: _expression.Expression, cls: tp.Type[T]) -> tp.List[T]:
30
- """
31
- Extract specified class object from Expression tree.
32
-
33
- Args:
34
- tree (Expression): Target expression tree.
35
- cls (Type): Target class.
36
-
37
- Returns:
38
- List: `cls` object list are included in `tree`.
39
-
40
- Examples:
41
- ```python
42
- import jijmodeling as jm
43
- d = jm.Placheolder("d", dim=1)
44
- n = d.shape[0]
45
- x = jm.Binary("x", shape=(n, ))
46
- i = jm.Element("i", n)
47
- term = jm.Sum(i, d[i]*x[i])
48
- jm.extract_nodes(term, jm.DecisionVariable)
49
- # [x]
50
- ```
51
- """
52
- if type_check_bool(tree, cls):
53
- nodes = [tree]
54
- else:
55
- nodes = []
56
- for child in tree.children():
57
- nodes = nodes + extract_nodes(child, cls) # type: ignore
58
- return nodes # type: ignore
59
-
60
-
61
- def get_order(expression: _expression.Expression) -> int:
62
- """
63
- Get an order of polynomial.
64
-
65
- For example, x_i * y_i + x_i -> 2 if x and y is a decision variable.
66
-
67
- Args:
68
- expression (Expression): expression
69
-
70
- Returns:
71
- int: Integer
72
- """
73
- if isinstance(expression, _deci_vars.DecisionVariable):
74
- return 1
75
- if isinstance(expression, _variable.Subscripts):
76
- if isinstance(expression.variable, _deci_vars.DecisionVariable):
77
- return 1
78
- else:
79
- return 0
80
- if isinstance(expression, (_expression.Add, _expression.Div)):
81
- child_order = [get_order(child) for child in expression.children()]
82
- return max(child_order)
83
- if isinstance(expression, _expression.Mul):
84
- child_order = [get_order(child) for child in expression.children()]
85
- return sum(child_order)
86
- if isinstance(expression, _expression.Power):
87
- base_order = get_order(expression.left)
88
- if base_order > 0:
89
- if isinstance(expression.right, _expression.Number):
90
- return base_order * int(expression.right.value)
91
- else:
92
- raise _exceptions.ModelingError("exponent should be number.")
93
- if isinstance(expression, _sum.SumOperator):
94
- return get_order(expression.operand)
95
- else:
96
- return 0
97
-
98
-
99
- def expression_indices(
100
- expression: _expression.Expression,
101
- ) -> tp.List[_variable.Element]:
102
- """
103
- Extract all indices from the expression.
104
-
105
- Args:
106
- expression (Expression): expression
107
-
108
- Returns:
109
- List[Element]:
110
- """
111
- # TODO: implement expression_indices for each expression?
112
- indices: tp.List[_variable.Element]
113
- if isinstance(expression, _variable.Element):
114
- set_indices: tp.List[_variable.Element] = []
115
- for child in expression.children():
116
- set_indices = set_indices + expression_indices(child)
117
- indices = [expression] + set_indices
118
- elif isinstance(expression, _expression.Number):
119
- indices = []
120
- elif isinstance(expression, _variable.Variable):
121
- indices = []
122
- elif isinstance(expression, _variable.Subscripts):
123
- indices = []
124
- for subs in expression.subscripts:
125
- indices = indices + expression_indices(subs)
126
- elif isinstance(expression, _expression.Expression):
127
- indices = []
128
- for child in expression.children():
129
- if child is not None:
130
- indices = indices + expression_indices(child)
131
- else:
132
- raise TypeError(f"expression is Expression, not {type(expression)}")
133
-
134
- # check duplicated element
135
- el_label = []
136
- if isinstance(expression, _sum.ReductionOperator):
137
- el_label = [expression.sum_index.label]
138
-
139
- unique_indices: tp.List[_variable.Element] = []
140
- for index in indices:
141
- if index.label not in el_label:
142
- el_label.append(index.label)
143
- unique_indices.append(index)
144
- return unique_indices
145
-
146
-
147
- def condition_indices(condition: _condition.Condition) -> tp.List[_variable.Element]:
148
- if isinstance(condition, _condition.CompareCondition):
149
- left_indices = expression_indices(condition.left)
150
- right_indices = expression_indices(condition.right)
151
- return left_indices + right_indices
152
- elif isinstance(condition, _condition.ConditionOperator):
153
- left_indices = condition_indices(condition.left)
154
- right_indices = condition_indices(condition.right)
155
- return left_indices + right_indices
156
- else:
157
- return []
158
-
159
-
160
- def check_non_decision_variable(
161
- exp_list: tp.Iterable[_expression.Expression], error_msg: str
162
- ):
163
- """
164
- Check if list has decision variable or not.
165
-
166
- Args:
167
- exp_list (Iterable[Expression]): target iterator.
168
- error_msg (str): error message.
169
-
170
- Raises:
171
- CannotContainDecisionVarError: if list has decision variable.
172
- """
173
- for e in exp_list:
174
- variables = _extract.extract_variables(e)
175
- for v in variables:
176
- if isinstance(v, _deci_vars.DecisionVariable):
177
- raise _exceptions.CannotContainDecisionVarError(error_msg)
178
-
179
-
180
- def flatten_binary_operator(
181
- expression: _expression.Expression,
182
- op_type: tp.Type[_expression.BinaryOperator] = _expression.Add,
183
- ) -> tp.List[_expression.Expression]:
184
- """
185
- Flatten `op_type` binary operator to list.
186
- This function flattens a given node to the following:
187
- node1 <> node2 <> node3 <> ... <> nodeN -> [node1, node2, node3, ..., nodeN]
188
- where <> is a specified binary operator by `op_type`.
189
-
190
- Args:
191
- expression (Expression): target expression.
192
- op_type (Type[BinaryOperator]): target binary operator.
193
-
194
- Returns:
195
- List[Expression]: list of expression. Each element is not binary operator.
196
- """
197
- if isinstance(expression, op_type):
198
- left = flatten_binary_operator(expression.left, op_type)
199
- right = flatten_binary_operator(expression.right, op_type)
200
- return list(it.chain.from_iterable([left, right]))
201
- else:
202
- return [expression]
@@ -1,39 +0,0 @@
1
- from pkgutil import extend_path
2
-
3
- __path__ = extend_path(__path__, __name__)
4
-
5
- import jijmodeling.expression.variables.deci_vars as deci_vars
6
- import jijmodeling.expression.variables.jagged_array as jagged_array
7
- import jijmodeling.expression.variables.placeholders as placeholders
8
- import jijmodeling.expression.variables.variable as variable
9
-
10
- from jijmodeling.expression.variables.deci_vars import (
11
- Binary,
12
- BinaryVar,
13
- DecisionVariable,
14
- Integer,
15
- IntegerVar,
16
- LogEncInteger,
17
- )
18
- from jijmodeling.expression.variables.jagged_array import JaggedArray
19
- from jijmodeling.expression.variables.placeholders import ArrayShape, Placeholder
20
- from jijmodeling.expression.variables.variable import Element, Subscripts, Variable
21
-
22
- __all__ = [
23
- "deci_vars",
24
- "jagged_array",
25
- "placeholders",
26
- "variable",
27
- "Variable",
28
- "Subscripts",
29
- "Element",
30
- "Placeholder",
31
- "ArrayShape",
32
- "JaggedArray",
33
- "DecisionVariable",
34
- "Binary",
35
- "BinaryVar",
36
- "LogEncInteger",
37
- "Integer",
38
- "IntegerVar",
39
- ]
@@ -1,212 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import warnings
4
-
5
- from typing import List, Optional, Tuple, Union
6
-
7
- from jijmodeling.deprecation.deprecation import (
8
- deprecated_kwargs,
9
- deprecated_name,
10
- JijFutureWarning
11
- )
12
- import jijmodeling.exceptions.exceptions as _exceptions
13
- import jijmodeling.expression.expression as _expression
14
- import jijmodeling.expression.type_annotations as _type_annotations
15
- import jijmodeling.expression.variables.variable as _variable
16
-
17
-
18
- class DecisionVariable(_variable.Variable):
19
- def __init__(
20
- self,
21
- label: str,
22
- shape: Union[
23
- List[_type_annotations.ShapeElemInputType],
24
- Tuple[_type_annotations.ShapeElemInputType, ...],
25
- _type_annotations.ShapeElemInputType,
26
- ],
27
- uuid: Optional[str] = None,
28
- ):
29
- if "[" in label or "]" in label:
30
- raise _exceptions.ModelingError(
31
- "The label of decision variable cannot contain '[' or ']'."
32
- )
33
- super().__init__(label, shape, uuid) # type: ignore
34
-
35
-
36
- class Binary(DecisionVariable):
37
- """Binary decision variable 0 or 1.
38
-
39
- Example:
40
- ```python
41
- import jijmodeling as jm
42
- n = jm.Placeholder("n")
43
- x = jm.Binary("x", shape=(n,))
44
- # scalar variable
45
- y = jm.Binary("y")
46
- ```
47
- """
48
-
49
- @deprecated_name("Binary", "BinaryVar", kind="class")
50
- def __init__(
51
- self,
52
- label: str,
53
- shape=(),
54
- uuid: Optional[str] = None,
55
- ):
56
- super().__init__(label, shape, uuid)
57
-
58
- @property
59
- def label(self) -> str:
60
- return self._label
61
-
62
- @property
63
- def dim(self) -> int:
64
- return len(self.shape)
65
-
66
-
67
- @deprecated_kwargs(removes=["uuid"])
68
- def BinaryVar(
69
- name: str,
70
- *,
71
- shape=(),
72
- uuid: Optional[str] = None,
73
- ) -> Binary:
74
- """Binary decision variable 0 or 1.
75
-
76
- Example:
77
- ```python
78
- import jijmodeling as jm
79
- n = jm.Placeholder("n")
80
- x = jm.BinaryVar("x", shape=(n,))
81
- # scalar variable
82
- y = jm.BinaryVar("y")
83
- ```
84
- """
85
- with warnings.catch_warnings():
86
- warnings.simplefilter("ignore", category=JijFutureWarning)
87
- return Binary(name, shape, uuid)
88
-
89
-
90
- class Integer(DecisionVariable):
91
- """Integer decision variable."""
92
-
93
- prefix = "_leint_"
94
-
95
- @deprecated_name("Integer", "IntegerVar", kind="class")
96
- def __init__(
97
- self,
98
- label: str,
99
- lower: Union[_expression.Expression, int, float],
100
- upper: Union[_expression.Expression, int, float],
101
- shape: Union[
102
- List[_type_annotations.ShapeElemInputType],
103
- Tuple[_type_annotations.ShapeElemInputType, ...],
104
- _type_annotations.ShapeElemInputType,
105
- ] = (),
106
- uuid: Optional[str] = None,
107
- ):
108
- super().__init__(label, shape, uuid)
109
-
110
- if isinstance(lower, (int, float)):
111
- self._lower: _expression.Expression = _expression.Number(lower)
112
- else:
113
- self._lower = lower
114
- if isinstance(upper, (int, float)):
115
- self._upper: _expression.Expression = _expression.Number(upper)
116
- else:
117
- self._upper = upper
118
-
119
- # check if self._lower is operatable or self._lower.shape equals to
120
- # self.shape
121
- from jijmodeling.match.expr_same import expr_same
122
-
123
- def has_equal_shape(shape1, shape2):
124
- if len(shape1) != len(shape2):
125
- return False
126
- else:
127
- return all(
128
- map(
129
- lambda x: expr_same(x[0], x[1], check_id=False),
130
- zip(list(shape1), list(shape2)),
131
- )
132
- )
133
-
134
- if not (
135
- self._lower.is_operatable()
136
- or has_equal_shape(self._lower.shape, self.shape)
137
- ): # type: ignore
138
- raise _exceptions.ModelingError(
139
- "self._lower must be operatable or self._lower.shape must be equal to self.shape"
140
- )
141
-
142
- if not (
143
- self._upper.is_operatable()
144
- or has_equal_shape(self._upper.shape, self.shape)
145
- ): # type: ignore
146
- raise _exceptions.ModelingError(
147
- "self._upper must be operatable or self._upper.shape must be equal to self.shape"
148
- )
149
-
150
- import jijmodeling.expression.utils as _utils
151
-
152
- _utils.check_non_decision_variable(
153
- [self.lower, self.upper],
154
- f"The lower and upper of '{self.label}' cannot contain decision variable.",
155
- )
156
-
157
- @property
158
- def label(self) -> str:
159
- return self._label
160
-
161
- @property
162
- def dim(self) -> int:
163
- return super().dim
164
-
165
- @property
166
- def lower(self) -> _expression.Expression:
167
- return self._lower
168
-
169
- @property
170
- def lower_bound(self) -> _expression.Expression:
171
- return self._lower
172
-
173
- @property
174
- def upper(self):
175
- return self._upper
176
-
177
- @property
178
- def upper_bound(self) -> _expression.Expression:
179
- return self._upper
180
-
181
- def children(self) -> List[_expression.Expression]:
182
- children = super().children() + [self.lower, self.upper]
183
- return children
184
-
185
-
186
- @deprecated_kwargs(removes=["uuid"])
187
- def IntegerVar(
188
- name: str,
189
- *,
190
- lower_bound: Union[_expression.Expression, int, float],
191
- upper_bound: Union[_expression.Expression, int, float],
192
- shape: Union[
193
- List[_type_annotations.ShapeElemInputType],
194
- Tuple[_type_annotations.ShapeElemInputType, ...],
195
- _type_annotations.ShapeElemInputType,
196
- ] = (),
197
- uuid: Optional[str] = None,
198
- ) -> Integer:
199
- with warnings.catch_warnings():
200
- warnings.simplefilter("ignore", category=JijFutureWarning)
201
- return Integer(name, lower_bound, upper_bound, shape, uuid)
202
-
203
-
204
- def LogEncInteger(*args, **kwargs) -> Integer:
205
- """
206
- This constructor method is deprecated.
207
-
208
- Returns:
209
- Integer: Integer object.
210
- """
211
- warnings.warn("LogEncInteger is deprecated. Please use jijmodeling.Integer.")
212
- return Integer(*args, **kwargs)
@@ -1,81 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from typing import Optional, Tuple
4
- import warnings
5
-
6
- from jijmodeling.deprecation.deprecation import (
7
- deprecated_name,
8
- JijFutureWarning
9
- )
10
- import jijmodeling.exceptions.exceptions as _exceptions
11
- import jijmodeling.expression.type_annotations as _type_annotations
12
- import jijmodeling.expression.variables.placeholders as _placeholders
13
-
14
-
15
- class JaggedArray(_placeholders.Placeholder):
16
- """
17
- Jagged array: A data structure in which each element in a two-dimensional.
18
-
19
- array has a different length in a one-dimensional array. The internal
20
- length of the data is different, so `shape` is not defined. Only `shape[0]`
21
- can be accessed directly in `.shape`.
22
-
23
- A jagged array is an array with the following data structure, for example
24
-
25
- ```python
26
- [[1, 2, 3],
27
- [3, 2, 4, 5],
28
- [0, 1]]
29
- ```
30
-
31
- The Placeholder class can handle multi-dimensional arrays that can be defined with shape, but it cannot handle a jagged arrays.
32
- Therefore, we need to use this class instead.
33
- """
34
-
35
- @deprecated_name("JaggedArray", kind="class")
36
- def __init__(
37
- self,
38
- label: str,
39
- dim: int,
40
- uuid: Optional[str] = None,
41
- ):
42
- """
43
- Args:
44
- label (str): label of variable
45
- dim (int): dimension of jagged array. Because of the jagged array data structure, `shape` cannot be specified in the constructor.
46
- uuid (Optional[str], optional): uuid. Defaults to None.
47
-
48
- Raises:
49
- ModelingError: The jagged array can currently only handle up to two dimensions. This limitation will be resolved in an update.
50
- """
51
-
52
- if dim > 5:
53
- raise _exceptions.ModelingError(
54
- "JaggedArray must be set to 5-dim or less, not {}.".format(dim)
55
- )
56
-
57
- self._dim = dim
58
- with warnings.catch_warnings():
59
- warnings.simplefilter("ignore", category=JijFutureWarning)
60
- super().__init__(label, dim, uuid=uuid)
61
-
62
- @property
63
- def dim(self) -> int:
64
- return self._dim
65
-
66
- @property
67
- def shape(self) -> Tuple[_type_annotations.ShapeElementType]:
68
- """
69
- Shape cannot be defined in the jagged array.
70
-
71
- Only the length can be
72
- defined, so only the `.shape[0]` corresponding to the length is returned.
73
-
74
- Returns:
75
- Tuple[Expression]: (length, )
76
- """
77
- return (super().shape[0],)
78
-
79
- @property
80
- def length(self) -> _type_annotations.ShapeElementType:
81
- return self.shape[0]
@@ -1,132 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import typing as tp
4
- import warnings
5
-
6
- from typeguard import check_type
7
-
8
- from jijmodeling.deprecation.deprecation import (
9
- deprecated_kwargs,
10
- JijFutureWarning
11
- )
12
- import jijmodeling.expression.expression as _expression
13
- import jijmodeling.expression.variables.variable as _variable
14
-
15
-
16
- class Placeholder(_variable.Variable):
17
- """
18
- Placeholder variable.
19
-
20
- Variables for pouring in data when converting to QUBO or to MIP.
21
- When using the Placeholder class,
22
- you can specify the specific value to be placed in the Placeholder
23
- by using the `ph_value` argument of methods such as `.to_pyqubo` and `.to_lp` of the Problem class.
24
- If you want to handle array data that cannot be defined with shape (called jagged array), you can use the `JaggedArray` class.
25
-
26
- Example:
27
- ```python
28
- import jijmodeling as jm
29
- d = jm.Placeholder("d", ndim=2)
30
- d.ndim
31
- # 2
32
- ```
33
- """
34
- @tp.overload
35
- def __init__(
36
- self,
37
- name: str,
38
- *,
39
- ndim: tp.Optional[int] = None,
40
- ): ...
41
-
42
- @deprecated_kwargs(
43
- name="Placeholder",
44
- pos_len=1,
45
- changes={"label":"name", "dim":"ndim"},
46
- removes=["shape", "uuid"],
47
- )
48
- def __init__(
49
- self,
50
- label: str,
51
- dim: tp.Optional[int] = None,
52
- shape=None,
53
- uuid: tp.Optional[str] = None,
54
- ):
55
- if shape is not None:
56
- _shape = shape
57
- elif shape is None and dim is not None:
58
- _shape = tuple(None for _ in range(dim))
59
- else:
60
- _shape = []
61
- super().__init__(label, shape=_shape, uuid=uuid)
62
-
63
- @property
64
- def label(self) -> str:
65
- return self._label
66
-
67
- @property
68
- def dim(self) -> int:
69
- return len(self.shape)
70
-
71
-
72
- class ArrayShape(Placeholder):
73
- """
74
- Shape of variable.
75
-
76
- Example:
77
- ```python
78
- import jijmodeling as jm
79
- d = jm.Placeholder("d", dim=1)
80
- n = d.shape[0]
81
- print(type(n))
82
- # <class 'ArrayShape'>
83
- ```
84
- """
85
-
86
- def __init__(
87
- self,
88
- array: tp.Union[_variable.Variable, _variable.Subscripts],
89
- dimension: int,
90
- uuid: tp.Optional[str] = None,
91
- ):
92
- """
93
- Basically, a user does not call the constuctor directly; an object of.
94
-
95
- this class is created instead when shape value of a variable is None.
96
-
97
- Args:
98
- array (Variable): parent array
99
- dimension (int): dimension is corresponded this object.
100
- """
101
- self._array = array
102
- self._dimension = dimension
103
-
104
- # type and value validation
105
- ArrayType = tp.Union[_variable.Variable, _variable.Subscripts]
106
- check_type(self._array, ArrayType)
107
- check_type(self._dimension, int)
108
-
109
- with warnings.catch_warnings():
110
- warnings.simplefilter("ignore", category=JijFutureWarning)
111
- super().__init__(str(self._array) + "_shape_%d" % dimension, uuid=uuid)
112
-
113
- @property
114
- def array(self):
115
- return self._array
116
-
117
- @property
118
- def array_dim(self):
119
- return self.array.dim
120
-
121
- @property
122
- def dimension(self):
123
- return self._dimension
124
-
125
- def is_operatable(self) -> bool:
126
- return True
127
-
128
- def children(self) -> tp.List[_expression.Expression]:
129
- return [self.array]
130
-
131
- def __hash__(self) -> int:
132
- return hash(self.label)