jijmodeling 0.13.2__cp39-cp39-win_amd64.whl → 1.11.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.11.0.dist-info/METADATA +235 -0
  16. jijmodeling-1.11.0.dist-info/RECORD +18 -0
  17. {jijmodeling-0.13.2.dist-info → jijmodeling-1.11.0.dist-info}/WHEEL +1 -2
  18. {jijmodeling-0.13.2.dist-info → jijmodeling-1.11.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,249 +0,0 @@
1
- import typing as tp
2
-
3
- from functools import singledispatch
4
-
5
- import jijmodeling as jm
6
- import jijmodeling.expression.condition as jc
7
-
8
- from jijmodeling.expression.extract import extract_expressions
9
- from jijmodeling.match.expr_same import expr_same
10
-
11
-
12
- def replace(
13
- expr: jm.Expression, target: jm.Expression, source: jm.Expression, check_id: bool
14
- ) -> jm.Expression:
15
- """
16
- replace expression (from `target` element to `source` one)
17
- This function selects the target element from the expression and recursively replaces it with the source element.
18
-
19
- Args:
20
- expr (jm.Expression): expression
21
- target (jm.Expression): target sub tree
22
- source (jm.Expression): new sub tree
23
- check_id (bool): replace only if the uuid is the same
24
-
25
- Returns:
26
- jm.Expression: replaced sub tree
27
-
28
- Examples:
29
- ```python
30
- import jijmodeling as jm
31
- n = jm.Placeholder("n")
32
- i = jm.Element("i", n)
33
- x = jm.Binary("x", shape=(n, n))
34
- x_i = x[i]
35
- expr = jm.Sum(i, x_i)
36
- u = jm.Integer("u", shape=(n,), lower=0, upper=10)
37
- k = jm.Placeholder("k")
38
- j = jm.Element("j", k)
39
- y = jm.Placeholder("y", shape=(n, k))
40
- replaced = replace(expr, x_i, jm.Sum(j, u[i]*y[i,j]), check_id=True)
41
- print(replaced)
42
- Sum_{i=0}^{n}(Sum_{j=0}^{k}(u[i]*y[i,j]))
43
- ```
44
-
45
- ```python
46
- import jijmodeling as jm
47
- n = jm.Placeholder("n")
48
- i = jm.Element("i", n)
49
- x = jm.Binary("x", shape=(n, n))
50
- expr = jm.Sum(i, x[i])
51
- u = jm.Integer("u", shape=(n,), lower=0, upper=10)
52
- k = jm.Placeholder("k")
53
- j = jm.Element("j", k)
54
- y = jm.Placeholder("y", shape=(n, k))
55
- replaced = replace(expr, x[i], jm.Sum(j, u[i]*y[i,j]), check_id=False) # check_id=False にすると、uuidが異なっていても置換できる
56
- print(replaced)
57
- Sum_{i=0}^{n}(Sum_{j=0}^{k}(u[i]*y[i,j]))
58
- ```
59
- """
60
- if expr_same(expr, target, check_id):
61
- return source
62
-
63
- return _replace(expr, target, source, check_id)
64
-
65
-
66
- def replace_if(
67
- expr: jm.Expression,
68
- replace_func: tp.Callable[[jm.Expression], tp.Optional[jm.Expression]],
69
- ):
70
- """recursively replace expression if `replace_func` returns `jm.Expression` object. Otherwise, the expression is not replaced.
71
- This function does the following process only once:
72
- 1. extract all the expressions that satisfies `replace_func`
73
- 2. replace the expression with the result of `replace_func`
74
-
75
- Args:
76
- expr (jm.Expression): expression
77
- replace_func (tp.Callable[[jm.Expression], tp.Optional[jm.Expression]]): `jm.Expression` object is given and `jm.Expression` object is returned if the expression is replaced.
78
-
79
- Returns:
80
- jm.Expression: replaced expression
81
- """
82
- # list all expression to be replaced
83
- replaced_expr = expr
84
- is_replaced = lambda expr: replace_func(expr) is not None
85
- replace_candidates = extract_expressions(replaced_expr, is_replaced)
86
- new_replaced_expr = replaced_expr
87
- for candidate in replace_candidates:
88
- new_replaced_expr = replace(
89
- new_replaced_expr,
90
- candidate,
91
- tp.cast(jm.Expression, replace_func(candidate)),
92
- check_id=False,
93
- )
94
-
95
- return new_replaced_expr
96
-
97
-
98
- @singledispatch
99
- def _replace(
100
- expr: jm.Expression, target: jm.Expression, source: jm.Expression, check_id: bool
101
- ) -> jm.Expression:
102
- raise TypeError(f"{type(expr)} is not supported in `replace`.")
103
-
104
-
105
- # List all the types that are inherited from `jm.Expression` and register them to `_replace` function.
106
- @_replace.register
107
- def _(
108
- expr: jm.ArrayShape, target: jm.Expression, source: jm.Expression, check_id: bool
109
- ) -> jm.Expression:
110
- if expr_same(expr, target, check_id):
111
- return source
112
- if isinstance(source, (jm.Variable, jm.Subscripts)) and expr_same(
113
- expr.array, target, check_id
114
- ):
115
- return source.shape[expr.dim]
116
- return expr
117
-
118
-
119
- @_replace.register
120
- def _(
121
- expr: jm.expression.Number,
122
- target: jm.Expression,
123
- source: jm.Expression,
124
- check_id: bool,
125
- ) -> jm.Expression:
126
- if expr_same(expr, target, check_id):
127
- return source
128
- return expr
129
-
130
-
131
- @_replace.register
132
- def _(
133
- expr: jm.expression.BinaryOperator,
134
- target: jm.Expression,
135
- source: jm.Expression,
136
- check_id: bool,
137
- ) -> jm.Expression:
138
- if expr_same(expr, target, check_id):
139
- return source
140
-
141
- cls = type(expr)
142
- replaced_left = _replace(expr.left, target, source, check_id)
143
- replaced_right = _replace(expr.right, target, source, check_id)
144
- return cls(replaced_left, replaced_right)
145
-
146
-
147
- @_replace.register
148
- def _(
149
- expr: jm.expression.UnaryOperator,
150
- target: jm.Expression,
151
- source: jm.Expression,
152
- check_id: bool,
153
- ) -> jm.Expression:
154
- if expr_same(expr, target, check_id):
155
- return source
156
-
157
- cls = type(expr)
158
- replaced = _replace(expr, target, source, check_id)
159
- return cls(replaced)
160
-
161
-
162
- @_replace.register
163
- def _(
164
- expr: jm.expression.sum.ReductionOperator,
165
- target: jm.Expression,
166
- source: jm.Expression,
167
- check_id: bool,
168
- ) -> jm.Expression:
169
- if expr_same(expr, target, check_id):
170
- return source
171
-
172
- replaced_sum_index = tp.cast(
173
- jm.Element, _replace(expr.sum_index, target, source, check_id)
174
- )
175
- replaced_operand = _replace(expr.operand, target, source, check_id)
176
- replaced_condition = _replace_condition(expr.condition, target, source, check_id)
177
- cls = type(expr)
178
- return cls(replaced_sum_index, replaced_operand, replaced_condition)
179
-
180
-
181
- @_replace.register
182
- def _(
183
- expr: jm.Variable, target: jm.Expression, source: jm.Expression, check_id: bool
184
- ) -> jm.Expression:
185
- if expr_same(expr, target, check_id):
186
- return source
187
- return expr
188
-
189
-
190
- @_replace.register
191
- def _(
192
- expr: jm.Subscripts, target: jm.Expression, source: jm.Expression, check_id: bool
193
- ) -> jm.Expression:
194
- if expr_same(expr, target, check_id):
195
- return source
196
- replaced_variable = tp.cast(
197
- jm.Variable, _replace(expr.variable, target, source, check_id)
198
- )
199
- replaced_subscripts = [
200
- _replace(s, target, source, check_id) for s in expr.subscripts
201
- ]
202
- cls = type(expr)
203
- return cls(replaced_variable, replaced_subscripts)
204
-
205
-
206
- @singledispatch
207
- def _replace_condition(
208
- condition: jc.Condition,
209
- target: jm.Expression,
210
- source: jm.Expression,
211
- check_id: bool,
212
- ) -> jc.Condition:
213
- raise TypeError(f"{type(condition)} is not supported in `replace`.")
214
-
215
-
216
- @_replace_condition.register
217
- def _(
218
- condition: jc.NoneCondition,
219
- target: jm.Expression,
220
- source: jm.Expression,
221
- check_id: bool,
222
- ) -> jc.Condition:
223
- return condition
224
-
225
-
226
- @_replace_condition.register
227
- def _(
228
- condition: jc.CompareCondition,
229
- target: jm.Expression,
230
- source: jm.Expression,
231
- check_id: bool,
232
- ) -> jc.Condition:
233
- replaced_left = _replace(condition.left, target, source, check_id)
234
- replaced_right = _replace(condition.right, target, source, check_id)
235
- cls = type(condition)
236
- return cls(replaced_left, replaced_right)
237
-
238
-
239
- @_replace_condition.register
240
- def _(
241
- condition: jc.ConditionOperator,
242
- target: jm.Expression,
243
- source: jm.Expression,
244
- check_id: bool,
245
- ) -> jc.Condition:
246
- replaced_left = _replace_condition(condition.left, target, source, check_id)
247
- replaced_right = _replace_condition(condition.right, target, source, check_id)
248
- cls = type(condition)
249
- return cls(replaced_left, replaced_right)
@@ -1,9 +0,0 @@
1
- from pkgutil import extend_path
2
-
3
- __path__ = extend_path(__path__, __name__)
4
-
5
- import jijmodeling.problem.problem as problem
6
-
7
- from jijmodeling.problem.problem import Problem, ProblemSense
8
-
9
- __all__ = ["problem", "ProblemSense", "Problem"]
@@ -1,186 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import copy as _copy
4
- import enum as _enum
5
- import typing as tp
6
-
7
- import typeguard as _typeguard
8
-
9
- from jijmodeling.deprecation.deprecation import deprecated_kwargs
10
- import jijmodeling.exceptions.exceptions as _exceptions
11
- import jijmodeling.expression.constraint as _constraint
12
- import jijmodeling.expression.expression as _expression
13
- import jijmodeling.expression.serializable as _serializable
14
- import jijmodeling.expression.utils as _utils
15
-
16
-
17
- class ProblemSense(_enum.Enum):
18
- """Problem sense.
19
-
20
- Attributes:
21
- MINIMUM (str): minimize problem.
22
- MAXIMUM (str): maximize problem.
23
- """
24
-
25
- MINIMUM = "MINIMUM"
26
- MAXIMUM = "MAXIMUM"
27
-
28
-
29
- class Problem(metaclass=_serializable.Serializable):
30
- """
31
- Optimization problem.
32
-
33
- Attributes:
34
- name (str): name of problem.
35
- model (Optional[Expression]): total optimization model.
36
- constraints (Dict[str, Constraint]): constraint objects of problem.
37
- penalties (Dict[str, Constraint]): penalty objects of problem.
38
- cost (Expression): cost term of problem. Defaults zero.
39
- """
40
- @tp.overload
41
- def __init__(
42
- self,
43
- name: str,
44
- *,
45
- sense: tp.Union[ProblemSense, str] = ProblemSense.MINIMUM,
46
- ) -> None: ...
47
-
48
- @deprecated_kwargs(
49
- name="Problem",
50
- pos_len=1,
51
- removes=["objective", "constraints", "penalties"]
52
- )
53
- def __init__(
54
- self,
55
- name: str,
56
- sense: tp.Union[ProblemSense, str] = ProblemSense.MINIMUM,
57
- objective: _expression.Expression = _expression.Number(0),
58
- constraints: tp.Dict[str, _constraint.Constraint] = {},
59
- penalties: tp.Dict[str, _constraint.Penalty] = {},
60
- ) -> None:
61
- """
62
- Initialize
63
-
64
- Args:
65
- name (str): problem name
66
- sense (ProblemKind): problem kind Minimum or Maximum
67
- objective (Expression): objective
68
- constraints (Dict[str, Constraint]): dict of constraints
69
- penalties (Dict[str, Penalty]): dict of penalties
70
- """
71
- self._name = name
72
- self._sense = ProblemSense(sense)
73
- # deepcopy to avoid having the same reference
74
- self._objective = _copy.deepcopy(objective)
75
- self._constraints: tp.Dict[str, _constraint.Constraint] = _copy.deepcopy(
76
- constraints
77
- )
78
- self._penalties: tp.Dict[str, _constraint.Penalty] = _copy.deepcopy(penalties)
79
-
80
- _typeguard.check_type(self._name, str)
81
- _typeguard.check_type(self._sense, ProblemSense)
82
- _typeguard.check_type(self._constraints, tp.Dict[str, _constraint.Constraint])
83
- _typeguard.check_type(self._penalties, tp.Dict[str, _constraint.Penalty])
84
-
85
- @property
86
- def name(self) -> str:
87
- return self._name
88
-
89
- @property
90
- def sense(self) -> ProblemSense:
91
- return self._sense
92
-
93
- @property
94
- def objective(self) -> _expression.Expression:
95
- return self._objective
96
-
97
- @property
98
- def constraints(self) -> tp.Dict[str, _constraint.Constraint]:
99
- return self._constraints
100
-
101
- @property
102
- def penalties(self) -> tp.Dict[str, _constraint.Penalty]:
103
- return self._penalties
104
-
105
- @property
106
- def custom_penalty_terms(self) -> tp.Dict[str, _constraint.Penalty]:
107
- return self._penalties
108
-
109
- def add(
110
- self,
111
- other: tp.Union[
112
- _expression.Expression, _constraint.Constraint, _constraint.Penalty
113
- ],
114
- ):
115
- """
116
- Add expression, constraint or penalty to problem.
117
-
118
- Args:
119
- other (Expression): expression
120
-
121
- Examples:
122
- ```python
123
- import jijmodeling as jm
124
- d = jm.Placeholder("d", dim=1)
125
- n = d.shape[0]
126
- i = jm.Element("i", n)
127
- x = jm.Binary("x", shape=(n,))
128
- problem = jm.Problem("sample")
129
- problem.add(x[:]) # add cost
130
- problem.add(jm.Constraint("onehot", x[:] == 1)) # add constraint
131
- problem.add(jm.Penalty("penalty", x[0] + x[2])) # add penalty
132
- problem += x[:] # syntax sugar `+=`
133
- problem += jm.Constraint("onehot", jm.Sum(i, d[i]*x[i]) <= 3)
134
- ```
135
- """
136
- if not isinstance(
137
- other,
138
- (
139
- int,
140
- float,
141
- _expression.Expression,
142
- _constraint.Constraint,
143
- _constraint.Penalty,
144
- ),
145
- ):
146
- raise TypeError(f"could not add {type(other)} to Problem.")
147
- # extract constraints
148
- if isinstance(other, _expression.Expression):
149
- # check index dependencies
150
- indices = _utils.expression_indices(other)
151
- if len(indices) > 0:
152
- raise _exceptions.ModelingError(
153
- "{} depends on {}. The dependence on subscripts needs to be eliminated.".format(
154
- other, indices
155
- )
156
- )
157
- self._objective += other
158
- elif isinstance(other, _constraint.Constraint):
159
- # TODO CHECK CONSTRAINT SUBSCRIPTION DEPENDENCES
160
- self._constraints[other.label] = other
161
- elif isinstance(other, _constraint.Penalty):
162
- # check index dependencies
163
- term = other.penalty_term
164
- indices = _utils.expression_indices(term)
165
- if len(indices) > len(other.forall):
166
- raise _exceptions.ModelingError(
167
- "{} depends on {}. The dependence on subscripts needs to be eliminated.".format(
168
- term, indices
169
- )
170
- )
171
- self._penalties[other.label] = other
172
-
173
- def __add__(
174
- self,
175
- other: tp.Union[
176
- _expression.Expression, _constraint.Constraint, _constraint.Penalty
177
- ],
178
- ) -> Problem:
179
- self.add(other)
180
- return self
181
-
182
- def _repr_latex_(self) -> str:
183
- from jijmodeling.latex_repr.problem_latex_repr import problem_latex_repr
184
-
185
- latex_repr = problem_latex_repr(self)
186
- return r"$$\begin{alignat*}{4}" + latex_repr + r"\end{alignat*}$$"
@@ -1,8 +0,0 @@
1
- from pkgutil import extend_path
2
-
3
- __path__ = extend_path(__path__, __name__)
4
-
5
- from jijmodeling.protobuf.to_protobuf import to_protobuf
6
- from jijmodeling.protobuf.from_protobuf import from_protobuf
7
-
8
- __all__ = ["to_protobuf", "from_protobuf"]