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,768 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import enum
4
-
5
- from abc import ABCMeta, abstractmethod
6
- from typing import Any, List, Optional, TypeVar, Union
7
- from uuid import uuid4
8
-
9
- from typeguard import check_type
10
-
11
- import jijmodeling.expression.serializable as _serializable
12
-
13
- NumericValue = Union[int, float]
14
-
15
- TExpression = TypeVar("TExpression", bound="Expression")
16
-
17
-
18
- class Expression(metaclass=_serializable.Serializable):
19
- """
20
- Mathematical expression of JijModeling.
21
-
22
- The Expression class provides each method that defines operator rules.
23
- """
24
-
25
- _paren_parents = ()
26
-
27
- def __init__(self, uuid: Optional[str] = None):
28
- self._latex_repr: Optional[str] = None
29
- self._uuid: str = uuid if uuid is not None else uuid4().hex
30
-
31
- @property
32
- def uuid(self) -> str:
33
- """
34
- Unique id which is str type since UUID object is not serializable.
35
-
36
- default value is generated by `uuid.uuid4().hex`.
37
-
38
- Returns:
39
- str: _description_
40
- """
41
- return self._uuid
42
-
43
- @abstractmethod
44
- def is_operatable(self) -> bool:
45
- """
46
- Specify whether the operators (+, -, *, /,...) can be applied to the.
47
-
48
- expression. For example, "a[3]" is true, whereas "a" is not.
49
-
50
- Returns:
51
- bool: defaults False.
52
- """
53
- return False
54
-
55
- def _needs_parens(self, parent) -> bool:
56
- """Whether this expression needs parentheses surrounding it, given that it is a child of `parent`.
57
-
58
- The default implementation always returns False. Subclasses override this method to indicate
59
- when they need parentheses to help disambiguate with the parent expression.
60
- """
61
- return False
62
-
63
- def _make_latex(self) -> str:
64
- """
65
- Outputs a latex representation.
66
-
67
- If `self._latex_repr` is not None, it
68
- will take precedence. If you want to get the latex representation of
69
- child objects in `_default_repr_latex_` of each class, use the method.
70
-
71
- Returns:
72
- str: latex representation.
73
- """
74
- if self._latex_repr is not None:
75
- return self._latex_repr
76
- else:
77
- from jijmodeling.latex_repr.latex_repr import expr_latex_repr
78
-
79
- return expr_latex_repr(self)
80
-
81
- def _repr_latex_(self) -> str:
82
- """
83
- Latex representation for Jupyter notebook.
84
-
85
- Returns:
86
- str: latex string
87
- """
88
- return f"${self._make_latex()}$"
89
-
90
- def set_latex(self: TExpression, latex_repr: str) -> TExpression:
91
- """
92
- Change LaTeX Representation.
93
-
94
- Returns:
95
- Expression: `self`
96
-
97
- Examples:
98
- ```python
99
- import jijmodeling as jm
100
- d = jm.Placeholder("d")
101
- n = d.shape[0]
102
- n._repr_latex_()
103
- # $|d|_0$
104
- n = d.shape[0].set_latex("n")
105
- n._repr_latex()
106
- # $n$
107
- ```
108
- """
109
- self._latex_repr = latex_repr
110
- return self
111
-
112
- def __add__(self, other):
113
- return Add.create(self, other)
114
-
115
- def __radd__(self, other):
116
- return Add.create(self, other)
117
-
118
- def __ladd__(self, other):
119
- return self.__add__(other)
120
-
121
- def __sub__(self, other):
122
- return Add.create(self, -1 * other)
123
-
124
- def __rsub__(self, other):
125
- return Add.create(other, -1 * self)
126
-
127
- def __lsub__(self, other):
128
- return Add.create(self, -1 * other)
129
-
130
- def __neg__(self):
131
- return -1 * self
132
-
133
- def __mul__(self, other):
134
- return Mul.create(self, other)
135
-
136
- def __rmul__(self, other):
137
- return self.__mul__(other)
138
-
139
- def __lmul__(self, other):
140
- return self.__mul__(other)
141
-
142
- def __truediv__(self, other):
143
- return Div.create(self, other)
144
-
145
- def __rtruediv__(self, other):
146
- return Div.create(other, self)
147
-
148
- def __pow__(self, other):
149
- return Power.create(self, other)
150
-
151
- def __rpow__(self, other):
152
- return Power.create(other, self)
153
-
154
- def __mod__(self, other):
155
- return Mod.create(self, other)
156
-
157
- def __eq__(self, other):
158
- import jijmodeling.expression.condition as _condition
159
-
160
- return _condition.Equal(self, other)
161
-
162
- def __ne__(self, other):
163
- import jijmodeling.expression.condition as _condition
164
-
165
- return _condition.NotEqual(self, other)
166
-
167
- def __lt__(self, other):
168
- import jijmodeling.expression.condition as _condition
169
-
170
- return _condition.LessThan(self, other)
171
-
172
- def __le__(self, other):
173
- import jijmodeling.expression.condition as _condition
174
-
175
- return _condition.LessThanEqual(self, other)
176
-
177
- def __gt__(self, other):
178
- import jijmodeling.expression.condition as _condition
179
-
180
- return _condition.LessThan(other, self)
181
-
182
- def __ge__(self, other):
183
- import jijmodeling.expression.condition as _condition
184
-
185
- return _condition.LessThanEqual(other, self)
186
-
187
- def __bool__(self):
188
- raise TypeError(
189
- "Cannot convert jm.Expression to bool to avoid unexpected bahavior. Consider us `jm.expr_same` instead in order to compare `jm.Expression` objects."
190
- )
191
-
192
- @abstractmethod
193
- def children(self) -> List[Expression]:
194
- """
195
- This method used at `jijmodeling.expression.extract`.
196
-
197
- Returns:
198
- List[Expression]: children of the expression.
199
- """
200
- return []
201
-
202
-
203
- class DataType(enum.Enum):
204
- INT = "INT"
205
- FLOAT = "FLOAT"
206
-
207
-
208
- class Number(Expression):
209
- """Number class."""
210
-
211
- def __init__(
212
- self,
213
- value: Union[NumericValue, Number],
214
- dtype: Optional[Union[str, DataType]] = None,
215
- uuid: Optional[str] = None,
216
- ):
217
- super().__init__(uuid=uuid)
218
- if isinstance(value, Number):
219
- value = value.value
220
- self._value: NumericValue = value
221
-
222
- self._dtype: DataType
223
- if dtype is None:
224
- self._dtype = (
225
- DataType("INT") if isinstance(value, int) else DataType("FLOAT")
226
- )
227
- elif isinstance(dtype, str):
228
- self._dtype = DataType(dtype.upper())
229
- elif isinstance(dtype, DataType):
230
- self._dtype = dtype
231
- else:
232
- raise TypeError(f"dtype is str or DataType, not {type(dtype)}.")
233
-
234
- if self._dtype == DataType.FLOAT:
235
- self._value = float(value)
236
- elif self._dtype == DataType.INT:
237
- self._value = int(value)
238
-
239
- def _default_repr_latex_(self) -> str:
240
- return str(self.value)
241
-
242
- @property
243
- def value(self) -> NumericValue:
244
- """Number's value."""
245
- return self._value
246
-
247
- @property
248
- def dtype(self) -> DataType:
249
- """Value type "INT" or "FLOAT"."""
250
- return self._dtype
251
-
252
- def is_operatable(self) -> bool:
253
- return True
254
-
255
- def __int__(self):
256
- return int(self.value)
257
-
258
- def __float__(self):
259
- return float(self.value)
260
-
261
- def __repr__(self) -> str:
262
- return str(self.value)
263
-
264
- def _make_latex(self) -> str:
265
- return str(self.value)
266
-
267
- def children(self) -> List[Expression]:
268
- return []
269
-
270
-
271
- def _numeric_to_expression(expr: Union[Expression, NumericValue]) -> Expression:
272
- if isinstance(expr, Expression):
273
- return expr
274
- else:
275
- return Number(expr)
276
-
277
-
278
- class BinaryOperator(Expression, metaclass=ABCMeta):
279
- _mark = ""
280
-
281
- def __init__(
282
- self,
283
- left: Expression,
284
- right: Expression,
285
- uuid: Optional[str] = None,
286
- ):
287
- """
288
- BinaryOperator Constructor.
289
-
290
- Args:
291
- left (Expression): left hand side
292
- right (Expression): right hand side
293
- """
294
- super().__init__(uuid=uuid)
295
-
296
- self._left = left
297
- self._right = right
298
-
299
- # make sure there is only `Expression`s.
300
- check_type(self._left, Expression)
301
- check_type(self._right, Expression)
302
-
303
- import jijmodeling.utils.utils as _uutils
304
-
305
- _error_msg = "{0} is not operatable. If {0} should be operatable, please check the subscripts and dim of {0}."
306
- _uutils.validate_value(
307
- "left.is_operatable()",
308
- self._left.is_operatable(),
309
- _error_msg.format(self._left),
310
- )
311
- _uutils.validate_value(
312
- "right.is_operatable()",
313
- self._right.is_operatable(),
314
- _error_msg.format(self._right),
315
- )
316
-
317
- @property
318
- def left(self) -> Expression:
319
- return self._left
320
-
321
- @property
322
- def right(self) -> Expression:
323
- return self._right
324
-
325
- def is_operatable(self):
326
- return True
327
-
328
- @classmethod
329
- @abstractmethod
330
- def operation(cls, left, right) -> Any:
331
- """
332
- Execute operation.
333
-
334
- Args:
335
- left (Any): left hand side operand
336
- right (Any): right hand side operand
337
-
338
- Example:
339
- ```python
340
- >>> Add.operation(1, 2)
341
- 3
342
- >>> Mul.operation(-1, 4)
343
- -4
344
- >>> Div.operation(1, 2)
345
- 0.5
346
- >>> Power.operation(2, 3)
347
- 8
348
- >>> Mod.operation(10, 3)
349
- 1
350
- ```
351
- """
352
-
353
- @classmethod
354
- def create(
355
- cls,
356
- left: Union[Expression, NumericValue],
357
- right: Union[Expression, NumericValue],
358
- ) -> Expression:
359
- """
360
- In BinaryOperator, there are some opeartions that can be simplified.
361
-
362
- during construction, such as 3+0=3.
363
-
364
- Therefore, it is recommended to call `.create` method to create
365
- the object instead of calling `__init__.` In the `create` metho,
366
- the operand is checked before calling the constructor.
367
- """
368
- _left = _numeric_to_expression(left)
369
- _right = _numeric_to_expression(right)
370
- if isinstance(_left, Number) and isinstance(_right, Number):
371
- return Number(cls.operation(_left.value, _right.value))
372
- return cls(_left, _right)
373
-
374
- def __repr__(self) -> str:
375
- def to_str(e):
376
- if e._needs_parens(self):
377
- return f"({e})"
378
- else:
379
- return f"{e}"
380
-
381
- left = to_str(self.left)
382
- right = to_str(self.right)
383
- return left + self._mark + right
384
-
385
- def children(self) -> List[Expression]:
386
- return [self.left, self.right]
387
-
388
-
389
- class Add(BinaryOperator):
390
- """Represents Add operator."""
391
-
392
- _mark = "+"
393
-
394
- @classmethod
395
- def create(
396
- cls,
397
- left: Union[Expression, NumericValue],
398
- right: Union[Expression, NumericValue],
399
- ) -> Expression:
400
- """
401
- Constructor for Add object.
402
-
403
- Args:
404
- left (Union[Expression, NumericValue]): left hand side
405
- right (Union[Expression, NumericValue]): right hand side
406
-
407
- Returns:
408
- Expression: left + right
409
-
410
- Example:
411
- ```python
412
- >>> import jijmodeling as jm
413
- >>> d, a = jm.Placeholder("d"), jm.Placeholder("a")
414
- >>> Add.create(d, a)
415
- d + a
416
- >>> Add.create(d, 0)
417
- d
418
- >>> type(Add.create(3, 2))
419
- <class 'jijmodeling.expression.expression.Number'>
420
- ```
421
- """
422
- _left: Expression = _numeric_to_expression(left)
423
- _right: Expression = _numeric_to_expression(right)
424
- if isinstance(_left, Number) and _left.value == 0.0:
425
- return _right
426
- if isinstance(_right, Number) and _right.value == 0.0:
427
- return _left
428
- if isinstance(_left, Number) and isinstance(_right, Number):
429
- return Number(_left.value + _right.value)
430
- return cls(_left, _right)
431
-
432
- @classmethod
433
- def operation(cls, left, right):
434
- return left + right
435
-
436
- def _needs_parens(self, parent) -> bool:
437
- needs = (Mul, Div, Power, Mod)
438
- return isinstance(parent, needs)
439
-
440
- def __repr__(self) -> str:
441
- if self.left._needs_parens(self):
442
- left = f"({self.left})"
443
- else:
444
- left = str(self.left)
445
-
446
- # right side needs addition consideration depending
447
- # on whether it's negative or positive
448
- right = str(self.right)
449
- # special-casing "-1*"
450
- if right.startswith("-1*"):
451
- mark = " - "
452
- right = right[3:]
453
- elif right[0] == "-":
454
- mark = " - "
455
- right = right[1:]
456
- else:
457
- mark = self._mark
458
-
459
- if self.right._needs_parens(self):
460
- right = f"({right})"
461
- return left + mark + right
462
-
463
-
464
- class Mul(BinaryOperator):
465
- _mark = r"*"
466
-
467
- @classmethod
468
- def create(
469
- cls,
470
- left: Union[Expression, NumericValue],
471
- right: Union[Expression, NumericValue],
472
- ) -> Expression:
473
- """
474
- Constructor for Mul object.
475
-
476
- Args:
477
- left (Union[Expression, NumericValue]): left hand side
478
- right (Union[Expression, NumericValue]): right hand side
479
-
480
- Returns:
481
- Expression: left * right
482
-
483
- Example:
484
- ```python
485
- >>> import jijmodeling as jm
486
- >>> d, a = jm.Placeholder("d"), jm.Placeholder("a")
487
- >>> Mul.create(d, a)
488
- d * a
489
- >>> Mul.create(d, 1)
490
- d
491
- >>> Mul.create(d, 0)
492
- 0.0
493
- >>> type(Mul.create(3, 2))
494
- <class 'jijmodeling.expression.expression.Number'>
495
- ```
496
- """
497
- _left: Expression = _numeric_to_expression(left)
498
- _right: Expression = _numeric_to_expression(right)
499
- # case: both hand sides are numbers
500
- if isinstance(_left, Number) and isinstance(_right, Number):
501
- return Number(_left.value * _right.value)
502
- elif isinstance(_left, Number):
503
- # case: left hand side is a number
504
- # case: identity element
505
- if _left.value == 1.0:
506
- return _right
507
- # case: zero element
508
- if _left.value == 0.0:
509
- return Number(0.0)
510
- elif isinstance(_right, Number):
511
- # case: right hand side is a number
512
- # case: identity element
513
- if _right.value == 1.0:
514
- return _left
515
- # case: zero element
516
- if _right.value == 0.0:
517
- return Number(0.0)
518
- # put coefficient in front of variable terms
519
- else:
520
- return cls(_right, _left)
521
- return cls(_left, _right)
522
-
523
- def _needs_parens(self, parent) -> bool:
524
- needs = (Div, Power, Mod)
525
- return isinstance(parent, needs)
526
-
527
- @classmethod
528
- def operation(cls, left, right):
529
- return left * right
530
-
531
-
532
- class Div(BinaryOperator):
533
- _mark = "/"
534
-
535
- def __init__(self, left: Expression, right: Expression, uuid: Optional[str] = None):
536
- # The .create method simplified operations (ex. 0 + d = d),
537
- # but does not handle errors for impossible operations such as division by zero.
538
- # Impossible operation errors must be raised in __init__ constructor
539
- # because they must raise in any path constration.
540
- if isinstance(right, Number) and right.value == 0.0:
541
- raise ZeroDivisionError()
542
-
543
- import jijmodeling.expression.utils as _utils
544
-
545
- _utils.check_non_decision_variable(
546
- [right],
547
- f"The denominotor cannot contain a decision variable in `{left}/{right} <-`.",
548
- )
549
-
550
- super().__init__(left, right, uuid=uuid)
551
-
552
- @classmethod
553
- def create(
554
- cls,
555
- left: Union[Expression, NumericValue],
556
- right: Union[Expression, NumericValue],
557
- ) -> Expression:
558
- """
559
- Constructor for Div object.
560
-
561
- Args:
562
- left (Union[Expression, NumericValue]): left hand side
563
- right (Union[Expression, NumericValue]): right hand side
564
-
565
- Returns:
566
- Expression: left // right
567
-
568
- Raises:
569
- ModelingError: The denominator cannot contain a decision variable.
570
-
571
- Example:
572
- ```python
573
- >>> import jijmodeling as jm
574
- >>> d, a = jm.Placeholder("d"), jm.Placeholder("a")
575
- >>> Div.create(d, a)
576
- d // a
577
- >>> Div.create(d, 1)
578
- d
579
- >>> x = jm.Binary("x")
580
- >>> Div.create(d, x)
581
- jijmodeling.exceptions.ModelingError: The denominator cannot contain a decision variable.
582
- >>> type(Div.create(3, 2))
583
- <class 'jijmodeling.expression.expression.Number'>
584
- ```
585
- """
586
- _left = _numeric_to_expression(left)
587
- _right = _numeric_to_expression(right)
588
-
589
- if isinstance(_right, Number) and (not isinstance(_left, Number)):
590
- if _right.value == 1.0:
591
- return _left
592
- elif isinstance(_left, Number) and (not isinstance(_right, Number)):
593
- if _left.value == 0.0:
594
- return _left # 0 / d = 0
595
- elif isinstance(_left, Number) and isinstance(_right, Number):
596
- return Number(_left.value / _right.value)
597
- return cls(_left, _right)
598
-
599
- def _needs_parens(self, parent) -> bool:
600
- needs = (Add, Mul, Div, Power)
601
- return isinstance(parent, needs)
602
-
603
- @classmethod
604
- def operation(cls, left, right):
605
- return left / right
606
-
607
-
608
- class Power(BinaryOperator):
609
- _mark = "^"
610
-
611
- def __init__(self, left: Expression, right: Expression, uuid: Optional[str] = None):
612
- import jijmodeling.expression.utils as _utils
613
-
614
- _utils.check_non_decision_variable(
615
- [right],
616
- f"The denominotor cannot contain a decision variable in `{left}/{right} <-`.",
617
- )
618
- super().__init__(left, right, uuid)
619
-
620
- @classmethod
621
- def create(
622
- cls,
623
- left: Union[Expression, NumericValue],
624
- right: Union[Expression, NumericValue],
625
- ) -> Expression:
626
- """
627
- Constructor for Power object.
628
-
629
- Args:
630
- left (Union[Expression, NumericValue]): left hand side
631
- right (Union[Expression, NumericValue]): right hand side
632
-
633
- Returns:
634
- Expression: left ** right
635
-
636
- Raises:
637
- ModelingError: The exponent cannot contain a decision variable.
638
- ModelingError: If there is a decision variable in left,
639
- the exponent cannot be specified other than Number.
640
- This condition may be relaxed in a version update.
641
-
642
- Example:
643
- ```python
644
- >>> import jijmodeling as jm
645
- >>> d, a = jm.Placeholder("d"), jm.Placeholder("a")
646
- >>> Power.create(d, a)
647
- d ^ a
648
- >>> Power.create(d, 1)
649
- d
650
- >>> x = jm.Binary("x")
651
- >>> Power.create(d, x)
652
- jijmodeling.exceptions.ModelingError: The exponent cannot contain a decision variable.
653
- >>> Power.create(x, d)
654
- jijmodeling.exceptions.ModelingError: If there is a decision variable in left,
655
- the exponent cannot be specified other than Number.
656
- This condition may be relaxed in a version update.
657
- >>> type(Power.create(3, 2))
658
- <class 'jijmodeling.expression.expression.Number'>
659
- ```
660
- """
661
- # obj: Power = cls(left, right tils import extract_nodes
662
-
663
- _left = _numeric_to_expression(left)
664
- _right = _numeric_to_expression(right)
665
-
666
- # The placeholder is now supported in the exponent part, but it must
667
- # contain an integer.
668
- if isinstance(_right, Number):
669
- if _right.value == 1.0:
670
- return _left
671
- elif _right.value == 0.0:
672
- return Number(1)
673
- if isinstance(_left, Number):
674
- if _left.value == 1.0:
675
- return Number(1)
676
- elif _left.value == 0.0:
677
- return Number(0)
678
- if isinstance(_left, Number) and isinstance(_right, Number):
679
- return Number(_left.value**_right.value)
680
- return cls(_left, _right)
681
-
682
- @classmethod
683
- def operation(cls, left, right):
684
- return left**right
685
-
686
- def _needs_parens(self, parent):
687
- needs = (Div, Power)
688
- return isinstance(parent, needs)
689
-
690
-
691
- class Mod(BinaryOperator):
692
- _mark = r"\mod"
693
-
694
- def __init__(self, left: Expression, right: Expression, uuid: Optional[str] = None):
695
- import jijmodeling.expression.utils as _utils
696
-
697
- _utils.check_non_decision_variable(
698
- [left, right],
699
- f"The left hand side and the right hand side cannot contain a decision variable in `{left}%{right} <-`.",
700
- )
701
-
702
- super().__init__(left, right, uuid)
703
-
704
- @classmethod
705
- def create(
706
- cls,
707
- left: Union[Expression, NumericValue],
708
- right: Union[Expression, NumericValue],
709
- ) -> Expression:
710
- """
711
- Constructor for Mod object.
712
-
713
- Args:
714
- left (Union[Expression, NumericValue]): left hand side
715
- right (Union[Expression, NumericValue]): right hand side
716
-
717
- Returns:
718
- Expression: left % right
719
-
720
- Raises:
721
- ModelingError: The left and the right cannot contain a decision variable.
722
-
723
- Example:
724
- ```python
725
- >>> import jijmodeling as jm
726
- >>> d, a = jm.Placeholder("d"), jm.Placeholder("a")
727
- >>> Mod.create(d, a)
728
- d ^ a
729
- >>> Mod.create(d, 1)
730
- d
731
- >>> x = jm.Binary("x")
732
- >>> Mod.create(d, x)
733
- jijmodeling.exceptions.ModelingError: The left and the right cannot contain a decision variable.
734
- >>> Mod.create(x, d)
735
- jijmodeling.exceptions.ModelingError: The left and the right cannot contain a decision variable.
736
- >>> type(Mod.create(3, 2))
737
- <class 'jijmodeling.expression.expression.Number'>
738
- ```
739
- """
740
- _left = _numeric_to_expression(left)
741
- _right = _numeric_to_expression(right)
742
-
743
- if isinstance(_right, Number) and _right.value == 1.0:
744
- return _left
745
- if isinstance(_left, Number) and isinstance(_right, Number):
746
- return Number(_left.value % _right.value)
747
- return cls(_left, _right)
748
-
749
- @classmethod
750
- def operation(cls, left, right):
751
- return left % right
752
-
753
- def _needs_parens(self, parent) -> bool:
754
- needs = (Mul, Div, Power, Mod)
755
- return isinstance(parent, needs)
756
-
757
- def __repr__(self) -> str:
758
- # same as `BinaryOperator`'s implementation
759
- # but using " mod " instead of `self._mark`
760
- def to_str(e):
761
- if e._needs_parens(self):
762
- return f"({e})"
763
- else:
764
- return f"{e}"
765
-
766
- left = to_str(self.left)
767
- right = to_str(self.right)
768
- return left + " mod " + right