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.

Files changed (234) hide show
  1. jijmodeling/__init__.py +1 -154
  2. jijmodeling/__init__.pyi +5152 -0
  3. jijmodeling/_jijmodeling.cp310-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-310.opt-1.pyc +0 -0
  20. jijmodeling/__pycache__/__init__.cpython-310.pyc +0 -0
  21. jijmodeling/__pycache__/_version.cpython-310.opt-1.pyc +0 -0
  22. jijmodeling/__pycache__/_version.cpython-310.pyc +0 -0
  23. jijmodeling/_version.py +0 -4
  24. jijmodeling/deprecation/__init__.py +0 -11
  25. jijmodeling/deprecation/__pycache__/__init__.cpython-310.opt-1.pyc +0 -0
  26. jijmodeling/deprecation/__pycache__/__init__.cpython-310.pyc +0 -0
  27. jijmodeling/deprecation/__pycache__/deprecation.cpython-310.opt-1.pyc +0 -0
  28. jijmodeling/deprecation/__pycache__/deprecation.cpython-310.pyc +0 -0
  29. jijmodeling/deprecation/deprecation.py +0 -108
  30. jijmodeling/exceptions/__init__.py +0 -26
  31. jijmodeling/exceptions/__pycache__/__init__.cpython-310.opt-1.pyc +0 -0
  32. jijmodeling/exceptions/__pycache__/__init__.cpython-310.pyc +0 -0
  33. jijmodeling/exceptions/__pycache__/exceptions.cpython-310.opt-1.pyc +0 -0
  34. jijmodeling/exceptions/__pycache__/exceptions.cpython-310.pyc +0 -0
  35. jijmodeling/exceptions/exceptions.py +0 -37
  36. jijmodeling/expression/__init__.py +0 -76
  37. jijmodeling/expression/__pycache__/__init__.cpython-310.opt-1.pyc +0 -0
  38. jijmodeling/expression/__pycache__/__init__.cpython-310.pyc +0 -0
  39. jijmodeling/expression/__pycache__/condition.cpython-310.opt-1.pyc +0 -0
  40. jijmodeling/expression/__pycache__/condition.cpython-310.pyc +0 -0
  41. jijmodeling/expression/__pycache__/constraint.cpython-310.opt-1.pyc +0 -0
  42. jijmodeling/expression/__pycache__/constraint.cpython-310.pyc +0 -0
  43. jijmodeling/expression/__pycache__/expression.cpython-310.opt-1.pyc +0 -0
  44. jijmodeling/expression/__pycache__/expression.cpython-310.pyc +0 -0
  45. jijmodeling/expression/__pycache__/extract.cpython-310.opt-1.pyc +0 -0
  46. jijmodeling/expression/__pycache__/extract.cpython-310.pyc +0 -0
  47. jijmodeling/expression/__pycache__/from_old_serializable.cpython-310.opt-1.pyc +0 -0
  48. jijmodeling/expression/__pycache__/from_old_serializable.cpython-310.pyc +0 -0
  49. jijmodeling/expression/__pycache__/mathfunc.cpython-310.opt-1.pyc +0 -0
  50. jijmodeling/expression/__pycache__/mathfunc.cpython-310.pyc +0 -0
  51. jijmodeling/expression/__pycache__/prod.cpython-310.opt-1.pyc +0 -0
  52. jijmodeling/expression/__pycache__/prod.cpython-310.pyc +0 -0
  53. jijmodeling/expression/__pycache__/serializable.cpython-310.opt-1.pyc +0 -0
  54. jijmodeling/expression/__pycache__/serializable.cpython-310.pyc +0 -0
  55. jijmodeling/expression/__pycache__/sum.cpython-310.opt-1.pyc +0 -0
  56. jijmodeling/expression/__pycache__/sum.cpython-310.pyc +0 -0
  57. jijmodeling/expression/__pycache__/type_annotations.cpython-310.opt-1.pyc +0 -0
  58. jijmodeling/expression/__pycache__/type_annotations.cpython-310.pyc +0 -0
  59. jijmodeling/expression/__pycache__/utils.cpython-310.opt-1.pyc +0 -0
  60. jijmodeling/expression/__pycache__/utils.cpython-310.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-310.opt-1.pyc +0 -0
  74. jijmodeling/expression/variables/__pycache__/__init__.cpython-310.pyc +0 -0
  75. jijmodeling/expression/variables/__pycache__/deci_vars.cpython-310.opt-1.pyc +0 -0
  76. jijmodeling/expression/variables/__pycache__/deci_vars.cpython-310.pyc +0 -0
  77. jijmodeling/expression/variables/__pycache__/jagged_array.cpython-310.opt-1.pyc +0 -0
  78. jijmodeling/expression/variables/__pycache__/jagged_array.cpython-310.pyc +0 -0
  79. jijmodeling/expression/variables/__pycache__/placeholders.cpython-310.opt-1.pyc +0 -0
  80. jijmodeling/expression/variables/__pycache__/placeholders.cpython-310.pyc +0 -0
  81. jijmodeling/expression/variables/__pycache__/variable.cpython-310.opt-1.pyc +0 -0
  82. jijmodeling/expression/variables/__pycache__/variable.cpython-310.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-310.opt-1.pyc +0 -0
  89. jijmodeling/latex_repr/__pycache__/__init__.cpython-310.pyc +0 -0
  90. jijmodeling/latex_repr/__pycache__/latex_repr.cpython-310.opt-1.pyc +0 -0
  91. jijmodeling/latex_repr/__pycache__/latex_repr.cpython-310.pyc +0 -0
  92. jijmodeling/latex_repr/__pycache__/problem_latex_repr.cpython-310.opt-1.pyc +0 -0
  93. jijmodeling/latex_repr/__pycache__/problem_latex_repr.cpython-310.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__.cp310-win_amd64.pyd +0 -0
  97. jijmodeling/match/__init__.py +0 -19
  98. jijmodeling/match/__pycache__/__init__.cpython-310.opt-1.pyc +0 -0
  99. jijmodeling/match/__pycache__/__init__.cpython-310.pyc +0 -0
  100. jijmodeling/match/__pycache__/condition_same.cpython-310.opt-1.pyc +0 -0
  101. jijmodeling/match/__pycache__/condition_same.cpython-310.pyc +0 -0
  102. jijmodeling/match/__pycache__/constraint_same.cpython-310.opt-1.pyc +0 -0
  103. jijmodeling/match/__pycache__/constraint_same.cpython-310.pyc +0 -0
  104. jijmodeling/match/__pycache__/expand.cpython-310.opt-1.pyc +0 -0
  105. jijmodeling/match/__pycache__/expand.cpython-310.pyc +0 -0
  106. jijmodeling/match/__pycache__/expr_same.cpython-310.opt-1.pyc +0 -0
  107. jijmodeling/match/__pycache__/expr_same.cpython-310.pyc +0 -0
  108. jijmodeling/match/__pycache__/is_same_expr.cpython-310.opt-1.pyc +0 -0
  109. jijmodeling/match/__pycache__/is_same_expr.cpython-310.pyc +0 -0
  110. jijmodeling/match/__pycache__/penalty_same.cpython-310.opt-1.pyc +0 -0
  111. jijmodeling/match/__pycache__/penalty_same.cpython-310.pyc +0 -0
  112. jijmodeling/match/__pycache__/problem_same.cpython-310.opt-1.pyc +0 -0
  113. jijmodeling/match/__pycache__/problem_same.cpython-310.pyc +0 -0
  114. jijmodeling/match/__pycache__/replace.cpython-310.opt-1.pyc +0 -0
  115. jijmodeling/match/__pycache__/replace.cpython-310.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-310.opt-1.pyc +0 -0
  126. jijmodeling/problem/__pycache__/__init__.cpython-310.pyc +0 -0
  127. jijmodeling/problem/__pycache__/problem.cpython-310.opt-1.pyc +0 -0
  128. jijmodeling/problem/__pycache__/problem.cpython-310.pyc +0 -0
  129. jijmodeling/problem/problem.py +0 -186
  130. jijmodeling/protobuf/__init__.py +0 -8
  131. jijmodeling/protobuf/__pycache__/__init__.cpython-310.opt-1.pyc +0 -0
  132. jijmodeling/protobuf/__pycache__/__init__.cpython-310.pyc +0 -0
  133. jijmodeling/protobuf/__pycache__/from_protobuf.cpython-310.opt-1.pyc +0 -0
  134. jijmodeling/protobuf/__pycache__/from_protobuf.cpython-310.pyc +0 -0
  135. jijmodeling/protobuf/__pycache__/to_protobuf.cpython-310.opt-1.pyc +0 -0
  136. jijmodeling/protobuf/__pycache__/to_protobuf.cpython-310.pyc +0 -0
  137. jijmodeling/protobuf/__pycache__/type_annotations.cpython-310.opt-1.pyc +0 -0
  138. jijmodeling/protobuf/__pycache__/type_annotations.cpython-310.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-310.opt-1.pyc +0 -0
  142. jijmodeling/protobuf/pb2/__pycache__/__init__.cpython-310.pyc +0 -0
  143. jijmodeling/protobuf/pb2/__pycache__/array_length_pb2.cpython-310.opt-1.pyc +0 -0
  144. jijmodeling/protobuf/pb2/__pycache__/array_length_pb2.cpython-310.pyc +0 -0
  145. jijmodeling/protobuf/pb2/__pycache__/binary_op_pb2.cpython-310.opt-1.pyc +0 -0
  146. jijmodeling/protobuf/pb2/__pycache__/binary_op_pb2.cpython-310.pyc +0 -0
  147. jijmodeling/protobuf/pb2/__pycache__/commutative_op_pb2.cpython-310.opt-1.pyc +0 -0
  148. jijmodeling/protobuf/pb2/__pycache__/commutative_op_pb2.cpython-310.pyc +0 -0
  149. jijmodeling/protobuf/pb2/__pycache__/constraint_pb2.cpython-310.opt-1.pyc +0 -0
  150. jijmodeling/protobuf/pb2/__pycache__/constraint_pb2.cpython-310.pyc +0 -0
  151. jijmodeling/protobuf/pb2/__pycache__/custom_penalty_term_pb2.cpython-310.opt-1.pyc +0 -0
  152. jijmodeling/protobuf/pb2/__pycache__/custom_penalty_term_pb2.cpython-310.pyc +0 -0
  153. jijmodeling/protobuf/pb2/__pycache__/decision_var_pb2.cpython-310.opt-1.pyc +0 -0
  154. jijmodeling/protobuf/pb2/__pycache__/decision_var_pb2.cpython-310.pyc +0 -0
  155. jijmodeling/protobuf/pb2/__pycache__/element_pb2.cpython-310.opt-1.pyc +0 -0
  156. jijmodeling/protobuf/pb2/__pycache__/element_pb2.cpython-310.pyc +0 -0
  157. jijmodeling/protobuf/pb2/__pycache__/expression_pb2.cpython-310.opt-1.pyc +0 -0
  158. jijmodeling/protobuf/pb2/__pycache__/expression_pb2.cpython-310.pyc +0 -0
  159. jijmodeling/protobuf/pb2/__pycache__/forall_pb2.cpython-310.opt-1.pyc +0 -0
  160. jijmodeling/protobuf/pb2/__pycache__/forall_pb2.cpython-310.pyc +0 -0
  161. jijmodeling/protobuf/pb2/__pycache__/header_pb2.cpython-310.opt-1.pyc +0 -0
  162. jijmodeling/protobuf/pb2/__pycache__/header_pb2.cpython-310.pyc +0 -0
  163. jijmodeling/protobuf/pb2/__pycache__/index_pb2.cpython-310.opt-1.pyc +0 -0
  164. jijmodeling/protobuf/pb2/__pycache__/index_pb2.cpython-310.pyc +0 -0
  165. jijmodeling/protobuf/pb2/__pycache__/number_lit_pb2.cpython-310.opt-1.pyc +0 -0
  166. jijmodeling/protobuf/pb2/__pycache__/number_lit_pb2.cpython-310.pyc +0 -0
  167. jijmodeling/protobuf/pb2/__pycache__/placeholder_pb2.cpython-310.opt-1.pyc +0 -0
  168. jijmodeling/protobuf/pb2/__pycache__/placeholder_pb2.cpython-310.pyc +0 -0
  169. jijmodeling/protobuf/pb2/__pycache__/problem_pb2.cpython-310.opt-1.pyc +0 -0
  170. jijmodeling/protobuf/pb2/__pycache__/problem_pb2.cpython-310.pyc +0 -0
  171. jijmodeling/protobuf/pb2/__pycache__/reduction_op_pb2.cpython-310.opt-1.pyc +0 -0
  172. jijmodeling/protobuf/pb2/__pycache__/reduction_op_pb2.cpython-310.pyc +0 -0
  173. jijmodeling/protobuf/pb2/__pycache__/subscript_pb2.cpython-310.opt-1.pyc +0 -0
  174. jijmodeling/protobuf/pb2/__pycache__/subscript_pb2.cpython-310.pyc +0 -0
  175. jijmodeling/protobuf/pb2/__pycache__/unary_op_pb2.cpython-310.opt-1.pyc +0 -0
  176. jijmodeling/protobuf/pb2/__pycache__/unary_op_pb2.cpython-310.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-310.opt-1.pyc +0 -0
  198. jijmodeling/sampleset/__pycache__/__init__.cpython-310.pyc +0 -0
  199. jijmodeling/sampleset/__pycache__/evaluation.cpython-310.opt-1.pyc +0 -0
  200. jijmodeling/sampleset/__pycache__/evaluation.cpython-310.pyc +0 -0
  201. jijmodeling/sampleset/__pycache__/measuring_time.cpython-310.opt-1.pyc +0 -0
  202. jijmodeling/sampleset/__pycache__/measuring_time.cpython-310.pyc +0 -0
  203. jijmodeling/sampleset/__pycache__/record.cpython-310.opt-1.pyc +0 -0
  204. jijmodeling/sampleset/__pycache__/record.cpython-310.pyc +0 -0
  205. jijmodeling/sampleset/__pycache__/sampleset.cpython-310.opt-1.pyc +0 -0
  206. jijmodeling/sampleset/__pycache__/sampleset.cpython-310.pyc +0 -0
  207. jijmodeling/sampleset/__pycache__/solving_time.cpython-310.opt-1.pyc +0 -0
  208. jijmodeling/sampleset/__pycache__/solving_time.cpython-310.pyc +0 -0
  209. jijmodeling/sampleset/__pycache__/system_time.cpython-310.opt-1.pyc +0 -0
  210. jijmodeling/sampleset/__pycache__/system_time.cpython-310.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-310.opt-1.pyc +0 -0
  219. jijmodeling/type_annotations/__pycache__/__init__.cpython-310.pyc +0 -0
  220. jijmodeling/type_annotations/__pycache__/type_annotations.cpython-310.opt-1.pyc +0 -0
  221. jijmodeling/type_annotations/__pycache__/type_annotations.cpython-310.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-310.opt-1.pyc +0 -0
  225. jijmodeling/utils/__pycache__/__init__.cpython-310.pyc +0 -0
  226. jijmodeling/utils/__pycache__/deprecated.cpython-310.opt-1.pyc +0 -0
  227. jijmodeling/utils/__pycache__/deprecated.cpython-310.pyc +0 -0
  228. jijmodeling/utils/__pycache__/utils.cpython-310.opt-1.pyc +0 -0
  229. jijmodeling/utils/__pycache__/utils.cpython-310.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,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)