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,631 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import struct
4
- from dataclasses import dataclass
5
- from typing import get_args
6
-
7
- import uuid
8
-
9
- from jijmodeling.expression.variables.placeholders import Placeholder, ArrayShape
10
- from jijmodeling.expression.variables.variable import Subscripts, Element, Range
11
- from jijmodeling.expression.variables.deci_vars import Binary, Integer
12
- from jijmodeling.expression.mathfunc import (
13
- AbsoluteValue,
14
- Ceil,
15
- Floor,
16
- Log2,
17
- Max,
18
- Min,
19
- )
20
- from jijmodeling.expression.expression import (
21
- Add,
22
- DataType,
23
- Div,
24
- Mod,
25
- Mul,
26
- Number,
27
- Power,
28
- )
29
- from jijmodeling.expression.condition import (
30
- AndOperator,
31
- Equal,
32
- LessThan,
33
- LessThanEqual,
34
- NoneCondition,
35
- NotEqual,
36
- OrOperator,
37
- XorOperator,
38
- )
39
- from jijmodeling.expression.prod import ProdOperator
40
- from jijmodeling.expression.sum import SumOperator
41
- from jijmodeling.problem.problem import Problem, ProblemSense
42
- from jijmodeling.expression.constraint import Constraint, Penalty
43
-
44
- import jijmodeling.protobuf.pb2 as pb2
45
- from jijmodeling.protobuf.type_annotations import (
46
- DecisionVar,
47
- UnaryOp,
48
- BinaryOp,
49
- CommutativeOp,
50
- ReductionOp,
51
- Expr,
52
- )
53
-
54
- # The current version of the schema.
55
- # This version is used to check the compatibility of the schema.
56
- # If the schema version of the input is not compatible with this version, an error will be returned.
57
- # The version of the schema should be incremented when the schema is changed.
58
- # The version should be satisfied the following conditions:
59
- #
60
- # 1. `MINIMUM_SUPPORTED_VERSION <= SCHEMA_VERSION`
61
- # 2. `SCHEMA_VERSION <= MAXIMUM_SUPPORTED_VERSION`
62
- #
63
- # The condition 1. would be broken when the deserializer is newer than the serializer generating the schema.
64
- # The condition 2. would be broken when the serializer generating the schema is newer than the deserializer.
65
- _SCHEMA_VERSION = 1
66
-
67
-
68
- def to_protobuf(obj) -> bytes:
69
- """
70
- Convert a Problem object to a bytes object serialized by protobuf.
71
-
72
- Args:
73
- expr (Expression): a instance object of the `Problem` class
74
-
75
- Raises:
76
- TypeError: The error raises if the instance object cannot be converted to a protobuf object
77
-
78
- Returns:
79
- bytes: a bytes object
80
- """
81
-
82
- # Create an empty `Header` message.
83
- header = pb2.Header()
84
-
85
- # Set the id.
86
- header.id = str(uuid.uuid4())
87
-
88
- # Set the version of the JijModeling schema.
89
- header.version = _SCHEMA_VERSION
90
-
91
- if isinstance(obj, get_args(Expr)):
92
- header.expression.MergeFrom(serialize_expr(obj))
93
- elif type(obj) is Problem:
94
- header.problem.MergeFrom(serialize_problem(obj))
95
- elif type(obj) is Constraint:
96
- header.constraint.MergeFrom(serialize_constraint(obj))
97
- elif type(obj) is Penalty:
98
- header.custom_penalty_term.MergeFrom(serialize_custom_penalty_term(obj))
99
- else:
100
- raise ValueError(
101
- f"{obj.__class__.__name__} is not a valid object to serialize."
102
- )
103
-
104
- return header.SerializeToString()
105
-
106
-
107
- def serialize_problem(problem: Problem) -> pb2.Problem:
108
- """
109
- Convert a `Problem` instance object to a `Problem` message.
110
-
111
- Args:
112
- problem (Problem): a `Problem` instance object
113
-
114
- Returns:
115
- pb.Problem: a `Problem` message
116
- """
117
-
118
- # Create an empty `Problem` message.
119
- message = pb2.Problem()
120
-
121
- # Set the sense of the problem.
122
- if problem.sense == ProblemSense.MINIMUM:
123
- message.sense = pb2.Problem.Sense.SENSE_MINIMIZE
124
- elif problem.sense == ProblemSense.MAXIMUM:
125
- message.sense = pb2.Problem.Sense.SENSE_MAXIMIZE
126
-
127
- message.id = str(uuid.uuid4())
128
- message.name = problem.name
129
- message.objective_function.MergeFrom(serialize_expr(problem.objective))
130
- for name, constraint in problem.constraints.items():
131
- message.constraints[name].MergeFrom(serialize_constraint(constraint))
132
- for name, penalty in problem.custom_penalty_terms.items():
133
- message.custom_penalty_terms[name].MergeFrom(
134
- serialize_custom_penalty_term(penalty)
135
- )
136
-
137
- return message
138
-
139
-
140
- def serialize_constraint(constraint: Constraint) -> pb2.Constraint:
141
- """
142
- Convert a `Constraint` instance object to a `Constraint` message.
143
-
144
- Args:
145
- constraint (Constraint): a `Constraint` instance object
146
-
147
- Raises:
148
- TypeError: the error occurs if the instance object cannot be converted to a protobuf object
149
-
150
- Returns:
151
- pb.Constraint: a `Constraint` message
152
- """
153
-
154
- # Create an empty `Constraint` message.
155
- message = pb2.Constraint()
156
-
157
- message.id = str(uuid.uuid4())
158
- message.name = constraint.name
159
-
160
- # Set the sense of the `Constraint` message.
161
- if type(constraint.expression) is Equal:
162
- message.sense = pb2.Constraint.Sense.SENSE_EQUAL
163
- elif type(constraint.expression) is LessThanEqual:
164
- message.sense = pb2.Constraint.Sense.SENSE_LESS_THAN_EQUAL
165
- else:
166
- raise ValueError(
167
- f"The equality {type(constraint.expression).__name__} is not supported."
168
- )
169
-
170
- message.left.MergeFrom(serialize_expr(constraint.expression.left))
171
- message.right.MergeFrom(serialize_expr(constraint.expression.right))
172
- message.forall_list.MergeFrom(serialize_forall_list(constraint.forall))
173
-
174
- return message
175
-
176
-
177
- def serialize_custom_penalty_term(penalty: Penalty) -> pb2.CustomPenaltyTerm:
178
- # Create an empty `CustomPenaltyTerm` message.
179
- message = pb2.CustomPenaltyTerm()
180
-
181
- message.id = str(uuid.uuid4())
182
- message.name = penalty.name
183
- message.term.MergeFrom(serialize_expr(penalty.expression))
184
- message.forall_list.MergeFrom(serialize_forall_list(penalty.forall))
185
- return message
186
-
187
-
188
- def serialize_forall_list(forall_list) -> pb2.ForallList:
189
- serializer = ProtobufSerializer()
190
- indices = [
191
- serializer.make_index_message(index, condition)
192
- for index, condition in forall_list
193
- ]
194
-
195
- message = pb2.ForallList()
196
- message.indices.extend(indices)
197
- message.expr_nodes.extend(serializer.expr_pool)
198
- return message
199
-
200
-
201
- def serialize_expr(expr: Expr) -> pb2.Expr:
202
- """
203
- Convert a `Expression` instance object to an `Expression` message.
204
-
205
- Args:
206
- expr (Expression): an `Expression` instance object
207
-
208
- Raises:
209
- TypeError: the error occurs if the instance ofject cannot be converted to a protobuf object
210
-
211
- Returns:
212
- pb.Expression: a `Expression` message
213
- """
214
-
215
- # Create an empty `Expression` message.
216
- message = pb2.Expr()
217
-
218
- # Set the unique id of the `Expression` message.
219
- message.id = str(uuid.uuid4())
220
-
221
- serializer = ProtobufSerializer()
222
- serializer.serialize_expr(expr)
223
- message.root_id = serializer.root_id
224
- message.expr_nodes.extend(serializer.expr_pool)
225
-
226
- return message
227
-
228
-
229
- @dataclass
230
- class ProtobufSerializer:
231
- root_id: int
232
- expr_pool: list
233
-
234
- def __init__(self):
235
- self.root_id = 0
236
- self.expr_pool = []
237
-
238
- def add_expr_node(self, node):
239
- message = pb2.ExprNode()
240
- if type(node) == pb2.NumberLit:
241
- message.number_lit.MergeFrom(node)
242
- elif type(node) == pb2.Placeholder:
243
- message.placeholder.MergeFrom(node)
244
- elif type(node) == pb2.Element:
245
- message.element.MergeFrom(node)
246
- elif type(node) == pb2.DecisionVar:
247
- message.decision_var.MergeFrom(node)
248
- elif type(node) == pb2.Subscript:
249
- message.subscript.MergeFrom(node)
250
- elif type(node) == pb2.ArrayLength:
251
- message.array_length.MergeFrom(node)
252
- elif type(node) == pb2.UnaryOp:
253
- message.unary_op.MergeFrom(node)
254
- elif type(node) == pb2.BinaryOp:
255
- message.binary_op.MergeFrom(node)
256
- elif type(node) == pb2.CommutativeOp:
257
- message.commutative_op.MergeFrom(node)
258
- elif type(node) == pb2.ReductionOp:
259
- message.reduction_op.MergeFrom(node)
260
-
261
- if message not in self.expr_pool:
262
- self.expr_pool.append(message)
263
- self.root_id = len(self.expr_pool) - 1
264
- else:
265
- self.root_id = self.expr_pool.index(message)
266
-
267
- def make_index_message(self, index: Element, condition):
268
- # Create an empty `Index` message.
269
- message = pb2.Index()
270
-
271
- # Visit the index.
272
- self.serialize_element(index)
273
- message.element_id = self.root_id
274
-
275
- # Set the condition of the index.
276
- if type(condition) is not NoneCondition:
277
- self.serialize_expr(condition)
278
- message.condition_id = self.root_id
279
-
280
- return message
281
-
282
- def serialize_number_lit(self, lit: Number):
283
- # Create an empty `NumberLit` message.
284
- message = pb2.NumberLit()
285
-
286
- # Set the type of the value.
287
- if lit.dtype == DataType.INT:
288
- message.type = pb2.NumberLit.Type.TYPE_INTEGER
289
-
290
- # Set the value that is converted to the bytes object with the big-endian.
291
- message.value = int.from_bytes(struct.pack(">q", lit.value), "big")
292
- elif lit.dtype == DataType.FLOAT:
293
- message.type = pb2.NumberLit.Type.TYPE_FLOAT
294
-
295
- # Set the value that is onverted to the bytes object with the big-endian.
296
- message.value = int.from_bytes(struct.pack(">d", lit.value), "big")
297
- else:
298
- raise ValueError(f"Unsupported data type: {lit.dtype}")
299
-
300
- self.add_expr_node(message)
301
-
302
- def serialize_placeholder(self, ph: Placeholder):
303
- # Create an empty `Placeholder` message.
304
- message = pb2.Placeholder()
305
-
306
- # Set the name of the placeholder.
307
- message.name = ph.name
308
-
309
- # Set the number of dimensions of the placeholder.
310
- message.ndim = ph.ndim
311
-
312
- self.add_expr_node(message)
313
-
314
- def serialize_element(self, elt: Element):
315
- # Create an empty `Element` message.
316
- message = pb2.Element()
317
-
318
- # Set the name of the element.
319
- message.name = elt.name
320
-
321
- # Set the number of dimensions of the element.
322
- message.ndim = elt.ndim
323
-
324
- # Set the parent of the element.
325
- if type(elt.belong_to) is Range:
326
- range = pb2.Element.Range()
327
- # Set the start of the range.
328
- self.serialize_expr(elt.belong_to.start)
329
- range.start_id = self.root_id
330
- # Set the end of the range.
331
- self.serialize_expr(elt.belong_to.last)
332
- range.end_id = self.root_id
333
-
334
- message.range.MergeFrom(range)
335
- else:
336
- bound = pb2.Element.Bound()
337
- # Set the type of the parent.
338
- if type(elt.belong_to) is Placeholder:
339
- bound.type = pb2.Element.Bound.Type.TYPE_PLACEHOLDER
340
- elif type(elt.belong_to) is Element:
341
- bound.type = pb2.Element.Bound.Type.TYPE_ELEMENT
342
- elif type(elt.belong_to) is Subscripts:
343
- if type(elt.belong_to.variable) is Placeholder:
344
- bound.type = pb2.Element.Bound.Type.TYPE_SUBSCRIPTED_PLACEHOLDER
345
- elif type(elt.belong_to.variable) is Element:
346
- bound.type = pb2.Element.Bound.Type.TYPE_SUBSCRIPTED_ELEMENT
347
- else:
348
- raise TypeError(
349
- f"Unsupported type of the parent: {type(elt.belong_to.variable).__name__}"
350
- )
351
- else:
352
- raise TypeError(
353
- f"Unsupported type of the parent: {type(elt.belong_to).__name__}"
354
- )
355
- # Set the placeholder.
356
- self.serialize_expr(elt.belong_to)
357
- bound.bound_id = self.root_id
358
-
359
- message.bound.MergeFrom(bound)
360
-
361
- self.add_expr_node(message)
362
-
363
- def serialize_decision_var(self, var: DecisionVar):
364
- # Create an empty `DecisionVar` message.
365
- message = pb2.DecisionVar()
366
-
367
- # Set the name of the decision variable.
368
- message.name = var.name
369
-
370
- # Set the shape of the decision variable.
371
- for shape in var.shape:
372
- self.serialize_expr(shape)
373
- message.shape_ids.append(self.root_id)
374
-
375
- if type(var) is Binary:
376
- # Set the type of the decision variable.
377
- message.type = pb2.DecisionVar.Type.TYPE_BINARY
378
- elif type(var) is Integer:
379
- message.type = pb2.DecisionVar.Type.TYPE_INTEGER
380
-
381
- # Set the lower bound of the decision variable.
382
- lower_bound = pb2.DecisionVar.Bound()
383
- if var.lower_bound.is_operatable():
384
- lower_bound.type = pb2.DecisionVar.Bound.Type.TYPE_EXPRESSION
385
- self.serialize_expr(var.lower_bound)
386
- elif type(var.lower_bound) is Placeholder:
387
- lower_bound.type = pb2.DecisionVar.Bound.Type.TYPE_PLACEHOLDER
388
- self.serialize_placeholder(var.lower_bound)
389
- elif type(var.lower_bound) is Subscripts:
390
- lower_bound.type = pb2.DecisionVar.Bound.Type.TYPE_SUBSCRIPTED_PLACEHOLDER
391
- self.serialize_subscript(var.lower_bound)
392
- else:
393
- raise TypeError(
394
- f"Unsupported type of lower bound: {type(var.lower_bound)}"
395
- )
396
- lower_bound.bound_id = self.root_id
397
-
398
- # Set the upper bound of the decision variable.
399
- upper_bound = pb2.DecisionVar.Bound()
400
- if var.upper_bound.is_operatable():
401
- upper_bound.type = pb2.DecisionVar.Bound.Type.TYPE_EXPRESSION
402
- self.serialize_expr(var.upper_bound)
403
- elif type(var.upper_bound) is Placeholder:
404
- upper_bound.type = pb2.DecisionVar.Bound.Type.TYPE_PLACEHOLDER
405
- self.serialize_placeholder(var.upper_bound)
406
- elif type(var.upper_bound) is Subscripts:
407
- upper_bound.type = pb2.DecisionVar.Bound.Type.TYPE_SUBSCRIPTED_PLACEHOLDER
408
- self.serialize_subscript(var.upper_bound)
409
- else:
410
- raise TypeError(
411
- f"Unsupported type of upper bound: {type(var.upper_bound)}"
412
- )
413
- upper_bound.bound_id = self.root_id
414
-
415
- # Set the bounds of the decision variable.
416
- message.lower_bound.MergeFrom(lower_bound)
417
- message.upper_bound.MergeFrom(upper_bound)
418
-
419
- # The following types are not supported yet.
420
- # - Continuous variable
421
- # - Semi-continuous variable
422
- # - Semi-integer variable
423
- else:
424
- raise TypeError(f"Unsupported decision variable type: {type(var)}")
425
-
426
- self.add_expr_node(message)
427
-
428
- def serialize_subscript(self, subscript: Subscripts):
429
- # Create an empty `Subscript` message.
430
- message = pb2.Subscript()
431
-
432
- # Set the number of dimensions of the subscript.
433
- message.ndim = subscript.dim
434
-
435
- if type(subscript.variable) is Placeholder:
436
- message.type = pb2.Subscript.Type.TYPE_PLACEHOLDER
437
- self.serialize_placeholder(subscript.variable)
438
- message.variable_id = self.root_id
439
- elif type(subscript.variable) is Element:
440
- message.type = pb2.Subscript.Type.TYPE_ELEMENT
441
- self.serialize_element(subscript.variable)
442
- message.variable_id = self.root_id
443
- elif isinstance(subscript.variable, get_args(DecisionVar)):
444
- message.type = pb2.Subscript.Type.TYPE_DECISION_VAR
445
- self.serialize_decision_var(subscript.variable)
446
- message.variable_id = self.root_id
447
- else:
448
- raise TypeError(
449
- f"Unsupported type of subscripted variable: {type(subscript.variable).__name__}"
450
- )
451
-
452
- for subs in subscript.subscripts:
453
- self.serialize_expr(subs)
454
- message.subscript_ids.append(self.root_id)
455
-
456
- self.add_expr_node(message)
457
-
458
- def serialize_array_length(self, len: ArrayShape):
459
- # Create an empty `ArrayLength` message.
460
- message = pb2.ArrayLength()
461
-
462
- # Serialize the array of the array length.
463
- if type(len.array) is Placeholder:
464
- message.type = pb2.ArrayLength.Type.TYPE_PLACEHOLDER
465
- self.serialize_placeholder(len.array)
466
- elif type(len.array) is Element:
467
- message.type = pb2.ArrayLength.Type.TYPE_ELEMENT
468
- self.serialize_element(len.array)
469
- elif type(len.array) is Subscripts:
470
- if type(len.array.variable) is Placeholder:
471
- message.type = pb2.ArrayLength.Type.TYPE_SUBSCRIPTED_PLACEHOLDER
472
- elif type(len.array.variable) is Element:
473
- message.type = pb2.ArrayLength.Type.TYPE_SUBSCRIPTED_ELEMENT
474
- else:
475
- raise TypeError(
476
- f"Unsupported type of subscripted variable: {type(len.array.variable).__name__}"
477
- )
478
- self.serialize_subscript(len.array)
479
- else:
480
- raise TypeError(f"Unsupported type of array: {type(len.array).__name__}")
481
- message.array_id = self.root_id
482
-
483
- # Set the axis of the array length.
484
- message.axis = len.dimension
485
-
486
- self.add_expr_node(message)
487
-
488
- def serialize_unary_op(self, op: UnaryOp):
489
- # Create an empty `UnaryOp` message.
490
- message = pb2.UnaryOp()
491
-
492
- # Visit the operand of the unary operator.
493
- self.serialize_expr(op.operand)
494
- message.operand_id = self.root_id
495
-
496
- # Set the kind of the unary operation.
497
- if type(op) is AbsoluteValue:
498
- message.kind = pb2.UnaryOp.Kind.KIND_ABS
499
- elif type(op) is Ceil:
500
- message.kind = pb2.UnaryOp.Kind.KIND_CEIL
501
- elif type(op) is Floor:
502
- message.kind = pb2.UnaryOp.Kind.KIND_FLOOR
503
- elif type(op) is Log2:
504
- message.kind = pb2.UnaryOp.Kind.KIND_LOG_2
505
- # The following unary operators are not supported in the current version of jijmodeling
506
- # - log10 (log10(a))
507
- # - natural log (ln(a))
508
- else:
509
- message.kind = pb2.UnaryOp.Kind.KIND_UNSPECIFIED
510
-
511
- self.add_expr_node(message)
512
-
513
- def serialize_binary_op(self, op: BinaryOp):
514
- if type(op) is Div:
515
- # Convert division to multiplication with inverse.
516
- expr = op.left * (op.right**-1)
517
- self.serialize_expr(expr)
518
- else:
519
- # Create an empty `BinaryOp` message.
520
- message = pb2.BinaryOp()
521
-
522
- # Visit the left hand side of the operator.
523
- self.serialize_expr(op.left)
524
- message.left_id = self.root_id
525
-
526
- # Visit the right hand side of the operator.
527
- self.serialize_expr(op.right)
528
- message.right_id = self.root_id
529
-
530
- # Set the kind of the binary operation.
531
- if type(op) is Power:
532
- message.kind = pb2.BinaryOp.Kind.KIND_POW
533
- elif type(op) is Mod:
534
- message.kind = pb2.BinaryOp.Kind.KIND_MOD
535
- elif type(op) is Equal:
536
- message.kind = pb2.BinaryOp.Kind.KIND_EQ
537
- elif type(op) is NotEqual:
538
- message.kind = pb2.BinaryOp.Kind.KIND_NOT_EQ
539
- elif type(op) is LessThan:
540
- message.kind = pb2.BinaryOp.Kind.KIND_LESS_THAN
541
- elif type(op) is LessThanEqual:
542
- message.kind = pb2.BinaryOp.Kind.KIND_LESS_THAN_EQ
543
- # The following binary operators are not supported in the current version of jijmodeling
544
- # - GreaterThan (a > b)
545
- # - GreaterThanEqual (a >= b)
546
- else:
547
- message.kind = pb2.BinaryOp.Kind.KIND_UNSPECIFIED
548
-
549
- self.add_expr_node(message)
550
-
551
- def serialize_commutative_op(self, op: CommutativeOp):
552
- # Create an empty `CommutativeOp` message.
553
- message = pb2.CommutativeOp()
554
-
555
- # Visit the left hand side of the operator.
556
- self.serialize_expr(op.left)
557
- left_id = self.root_id
558
-
559
- # Visit the right hand side of the operator.
560
- self.serialize_expr(op.right)
561
- right_id = self.root_id
562
-
563
- # Set the kind of the commutative operator.
564
- if type(op) is Add:
565
- message.kind = pb2.CommutativeOp.Kind.KIND_ADD
566
- elif type(op) is Mul:
567
- message.kind = pb2.CommutativeOp.Kind.KIND_MUL
568
- elif type(op) is Min:
569
- message.kind = pb2.CommutativeOp.Kind.KIND_MIN
570
- elif type(op) is Max:
571
- message.kind = pb2.CommutativeOp.Kind.KIND_MAX
572
- elif type(op) is AndOperator:
573
- message.kind = pb2.CommutativeOp.Kind.KIND_AND
574
- elif type(op) is OrOperator:
575
- message.kind = pb2.CommutativeOp.Kind.KIND_OR
576
- elif type(op) is XorOperator:
577
- message.kind = pb2.CommutativeOp.Kind.KIND_XOR
578
- else:
579
- message.kind = pb2.CommutativeOp.Kind.KIND_UNSPECIFIED
580
-
581
- # Set the id of the operands.
582
- message.term_ids.extend([left_id, right_id])
583
-
584
- self.add_expr_node(message)
585
-
586
- def serialize_reduction_op(self, op: ReductionOp):
587
- # Create an empty `ReductionOp` message.
588
- message = pb2.ReductionOp()
589
-
590
- # Set the kind of the reduction operator.
591
- if type(op) is SumOperator:
592
- message.kind = pb2.ReductionOp.Kind.KIND_SUM
593
- elif type(op) is ProdOperator:
594
- message.kind = pb2.ReductionOp.Kind.KIND_PROD
595
- else:
596
- message.kind = pb2.ReductionOp.Kind.KIND_UNSPECIFIED
597
-
598
- # Serialize the index of the reduction operator.
599
- message.index.MergeFrom(self.make_index_message(op.sum_index, op.condition))
600
-
601
- # Visit the operand of the reduction operator.
602
- self.serialize_expr(op.operand)
603
- message.operand_id = self.root_id
604
-
605
- self.add_expr_node(message)
606
-
607
- def serialize_expr(self, expr: Expr):
608
- if type(expr) is Number:
609
- self.serialize_number_lit(expr)
610
- elif type(expr) is Placeholder:
611
- self.serialize_placeholder(expr)
612
- elif isinstance(expr, get_args(DecisionVar)):
613
- self.serialize_decision_var(expr)
614
- elif type(expr) is Element:
615
- self.serialize_element(expr)
616
- elif type(expr) is Subscripts:
617
- self.serialize_subscript(expr)
618
- elif type(expr) is ArrayShape:
619
- self.serialize_array_length(expr)
620
- elif isinstance(expr, get_args(UnaryOp)):
621
- self.serialize_unary_op(expr)
622
- elif isinstance(expr, get_args(BinaryOp)):
623
- self.serialize_binary_op(expr)
624
- elif isinstance(expr, get_args(CommutativeOp)):
625
- self.serialize_commutative_op(expr)
626
- elif isinstance(expr, get_args(ReductionOp)):
627
- self.serialize_reduction_op(expr)
628
- else:
629
- raise TypeError(
630
- f"{expr.__class__.__name__} is not supported for protobuf serialization."
631
- )
@@ -1,52 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from typing import Union
4
-
5
- from jijmodeling.expression.variables.placeholders import Placeholder, ArrayShape
6
- from jijmodeling.expression.variables.variable import Subscripts, Element
7
- from jijmodeling.expression.variables.deci_vars import Binary, Integer
8
- from jijmodeling.expression.mathfunc import (
9
- AbsoluteValue,
10
- Ceil,
11
- Floor,
12
- Log2,
13
- Max,
14
- Min,
15
- )
16
- from jijmodeling.expression.expression import (
17
- Add,
18
- Div,
19
- Mod,
20
- Mul,
21
- Number,
22
- Power,
23
- )
24
- from jijmodeling.expression.condition import (
25
- AndOperator,
26
- Equal,
27
- LessThan,
28
- LessThanEqual,
29
- NotEqual,
30
- OrOperator,
31
- XorOperator,
32
- )
33
- from jijmodeling.expression.prod import ProdOperator
34
- from jijmodeling.expression.sum import SumOperator
35
-
36
- DecisionVar = Union[Binary, Integer]
37
- UnaryOp = Union[AbsoluteValue, Ceil, Floor, Log2]
38
- BinaryOp = Union[Div, Mod, Power, Equal, NotEqual, LessThan, LessThanEqual]
39
- CommutativeOp = Union[Add, Mul, Min, Max, AndOperator, OrOperator, XorOperator]
40
- ReductionOp = Union[SumOperator, ProdOperator]
41
- Expr = Union[
42
- Number,
43
- Placeholder,
44
- DecisionVar,
45
- Element,
46
- ArrayShape,
47
- Subscripts,
48
- UnaryOp,
49
- BinaryOp,
50
- CommutativeOp,
51
- ReductionOp,
52
- ]