jijmodeling 2.0.0b2__cp38-abi3-win_amd64.whl → 2.0.0b3__cp38-abi3-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.
- jijmodeling/_jijmodeling.pyd +0 -0
- jijmodeling/_jijmodeling.pyi +2008 -3
- {jijmodeling-2.0.0b2.dist-info → jijmodeling-2.0.0b3.dist-info}/METADATA +1 -1
- jijmodeling-2.0.0b3.dist-info/RECORD +8 -0
- {jijmodeling-2.0.0b2.dist-info → jijmodeling-2.0.0b3.dist-info}/WHEEL +1 -1
- jijmodeling/__init__.pyi +0 -1657
- jijmodeling-2.0.0b2.dist-info/RECORD +0 -9
- {jijmodeling-2.0.0b2.dist-info → jijmodeling-2.0.0b3.dist-info}/licenses/LICENSE.txt +0 -0
jijmodeling/_jijmodeling.pyi
CHANGED
|
@@ -1,13 +1,2018 @@
|
|
|
1
1
|
# This file is automatically generated by pyo3_stub_gen
|
|
2
2
|
# ruff: noqa: E501, F401
|
|
3
3
|
|
|
4
|
+
import builtins
|
|
5
|
+
import enum
|
|
6
|
+
import numpy
|
|
7
|
+
import numpy.typing
|
|
8
|
+
import ommx.v1
|
|
9
|
+
import typing
|
|
4
10
|
|
|
5
|
-
|
|
11
|
+
__version__: builtins.str
|
|
12
|
+
@typing.final
|
|
13
|
+
class CategoryLabel:
|
|
14
|
+
r"""
|
|
15
|
+
A category label corresponds to a set of labels representing some specific category (e.g. the name of percels, or the ids of factors, etc).
|
|
16
|
+
A value of category label is treated opaque in JijModeling, and can only be tested for equality / non-equality and used as keys in dictionary-like structures.
|
|
17
|
+
|
|
18
|
+
:class:`CategoryLabel` objects can be created via :meth:`Problem.CategoryLabel`.
|
|
19
|
+
The concrete values should be given in `instance_data` dictionary together with placeholder values when creating a :class:`Compiler` object or in `Problem.eval`.
|
|
20
|
+
In `instance_data`, category label should be given a list of either strings or integers.
|
|
21
|
+
"""
|
|
22
|
+
def name(self) -> builtins.str: ...
|
|
23
|
+
def description(self) -> typing.Optional[builtins.str]: ...
|
|
24
|
+
def custom_latex(self) -> typing.Optional[builtins.str]: ...
|
|
25
|
+
def __next__(self) -> Expression:
|
|
26
|
+
r"""
|
|
27
|
+
A dummy implementation to make CategoryLabel usable in comprehension syntax with Decorator API.
|
|
28
|
+
Do not call this directly.
|
|
29
|
+
"""
|
|
30
|
+
def __iter__(self) -> CategoryLabel:
|
|
31
|
+
r"""
|
|
32
|
+
A dummy implementation to make CategoryLabel usable in comprehension syntax with Decorator API.
|
|
33
|
+
Do not call this directly.
|
|
34
|
+
"""
|
|
35
|
+
def __and__(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
36
|
+
def __rand__(self, lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
37
|
+
def __or__(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
38
|
+
def __ror__(self, lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
39
|
+
def __xor__(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
40
|
+
def __rxor__(self, lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
41
|
+
def diff(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
42
|
+
def bnot(self) -> Expression: ...
|
|
43
|
+
def __eq__(self, other:typing.Any) -> Expression: ... # type: ignore[reportIncompatibleMethodOverride]
|
|
44
|
+
def __ne__(self, other:typing.Any) -> Expression: ... # type: ignore[reportIncompatibleMethodOverride]
|
|
45
|
+
def __lt__(self, other:typing.Any) -> Expression: ...
|
|
46
|
+
def __le__(self, other:typing.Any) -> Expression: ...
|
|
47
|
+
def __gt__(self, other:typing.Any) -> Expression: ...
|
|
48
|
+
def __ge__(self, other:typing.Any) -> Expression: ...
|
|
49
|
+
|
|
50
|
+
class CompileError(builtins.Exception):
|
|
6
51
|
...
|
|
7
52
|
|
|
8
|
-
|
|
53
|
+
@typing.final
|
|
54
|
+
class Compiler:
|
|
55
|
+
r"""
|
|
56
|
+
A compiler that conerts problems / expressions into OMMX instance / functions.
|
|
57
|
+
|
|
58
|
+
:class:`Compiler` objects can be created via constructor of `Compiler.from_problem` class method.
|
|
59
|
+
In this section we explain the usage of :class:`Compiler` constructor.
|
|
60
|
+
|
|
61
|
+
Args
|
|
62
|
+
----
|
|
63
|
+
- `namespace` (:class:`Namespace`): The namespace containing decision variables and other symbols used in the problem. (Typically obtained via `Problem.namespace`.)
|
|
64
|
+
- `instance_data` (dict[str, typing.Any]): A dictionary mapping names of placeholders and category labels to their concrete values for instance generation.
|
|
65
|
+
|
|
66
|
+
Instance Data
|
|
67
|
+
--------------
|
|
68
|
+
For placeholders, you can pass any of the following:
|
|
69
|
+
|
|
70
|
+
1. a scalar (integer or floating number point) value,
|
|
71
|
+
2. a tuple of scalars,
|
|
72
|
+
3. a (nested) list of (1) or (2).
|
|
73
|
+
4. a `ndarray.array` object from `numpy` package with `dtype` float or int.
|
|
74
|
+
|
|
75
|
+
For category labels, you can pass a list of strings or integers representing the concrete labels.
|
|
76
|
+
|
|
77
|
+
Returns
|
|
78
|
+
-------
|
|
79
|
+
A :class:`Compiler` object.
|
|
80
|
+
|
|
81
|
+
Raises
|
|
82
|
+
------
|
|
83
|
+
Raises `ModelingError` when there is missing or redundant placeholder(s) or category label(s) in `instance_data`.
|
|
84
|
+
"""
|
|
85
|
+
def get_constraint_id_by_name(self, name:builtins.str) -> dict:
|
|
86
|
+
r"""
|
|
87
|
+
Obtains a dictionary from subscript to constraint Id.
|
|
88
|
+
"""
|
|
89
|
+
def get_decision_variable_by_name(self, name:builtins.str, subscript:typing.Optional[typing.Sequence[builtins.int | builtins.str | CategoryLabel]]=None) -> ommx.v1.DecisionVariable:
|
|
90
|
+
r"""
|
|
91
|
+
Retrieves an OMMX decision variable by its name and optional subscript.
|
|
92
|
+
"""
|
|
93
|
+
def eval_constraints(self, constraint:Constraint) -> builtins.list[ommx.v1.Constraint]: ...
|
|
94
|
+
def eval_problem(self, constraint:Problem) -> ommx.v1.Instance: ...
|
|
95
|
+
def eval_function(self, expr:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> ommx.v1.Function: ...
|
|
96
|
+
def __new__(cls, namespace:Namespace, instance_data:typing.Mapping[builtins.str, builtins.int | builtins.float | numpy.typing.NDArray[numpy.float64] | numpy.typing.NDArray[numpy.int64] | list | dict | builtins.str]) -> Compiler: ...
|
|
97
|
+
@staticmethod
|
|
98
|
+
def from_problem(problem:Problem, instance_data:typing.Mapping[builtins.str, builtins.int | builtins.float | numpy.typing.NDArray[numpy.float64] | numpy.typing.NDArray[numpy.int64] | list | dict | builtins.str]) -> Compiler:
|
|
99
|
+
r"""
|
|
100
|
+
Creates a :class:`Compiler` object from a :class:`Problem` object and instance data.
|
|
101
|
+
|
|
102
|
+
See :class:`Compiler` constructor for details about `instance_data`.
|
|
103
|
+
"""
|
|
104
|
+
|
|
105
|
+
@typing.final
|
|
106
|
+
class Constraint:
|
|
107
|
+
@property
|
|
108
|
+
def name(self) -> builtins.str: ...
|
|
109
|
+
@property
|
|
110
|
+
def sense(self) -> ConstraintSense:
|
|
111
|
+
r"""
|
|
112
|
+
An enum representing the comparison involved in this constraint: whether it's
|
|
113
|
+
equality (==), greater-than (>=), or lesser-than (<=).
|
|
114
|
+
"""
|
|
115
|
+
@property
|
|
116
|
+
def left(self) -> Expression:
|
|
117
|
+
r"""
|
|
118
|
+
The left-hand side expression of the equality/inequality this constraint represents.
|
|
119
|
+
"""
|
|
120
|
+
@property
|
|
121
|
+
def right(self) -> Expression:
|
|
122
|
+
r"""
|
|
123
|
+
The right-hand side expression of the equality/inequality this constraint represents.
|
|
124
|
+
"""
|
|
125
|
+
@property
|
|
126
|
+
def expression(self) -> Expression:
|
|
127
|
+
r"""
|
|
128
|
+
The full expression of the equality/inequality this constraint represents.
|
|
129
|
+
"""
|
|
130
|
+
@property
|
|
131
|
+
def is_equality(self) -> builtins.bool:
|
|
132
|
+
r"""
|
|
133
|
+
Returns true if the constraint is an equality constraint.
|
|
134
|
+
|
|
135
|
+
Returns
|
|
136
|
+
--------
|
|
137
|
+
`bool`: True if the constraint is an equality constraint. Otherwise, False.
|
|
138
|
+
|
|
139
|
+
Examples
|
|
140
|
+
---------
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
>>> import jijmodeling as jm
|
|
144
|
+
>>> N = jm.Placeholder("N")
|
|
145
|
+
>>> i = jm.Element("i", belong_to=N)
|
|
146
|
+
>>> x = jm.BinaryVar("x", shape=(N,))
|
|
147
|
+
>>> constraint = jm.Constraint("constraint", jm.sum(i, x[i]) == 1)
|
|
148
|
+
>>> assert constraint.is_equality()
|
|
149
|
+
|
|
150
|
+
```
|
|
151
|
+
"""
|
|
152
|
+
@property
|
|
153
|
+
def is_inequality(self) -> builtins.bool:
|
|
154
|
+
r"""
|
|
155
|
+
Returns true if the constraint is an inequality constraint.
|
|
156
|
+
|
|
157
|
+
Returns
|
|
158
|
+
--------
|
|
159
|
+
`bool`: True if the constraint is an inequality constraint. Otherwise, False.
|
|
160
|
+
|
|
161
|
+
Examples
|
|
162
|
+
---------
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
>>> import jijmodeling as jm
|
|
166
|
+
>>> N = jm.Placeholder("N")
|
|
167
|
+
>>> i = jm.Element("i", belong_to=N)
|
|
168
|
+
>>> x = jm.BinaryVar("x", shape=(N,))
|
|
169
|
+
>>> constraint = jm.Constraint("constraint", jm.sum(i, x[i]) <= 1)
|
|
170
|
+
>>> assert constraint.is_inequality()
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
"""
|
|
174
|
+
def __repr__(self) -> builtins.str: ...
|
|
175
|
+
def _repr_latex_(self) -> builtins.str: ...
|
|
176
|
+
|
|
177
|
+
@typing.final
|
|
178
|
+
class DecisionVar:
|
|
179
|
+
r"""
|
|
180
|
+
A class representing a decision variable in a mathematical model.
|
|
181
|
+
As the decision variables must belong to some namespace, you CANNOT construct it directly.
|
|
182
|
+
Instead, you should use `Problem.DecisionVar`, `Problem.BinaryVar`,
|
|
183
|
+
`Problem.IntegerVar`, `Problem.ContinuousVar`,`Problem.SemiIntegerVar`,
|
|
184
|
+
or `Problem.SemiContinuousVar`.
|
|
185
|
+
|
|
186
|
+
The `DecisonVar` class is used to create a continuous variable.
|
|
187
|
+
The lower and upper bounds of the variable can be any scalar or tensor with the same shape as the variable expression which DOES NOT contain any decision variable.
|
|
188
|
+
|
|
189
|
+
The `DecisionVar` class itself represents a definition of a decision variable,
|
|
190
|
+
but you can use ordinary operations on `Expression`s to create expressions that contain decision variables.
|
|
191
|
+
|
|
192
|
+
Attributes
|
|
193
|
+
-----------
|
|
194
|
+
- `name` (`str`): A name of the continuous variable.
|
|
195
|
+
- `kind` (`DecisionVarKind`): The kind of the decision variable, which can be one of the following:
|
|
196
|
+
- `BINARY`: A binary variable.
|
|
197
|
+
- `INTEGER`: An integer variable.
|
|
198
|
+
- `CONTINUOUS`: A continuous variable.
|
|
199
|
+
- `SEMI_INTEGER`: A semi-integer variable.
|
|
200
|
+
- `SEMI_CONTINUOUS`: A semi-continuous variable.
|
|
201
|
+
- `shape` (`tuple`): A tuple with the size of each dimension of the integer variable. Empty if the variable is not multi-dimensional.
|
|
202
|
+
- `lower_bound`: The lower bound of the variable.
|
|
203
|
+
- `upper_bound`: The upper bound of the variable.
|
|
204
|
+
- `description` (`str`): A description of the continuous variable.
|
|
205
|
+
|
|
206
|
+
Examples
|
|
207
|
+
---------
|
|
208
|
+
Create a scalar continuous variable whose name is "z" and domain is `[-1, 1]`.
|
|
209
|
+
|
|
210
|
+
```python
|
|
211
|
+
>>> import jijmodeling as jm
|
|
212
|
+
>>> problem = jm.Problem("example")
|
|
213
|
+
>>> z = problem.DecisionVar(
|
|
214
|
+
>>> "z",
|
|
215
|
+
>>> kind=jm.DecisionVarKind.CONTINUOUS,
|
|
216
|
+
>>> lower_bound=-1, upper_bound=1
|
|
217
|
+
>>> )
|
|
218
|
+
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
or equivalently:
|
|
222
|
+
|
|
223
|
+
```python
|
|
224
|
+
>>> import jijmodeling as jm
|
|
225
|
+
>>> problem = jm.Problem("example")
|
|
226
|
+
>>> z = problem.ContinuousVar("z", lower_bound=-1, upper_bound=1)
|
|
227
|
+
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Create a 2-dimensional integer variable...
|
|
231
|
+
- whose name is "x".
|
|
232
|
+
- whose domain is [0, 2].
|
|
233
|
+
- where each dimension has length 2 (making this a 2x2 matrix).
|
|
234
|
+
|
|
235
|
+
```python
|
|
236
|
+
>>> import jijmodeling as jm
|
|
237
|
+
>>> problem = jm.Problem("example")
|
|
238
|
+
>>> x = problem.IntegerVar("x", shape=[2, 2], lower_bound=0, upper_bound=2)
|
|
239
|
+
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Create a 1-dimensional continuous variable, and construct an expression
|
|
243
|
+
accessing the 123rd component of it..
|
|
244
|
+
|
|
245
|
+
```python
|
|
246
|
+
>>> import jijmodeling as jm
|
|
247
|
+
>>> problem = jm.Problem("example")
|
|
248
|
+
>>> x = problem.ContinuousVar("x", shape=[124], lower_bound=0, upper_bound=2)
|
|
249
|
+
>>> x[123]
|
|
250
|
+
x[123]
|
|
251
|
+
|
|
252
|
+
```
|
|
253
|
+
"""
|
|
254
|
+
@property
|
|
255
|
+
def name(self) -> builtins.str: ...
|
|
256
|
+
@property
|
|
257
|
+
def kind(self) -> DecisionVarKind: ...
|
|
258
|
+
@property
|
|
259
|
+
def description(self) -> builtins.str: ...
|
|
260
|
+
@property
|
|
261
|
+
def ndim(self) -> builtins.int: ...
|
|
262
|
+
@property
|
|
263
|
+
def shape(self) -> typing.Optional[tuple]: ...
|
|
264
|
+
@property
|
|
265
|
+
def lower_bound(self) -> Expression | builtins.list[Expression]: ...
|
|
266
|
+
@property
|
|
267
|
+
def upper_bound(self) -> Expression | builtins.list[Expression]: ...
|
|
268
|
+
def __repr__(self) -> builtins.str: ...
|
|
269
|
+
def _repr_latex_(self) -> builtins.str: ...
|
|
270
|
+
@typing.overload
|
|
271
|
+
def max(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression:
|
|
272
|
+
r"""
|
|
273
|
+
Return the larger of this expression and rhs.
|
|
274
|
+
"""
|
|
275
|
+
@typing.overload
|
|
276
|
+
def max(self) -> Expression:
|
|
277
|
+
r"""
|
|
278
|
+
Return the maximum element of this foldable expression.
|
|
279
|
+
"""
|
|
280
|
+
@typing.overload
|
|
281
|
+
def min(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression:
|
|
282
|
+
r"""
|
|
283
|
+
Return the smaller of this expression and rhs.
|
|
284
|
+
"""
|
|
285
|
+
@typing.overload
|
|
286
|
+
def min(self) -> Expression:
|
|
287
|
+
r"""
|
|
288
|
+
Return the minimum element of this foldable expression.
|
|
289
|
+
"""
|
|
290
|
+
def __pow__(self, exponent:typing.Any, modulo:typing.Optional[typing.Any]=None) -> Expression: ...
|
|
291
|
+
def __rpow__(self, base:typing.Any, modulo:typing.Optional[typing.Any]=None) -> Expression: ...
|
|
292
|
+
def __add__(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
293
|
+
def __radd__(self, lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
294
|
+
def __sub__(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
295
|
+
def __rsub__(self, lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
296
|
+
def __mul__(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
297
|
+
def __rmul__(self, lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
298
|
+
def __truediv__(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
299
|
+
def __rtruediv__(self, lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
300
|
+
def __mod__(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
301
|
+
def __rmod__(self, lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
302
|
+
def __neg__(self) -> Expression: ...
|
|
303
|
+
def abs(self) -> Expression: ...
|
|
304
|
+
def sqrt(self) -> Expression: ...
|
|
305
|
+
def sin(self) -> Expression: ...
|
|
306
|
+
def cos(self) -> Expression: ...
|
|
307
|
+
def tan(self) -> Expression: ...
|
|
308
|
+
def asin(self) -> Expression: ...
|
|
309
|
+
def acos(self) -> Expression: ...
|
|
310
|
+
def atan(self) -> Expression: ...
|
|
311
|
+
def sinh(self) -> Expression: ...
|
|
312
|
+
def cosh(self) -> Expression: ...
|
|
313
|
+
def tanh(self) -> Expression: ...
|
|
314
|
+
def asinh(self) -> Expression: ...
|
|
315
|
+
def acosh(self) -> Expression: ...
|
|
316
|
+
def atanh(self) -> Expression: ...
|
|
317
|
+
def exp(self) -> Expression: ...
|
|
318
|
+
def ln(self) -> Expression: ...
|
|
319
|
+
def log10(self) -> Expression: ...
|
|
320
|
+
def log2(self) -> Expression: ...
|
|
321
|
+
def ceil(self) -> Expression: ...
|
|
322
|
+
def floor(self) -> Expression: ...
|
|
323
|
+
def keys(self) -> Expression: ...
|
|
324
|
+
def values(self) -> Expression: ...
|
|
325
|
+
def items(self) -> Expression: ...
|
|
326
|
+
def map(self, func:typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any]) -> Expression: ...
|
|
327
|
+
def roll(self, shift:typing.Any, *, axis:typing.Optional[builtins.int]=None) -> Expression: ...
|
|
328
|
+
def filter(self, predicate:typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any]) -> Expression: ...
|
|
329
|
+
def flat_map(self, func:typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any]) -> Expression: ...
|
|
330
|
+
def rows(self) -> Expression: ...
|
|
331
|
+
def __getitem__(self, subscripts:typing.Any) -> Expression: ...
|
|
332
|
+
def sum(self, axis:typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | builtins.int | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict] | typing.Sequence[builtins.int]]=None) -> Expression: ...
|
|
333
|
+
def prod(self, axis:typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | builtins.int | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict] | typing.Sequence[builtins.int]]=None) -> Expression: ...
|
|
334
|
+
def __eq__(self, other:typing.Any) -> Expression: ... # type: ignore[reportIncompatibleMethodOverride]
|
|
335
|
+
def __ne__(self, other:typing.Any) -> Expression: ... # type: ignore[reportIncompatibleMethodOverride]
|
|
336
|
+
def __lt__(self, other:typing.Any) -> Expression: ...
|
|
337
|
+
def __le__(self, other:typing.Any) -> Expression: ...
|
|
338
|
+
def __gt__(self, other:typing.Any) -> Expression: ...
|
|
339
|
+
def __ge__(self, other:typing.Any) -> Expression: ...
|
|
340
|
+
|
|
341
|
+
@typing.final
|
|
342
|
+
class DecoratedProblem(typing.Protocol):
|
|
343
|
+
r"""
|
|
344
|
+
A variant of `Problem` that is only available in Decorator API provided by `Problem.update`.
|
|
345
|
+
See `Problem` for more details.
|
|
346
|
+
"""
|
|
347
|
+
@property
|
|
348
|
+
def objective(self) -> Expression: ...
|
|
349
|
+
@property
|
|
350
|
+
def description(self) -> builtins.str:
|
|
351
|
+
r"""
|
|
352
|
+
The problem description.
|
|
353
|
+
|
|
354
|
+
An empty string if no description was defined.
|
|
355
|
+
"""
|
|
356
|
+
@property
|
|
357
|
+
def constraints(self) -> builtins.dict[builtins.str, builtins.list[Constraint]]:
|
|
358
|
+
r"""
|
|
359
|
+
Returns a dictionary of the constraints in the problem.
|
|
360
|
+
|
|
361
|
+
Returns
|
|
362
|
+
--------
|
|
363
|
+
`dict[str, [Constraint]]`: Dictionary mapping constraint names to Constraint objects.
|
|
364
|
+
"""
|
|
365
|
+
@typing.overload
|
|
366
|
+
def __iadd__(self, other:Constraint) -> DecoratedProblem:
|
|
367
|
+
r"""
|
|
368
|
+
Add constraint to the problem.
|
|
369
|
+
"""
|
|
370
|
+
@typing.overload
|
|
371
|
+
def __iadd__(self, other:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> DecoratedProblem:
|
|
372
|
+
r"""
|
|
373
|
+
Add an expression as a term to the objective function of the problem.
|
|
374
|
+
"""
|
|
375
|
+
def eval(self, instance_data:typing.Mapping[builtins.str, builtins.int | builtins.float | numpy.typing.NDArray[numpy.float64] | numpy.typing.NDArray[numpy.int64] | list | dict | builtins.str]) -> ommx.v1.Instance:
|
|
376
|
+
r"""
|
|
377
|
+
Compiles and evaluates the problem given the specified instance data, returning an OMMX instance.
|
|
378
|
+
|
|
379
|
+
A short-hand of `Compiler.from_problem(self, data).eval_problem(self)`.
|
|
380
|
+
|
|
381
|
+
Args
|
|
382
|
+
----
|
|
383
|
+
- `instance_data` (`dict[str, InstanceValue]`): A dictionary mapping placeholder and category label names to their corresponding values for this instance. See :class:`Compiler` for more details on the expected format of `instance_data`.
|
|
384
|
+
"""
|
|
385
|
+
def Placeholder(self, name:typing.Optional[builtins.str]=None, *, dtype:DataType | type | tuple, ndim:typing.Optional[builtins.int]=None, shape:typing.Optional[typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]]=None, jagged:builtins.bool=False, dict_keys:typing.Optional[DataType | type | CategoryLabel | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | tuple]=None, partial_dict:typing.Optional[builtins.bool]=None, latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> Placeholder:
|
|
386
|
+
r"""
|
|
387
|
+
Defines a :class:`Placeholder` in this problem's namespace.
|
|
388
|
+
|
|
389
|
+
Placeholders can be a scalar, multi-dimensional array (representing arrays and
|
|
390
|
+
matrices), or dictionary keyed by integers or strings.
|
|
391
|
+
|
|
392
|
+
When calling `DecoratedProblem.Placehoder`, you must specify `dtype` explicitly to indicate the type of data the placeholder holds.
|
|
393
|
+
Alternative shorthand methods like `DecoratedProblem.Integer`, `DecoratedProblem.Binary`,
|
|
394
|
+
or `DecoratedProblem.Natural` are recommended for convenience in their specific
|
|
395
|
+
use cases.
|
|
396
|
+
|
|
397
|
+
Representation
|
|
398
|
+
--------------
|
|
399
|
+
Depending on the arguments described below, the representation of the placeholder will be determined as follows:
|
|
400
|
+
|
|
401
|
+
1. If none none of `ndim`, `shape`, `jagged`, `dict_keys`, or `partial_dict` is provided, or, `ndim` is set to zero, Placeholder will be considered as a scalar value (= array of dimension 0).
|
|
402
|
+
2. If either (or both consistently) of `ndim` or `shape` is provided and `jagged` is `False` (or omitted), and none of `dict_keys` or `partial_dict` is given, Placeholder will be considered as a multi-dimensional array with fixed shape.
|
|
403
|
+
3. If either (or both consistently), of `ndim` or `shape` is provided and `jagged` is `True`, and none of `dict_keys` or `partial_dict` is given,Placeholder will be considered as a jagged array (i.e. a non-rectangular ndim array).
|
|
404
|
+
4. If `dict_keys` is specified but none of `ndim`, `shape`, `jagged` is provided, then Placeholder will be considered as a total dictionary-like structure with keys specified by `dict_keys`.
|
|
405
|
+
5. If both `dict_keys` and `partial_dict` (set to `True`) are specified, and none of `ndim`, `shape`, or `jagged` is provided, then Placeholder will be considered as a partial dictionary-like structure with keys specified by `dict_keys`.
|
|
406
|
+
6. Otherwise, an error is raised.
|
|
407
|
+
|
|
408
|
+
Args
|
|
409
|
+
-----
|
|
410
|
+
- `name` (`str | None`): The placeholder's name. If omitted, the local variable name is used.
|
|
411
|
+
- `dtype` (`DataType`): The type of data this placeholder holds (integer, floating point, etc.).
|
|
412
|
+
- `ndim` (`int`): The number of dimensions in this placeholder. Defaults to 0 (a scalar value).
|
|
413
|
+
- `shape` (`list | tuple`): A sequence with the size of each dimension of the placeholder. Defaults to an empty tuple (a scalar value).
|
|
414
|
+
- Each item in `shape` must be a valid expression evaluating to a non-negative scalar.
|
|
415
|
+
- There is no need to provide `ndim` if `shape` is specified, but they must not conflict if both specified.
|
|
416
|
+
- `jagged` (`bool`): Whether this placeholder represents a jagged array (ie. a non-square matrix). Ignored if scalar.
|
|
417
|
+
- `dict_keys` (`tuple[Expression, ...]`, optional): If provided, specifies that this placeholder represents a dictionary-like structure with keys `dict_keys`.
|
|
418
|
+
- `partial_dict` (`bool`, optional): If `dict_keys` is provided, specifies whether this placeholder represents a partial dictionary (i.e., not all keys are guaranteed to be present). Defaults to `False`.
|
|
419
|
+
- `latex` (`str`, optional): An optional LaTeX representation to be used in Jupyter notebook.
|
|
420
|
+
- When not provided, `name` is used by default.
|
|
421
|
+
- `description` (`str`, optional): An optional description for user reference.
|
|
422
|
+
|
|
423
|
+
Examples
|
|
424
|
+
---------
|
|
425
|
+
Create a scalar integer placeholder whose name is "a".
|
|
426
|
+
|
|
427
|
+
```python
|
|
428
|
+
>>> import jijmodeling as jm
|
|
429
|
+
>>> problem = jm.Problem("my_problem")
|
|
430
|
+
>>> @problem.update
|
|
431
|
+
>>> def _(problem: jm.DecoratedProblem)
|
|
432
|
+
>>> a = problem.Placeholder("a", dtype=jm.DataType.INTEGER)
|
|
433
|
+
```
|
|
434
|
+
"""
|
|
435
|
+
def Integer(self, name:typing.Optional[builtins.str]=None, *, ndim:typing.Optional[builtins.int]=None, shape:typing.Optional[typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict] | typing.Sequence[typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]]]=None, jagged:builtins.bool=False, dict_keys:typing.Optional[DataType | type | CategoryLabel | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | tuple]=None, partial_dict:typing.Optional[builtins.bool]=None, latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> Placeholder:
|
|
436
|
+
r"""
|
|
437
|
+
Defines a :class:`Placeholder` representing an integer in this problem's namespace.
|
|
438
|
+
|
|
439
|
+
A shorthand for `DecoratedProblem.Placeholder(dtype=DataType.INTEGER)`, provided for clarity and convenience.
|
|
440
|
+
See `DecoratedProblem.Placeholder` for more details on placeholders.
|
|
441
|
+
"""
|
|
442
|
+
def Float(self, name:typing.Optional[builtins.str]=None, *, ndim:typing.Optional[builtins.int]=None, shape:typing.Optional[typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict] | typing.Sequence[typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]]]=None, jagged:builtins.bool=False, dict_keys:typing.Optional[DataType | type | CategoryLabel | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | tuple]=None, partial_dict:typing.Optional[builtins.bool]=None, latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> Placeholder:
|
|
443
|
+
r"""
|
|
444
|
+
Defines a :class:`Placeholder` representing a floating-point (real) number in this problem's namespace.
|
|
445
|
+
|
|
446
|
+
A shorthand for `DecoratedProblem.Placeholder(dtype=DataType.FLOAT)`, provided for clarity and convenience.
|
|
447
|
+
See `DecoratedProblem.Placeholder` for more details on placeholders.
|
|
448
|
+
"""
|
|
449
|
+
def Natural(self, name:typing.Optional[builtins.str]=None, *, ndim:typing.Optional[builtins.int]=None, shape:typing.Optional[typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict] | typing.Sequence[typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]]]=None, jagged:builtins.bool=False, dict_keys:typing.Optional[DataType | type | CategoryLabel | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | tuple]=None, partial_dict:typing.Optional[builtins.bool]=None, latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> Placeholder:
|
|
450
|
+
r"""
|
|
451
|
+
Defines a :class:`Placeholder` representing a natural number in this problem's namespace.
|
|
452
|
+
|
|
453
|
+
A shorthand for `DecoratedProblem.Placeholder(dtype=DataType.NATURAL)`, provided for clarity and convenience.
|
|
454
|
+
See `DecoratedProblem.Placeholder` for more details on placeholders.
|
|
455
|
+
"""
|
|
456
|
+
def Length(self, name:typing.Optional[builtins.str]=None, *, ndim:typing.Optional[builtins.int]=0, shape:typing.Optional[typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict] | typing.Sequence[typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]]]=None, jagged:builtins.bool=False, dict_keys:typing.Optional[DataType | type | CategoryLabel | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | tuple]=None, partial_dict:typing.Optional[builtins.bool]=None, latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> Placeholder:
|
|
457
|
+
r"""
|
|
458
|
+
Defines a :class:`Placeholder` representing a natural number in this problem's namespace.
|
|
459
|
+
|
|
460
|
+
This is just a shorthand for `DecoratedProblem.Natural(ndim=0)` and effectively the same as any other natural
|
|
461
|
+
placeholder for practical purposes. The use of `Length` is recommended just for clarity when
|
|
462
|
+
defining a placeholder which will be used to define the length of multi-dimensional objects.
|
|
463
|
+
|
|
464
|
+
See `DecoratedProblem.Placeholder` for more details on placeholders.
|
|
465
|
+
"""
|
|
466
|
+
def Dim(self, name:typing.Optional[builtins.str]=None, *, ndim:typing.Optional[builtins.int]=0, shape:typing.Optional[typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict] | typing.Sequence[typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]]]=None, jagged:builtins.bool=False, dict_keys:typing.Optional[DataType | type | CategoryLabel | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | tuple]=None, partial_dict:typing.Optional[builtins.bool]=None, latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> Placeholder:
|
|
467
|
+
r"""
|
|
468
|
+
Defines a :class:`Placeholder` representing a natural number in this problem's namespace.
|
|
469
|
+
|
|
470
|
+
This is just a shorthand for `DecoratedProblem.Natural(ndim=0)` and effectively the same as any other natural
|
|
471
|
+
placeholder for practical purposes. The use of `Dim` is recommended just for clarity when
|
|
472
|
+
defining a placeholder which will be used to define the length of multi-dimensional objects.
|
|
473
|
+
|
|
474
|
+
See `DecoratedProblem.Placeholder` for more details on placeholders.
|
|
475
|
+
"""
|
|
476
|
+
def Binary(self, name:typing.Optional[builtins.str]=None, *, ndim:typing.Optional[builtins.int]=None, shape:typing.Optional[typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict] | typing.Sequence[typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]]]=None, jagged:builtins.bool=False, dict_keys:typing.Optional[DataType | type | CategoryLabel | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | tuple]=None, partial_dict:typing.Optional[builtins.bool]=None, latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> Placeholder:
|
|
477
|
+
r"""
|
|
478
|
+
Defines a `Placeholder` representing a binary number in this problem's namespace.
|
|
479
|
+
|
|
480
|
+
A shorthand for `DecoratedProblem.Placeholder(dtype=DataType.BINARY)`, provided for clarity and convenience.
|
|
481
|
+
See `DecoratedProblem.Placeholder` for more details on placeholders.
|
|
482
|
+
"""
|
|
483
|
+
def PartialDict(self, name:typing.Optional[builtins.str]=None, *, dict_keys:DataType | type | CategoryLabel | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | tuple, dtype:DataType | type | tuple, latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> Placeholder:
|
|
484
|
+
r"""
|
|
485
|
+
A shorthand for creating a partial dictionary placeholder with key type
|
|
486
|
+
"""
|
|
487
|
+
def TotalDict(self, name:typing.Optional[builtins.str]=None, *, dict_keys:DataType | type | CategoryLabel | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | tuple, dtype:DataType | type | tuple, latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> Placeholder:
|
|
488
|
+
r"""
|
|
489
|
+
A shorthand for creating a total dictionary placeholder with key type
|
|
490
|
+
"""
|
|
491
|
+
def Graph(self, name:typing.Optional[builtins.str]=None, *, dtype:DataType | type | tuple=DataType.NATURAL, latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> Placeholder:
|
|
492
|
+
r"""
|
|
493
|
+
A placeholder expressing a directed graph with vertices of type `dtype` (without edge weights), represented by a 1-dimensional array of tuples.
|
|
494
|
+
|
|
495
|
+
A shorthand for `DecoratedProblem.Placeholder(dtype=(dtype, dtype), ndim=1)`.
|
|
496
|
+
By default `dtype` is `DataType.Natural` but can be specified.
|
|
497
|
+
"""
|
|
498
|
+
def DecisionVar(self, name:typing.Optional[builtins.str]=None, *, kind:DecisionVarKind, shape:typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]]=None, dict_keys:typing.Optional[DataType | type | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]=None, lower_bound:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict], upper_bound:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict], latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> DecisionVar:
|
|
499
|
+
r"""
|
|
500
|
+
Defines a :class:`DecisionVar` and registers it to the problem namespace.
|
|
501
|
+
|
|
502
|
+
Decision variables can be scalars, multi-dimensional arrays (eg. representing
|
|
503
|
+
arrays and matrices of variables), or total dictionaries.
|
|
504
|
+
|
|
505
|
+
Variables must have a `DecisionVarKind` (such as `BINARY`, `INTEGER`, `CONTINUOUS`),
|
|
506
|
+
as well as defined lower and upper bounds.
|
|
507
|
+
|
|
508
|
+
We recommend using alternative convenience methods which predefine the
|
|
509
|
+
decision variable's kind, such as `DecoratedProblem.IntegerVar` for integers, or
|
|
510
|
+
`DecoratedProblem.BinaryVar` for binary variables.
|
|
511
|
+
|
|
512
|
+
Representation
|
|
513
|
+
--------------
|
|
514
|
+
Depending on the arguments described below, the representation of the decision variable will be determined as follows:
|
|
515
|
+
|
|
516
|
+
1. If none of `shape` or `dict_keys` is provided, or `shape` is `()`, DecisionVar will be considered as a scalar value (= array of dimension 0).
|
|
517
|
+
2. If `shape` is provided and `dict_keys` is not provided, DecisionVar will be considered as a multi-dimensional array with fixed shape.
|
|
518
|
+
3. If `dict_keys` is provided without `shape`, DecisionVar will be considered as a dictionary-like structure with keys specified by `dict_keys`.
|
|
519
|
+
4. Otherwise, an error is raised.
|
|
520
|
+
|
|
521
|
+
Args
|
|
522
|
+
-----
|
|
523
|
+
- `name` (`str | None`): A name for the binary variable. If omitted, local variable name is used.
|
|
524
|
+
- `kind` (`DecisionVarKind`): A kind of the decision variable.
|
|
525
|
+
- `shape` (`list | tuple`): A sequence with the size of each dimension of the variable. Defaults to an empty tuple (a scalar value).
|
|
526
|
+
- Each item in `shape` must be a valid expression evaluating to a non-negative scalar.
|
|
527
|
+
- `dict_keys` (`tuple[Expression, ...]`, optional): If provided, specifies that this variable represents a dictionary-like structure with keys `dict_keys`.
|
|
528
|
+
- `lower_bound` and `upper_bound` (`jijmodeling.Expression`): A lower and upper bounds of the variable.
|
|
529
|
+
- `kind` (`DecisionVarKind`): The kind of the decision variable.
|
|
530
|
+
- `latex` (`str`, optional): An optional LaTeX representation to be used in Jupyter notebook.
|
|
531
|
+
- It is set to be the same as `name` by default.
|
|
532
|
+
- `description` (`str`, optional): An optional description, for user reference.
|
|
533
|
+
|
|
534
|
+
Examples
|
|
535
|
+
---------
|
|
536
|
+
Create a scalar binary variable whose name is "z".
|
|
537
|
+
|
|
538
|
+
```python
|
|
539
|
+
>>> import jijmodeling as jm
|
|
540
|
+
>>> problem = jm.Problem("my_problem")
|
|
541
|
+
>>> @problem.update
|
|
542
|
+
>>> def update(problem: DecoratedProblem):
|
|
543
|
+
>>> z = problem.DecisionVar(kind=jm.DecisionVarKind.BINARY, lower_bound=0, upper_bound=1)
|
|
544
|
+
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
Create a 2-dimensional binary variable whose name is "x" and has a 2x2 shape.
|
|
548
|
+
|
|
549
|
+
```python
|
|
550
|
+
>>> import jijmodeling as jm
|
|
551
|
+
>>> problem = jm.Problem("my_problem")
|
|
552
|
+
>>> @problem.update
|
|
553
|
+
>>> def update(problem: DecoratedProblem):
|
|
554
|
+
>>> z = problem.BinaryVar(shape=[2, 2])
|
|
555
|
+
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
Create a total dictionary of integer variables with the keys `(I, J, 5)`
|
|
559
|
+
|
|
560
|
+
```python
|
|
561
|
+
>>> import jijmodeling as jm
|
|
562
|
+
>>> problem = jm.Problem("my_problem")
|
|
563
|
+
>>> @problem.update
|
|
564
|
+
>>> def update(problem: DecoratedProblem):
|
|
565
|
+
>>> w = problem.IntegerVar(
|
|
566
|
+
>>> lower_bound=l,
|
|
567
|
+
>>> upper_bound=u,
|
|
568
|
+
>>> dict_keys=(I, J, 5)
|
|
569
|
+
>>> )
|
|
570
|
+
|
|
571
|
+
```
|
|
572
|
+
"""
|
|
573
|
+
def BinaryVar(self, name:typing.Optional[builtins.str]=None, *, shape:typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]]=None, dict_keys:typing.Optional[DataType | type | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]=None, latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> DecisionVar:
|
|
574
|
+
r"""
|
|
575
|
+
Defines a binary decision variable and registers it to the problem namespace. See `DecoratedProblem.DecisionVariable` for more details.
|
|
576
|
+
|
|
577
|
+
A shorthand for `DecoratedProblem.DecisionVariable(dtype=DecisionVarKind.BINARY,
|
|
578
|
+
lower_bound=0, upper_bound=1)`, provided for clarity and convenience.
|
|
579
|
+
|
|
580
|
+
Args
|
|
581
|
+
-----
|
|
582
|
+
- `name` (`str | None`): A name for the binary variable. If omitted, local variable name is used.
|
|
583
|
+
- `shape` (`list | tuple`): A sequence with the size of each dimension of the binary variable. Defaults to an empty tuple (a scalar value).
|
|
584
|
+
- Each item in `shape` must be a valid expression evaluating to a non-negative scalar.
|
|
585
|
+
- `dict_keys` (`tuple[Expression, ...]`, optional): If provided, specifies that this variable represents a dictionary-like structure with keys `dict_keys`.
|
|
586
|
+
- `latex` (`str`, optional): A LaTeX-name of the binary variable to be represented in Jupyter notebook.
|
|
587
|
+
- It is set to `name` by default.
|
|
588
|
+
- `description` (`str`, optional): A description of the binary variable.
|
|
589
|
+
"""
|
|
590
|
+
def IntegerVar(self, name:typing.Optional[builtins.str]=None, *, shape:typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]]=None, dict_keys:typing.Optional[DataType | type | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]=None, lower_bound:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict], upper_bound:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict], latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> DecisionVar:
|
|
591
|
+
r"""
|
|
592
|
+
Defines an integer decision variable and registers it to the problem namespace. See `DecoratedProblem.DecisionVar` for more details.
|
|
593
|
+
|
|
594
|
+
This is shorthand for `Problem.DecisionVariable(kind=DecisionVarKind.INTEGER)`.
|
|
595
|
+
|
|
596
|
+
Args
|
|
597
|
+
-----
|
|
598
|
+
- `name` (`str | None`): A name for the binary variable. If omitted, local variable name is used.
|
|
599
|
+
- `shape` (`list | tuple`): A sequence with the size of each dimension of the integer variable. Defaults to an empty tuple (a scalar value).
|
|
600
|
+
- Each item in `shape` must be a valid expression evaluating to a non-negative scalar.
|
|
601
|
+
- `dict_keys` (`tuple[Expression, ...]`, optional): If provided, specifies that this variable represents a dictionary-like structure with keys `dict_keys`.
|
|
602
|
+
- `lower_bound`: The lower bound of the variable.
|
|
603
|
+
- `upper_bound`: The upper bound of the variable.
|
|
604
|
+
- `latex` (`str`, optional): A LaTeX-name of the integer variable to be represented in Jupyter notebook.
|
|
605
|
+
- It is set to `name` by default.
|
|
606
|
+
- `description` (`str`, optional): A description of the integer variable.
|
|
607
|
+
|
|
608
|
+
Raises
|
|
609
|
+
-------
|
|
610
|
+
`ModelingError`: Raises if a bound is a `Placeholder` or `Subscript` object whose `ndim`
|
|
611
|
+
is neither `0` nor the same value as `ndim` of the integer variable.
|
|
612
|
+
"""
|
|
613
|
+
def SemiIntegerVar(self, name:typing.Optional[builtins.str]=None, *, shape:typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]]=None, dict_keys:typing.Optional[DataType | type | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]=None, lower_bound:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict], upper_bound:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict], latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> DecisionVar:
|
|
614
|
+
r"""
|
|
615
|
+
Defines a semi-integer decision variable and registers it to the problem namespace. See `DecoratedProblem.DecisionVar` for more details.
|
|
616
|
+
|
|
617
|
+
This is shorthand for `problem.DecisionVariable(kind=DecisionVarKind.SEMI_INTEGER)`.
|
|
618
|
+
"""
|
|
619
|
+
def ContinuousVar(self, name:typing.Optional[builtins.str]=None, *, shape:typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]]=None, dict_keys:typing.Optional[DataType | type | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]=None, lower_bound:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict], upper_bound:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict], latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> DecisionVar:
|
|
620
|
+
r"""
|
|
621
|
+
Defines a continuous decision variable and registers it to the problem namespace. See `Problem.DecisionVar` for more details.
|
|
622
|
+
|
|
623
|
+
This is shorthand for `problem.DecisionVariable(dtype=DecisionVarKind.CONTINUOUS)`.
|
|
624
|
+
|
|
625
|
+
Args
|
|
626
|
+
-----
|
|
627
|
+
- `name` (`str | None`): A name for the binary variable. If omitted, local variable name is used.
|
|
628
|
+
- `shape` (`list | tuple`): A sequence with the size of each dimension of the continuous variable. Defaults to an empty tuple (a scalar value).
|
|
629
|
+
- Each item in `shape` must be a valid expression evaluating to a non-negative scalar.
|
|
630
|
+
- `dict_keys` (`tuple[Expression, ...]`, optional): If provided, specifies that this variable represents a dictionary-like structure with keys `dict_keys`.
|
|
631
|
+
- `lower_bound`: The lower bound of the variable.
|
|
632
|
+
- `upper_bound`: The upper bound of the variable.
|
|
633
|
+
- `latex` (`str`, optional): A LaTeX-name of the continuous variable to be represented in Jupyter notebook.
|
|
634
|
+
- It is set to `name` by default.
|
|
635
|
+
- `description` (`str`, optional): A description of the continuous variable.
|
|
636
|
+
|
|
637
|
+
Raises
|
|
638
|
+
-------
|
|
639
|
+
`ModelingError`: Raises if a bound is a `Placeholder` or `Subscript` object whose `ndim` is neither `0` nor the same value as `ndim` of the continuous variable.
|
|
640
|
+
"""
|
|
641
|
+
def SemiContinuousVar(self, name:typing.Optional[builtins.str]=None, *, shape:typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]]=None, dict_keys:typing.Optional[DataType | type | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]=None, lower_bound:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict], upper_bound:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict], latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> DecisionVar: ...
|
|
642
|
+
def CategoryLabel(self, name:typing.Optional[builtins.str]=None, *, latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> CategoryLabel:
|
|
643
|
+
r"""
|
|
644
|
+
Add a new opaque category label to the namespace.
|
|
645
|
+
|
|
646
|
+
A category label corresponds to a set of labels representing some specific category (e.g. the name of percels, or the ids of factors, etc).
|
|
647
|
+
A value of category label is treated opaque in JijModeling, and can only be tested for equality / non-equality and used as keys in dictionary-like structures.
|
|
648
|
+
|
|
649
|
+
:class:`CategoryLabel` objects can be created via :meth:`Problem.CategoryLabel`.
|
|
650
|
+
The concrete values should be given in `instance_data` dictionary together with placeholder values when creating a :class:`Compiler` object or in `Problem.eval`.
|
|
651
|
+
In `instance_data`, category label should be given a list of either strings or integers.
|
|
652
|
+
///
|
|
653
|
+
Args
|
|
654
|
+
----
|
|
655
|
+
- `name` (`str | None`): A name for the category label. If omitted, local variable name is used.
|
|
656
|
+
- `latex` (`str`, optional): An optional LaTeX representation to be used in Jupyter notebook.
|
|
657
|
+
- When not provided, `name` is used by default.
|
|
658
|
+
- `description` (`str`, optional): An optional description for user reference.
|
|
659
|
+
"""
|
|
660
|
+
def used_placeholders(self) -> builtins.list[Placeholder]: ...
|
|
661
|
+
def get_problem_schema(self) -> dict:
|
|
662
|
+
r"""
|
|
663
|
+
Returns the schema of the problem.
|
|
664
|
+
|
|
665
|
+
Returns
|
|
666
|
+
--------
|
|
667
|
+
- `schema`: The dictionary containing the schema of the problem.
|
|
668
|
+
"""
|
|
669
|
+
def generate_random_dataset(self, _default:typing.Any, _options:typing.Any, _seed:typing.Optional[builtins.int]) -> typing.Any:
|
|
670
|
+
r"""
|
|
671
|
+
Generates a dictionary of random `InstanceDataValue` for a given problem.
|
|
672
|
+
To generate `ommx.v1.Instance` object directly, use `InstanceDataValue.generate_random_instance` instead.
|
|
673
|
+
|
|
674
|
+
Args
|
|
675
|
+
-----
|
|
676
|
+
- `options` (optional): a dictionary of range parameters for each separate placeholders. The key must be the name of the placeholder and the value must be range parameter (as described in "Range Parameters and Range Syntax" below).
|
|
677
|
+
- `default` (optional): default range parameters for placeholders which is not specified in `options`.
|
|
678
|
+
- `seed` (optional): seed for random number generation.
|
|
679
|
+
|
|
680
|
+
Returns
|
|
681
|
+
--------
|
|
682
|
+
`dict`: The dictionary from the name of placeholders to the generated `InstanceDataValue` objects. To be fed to `Interpreter.eval_problem`.
|
|
683
|
+
|
|
684
|
+
Range Parameters and Range Syntax
|
|
685
|
+
----------------------------------
|
|
686
|
+
A range parameter is a dictionary consisting of the following fields:
|
|
687
|
+
- `size` (optional): interval of natural numbers for the size of each array dimension (default: `range(1, 6)`)
|
|
688
|
+
- `value` (optional): interval of real numbers for the value of each array element (default: `range(-1.0, 1.0)` - a uniform distribution on a closed interval $[-1.0, 1.0]$).
|
|
689
|
+
|
|
690
|
+
Example range parameter config:
|
|
691
|
+
|
|
692
|
+
```python
|
|
693
|
+
{"size": range(2, 10), "value": jm.range.value.closed(100.0, 200.0)}
|
|
694
|
+
```
|
|
695
|
+
|
|
696
|
+
Intervals are expressed as a range object.
|
|
697
|
+
Currently, the following syntax is supported for range objects:
|
|
698
|
+
|
|
699
|
+
1. Direct value of type `int` or `float` - it corresponds to a singleton interval $[a, a] = \{a\}$. In random generation context, this just means a constant fixed value.
|
|
700
|
+
2. Use the functions from `jijmodeling.range`, `jijmodeling.range.size`, or `jijmodeling.range.value` modules.
|
|
701
|
+
- Use functions from `jij.modeling.range.size` to specify (non-negative) integer intervals, and `jij.modeling.range.value` for real intervals. `jij.modeling.range` dynamically determines the type of the range based on the input.
|
|
702
|
+
- These three modules provides the following combinators (see the module documents for more details.):
|
|
703
|
+
- `closed(a, b)`: a closed interval $[a, b]$
|
|
704
|
+
- `open(a, b)`: an open interval $(a, b)$
|
|
705
|
+
- `closed_open(a, b)`: an upper half-open interval $[a, b)$
|
|
706
|
+
- `open_closed(a, b)`: a lower half-open interval $(a, b]$
|
|
707
|
+
- `greater_than(a)`: an open interval $(a, \infty)$
|
|
708
|
+
- `at_least(a)`: a closed interval $[a, \infty)$
|
|
709
|
+
- `less_than(a)`: an open interval $(-\infty, a)$
|
|
710
|
+
- `at_most(a)`: a closed interval $(-\infty, a]$
|
|
711
|
+
3. Use `range` builtin function: this is equivalent to `jijmodeling.range.value.closed_open(a, b)`.
|
|
712
|
+
- Any python range object with `step = 1` can be used as a size range; otherwise it results in runtime error.
|
|
713
|
+
4. Use a tuple: raw tuple `(a, b)` is equivalent to `jijmodeling.range.closed_open(a, b)` if `a` and `b` are either `int` or `float`.
|
|
714
|
+
- You can also use bound object as a tuple component; in such case, both tuple components must be one of the following:
|
|
715
|
+
|
|
716
|
+
1. A string `"Unbounded"` means $-\infty$ (in the first component) or $\infty$ (the second).
|
|
717
|
+
2. A dictionary `{"Included": a}` means the endpoint is inclusive.
|
|
718
|
+
3. A dictionary `{"Excluded": a}` means the endpoint is exclusive.
|
|
719
|
+
- Examples:
|
|
720
|
+
- `(1.2, 4)` is equivalent to `closed_open(1.2, 4)`,
|
|
721
|
+
- `(-1, {"Included": 1})` is equivalent to `closed(-1, 1)`,
|
|
722
|
+
- `(-5, {"Excluded": 4})` is equivalent to `closed_open(-5, 4)` and built in function `range(-5, 4)`,
|
|
723
|
+
- `({"Excluded": 1}, {"Excluded": 2.5})` is equivalent to `open(1, 2.5)`,
|
|
724
|
+
- `({"Included": -1}, "Unbounded")` is equivalent to `at_least(-1)`.
|
|
725
|
+
- `(5, "Unbounded")` is **INVALID**; `5` must be bound object.
|
|
726
|
+
5. The range object: A dictionary of form `{"start": lb, "end": ub}`, where both `lb` and `ub` are the bound object described as above.
|
|
727
|
+
|
|
728
|
+
Examples
|
|
729
|
+
---------
|
|
730
|
+
```python
|
|
731
|
+
>>> import jijmodeling as jm
|
|
732
|
+
>>> import builtins
|
|
733
|
+
>>> N = jm.Placeholder("N", dtype=jm.DataType.INTEGER)
|
|
734
|
+
>>> c = jm.Placeholder("c", dtype=jm.DataType.FLOAT, shape=(N,))
|
|
735
|
+
>>> x = jm.BinaryVar("x", shape=(N,))
|
|
736
|
+
>>> i = jm.Element("i", belong_to=N)
|
|
737
|
+
|
|
738
|
+
>>> problem = jm.Problem("problem")
|
|
739
|
+
>>> problem += jm.sum(i, c[i] * x[i])
|
|
740
|
+
|
|
741
|
+
>>> inputs = problem.generate_random_dataset(
|
|
742
|
+
... options={
|
|
743
|
+
... 'N': {"value": builtins.range(10, 20)},
|
|
744
|
+
... 'c': {"value": jm.range.value.closed(-1.0, 1.0)}
|
|
745
|
+
... # You can also specify "size" for the range of jagged array dimension size.
|
|
746
|
+
... },
|
|
747
|
+
... seed=123 # omittable
|
|
748
|
+
... )
|
|
749
|
+
>>> assert set(inputs.keys()) == {"N", "c"}
|
|
750
|
+
>>> inputs
|
|
751
|
+
{'N': 11.0, 'c': array([ 0.93914459, -0.06511935, -0.7460324 , -0.32443706, 0.99981451,
|
|
752
|
+
-0.24407535, 0.31329469, 0.52206453, -0.1291936 , 0.30443087,
|
|
753
|
+
0.53125838])}
|
|
754
|
+
|
|
755
|
+
```
|
|
756
|
+
"""
|
|
757
|
+
def generate_random_instance(self, _default:typing.Any, _options:typing.Any, _seed:typing.Optional[builtins.int], _hints:typing.Optional[typing.Any]) -> typing.Any:
|
|
758
|
+
r"""
|
|
759
|
+
Generates random `ommx.v1.Instance` for a given problem.
|
|
760
|
+
See also `InstanceDataValue.generate_random_dataset`.
|
|
761
|
+
|
|
762
|
+
Args
|
|
763
|
+
-----
|
|
764
|
+
- `options` (optional): a dictionary of range parameters for each separate placeholders. The key must be the name of the placeholder and the value must be range parameter (as described in "Range Parameters and Range Syntax" section in :func:`~jijmodeling.Problem.generate_random_dataset`).
|
|
765
|
+
- `default` (optional): default range parameters for placeholders which is not specified in `options`.
|
|
766
|
+
- `seed` (optional): seed for random number generation.
|
|
767
|
+
- `hints` (optional): the hints to be detected during compilation see `Interpreter.eval_problem` for more details.
|
|
768
|
+
|
|
769
|
+
Returns
|
|
770
|
+
--------
|
|
771
|
+
`instance`: The OMMX v1 instance object.
|
|
772
|
+
|
|
773
|
+
Examples
|
|
774
|
+
---------
|
|
775
|
+
```python
|
|
776
|
+
>>> import jijmodeling as jm
|
|
777
|
+
>>> import builtins
|
|
778
|
+
>>> import ommx.v1
|
|
779
|
+
>>> N = jm.Placeholder("N", dtype=jm.DataType.INTEGER)
|
|
780
|
+
>>> c = jm.Placeholder("c", dtype=jm.DataType.FLOAT, shape=(N,))
|
|
781
|
+
>>> x = jm.BinaryVar("x", shape=(N,))
|
|
782
|
+
>>> i = jm.Element("i", belong_to=N)
|
|
783
|
+
|
|
784
|
+
>>> problem = jm.Problem("problem")
|
|
785
|
+
>>> problem += jm.sum(i, c[i] * x[i])
|
|
786
|
+
|
|
787
|
+
>>> instance = problem.generate_random_instance(
|
|
788
|
+
... options={
|
|
789
|
+
... 'N': {"value": builtins.range(10, 20)},
|
|
790
|
+
... 'c': {"value": jm.range.value.closed(-1.0, 1.0)}
|
|
791
|
+
... },
|
|
792
|
+
... seed=123
|
|
793
|
+
... )
|
|
794
|
+
>>> assert type(instance) is ommx.v1.Instance
|
|
795
|
+
|
|
796
|
+
```
|
|
797
|
+
"""
|
|
798
|
+
def type_of(self, name:builtins.str) -> Type:
|
|
799
|
+
r"""
|
|
800
|
+
Returns the type associated with a given name (eg. of a placeholder or decision variable).
|
|
801
|
+
|
|
802
|
+
This is mostly inteded for testing purposes, and not as part of standard model writing.
|
|
803
|
+
|
|
804
|
+
:raises ModelingError: If the name is undefined in this problem's namespace.
|
|
805
|
+
"""
|
|
806
|
+
def infer(self, expr:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Type:
|
|
807
|
+
r"""
|
|
808
|
+
Infers the resulting type of an expression using this problem as a namespace.
|
|
809
|
+
|
|
810
|
+
This is mostly intended for testing purposes, and not as part of standard model writing.
|
|
811
|
+
|
|
812
|
+
Examples
|
|
813
|
+
===
|
|
814
|
+
```python
|
|
815
|
+
>>> problem = jm.Problem("MyProblem")
|
|
816
|
+
>>> N = problem.Length(name="N")
|
|
817
|
+
>>> x = problem.BinaryVar("x", shape=(N,))
|
|
818
|
+
>>> y = problem.IntegerVar("y", shape=(N,), lower_bound=0,upper_bound=10)
|
|
819
|
+
>>> problem.infer(jm.sum(x))
|
|
820
|
+
binary!
|
|
821
|
+
>>> problem.infer(jm.sum(y))
|
|
822
|
+
int!
|
|
823
|
+
```
|
|
824
|
+
"""
|
|
825
|
+
def decision_vars(self) -> builtins.dict[builtins.str, DecisionVar]:
|
|
826
|
+
r"""
|
|
827
|
+
Returns a dictionary of decision variables in the problem.
|
|
828
|
+
|
|
829
|
+
Returns
|
|
830
|
+
--------
|
|
831
|
+
`dict[str, DecisionVar]`: Dictionary mapping variable names to DecisionVar objects.
|
|
832
|
+
"""
|
|
833
|
+
def placeholders(self) -> builtins.dict[builtins.str, Placeholder]:
|
|
834
|
+
r"""
|
|
835
|
+
Returns a dictionary of placeholders in the problem.
|
|
836
|
+
The dictionary may contain placeholders that are not used in the problem;
|
|
837
|
+
to get only used placeholders, use `used_placeholders` method.
|
|
838
|
+
|
|
839
|
+
Returns
|
|
840
|
+
--------
|
|
841
|
+
`dict[str, Placeholder]`: Dictionary mapping placeholder names to Placeholder objects.
|
|
842
|
+
"""
|
|
843
|
+
@typing.overload
|
|
844
|
+
def Constraint(self, name:builtins.str, expressions:typing.Generator[Expression], description:typing.Optional[builtins.str]=None) -> Constraint:
|
|
845
|
+
r"""
|
|
846
|
+
Comprehension syntax for jm.prod (NOTE: only works with decorated API!)
|
|
847
|
+
"""
|
|
848
|
+
@typing.overload
|
|
849
|
+
def Constraint(self, name:builtins.str, expression:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict, description:typing.Optional[builtins.str]=None) -> Constraint:
|
|
850
|
+
r"""
|
|
851
|
+
Constructs `Constraint` object from comparison expression, __WITHOUT__ registering it to the problem.
|
|
852
|
+
Use `+=` operator to register the constraint to the problem.
|
|
853
|
+
"""
|
|
854
|
+
@typing.overload
|
|
855
|
+
def Constraint(self, name:builtins.str, expression:typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any], domain:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict, description:typing.Optional[builtins.str]=None) -> Constraint:
|
|
856
|
+
r"""
|
|
857
|
+
Constructs ``Constraint`` family with the index set ``domain`` and function ``expression`` to build comparison expression from each index, __WITHOUT__ registering it to the problem.
|
|
858
|
+
Use `+=` operator to register the constraint to the problem.
|
|
859
|
+
"""
|
|
860
|
+
|
|
861
|
+
@typing.final
|
|
862
|
+
class DesugaredProblemBuilder:
|
|
863
|
+
def __call__(self) -> None: ...
|
|
864
|
+
|
|
865
|
+
@typing.final
|
|
866
|
+
class Expression:
|
|
867
|
+
r"""
|
|
868
|
+
Any expression in Python.
|
|
869
|
+
"""
|
|
870
|
+
def _repr_latex_(self) -> builtins.str: ...
|
|
871
|
+
def __call__(self, *args) -> Expression: ...
|
|
872
|
+
def shape(self) -> Expression: ...
|
|
873
|
+
def len_at(self, axis:builtins.int) -> Expression: ...
|
|
874
|
+
def __repr__(self) -> builtins.str: ...
|
|
875
|
+
def or_else(self, default:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression:
|
|
876
|
+
r"""
|
|
877
|
+
Returns the value inside `option` if `Some`, otherwise returns `default`.
|
|
878
|
+
"""
|
|
879
|
+
def map_or_else(self, default:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict, mapper:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression:
|
|
880
|
+
r"""
|
|
881
|
+
If self is `Some(value)`, applies `mapper(value)`, otherwise returns `default`.
|
|
882
|
+
"""
|
|
883
|
+
@typing.overload
|
|
884
|
+
def max(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression:
|
|
885
|
+
r"""
|
|
886
|
+
Return the larger of this expression and rhs.
|
|
887
|
+
"""
|
|
888
|
+
@typing.overload
|
|
889
|
+
def max(self) -> Expression:
|
|
890
|
+
r"""
|
|
891
|
+
Return the maximum element of this foldable expression.
|
|
892
|
+
"""
|
|
893
|
+
@typing.overload
|
|
894
|
+
def min(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression:
|
|
895
|
+
r"""
|
|
896
|
+
Return the smaller of this expression and rhs.
|
|
897
|
+
"""
|
|
898
|
+
@typing.overload
|
|
899
|
+
def min(self) -> Expression:
|
|
900
|
+
r"""
|
|
901
|
+
Return the minimum element of this foldable expression.
|
|
902
|
+
"""
|
|
903
|
+
def __pow__(self, exponent:typing.Any, modulo:typing.Optional[typing.Any]=None) -> Expression: ...
|
|
904
|
+
def __rpow__(self, base:typing.Any, modulo:typing.Optional[typing.Any]=None) -> Expression: ...
|
|
905
|
+
def __add__(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
906
|
+
def __radd__(self, lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
907
|
+
def __sub__(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
908
|
+
def __rsub__(self, lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
909
|
+
def __mul__(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
910
|
+
def __rmul__(self, lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
911
|
+
def __truediv__(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
912
|
+
def __rtruediv__(self, lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
913
|
+
def __mod__(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
914
|
+
def __rmod__(self, lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
915
|
+
def __neg__(self) -> Expression: ...
|
|
916
|
+
def abs(self) -> Expression: ...
|
|
917
|
+
def sqrt(self) -> Expression: ...
|
|
918
|
+
def sin(self) -> Expression: ...
|
|
919
|
+
def cos(self) -> Expression: ...
|
|
920
|
+
def tan(self) -> Expression: ...
|
|
921
|
+
def asin(self) -> Expression: ...
|
|
922
|
+
def acos(self) -> Expression: ...
|
|
923
|
+
def atan(self) -> Expression: ...
|
|
924
|
+
def sinh(self) -> Expression: ...
|
|
925
|
+
def cosh(self) -> Expression: ...
|
|
926
|
+
def tanh(self) -> Expression: ...
|
|
927
|
+
def asinh(self) -> Expression: ...
|
|
928
|
+
def acosh(self) -> Expression: ...
|
|
929
|
+
def atanh(self) -> Expression: ...
|
|
930
|
+
def exp(self) -> Expression: ...
|
|
931
|
+
def ln(self) -> Expression: ...
|
|
932
|
+
def log10(self) -> Expression: ...
|
|
933
|
+
def log2(self) -> Expression: ...
|
|
934
|
+
def ceil(self) -> Expression: ...
|
|
935
|
+
def floor(self) -> Expression: ...
|
|
936
|
+
def keys(self) -> Expression: ...
|
|
937
|
+
def values(self) -> Expression: ...
|
|
938
|
+
def items(self) -> Expression: ...
|
|
939
|
+
def map(self, func:typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any]) -> Expression: ...
|
|
940
|
+
def roll(self, shift:typing.Any, *, axis:typing.Optional[builtins.int]=None) -> Expression: ...
|
|
941
|
+
def filter(self, predicate:typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any]) -> Expression: ...
|
|
942
|
+
def flat_map(self, func:typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any]) -> Expression: ...
|
|
943
|
+
def rows(self) -> Expression: ...
|
|
944
|
+
def __getitem__(self, subscripts:typing.Any) -> Expression: ...
|
|
945
|
+
def sum(self, axis:typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | builtins.int | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict] | typing.Sequence[builtins.int]]=None) -> Expression: ...
|
|
946
|
+
def prod(self, axis:typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | builtins.int | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict] | typing.Sequence[builtins.int]]=None) -> Expression: ...
|
|
947
|
+
def __and__(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
948
|
+
def __rand__(self, lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
949
|
+
def __or__(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
950
|
+
def __ror__(self, lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
951
|
+
def __xor__(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
952
|
+
def __rxor__(self, lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
953
|
+
def diff(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
954
|
+
def bnot(self) -> Expression: ...
|
|
955
|
+
def __eq__(self, other:typing.Any) -> Expression: ... # type: ignore[reportIncompatibleMethodOverride]
|
|
956
|
+
def __ne__(self, other:typing.Any) -> Expression: ... # type: ignore[reportIncompatibleMethodOverride]
|
|
957
|
+
def __lt__(self, other:typing.Any) -> Expression: ...
|
|
958
|
+
def __le__(self, other:typing.Any) -> Expression: ...
|
|
959
|
+
def __gt__(self, other:typing.Any) -> Expression: ...
|
|
960
|
+
def __ge__(self, other:typing.Any) -> Expression: ...
|
|
961
|
+
|
|
962
|
+
class ModelingError(builtins.Exception):
|
|
9
963
|
...
|
|
10
964
|
|
|
11
|
-
|
|
965
|
+
@typing.final
|
|
966
|
+
class Namespace:
|
|
967
|
+
def __new__(cls) -> Namespace: ...
|
|
968
|
+
@staticmethod
|
|
969
|
+
def from_problem(problem:Problem) -> Namespace: ...
|
|
970
|
+
def add_category_label(self, label:CategoryLabel) -> None:
|
|
971
|
+
r"""
|
|
972
|
+
Add a new opaque category label to the namespace.
|
|
973
|
+
"""
|
|
974
|
+
def add_placeholder(self, placeholder:Placeholder) -> None: ...
|
|
975
|
+
def Placeholder(self, name:builtins.str, *, ndim:typing.Optional[builtins.int]=None, shape:typing.Optional[typing.Sequence[typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]]]=None, dtype:DataType | type | tuple=DataType.FLOAT, jagged:builtins.bool=False, latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> Placeholder: ...
|
|
976
|
+
def add_decision_var(self, var:DecisionVar) -> None: ...
|
|
977
|
+
def type_of(self, name:builtins.str) -> typing.Optional[Type]: ...
|
|
978
|
+
def infer(self, expr:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Type: ...
|
|
979
|
+
|
|
980
|
+
@typing.final
|
|
981
|
+
class Placeholder:
|
|
982
|
+
r"""
|
|
983
|
+
A spec of a placeholder value.
|
|
984
|
+
|
|
985
|
+
This class represents a symbol of unspecified value, which is maintained in namespace (i.e. :class:`Problem`).
|
|
986
|
+
This symbol is to be replaced by a numerical value when you evaluate an optimization problem before solving it.
|
|
987
|
+
|
|
988
|
+
Use `Problem.Placeholder` and their shorthands (e.g., `Problem.Integer`, `Problem.Float`, etc.) to create placeholders.
|
|
989
|
+
|
|
990
|
+
Expressions on Placeholder automatically turns into an `Expression` object.
|
|
991
|
+
|
|
992
|
+
Attributes
|
|
993
|
+
-----------
|
|
994
|
+
- `name` (`str`): A name of the placeholder.
|
|
995
|
+
- `dtype` (`DataType`, optional): The data type (eg. `DataType.INT` or `DataType.FLOAT`) of the placeholder.
|
|
996
|
+
- `ndim` (`int`): The number of dimensions of the placeholder.
|
|
997
|
+
- `shape` (`tuple` of `Optional[Expression]`, optional): The (partial) shape of the placeholder if given.
|
|
998
|
+
- `jagged` (`boolean`, defaut: `False`): `True` if the placeholder will be treated as a jagged array in random data generation. Ignored for scalars.
|
|
999
|
+
- `dict_keys` (`DictKeySpec`): The specification of dictionary keys if the placeholder is a dictionary type.
|
|
1000
|
+
- `partial_dict` (`bool`, default: `False`): `True` if the placeholder is a partial dictionary. Ignored if `dict_keys` is not given.
|
|
1001
|
+
- `description` (`str`, optional): A description for user reference.
|
|
1002
|
+
|
|
1003
|
+
Raises
|
|
1004
|
+
-------
|
|
1005
|
+
- `TypeError`: Raises if set a float value to `ndim`.
|
|
1006
|
+
- `OverflowError`: Raises if set a negative value to `ndim`.
|
|
1007
|
+
|
|
1008
|
+
Examples
|
|
1009
|
+
---------
|
|
1010
|
+
Create a scalar (or `ndim` is `0`) placeholder whose name is "a".
|
|
1011
|
+
|
|
1012
|
+
```python
|
|
1013
|
+
>>> import jijmodeling as jm
|
|
1014
|
+
>>> problem = jm.Problem("example")
|
|
1015
|
+
>>> a = problem.Placeholder("a", dtype=float)
|
|
1016
|
+
|
|
1017
|
+
```
|
|
1018
|
+
|
|
1019
|
+
Create a 2-dimensional integer placeholder whose name is "m".
|
|
1020
|
+
|
|
1021
|
+
```python
|
|
1022
|
+
>>> import jijmodeling as jm
|
|
1023
|
+
>>> problem = jm.Problem("example")
|
|
1024
|
+
>>> m = problem.Integer("m", ndim=2)
|
|
1025
|
+
|
|
1026
|
+
```
|
|
1027
|
+
|
|
1028
|
+
Create a 1-dimensional natural number placeholder with the index of `123`.
|
|
1029
|
+
|
|
1030
|
+
```python
|
|
1031
|
+
>>> import jijmodeling as jm
|
|
1032
|
+
>>> problem = jm.Problem("example")
|
|
1033
|
+
>>> a = problem.Natural("a", ndim=2)
|
|
1034
|
+
>>> a[123]
|
|
1035
|
+
a[123]
|
|
1036
|
+
>>> problem.get_placeholder("a")
|
|
1037
|
+
Placeholder(name='a', ndim=2, shape=None, dtype=typing.float, jagged=False)
|
|
1038
|
+
```
|
|
1039
|
+
"""
|
|
1040
|
+
@property
|
|
1041
|
+
def name(self) -> builtins.str: ...
|
|
1042
|
+
@property
|
|
1043
|
+
def ndim(self) -> typing.Optional[builtins.int]:
|
|
1044
|
+
r"""
|
|
1045
|
+
The number of dimensions in this placeholder. 0 for scalars.
|
|
1046
|
+
"""
|
|
1047
|
+
@property
|
|
1048
|
+
def shape(self) -> typing.Optional[typing.Tuple[Expression,...]]:
|
|
1049
|
+
r"""
|
|
1050
|
+
Get the shape tuple of the placeholder, consisting of `Expression`s.
|
|
1051
|
+
|
|
1052
|
+
See also `Placeholder.shape_spec` property to get the original value
|
|
1053
|
+
given at the declaration time.
|
|
1054
|
+
|
|
1055
|
+
## Difference between `Placeholder.shape` and `Placeholder.shape_spec`
|
|
1056
|
+
|
|
1057
|
+
- `Placeholder.shape` property always returns a tuple of `Expression`s,
|
|
1058
|
+
filling `None` with `len_at` expressions so that i-th component
|
|
1059
|
+
coincides with the value of `ph.len_at(i)`
|
|
1060
|
+
- `Placeholder.shape_spec` just returns the original `shape` definition,
|
|
1061
|
+
hence the spec itself can be `None` or contain `None` components.
|
|
1062
|
+
|
|
1063
|
+
## Use cases
|
|
1064
|
+
|
|
1065
|
+
- use `Placeholder.shape` property if you want to construct expressions involving the shape of the placeholder.
|
|
1066
|
+
- use `Placeholder.shape_spec` property if you want to inspect the very definition of the placeholder.
|
|
1067
|
+
"""
|
|
1068
|
+
@property
|
|
1069
|
+
def shape_spec(self) -> typing.Optional[typing.Tuple[typing.Optional[Expression],...]]:
|
|
1070
|
+
r"""
|
|
1071
|
+
Get the original definition of shape given at the declaration time, possibly `None` if omitted.
|
|
1072
|
+
See also `Placeholder.shape` property to get the shape as `Expression`s.
|
|
1073
|
+
|
|
1074
|
+
## Difference between `Placeholder.shape` and `Placeholder.shape_spec`
|
|
1075
|
+
|
|
1076
|
+
- `Placeholder.shape` property always returns a tuple of `Expression`s,
|
|
1077
|
+
filling `None` with `len_at` expressions so that i-th component
|
|
1078
|
+
coincides with the value of `ph.len_at(i)`
|
|
1079
|
+
- `Placeholder.shape_spec` just returns the original `shape` definition,
|
|
1080
|
+
hence the spec itself can be `None` or contain `None` components.
|
|
1081
|
+
|
|
1082
|
+
## Use cases
|
|
1083
|
+
|
|
1084
|
+
- use `Placeholder.shape_spec` property if you want to inspect the very definition of the placeholder.
|
|
1085
|
+
- use `Placeholder.shape` property if you want to construct expressions involving the shape of the placeholder.
|
|
1086
|
+
"""
|
|
1087
|
+
@property
|
|
1088
|
+
def dtype(self) -> DataType | type | tuple:
|
|
1089
|
+
r"""
|
|
1090
|
+
This placeholder's data type (natural, integer, float, etc.)
|
|
1091
|
+
"""
|
|
1092
|
+
@property
|
|
1093
|
+
def jagged(self) -> builtins.bool: ...
|
|
1094
|
+
@property
|
|
1095
|
+
def description(self) -> typing.Optional[builtins.str]: ...
|
|
1096
|
+
@property
|
|
1097
|
+
def custom_latex(self) -> typing.Optional[builtins.str]: ...
|
|
1098
|
+
def __repr__(self) -> builtins.str: ...
|
|
1099
|
+
def _repr_latex_(self) -> builtins.str: ...
|
|
1100
|
+
def len_at(self, index:builtins.int) -> Expression:
|
|
1101
|
+
r"""
|
|
1102
|
+
Returns an expression representing the length (number of values) a placeholder
|
|
1103
|
+
has at a given dimension (0-indexed).
|
|
1104
|
+
|
|
1105
|
+
This can be used, for example, when trying to match the shape of
|
|
1106
|
+
an object to the number of values in an array.
|
|
1107
|
+
|
|
1108
|
+
Examples
|
|
1109
|
+
------
|
|
1110
|
+
|
|
1111
|
+
```python
|
|
1112
|
+
>>> problem = jm.Problem("MyProblem")
|
|
1113
|
+
>>> V = problem.Integer(name="V", ndim=1)
|
|
1114
|
+
>>> N = V.len_at(0)
|
|
1115
|
+
>>> x = problem.BinaryVar("x", shape=(N,))
|
|
1116
|
+
```
|
|
1117
|
+
"""
|
|
1118
|
+
@typing.overload
|
|
1119
|
+
def max(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression:
|
|
1120
|
+
r"""
|
|
1121
|
+
Return the larger of this expression and rhs.
|
|
1122
|
+
"""
|
|
1123
|
+
@typing.overload
|
|
1124
|
+
def max(self) -> Expression:
|
|
1125
|
+
r"""
|
|
1126
|
+
Return the maximum element of this foldable expression.
|
|
1127
|
+
"""
|
|
1128
|
+
@typing.overload
|
|
1129
|
+
def min(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression:
|
|
1130
|
+
r"""
|
|
1131
|
+
Return the smaller of this expression and rhs.
|
|
1132
|
+
"""
|
|
1133
|
+
@typing.overload
|
|
1134
|
+
def min(self) -> Expression:
|
|
1135
|
+
r"""
|
|
1136
|
+
Return the minimum element of this foldable expression.
|
|
1137
|
+
"""
|
|
1138
|
+
def __pow__(self, exponent:typing.Any, modulo:typing.Optional[typing.Any]=None) -> Expression: ...
|
|
1139
|
+
def __rpow__(self, base:typing.Any, modulo:typing.Optional[typing.Any]=None) -> Expression: ...
|
|
1140
|
+
def __add__(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1141
|
+
def __radd__(self, lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1142
|
+
def __sub__(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1143
|
+
def __rsub__(self, lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1144
|
+
def __mul__(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1145
|
+
def __rmul__(self, lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1146
|
+
def __truediv__(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1147
|
+
def __rtruediv__(self, lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1148
|
+
def __mod__(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1149
|
+
def __rmod__(self, lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1150
|
+
def __neg__(self) -> Expression: ...
|
|
1151
|
+
def abs(self) -> Expression: ...
|
|
1152
|
+
def sqrt(self) -> Expression: ...
|
|
1153
|
+
def sin(self) -> Expression: ...
|
|
1154
|
+
def cos(self) -> Expression: ...
|
|
1155
|
+
def tan(self) -> Expression: ...
|
|
1156
|
+
def asin(self) -> Expression: ...
|
|
1157
|
+
def acos(self) -> Expression: ...
|
|
1158
|
+
def atan(self) -> Expression: ...
|
|
1159
|
+
def sinh(self) -> Expression: ...
|
|
1160
|
+
def cosh(self) -> Expression: ...
|
|
1161
|
+
def tanh(self) -> Expression: ...
|
|
1162
|
+
def asinh(self) -> Expression: ...
|
|
1163
|
+
def acosh(self) -> Expression: ...
|
|
1164
|
+
def atanh(self) -> Expression: ...
|
|
1165
|
+
def exp(self) -> Expression: ...
|
|
1166
|
+
def ln(self) -> Expression: ...
|
|
1167
|
+
def log10(self) -> Expression: ...
|
|
1168
|
+
def log2(self) -> Expression: ...
|
|
1169
|
+
def ceil(self) -> Expression: ...
|
|
1170
|
+
def floor(self) -> Expression: ...
|
|
1171
|
+
def keys(self) -> Expression: ...
|
|
1172
|
+
def values(self) -> Expression: ...
|
|
1173
|
+
def items(self) -> Expression: ...
|
|
1174
|
+
def map(self, func:typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any]) -> Expression: ...
|
|
1175
|
+
def roll(self, shift:typing.Any, *, axis:typing.Optional[builtins.int]=None) -> Expression: ...
|
|
1176
|
+
def filter(self, predicate:typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any]) -> Expression: ...
|
|
1177
|
+
def flat_map(self, func:typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any]) -> Expression: ...
|
|
1178
|
+
def rows(self) -> Expression: ...
|
|
1179
|
+
def __getitem__(self, subscripts:typing.Any) -> Expression: ...
|
|
1180
|
+
def sum(self, axis:typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | builtins.int | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict] | typing.Sequence[builtins.int]]=None) -> Expression: ...
|
|
1181
|
+
def prod(self, axis:typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | builtins.int | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict] | typing.Sequence[builtins.int]]=None) -> Expression: ...
|
|
1182
|
+
def __and__(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1183
|
+
def __rand__(self, lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1184
|
+
def __or__(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1185
|
+
def __ror__(self, lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1186
|
+
def __xor__(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1187
|
+
def __rxor__(self, lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1188
|
+
def diff(self, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1189
|
+
def bnot(self) -> Expression: ...
|
|
1190
|
+
def __eq__(self, other:typing.Any) -> Expression: ... # type: ignore[reportIncompatibleMethodOverride]
|
|
1191
|
+
def __ne__(self, other:typing.Any) -> Expression: ... # type: ignore[reportIncompatibleMethodOverride]
|
|
1192
|
+
def __lt__(self, other:typing.Any) -> Expression: ...
|
|
1193
|
+
def __le__(self, other:typing.Any) -> Expression: ...
|
|
1194
|
+
def __gt__(self, other:typing.Any) -> Expression: ...
|
|
1195
|
+
def __ge__(self, other:typing.Any) -> Expression: ...
|
|
1196
|
+
|
|
1197
|
+
@typing.final
|
|
1198
|
+
class Problem:
|
|
1199
|
+
r"""
|
|
1200
|
+
A class for creating an optimization problem.
|
|
1201
|
+
|
|
1202
|
+
Attributes
|
|
1203
|
+
-----------
|
|
1204
|
+
- `name` (`str`): A name of the optimization problem.
|
|
1205
|
+
- `sense` (`ProblemSense`): Sense of the optimization problem.
|
|
1206
|
+
- `objective`: The objective function of the optimization problem.
|
|
1207
|
+
- `constraints` (`dict`): A dictionary that stores constraints.
|
|
1208
|
+
- A key is the name of a constraint and the value is the constraint object.
|
|
1209
|
+
|
|
1210
|
+
Args
|
|
1211
|
+
-----
|
|
1212
|
+
- `name` (`str`): A name of the optimization problem.
|
|
1213
|
+
- `sense` (optional): Sense of the optimization problem. Defaults to `ProblemSense.MINIMIZE`.
|
|
1214
|
+
- `description` (`str`, optional): An optional description of the problem, for user reference.
|
|
1215
|
+
"""
|
|
1216
|
+
@property
|
|
1217
|
+
def objective(self) -> Expression: ...
|
|
1218
|
+
@property
|
|
1219
|
+
def description(self) -> builtins.str:
|
|
1220
|
+
r"""
|
|
1221
|
+
The problem description.
|
|
1222
|
+
|
|
1223
|
+
An empty string if no description was defined.
|
|
1224
|
+
"""
|
|
1225
|
+
@property
|
|
1226
|
+
def constraints(self) -> builtins.dict[builtins.str, builtins.list[Constraint]]:
|
|
1227
|
+
r"""
|
|
1228
|
+
Returns a dictionary of the constraints in the problem.
|
|
1229
|
+
|
|
1230
|
+
Returns
|
|
1231
|
+
--------
|
|
1232
|
+
`dict[str, [Constraint]]`: Dictionary mapping constraint names to Constraint objects.
|
|
1233
|
+
"""
|
|
1234
|
+
@property
|
|
1235
|
+
def used_placeholders(self) -> builtins.list[Placeholder]: ...
|
|
1236
|
+
@property
|
|
1237
|
+
def decision_vars(self) -> builtins.dict[builtins.str, DecisionVar]:
|
|
1238
|
+
r"""
|
|
1239
|
+
Returns a dictionary of decision variables in the problem.
|
|
1240
|
+
The dictionary may contain decision variables that are not used in the problem.
|
|
1241
|
+
|
|
1242
|
+
Returns
|
|
1243
|
+
--------
|
|
1244
|
+
`dict[str, DecisionVar]`: Dictionary mapping variable names to DecisionVar objects.
|
|
1245
|
+
"""
|
|
1246
|
+
@property
|
|
1247
|
+
def placeholders(self) -> builtins.dict[builtins.str, Placeholder]:
|
|
1248
|
+
r"""
|
|
1249
|
+
Returns a dictionary of placeholders in the problem.
|
|
1250
|
+
The dictionary may contain placeholders that are not used in the problem;
|
|
1251
|
+
to get only used placeholders, use `used_placeholders` method.
|
|
1252
|
+
|
|
1253
|
+
Returns
|
|
1254
|
+
--------
|
|
1255
|
+
`dict[str, Placeholder]`: Dictionary mapping placeholder names to Placeholder objects.
|
|
1256
|
+
"""
|
|
1257
|
+
@typing.overload
|
|
1258
|
+
def __iadd__(self, other:Constraint) -> Problem:
|
|
1259
|
+
r"""
|
|
1260
|
+
Add constraint to the problem.
|
|
1261
|
+
"""
|
|
1262
|
+
@typing.overload
|
|
1263
|
+
def __iadd__(self, other:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Problem:
|
|
1264
|
+
r"""
|
|
1265
|
+
Add an expression as a term to the objective function of the problem.
|
|
1266
|
+
"""
|
|
1267
|
+
def __repr__(self) -> builtins.str: ...
|
|
1268
|
+
def _repr_latex_(self) -> builtins.str: ...
|
|
1269
|
+
def eval(self, instance_data:typing.Mapping[builtins.str, builtins.int | builtins.float | numpy.typing.NDArray[numpy.float64] | numpy.typing.NDArray[numpy.int64] | list | dict | builtins.str]) -> ommx.v1.Instance:
|
|
1270
|
+
r"""
|
|
1271
|
+
Compiles and evaluates the problem given the specified instance data, returning an OMMX instance.
|
|
1272
|
+
|
|
1273
|
+
A short-hand of `Compiler.from_problem(self, data).eval_problem(self)`.
|
|
1274
|
+
|
|
1275
|
+
Args
|
|
1276
|
+
----
|
|
1277
|
+
- `instance_data` (`dict[str, InstanceValue]`): A dictionary mapping placeholder and category label names to their corresponding values for this instance. See :class:`Compiler` for more details on the expected format of `instance_data`.
|
|
1278
|
+
"""
|
|
1279
|
+
def Placeholder(self, name:builtins.str, *, dtype:DataType | type | tuple, ndim:typing.Optional[builtins.int]=None, shape:typing.Optional[typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict] | typing.Sequence[typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]]]=None, jagged:builtins.bool=False, dict_keys:typing.Optional[DataType | type | CategoryLabel | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | tuple]=None, partial_dict:typing.Optional[builtins.bool]=None, latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> Placeholder:
|
|
1280
|
+
r"""
|
|
1281
|
+
Defines a :class:`Placeholder` in this problem's namespace.
|
|
1282
|
+
|
|
1283
|
+
Placeholders can be a scalar, multi-dimensional array (representing arrays and
|
|
1284
|
+
matrices), or dictionary keyed by integers or strings.
|
|
1285
|
+
|
|
1286
|
+
When calling `Problem.Placehoder`, you must specify `dtype` explicitly to indicate the type of data the placeholder holds.
|
|
1287
|
+
Alternative shorthand methods like `Problem.Integer`, `Problem.Binary`,
|
|
1288
|
+
or `Problem.Natural` are recommended for convenience in their specific
|
|
1289
|
+
use cases.
|
|
1290
|
+
|
|
1291
|
+
Representation
|
|
1292
|
+
--------------
|
|
1293
|
+
Depending on the arguments described below, the representation of the placeholder will be determined as follows:
|
|
1294
|
+
|
|
1295
|
+
1. If none none of `ndim`, `shape`, `jagged`, `dict_keys`, or `partial_dict` is provided, or, `ndim` is set to zero, Placeholder will be considered as a scalar value (= array of dimension 0).
|
|
1296
|
+
2. If either (or both consistently) of `ndim` or `shape` is provided and `jagged` is `False` (or omitted), and none of `dict_keys` or `partial_dict` is given, Placeholder will be considered as a multi-dimensional array with fixed shape.
|
|
1297
|
+
3. If either (or both consistently), of `ndim` or `shape` is provided and `jagged` is `True`, and none of `dict_keys` or `partial_dict` is given,Placeholder will be considered as a jagged array (i.e. a non-rectangular ndim array).
|
|
1298
|
+
4. If `dict_keys` is specified but none of `ndim`, `shape`, `jagged` is provided, then Placeholder will be considered as a total dictionary-like structure with keys specified by `dict_keys`.
|
|
1299
|
+
5. If both `dict_keys` and `partial_dict` (set to `True`) are specified, and none of `ndim`, `shape`, or `jagged` is provided, then Placeholder will be considered as a partial dictionary-like structure with keys specified by `dict_keys`.
|
|
1300
|
+
6. Otherwise, an error is raised.
|
|
1301
|
+
|
|
1302
|
+
Args
|
|
1303
|
+
-----
|
|
1304
|
+
- `name` (`str`): The placeholder's name
|
|
1305
|
+
- `dtype` (`DataType`): The type of data this placeholder holds (integer, floating point, etc.).
|
|
1306
|
+
- `ndim` (`int`): The number of dimensions in this placeholder. Defaults to 0 (a scalar value).
|
|
1307
|
+
- `shape` (`list | tuple`): A sequence with the size of each dimension of the placeholder. Defaults to an empty tuple (a scalar value).
|
|
1308
|
+
- Each item in `shape` must be a valid expression evaluating to a non-negative scalar.
|
|
1309
|
+
- There is no need to provide `ndim` if `shape` is specified, but they must not conflict if both specified.
|
|
1310
|
+
- `jagged` (`bool`): Whether this placeholder represents a jagged array (ie. a non-square matrix). Ignored if scalar.
|
|
1311
|
+
- `dict_keys` (`tuple[Expression, ...]`, optional): If provided, specifies that this placeholder represents a dictionary-like structure with keys `dict_keys`.
|
|
1312
|
+
- `partial_dict` (`bool`, optional): If `dict_keys` is provided, specifies whether this placeholder represents a partial dictionary (i.e., not all keys are guaranteed to be present). Defaults to `False`.
|
|
1313
|
+
- `latex` (`str`, optional): An optional LaTeX representation to be used in Jupyter notebook.
|
|
1314
|
+
- When not provided, `name` is used by default.
|
|
1315
|
+
- `description` (`str`, optional): An optional description for user reference.
|
|
1316
|
+
|
|
1317
|
+
Examples
|
|
1318
|
+
---------
|
|
1319
|
+
Create a scalar integer placeholder whose name is "a".
|
|
1320
|
+
|
|
1321
|
+
```python
|
|
1322
|
+
>>> import jijmodeling as jm
|
|
1323
|
+
>>> problem = jm.Problem("my_problem")
|
|
1324
|
+
>>> a = problem.Placeholder("a", dtype=jm.DataType.INTEGER)
|
|
1325
|
+
```
|
|
1326
|
+
|
|
1327
|
+
Create a 2-dimensional floating-point placeholder whose name is "y" and has a 2x2 shape.
|
|
1328
|
+
|
|
1329
|
+
```python
|
|
1330
|
+
>>> import jijmodeling as jm
|
|
1331
|
+
>>> problem = jm.Problem("my_problem")
|
|
1332
|
+
>>> y = problem.Float("x", shape=(2, 2))
|
|
1333
|
+
```
|
|
1334
|
+
"""
|
|
1335
|
+
def Integer(self, name:builtins.str, *, ndim:typing.Optional[builtins.int]=None, shape:typing.Optional[typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict] | typing.Sequence[typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]]]=None, jagged:builtins.bool=False, dict_keys:typing.Optional[DataType | type | CategoryLabel | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | tuple]=None, partial_dict:typing.Optional[builtins.bool]=None, latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> Placeholder:
|
|
1336
|
+
r"""
|
|
1337
|
+
Defines a :class:`Placeholder` representing an integer in this problem's namespace.
|
|
1338
|
+
|
|
1339
|
+
A shorthand for `Problem.Placeholder(dtype=DataType.INTEGER)`, provided for clarity and convenience.
|
|
1340
|
+
See `Problem.Placeholder` for more details on placeholders.
|
|
1341
|
+
"""
|
|
1342
|
+
def Float(self, name:builtins.str, *, ndim:typing.Optional[builtins.int]=None, shape:typing.Optional[typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict] | typing.Sequence[typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]]]=None, jagged:builtins.bool=False, dict_keys:typing.Optional[DataType | type | CategoryLabel | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | tuple]=None, partial_dict:typing.Optional[builtins.bool]=None, latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> Placeholder:
|
|
1343
|
+
r"""
|
|
1344
|
+
Defines a :class:`Placeholder` representing a floating-point (real) number in this problem's namespace.
|
|
1345
|
+
|
|
1346
|
+
A shorthand for `Problem.Placeholder(dtype=DataType.FLOAT)`, provided for clarity and convenience.
|
|
1347
|
+
See `Problem.Placeholder` for more details on placeholders.
|
|
1348
|
+
"""
|
|
1349
|
+
def Natural(self, name:builtins.str, *, ndim:typing.Optional[builtins.int]=None, shape:typing.Optional[typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict] | typing.Sequence[typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]]]=None, jagged:builtins.bool=False, dict_keys:typing.Optional[DataType | type | CategoryLabel | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | tuple]=None, partial_dict:typing.Optional[builtins.bool]=None, latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> Placeholder:
|
|
1350
|
+
r"""
|
|
1351
|
+
Defines a :class:`Placeholder` representing a natural number in this problem's namespace.
|
|
1352
|
+
|
|
1353
|
+
A shorthand for `Problem.Placeholder(dtype=DataType.NATURAL)`, provided for clarity and convenience.
|
|
1354
|
+
See `Problem.Placeholder` for more details on placeholders.
|
|
1355
|
+
"""
|
|
1356
|
+
def Length(self, name:builtins.str, *, ndim:typing.Optional[builtins.int]=0, shape:typing.Optional[typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict] | typing.Sequence[typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]]]=None, jagged:builtins.bool=False, dict_keys:typing.Optional[DataType | type | CategoryLabel | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | tuple]=None, partial_dict:typing.Optional[builtins.bool]=None, latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> Placeholder:
|
|
1357
|
+
r"""
|
|
1358
|
+
Defines a :class:`Placeholder` representing a natural number in this problem's namespace.
|
|
1359
|
+
|
|
1360
|
+
This is just a shorthand for `Problem.Natural(ndim=0)` and effectively the same as any other natural
|
|
1361
|
+
placeholder for practical purposes. The use of `Length` is recommended just for clarity when
|
|
1362
|
+
defining a placeholder which will be used to define the length of multi-dimensional objects.
|
|
1363
|
+
|
|
1364
|
+
See `Problem.Placeholder` for more details on placeholders.
|
|
1365
|
+
"""
|
|
1366
|
+
def Dim(self, name:builtins.str, *, ndim:typing.Optional[builtins.int]=0, shape:typing.Optional[typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict] | typing.Sequence[typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]]]=None, jagged:builtins.bool=False, dict_keys:typing.Optional[DataType | type | CategoryLabel | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | tuple]=None, partial_dict:typing.Optional[builtins.bool]=None, latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> Placeholder:
|
|
1367
|
+
r"""
|
|
1368
|
+
Defines a :class:`Placeholder` representing a natural number in this problem's namespace.
|
|
1369
|
+
|
|
1370
|
+
This is just a shorthand for `Problem.Natural(ndim=0)` and effectively the same as any other natural
|
|
1371
|
+
placeholder for practical purposes. The use of `Dim` is recommended just for clarity when
|
|
1372
|
+
defining a placeholder which will be used to define the length of multi-dimensional objects.
|
|
1373
|
+
|
|
1374
|
+
See `Problem.Placeholder` for more details on placeholders.
|
|
1375
|
+
"""
|
|
1376
|
+
def Binary(self, name:builtins.str, *, ndim:typing.Optional[builtins.int]=None, shape:typing.Optional[typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict] | typing.Sequence[typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]]]=None, jagged:builtins.bool=False, dict_keys:typing.Optional[DataType | type | CategoryLabel | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | tuple]=None, partial_dict:typing.Optional[builtins.bool]=None, latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> Placeholder:
|
|
1377
|
+
r"""
|
|
1378
|
+
Defines a `Placeholder` representing a binary number in this problem's namespace.
|
|
1379
|
+
|
|
1380
|
+
A shorthand for `Problem.Placeholder(dtype=DataType.BINARY)`, provided for clarity and convenience.
|
|
1381
|
+
See `Problem.Placeholder` for more details on placeholders.
|
|
1382
|
+
"""
|
|
1383
|
+
def PartialDict(self, name:builtins.str, *, dtype:DataType | type | tuple, dict_keys:DataType | type | CategoryLabel | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | tuple, latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> Placeholder:
|
|
1384
|
+
r"""
|
|
1385
|
+
A shorthand for creating a partial dictionary placeholder with key type
|
|
1386
|
+
"""
|
|
1387
|
+
def TotalDict(self, name:builtins.str, *, dtype:DataType | type | tuple, dict_keys:DataType | type | CategoryLabel | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | tuple, latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> Placeholder:
|
|
1388
|
+
r"""
|
|
1389
|
+
A shorthand for creating a total dictionary placeholder with key type
|
|
1390
|
+
"""
|
|
1391
|
+
def Graph(self, name:builtins.str, *, dtype:DataType | type | tuple=DataType.NATURAL, latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> Placeholder:
|
|
1392
|
+
r"""
|
|
1393
|
+
A placeholder expressing a directed graph (without edge weights), represented by a 1-dimensional array of tuples.
|
|
1394
|
+
|
|
1395
|
+
A shorthand for `Problem.Placeholder(dtype=(vertex, vertex), ndim=1)`.
|
|
1396
|
+
By default `vertex` is `DataType.Natural` but can be specified.
|
|
1397
|
+
"""
|
|
1398
|
+
def DecisionVar(self, name:builtins.str, *, kind:DecisionVarKind, shape:typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]]=None, dict_keys:typing.Optional[DataType | type | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]=None, lower_bound:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict], upper_bound:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict], latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> DecisionVar:
|
|
1399
|
+
r"""
|
|
1400
|
+
Defines a :class:`DecisionVar` and registers it to the problem namespace.
|
|
1401
|
+
|
|
1402
|
+
Decision variables can be scalars, multi-dimensional arrays (eg. representing
|
|
1403
|
+
arrays and matrices of variables), or total dictionaries.
|
|
1404
|
+
|
|
1405
|
+
Variables must have a `DecisionVarKind` (such as `BINARY`, `INTEGER`, `CONTINUOUS`),
|
|
1406
|
+
as well as defined lower and upper bounds.
|
|
1407
|
+
|
|
1408
|
+
We recommend using alternative convenience methods which predefine the
|
|
1409
|
+
decision variable's kind, such as `Problem.IntegerVar` for integers, or
|
|
1410
|
+
`Problem.BinaryVar` for binary variables.
|
|
1411
|
+
|
|
1412
|
+
Representation
|
|
1413
|
+
--------------
|
|
1414
|
+
Depending on the arguments described below, the representation of the decision variable will be determined as follows:
|
|
1415
|
+
|
|
1416
|
+
1. If none of `shape` or `dict_keys` is provided, or `shape` is `()`, DecisionVar will be considered as a scalar value (= array of dimension 0).
|
|
1417
|
+
2. If `shape` is provided and `dict_keys` is not provided, DecisionVar will be considered as a multi-dimensional array with fixed shape.
|
|
1418
|
+
3. If `dict_keys` is provided without `shape`, DecisionVar will be considered as a dictionary-like structure with keys specified by `dict_keys`.
|
|
1419
|
+
4. Otherwise, an error is raised.
|
|
1420
|
+
|
|
1421
|
+
Args
|
|
1422
|
+
-----
|
|
1423
|
+
- `name` (`str`): A name for the binary variable.
|
|
1424
|
+
- `kind` (`DecisionVarKind`): A kind of the decision variable.
|
|
1425
|
+
- `shape` (`list | tuple`): A sequence with the size of each dimension of the variable. Defaults to an empty tuple (a scalar value).
|
|
1426
|
+
- Each item in `shape` must be a valid expression evaluating to a non-negative scalar.
|
|
1427
|
+
- `dict_keys` (`tuple[Expression, ...]`, optional): If provided, specifies that this variable represents a dictionary-like structure with keys `dict_keys`.
|
|
1428
|
+
- `lower_bound` and `upper_bound` (`jijmodeling.Expression`): A lower and upper bounds of the variable.
|
|
1429
|
+
- `kind` (`DecisionVarKind`): The kind of the decision variable.
|
|
1430
|
+
- `latex` (`str`, optional): An optional LaTeX representation to be used in Jupyter notebook.
|
|
1431
|
+
- It is set to be the same as `name` by default.
|
|
1432
|
+
- `description` (`str`, optional): An optional description, for user reference.
|
|
1433
|
+
|
|
1434
|
+
Examples
|
|
1435
|
+
---------
|
|
1436
|
+
Create a scalar binary variable whose name is "z".
|
|
1437
|
+
|
|
1438
|
+
```python
|
|
1439
|
+
>>> import jijmodeling as jm
|
|
1440
|
+
>>> problem = jm.Problem("my_problem")
|
|
1441
|
+
>>> z = problem.DecisionVar("z", kind=jm.DecisionVarKind.BINARY, lower_bound=0, upper_bound=1)
|
|
1442
|
+
|
|
1443
|
+
```
|
|
1444
|
+
|
|
1445
|
+
Create a 2-dimensional binary variable whose name is "x" and has a 2x2 shape.
|
|
1446
|
+
|
|
1447
|
+
```python
|
|
1448
|
+
>>> import jijmodeling as jm
|
|
1449
|
+
>>> problem = jm.Problem("my_problem")
|
|
1450
|
+
>>> x = problem.BinaryVar("x", shape=[2, 2])
|
|
1451
|
+
|
|
1452
|
+
```
|
|
1453
|
+
|
|
1454
|
+
Create a 1-dimensional binary variable with the index of `123`.
|
|
1455
|
+
|
|
1456
|
+
```python
|
|
1457
|
+
>>> import jijmodeling as jm
|
|
1458
|
+
>>> problem = jm.Problem("my_problem")
|
|
1459
|
+
>>> x = jm.BinaryVar("x", shape=[124])
|
|
1460
|
+
>>> x[123]
|
|
1461
|
+
BinaryVar(name='x', shape=[NumberLit(value=124)])[NumberLit(value=123)]
|
|
1462
|
+
|
|
1463
|
+
```
|
|
1464
|
+
"""
|
|
1465
|
+
def BinaryVar(self, name:builtins.str, *, shape:typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]]=None, dict_keys:typing.Optional[DataType | type | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]=None, latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> DecisionVar:
|
|
1466
|
+
r"""
|
|
1467
|
+
Defines a binary decision variable and registers it to the problem namespace. See `Problem.DecisionVar` for more details.
|
|
1468
|
+
|
|
1469
|
+
A shorthand for `Problem.DecisionVariable(dtype=DecisionVarKind.BINARY,
|
|
1470
|
+
lower_bound=0, upper_bound=1)`, provided for clarity and convenience.
|
|
1471
|
+
|
|
1472
|
+
Args
|
|
1473
|
+
-----
|
|
1474
|
+
- `name` (`str`): A name of the binary variable.
|
|
1475
|
+
- `shape` (`list | tuple`): A sequence with the size of each dimension of the binary variable. Defaults to an empty tuple (a scalar value).
|
|
1476
|
+
- Each item in `shape` must be a valid expression evaluating to a non-negative scalar.
|
|
1477
|
+
- `dict_keys` (`tuple[Expression, ...]`, optional): If provided, specifies that this variable represents a dictionary-like structure with keys `dict_keys`.
|
|
1478
|
+
- `latex` (`str`, optional): A LaTeX-name of the binary variable to be represented in Jupyter notebook.
|
|
1479
|
+
- It is set to `name` by default.
|
|
1480
|
+
- `description` (`str`, optional): A description of the binary variable.
|
|
1481
|
+
"""
|
|
1482
|
+
def IntegerVar(self, name:builtins.str, *, shape:typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]]=None, dict_keys:typing.Optional[DataType | type | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]=None, lower_bound:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict], upper_bound:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict], latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> DecisionVar:
|
|
1483
|
+
r"""
|
|
1484
|
+
Defines an integer decision variable and registers it to the problem namespace. See `Problem.DecisionVar` for more details.
|
|
1485
|
+
|
|
1486
|
+
This is shorthand for `Problem.DecisionVariable(kind=DecisionVarKind.INTEGER)`.
|
|
1487
|
+
|
|
1488
|
+
Args
|
|
1489
|
+
-----
|
|
1490
|
+
- `name` (`str): A name of the integer variable.
|
|
1491
|
+
- `shape` (`list | tuple`): A sequence with the size of each dimension of the integer variable. Defaults to an empty tuple (a scalar value).
|
|
1492
|
+
- Each item in `shape` must be a valid expression evaluating to a non-negative scalar.
|
|
1493
|
+
- `dict_keys` (`tuple[Expression, ...]`, optional): If provided, specifies that this variable represents a dictionary-like structure with keys `dict_keys`.
|
|
1494
|
+
- `lower_bound`: The lower bound of the variable.
|
|
1495
|
+
- `upper_bound`: The upper bound of the variable.
|
|
1496
|
+
- `latex` (`str`, optional): A LaTeX-name of the integer variable to be represented in Jupyter notebook.
|
|
1497
|
+
- It is set to `name` by default.
|
|
1498
|
+
- `description` (`str`, optional): A description of the integer variable.
|
|
1499
|
+
|
|
1500
|
+
Raises
|
|
1501
|
+
-------
|
|
1502
|
+
`ModelingError`: Raises if a bound is a `Placeholder` or `Subscript` object whose `ndim`
|
|
1503
|
+
is neither `0` nor the same value as `ndim` of the integer variable.
|
|
1504
|
+
"""
|
|
1505
|
+
def SemiIntegerVar(self, name:builtins.str, *, shape:typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]]=None, dict_keys:typing.Optional[DataType | type | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]=None, lower_bound:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict], upper_bound:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict], latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> DecisionVar:
|
|
1506
|
+
r"""
|
|
1507
|
+
Defines a semi-integer decision variable and registers it to the problem namespace. See :class:`DecisionVar` for more details.
|
|
1508
|
+
|
|
1509
|
+
This is shorthand for `Problem.DecisionVariable(kind=DecisionVarKind.SEMI_INTEGER)`.
|
|
1510
|
+
"""
|
|
1511
|
+
def ContinuousVar(self, name:builtins.str, *, shape:typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]]=None, dict_keys:typing.Optional[DataType | type | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]=None, lower_bound:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict], upper_bound:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict], latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> DecisionVar:
|
|
1512
|
+
r"""
|
|
1513
|
+
Defines a continuous decision variable and registers it to the problem namespace. See `Problem.DecisionVar` for more details.
|
|
1514
|
+
|
|
1515
|
+
This is shorthand for `problem.DecisionVariable(dtype=DecisionVarKind.CONTINUOUS)`.
|
|
1516
|
+
|
|
1517
|
+
Args
|
|
1518
|
+
-----
|
|
1519
|
+
- `name` (`str`): A name of the continuous variable.
|
|
1520
|
+
- `shape` (`list | tuple`): A sequence with the size of each dimension of the continuous variable. Defaults to an empty tuple (a scalar value).
|
|
1521
|
+
- Each item in `shape` must be a valid expression evaluating to a non-negative scalar.
|
|
1522
|
+
- `dict_keys` (`tuple[Expression, ...]`, optional): If provided, specifies that this variable represents a dictionary-like structure with keys `dict_keys`.
|
|
1523
|
+
- `lower_bound`: The lower bound of the variable.
|
|
1524
|
+
- `upper_bound`: The upper bound of the variable.
|
|
1525
|
+
- `latex` (`str`, optional): A LaTeX-name of the continuous variable to be represented in Jupyter notebook.
|
|
1526
|
+
- It is set to `name` by default.
|
|
1527
|
+
- `description` (`str`, optional): A description of the continuous variable.
|
|
1528
|
+
|
|
1529
|
+
Raises
|
|
1530
|
+
-------
|
|
1531
|
+
`ModelingError`: Raises if a bound is a `Placeholder` or `Subscript` object whose `ndim` is neither `0` nor the same value as `ndim` of the continuous variable.
|
|
1532
|
+
"""
|
|
1533
|
+
def SemiContinuousVar(self, name:builtins.str, *, shape:typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]]=None, dict_keys:typing.Optional[DataType | type | Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]=None, lower_bound:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict], upper_bound:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict | typing.Sequence[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict], latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> DecisionVar: ...
|
|
1534
|
+
def namespace(self) -> Namespace:
|
|
1535
|
+
r"""
|
|
1536
|
+
Access to the internal `Namespace` associated with this problem.
|
|
1537
|
+
|
|
1538
|
+
Accessing this directly is not normally necessary for regular users.
|
|
1539
|
+
"""
|
|
1540
|
+
def CategoryLabel(self, name:builtins.str, *, latex:typing.Optional[builtins.str]=None, description:typing.Optional[builtins.str]=None) -> CategoryLabel:
|
|
1541
|
+
r"""
|
|
1542
|
+
Add a new opaque category label to the namespace.
|
|
1543
|
+
|
|
1544
|
+
A category label corresponds to a set of labels representing some specific category (e.g. the name of percels, or the ids of factors, etc).
|
|
1545
|
+
A value of category label is treated opaque in JijModeling, and can only be tested for equality / non-equality and used as keys in dictionary-like structures.
|
|
1546
|
+
|
|
1547
|
+
:class:`CategoryLabel` objects can be created via :meth:`Problem.CategoryLabel`.
|
|
1548
|
+
The concrete values should be given in `instance_data` dictionary together with placeholder values when creating a :class:`Compiler` object or in `Problem.eval`.
|
|
1549
|
+
In `instance_data`, category label should be given a list of either strings or integers.
|
|
1550
|
+
|
|
1551
|
+
Args
|
|
1552
|
+
----
|
|
1553
|
+
- `name` (`str`): The name of the category label.
|
|
1554
|
+
- `latex` (`str`, optional): An optional LaTeX representation to be used in Jupyter notebook.
|
|
1555
|
+
- When not provided, `name` is used by default.
|
|
1556
|
+
- `description` (`str`, optional): An optional description for user reference.
|
|
1557
|
+
"""
|
|
1558
|
+
def update(self, func:typing.Callable[[DecoratedProblem]]) -> DesugaredProblemBuilder:
|
|
1559
|
+
r"""
|
|
1560
|
+
A function decorator to modify an existing `Problem` using the decorated API.
|
|
1561
|
+
This must be decorated to a function that takes `DecoratedProblem` as the only argument and returns None.
|
|
1562
|
+
You can call `update` multiple times.
|
|
1563
|
+
The given function will automatically be evaluated exactly once by the decocrator, so you DO NOT need to call the original function again.
|
|
1564
|
+
|
|
1565
|
+
Example
|
|
1566
|
+
-------
|
|
1567
|
+
|
|
1568
|
+
```python
|
|
1569
|
+
>>> import jijmodeling as jm
|
|
1570
|
+
>>> problem = jm.Problem("Knapsack Problem", sense=jm.ProblemSense.MAXIMIZE)
|
|
1571
|
+
>>>
|
|
1572
|
+
>>> @problem.update
|
|
1573
|
+
>>> def my_updater(problem: jm.DecoratedProblem):
|
|
1574
|
+
>>> w = problem.Float(ndim=1, description="Weights of the items")
|
|
1575
|
+
>>> N = w.len_at(0)
|
|
1576
|
+
>>> v = problem.Float(ndim=1, description="Values of the items")
|
|
1577
|
+
>>> W = problem.Float(description="Total weight")
|
|
1578
|
+
>>> x = problem.BinaryVar(shape=(N,), description="Selected items")
|
|
1579
|
+
>>>
|
|
1580
|
+
>>> problem += problem.Constraint("weight", jm.sum(w * x) <= W)
|
|
1581
|
+
>>> problem += jm.sum(v * x)
|
|
1582
|
+
>>>
|
|
1583
|
+
>>> w_data = [10, 20, 30]
|
|
1584
|
+
>>> v_data = [60, 100, 120]
|
|
1585
|
+
>>> instance_data = {"w": w_data, "v": v_data, "W": 50}
|
|
1586
|
+
>>> instance = problem.eval(instance_data)
|
|
1587
|
+
```
|
|
1588
|
+
"""
|
|
1589
|
+
def get_problem_schema(self) -> dict:
|
|
1590
|
+
r"""
|
|
1591
|
+
Returns the schema of the problem.
|
|
1592
|
+
|
|
1593
|
+
Returns
|
|
1594
|
+
--------
|
|
1595
|
+
- `schema`: The dictionary containing the schema of the problem.
|
|
1596
|
+
"""
|
|
1597
|
+
def generate_random_dataset(self, _default:typing.Any, _options:typing.Any, _seed:typing.Optional[builtins.int]) -> typing.Any:
|
|
1598
|
+
r"""
|
|
1599
|
+
Generates a dictionary of random `InstanceDataValue` for a given problem.
|
|
1600
|
+
To generate `ommx.v1.Instance` object directly, use `InstanceDataValue.generate_random_instance` instead.
|
|
1601
|
+
|
|
1602
|
+
Args
|
|
1603
|
+
-----
|
|
1604
|
+
- `options` (optional): a dictionary of range parameters for each separate placeholders. The key must be the name of the placeholder and the value must be range parameter (as described in "Range Parameters and Range Syntax" below).
|
|
1605
|
+
- `default` (optional): default range parameters for placeholders which is not specified in `options`.
|
|
1606
|
+
- `seed` (optional): seed for random number generation.
|
|
1607
|
+
|
|
1608
|
+
Returns
|
|
1609
|
+
--------
|
|
1610
|
+
`dict`: The dictionary from the name of placeholders to the generated `InstanceDataValue` objects. To be fed to `Interpreter.eval_problem`.
|
|
1611
|
+
|
|
1612
|
+
Range Parameters and Range Syntax
|
|
1613
|
+
----------------------------------
|
|
1614
|
+
A range parameter is a dictionary consisting of the following fields:
|
|
1615
|
+
- `size` (optional): interval of natural numbers for the size of each array dimension (default: `range(1, 6)`)
|
|
1616
|
+
- `value` (optional): interval of real numbers for the value of each array element (default: `range(-1.0, 1.0)` - a uniform distribution on a closed interval $[-1.0, 1.0]$).
|
|
1617
|
+
|
|
1618
|
+
Example range parameter config:
|
|
1619
|
+
|
|
1620
|
+
```python
|
|
1621
|
+
{"size": range(2, 10), "value": jm.range.value.closed(100.0, 200.0)}
|
|
1622
|
+
```
|
|
1623
|
+
|
|
1624
|
+
Intervals are expressed as a range object.
|
|
1625
|
+
Currently, the following syntax is supported for range objects:
|
|
1626
|
+
|
|
1627
|
+
1. Direct value of type `int` or `float` - it corresponds to a singleton interval $[a, a] = \{a\}$. In random generation context, this just means a constant fixed value.
|
|
1628
|
+
2. Use the functions from `jijmodeling.range`, `jijmodeling.range.size`, or `jijmodeling.range.value` modules.
|
|
1629
|
+
- Use functions from `jij.modeling.range.size` to specify (non-negative) integer intervals, and `jij.modeling.range.value` for real intervals. `jij.modeling.range` dynamically determines the type of the range based on the input.
|
|
1630
|
+
- These three modules provides the following combinators (see the module documents for more details.):
|
|
1631
|
+
- `closed(a, b)`: a closed interval $[a, b]$
|
|
1632
|
+
- `open(a, b)`: an open interval $(a, b)$
|
|
1633
|
+
- `closed_open(a, b)`: an upper half-open interval $[a, b)$
|
|
1634
|
+
- `open_closed(a, b)`: a lower half-open interval $(a, b]$
|
|
1635
|
+
- `greater_than(a)`: an open interval $(a, \infty)$
|
|
1636
|
+
- `at_least(a)`: a closed interval $[a, \infty)$
|
|
1637
|
+
- `less_than(a)`: an open interval $(-\infty, a)$
|
|
1638
|
+
- `at_most(a)`: a closed interval $(-\infty, a]$
|
|
1639
|
+
3. Use `range` builtin function: this is equivalent to `jijmodeling.range.value.closed_open(a, b)`.
|
|
1640
|
+
- Any python range object with `step = 1` can be used as a size range; otherwise it results in runtime error.
|
|
1641
|
+
4. Use a tuple: raw tuple `(a, b)` is equivalent to `jijmodeling.range.closed_open(a, b)` if `a` and `b` are either `int` or `float`.
|
|
1642
|
+
- You can also use bound object as a tuple component; in such case, both tuple components must be one of the following:
|
|
1643
|
+
|
|
1644
|
+
1. A string `"Unbounded"` means $-\infty$ (in the first component) or $\infty$ (the second).
|
|
1645
|
+
2. A dictionary `{"Included": a}` means the endpoint is inclusive.
|
|
1646
|
+
3. A dictionary `{"Excluded": a}` means the endpoint is exclusive.
|
|
1647
|
+
- Examples:
|
|
1648
|
+
- `(1.2, 4)` is equivalent to `closed_open(1.2, 4)`,
|
|
1649
|
+
- `(-1, {"Included": 1})` is equivalent to `closed(-1, 1)`,
|
|
1650
|
+
- `(-5, {"Excluded": 4})` is equivalent to `closed_open(-5, 4)` and built in function `range(-5, 4)`,
|
|
1651
|
+
- `({"Excluded": 1}, {"Excluded": 2.5})` is equivalent to `open(1, 2.5)`,
|
|
1652
|
+
- `({"Included": -1}, "Unbounded")` is equivalent to `at_least(-1)`.
|
|
1653
|
+
- `(5, "Unbounded")` is **INVALID**; `5` must be bound object.
|
|
1654
|
+
5. The range object: A dictionary of form `{"start": lb, "end": ub}`, where both `lb` and `ub` are the bound object described as above.
|
|
1655
|
+
|
|
1656
|
+
Examples
|
|
1657
|
+
---------
|
|
1658
|
+
```python
|
|
1659
|
+
>>> import jijmodeling as jm
|
|
1660
|
+
>>> import builtins
|
|
1661
|
+
>>> N = jm.Placeholder("N", dtype=jm.DataType.INTEGER)
|
|
1662
|
+
>>> c = jm.Placeholder("c", dtype=jm.DataType.FLOAT, shape=(N,))
|
|
1663
|
+
>>> x = jm.BinaryVar("x", shape=(N,))
|
|
1664
|
+
>>> i = jm.Element("i", belong_to=N)
|
|
1665
|
+
|
|
1666
|
+
>>> problem = jm.Problem("problem")
|
|
1667
|
+
>>> problem += jm.sum(i, c[i] * x[i])
|
|
1668
|
+
|
|
1669
|
+
>>> inputs = problem.generate_random_dataset(
|
|
1670
|
+
... options={
|
|
1671
|
+
... 'N': {"value": builtins.range(10, 20)},
|
|
1672
|
+
... 'c': {"value": jm.range.value.closed(-1.0, 1.0)}
|
|
1673
|
+
... # You can also specify "size" for the range of jagged array dimension size.
|
|
1674
|
+
... },
|
|
1675
|
+
... seed=123 # omittable
|
|
1676
|
+
... )
|
|
1677
|
+
>>> assert set(inputs.keys()) == {"N", "c"}
|
|
1678
|
+
>>> inputs
|
|
1679
|
+
{'N': 11.0, 'c': array([ 0.93914459, -0.06511935, -0.7460324 , -0.32443706, 0.99981451,
|
|
1680
|
+
-0.24407535, 0.31329469, 0.52206453, -0.1291936 , 0.30443087,
|
|
1681
|
+
0.53125838])}
|
|
1682
|
+
|
|
1683
|
+
```
|
|
1684
|
+
"""
|
|
1685
|
+
def generate_random_instance(self, _default:typing.Any, _options:typing.Any, _seed:typing.Optional[builtins.int], _hints:typing.Optional[typing.Any]) -> typing.Any:
|
|
1686
|
+
r"""
|
|
1687
|
+
Generates random `ommx.v1.Instance` for a given problem.
|
|
1688
|
+
See also `InstanceDataValue.generate_random_dataset`.
|
|
1689
|
+
|
|
1690
|
+
Args
|
|
1691
|
+
-----
|
|
1692
|
+
- `options` (optional): a dictionary of range parameters for each separate placeholders. The key must be the name of the placeholder and the value must be range parameter (as described in "Range Parameters and Range Syntax" section in :func:`~jijmodeling.Problem.generate_random_dataset`).
|
|
1693
|
+
- `default` (optional): default range parameters for placeholders which is not specified in `options`.
|
|
1694
|
+
- `seed` (optional): seed for random number generation.
|
|
1695
|
+
- `hints` (optional): the hints to be detected during compilation see `Interpreter.eval_problem` for more details.
|
|
1696
|
+
|
|
1697
|
+
Returns
|
|
1698
|
+
--------
|
|
1699
|
+
`instance`: The OMMX v1 instance object.
|
|
1700
|
+
|
|
1701
|
+
Examples
|
|
1702
|
+
---------
|
|
1703
|
+
```python
|
|
1704
|
+
>>> import jijmodeling as jm
|
|
1705
|
+
>>> import builtins
|
|
1706
|
+
>>> import ommx.v1
|
|
1707
|
+
>>> N = jm.Placeholder("N", dtype=jm.DataType.INTEGER)
|
|
1708
|
+
>>> c = jm.Placeholder("c", dtype=jm.DataType.FLOAT, shape=(N,))
|
|
1709
|
+
>>> x = jm.BinaryVar("x", shape=(N,))
|
|
1710
|
+
>>> i = jm.Element("i", belong_to=N)
|
|
1711
|
+
|
|
1712
|
+
>>> problem = jm.Problem("problem")
|
|
1713
|
+
>>> problem += jm.sum(i, c[i] * x[i])
|
|
1714
|
+
|
|
1715
|
+
>>> instance = problem.generate_random_instance(
|
|
1716
|
+
... options={
|
|
1717
|
+
... 'N': {"value": builtins.range(10, 20)},
|
|
1718
|
+
... 'c': {"value": jm.range.value.closed(-1.0, 1.0)}
|
|
1719
|
+
... },
|
|
1720
|
+
... seed=123
|
|
1721
|
+
... )
|
|
1722
|
+
>>> assert type(instance) is ommx.v1.Instance
|
|
1723
|
+
|
|
1724
|
+
```
|
|
1725
|
+
"""
|
|
1726
|
+
def type_of(self, name:builtins.str) -> typing.Optional[Type]:
|
|
1727
|
+
r"""
|
|
1728
|
+
Returns the type associated with a given name (eg. of a placeholder or decision variable).
|
|
1729
|
+
|
|
1730
|
+
This is mostly inteded for testing purposes, and not as part of standard model writing.
|
|
1731
|
+
|
|
1732
|
+
:raises ModelingError: If the name is undefined in this problem's namespace.
|
|
1733
|
+
"""
|
|
1734
|
+
def infer(self, expr:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Type:
|
|
1735
|
+
r"""
|
|
1736
|
+
Infers the resulting type of an expression using this problem as a namespace.
|
|
1737
|
+
|
|
1738
|
+
This is mostly intended for testing purposes, and not as part of standard model writing.
|
|
1739
|
+
|
|
1740
|
+
Examples
|
|
1741
|
+
===
|
|
1742
|
+
```python
|
|
1743
|
+
>>> problem = jm.Problem("MyProblem")
|
|
1744
|
+
>>> N = problem.Length(name="N")
|
|
1745
|
+
>>> x = problem.BinaryVar("x", shape=(N,))
|
|
1746
|
+
>>> y = problem.IntegerVar("y", shape=(N,), lower_bound=0,upper_bound=10)
|
|
1747
|
+
>>> problem.infer(jm.sum(x))
|
|
1748
|
+
binary!
|
|
1749
|
+
>>> problem.infer(jm.sum(y))
|
|
1750
|
+
int!
|
|
1751
|
+
```
|
|
1752
|
+
"""
|
|
1753
|
+
@typing.overload
|
|
1754
|
+
def Constraint(self, name:builtins.str, expression:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict, description:typing.Optional[builtins.str]=None) -> Constraint:
|
|
1755
|
+
r"""
|
|
1756
|
+
Constructs `Constraint` object from comparison expression, __WITHOUT__ registering it to the problem.
|
|
1757
|
+
Use `+=` operator to register the constraint to the problem.
|
|
1758
|
+
"""
|
|
1759
|
+
@typing.overload
|
|
1760
|
+
def Constraint(self, name:builtins.str, expression:typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any], domain:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict, description:typing.Optional[builtins.str]=None) -> Constraint:
|
|
1761
|
+
r"""
|
|
1762
|
+
Constructs ``Constraint`` family with the index set ``domain`` and function ``expression`` to build comparison expression from each index, __WITHOUT__ registering it to the problem.
|
|
1763
|
+
Use `+=` operator to register the constraint to the problem.
|
|
1764
|
+
"""
|
|
1765
|
+
def __new__(cls, name:builtins.str, *, sense:ProblemSense=ProblemSense.MINIMIZE, description:typing.Optional[builtins.str]=None) -> Problem: ...
|
|
1766
|
+
|
|
1767
|
+
@typing.final
|
|
1768
|
+
class Type:
|
|
1769
|
+
def __eq__(self, other:builtins.object) -> builtins.bool: ...
|
|
1770
|
+
|
|
1771
|
+
class TypeError(builtins.Exception):
|
|
12
1772
|
...
|
|
13
1773
|
|
|
1774
|
+
@typing.final
|
|
1775
|
+
class ConstraintSense(enum.Enum):
|
|
1776
|
+
EQUAL = ...
|
|
1777
|
+
LESS_THAN_EQUAL = ...
|
|
1778
|
+
GREATER_THAN_EQUAL = ...
|
|
1779
|
+
|
|
1780
|
+
@typing.final
|
|
1781
|
+
class DataType(enum.Enum):
|
|
1782
|
+
r"""
|
|
1783
|
+
The type of values in the instance data.
|
|
1784
|
+
|
|
1785
|
+
Used to specify the types of values :class:`Placeholder` will be able to
|
|
1786
|
+
hold. This type is used for type checking and error detection, particularly
|
|
1787
|
+
when compiling models into ommx instances -- not allowing data of the wrong
|
|
1788
|
+
kind to be used in a given placeholder. This is also used when trying to
|
|
1789
|
+
generate random instances from a model.
|
|
1790
|
+
|
|
1791
|
+
Placeholders may also have tuples of `DataType`s as their types, eg.
|
|
1792
|
+
`(DataType.NATURAL, DataType.NATURAL)` for representing edges in a graph.
|
|
1793
|
+
"""
|
|
1794
|
+
INTEGER = ...
|
|
1795
|
+
FLOAT = ...
|
|
1796
|
+
BINARY = ...
|
|
1797
|
+
NATURAL = ...
|
|
1798
|
+
|
|
1799
|
+
@typing.final
|
|
1800
|
+
class DecisionVarKind(enum.Enum):
|
|
1801
|
+
BINARY = ...
|
|
1802
|
+
INTEGER = ...
|
|
1803
|
+
CONTINUOUS = ...
|
|
1804
|
+
SEMI_INTEGER = ...
|
|
1805
|
+
SEMI_CONTINUOUS = ...
|
|
1806
|
+
|
|
1807
|
+
@typing.final
|
|
1808
|
+
class ProblemSense(enum.Enum):
|
|
1809
|
+
r"""
|
|
1810
|
+
An optimization sense
|
|
1811
|
+
|
|
1812
|
+
Specifies whether the problem is a minization or maximization problem.
|
|
1813
|
+
Mostly used in the constructor for :class:`Problem`, or obtained from
|
|
1814
|
+
an existing problem through `Problem.sense()`
|
|
1815
|
+
"""
|
|
1816
|
+
MINIMIZE = ...
|
|
1817
|
+
MAXIMIZE = ...
|
|
1818
|
+
|
|
1819
|
+
def Some(inner:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1820
|
+
|
|
1821
|
+
def abs(expr:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1822
|
+
|
|
1823
|
+
def acos(expr:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1824
|
+
|
|
1825
|
+
def acosh(expr:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1826
|
+
|
|
1827
|
+
def asin(expr:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1828
|
+
|
|
1829
|
+
def asinh(expr:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1830
|
+
|
|
1831
|
+
def atan(expr:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1832
|
+
|
|
1833
|
+
def atanh(expr:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1834
|
+
|
|
1835
|
+
def band(lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1836
|
+
|
|
1837
|
+
def bnot(expr:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1838
|
+
|
|
1839
|
+
def bor(lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1840
|
+
|
|
1841
|
+
def ceil(expr:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1842
|
+
|
|
1843
|
+
def cos(expr:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1844
|
+
|
|
1845
|
+
def cosh(expr:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1846
|
+
|
|
1847
|
+
def diff(lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1848
|
+
|
|
1849
|
+
def exp(expr:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1850
|
+
|
|
1851
|
+
def filter(predicate:typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any], operand:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1852
|
+
|
|
1853
|
+
def flat_map(func:typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any], arg:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1854
|
+
|
|
1855
|
+
def floor(expr:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1856
|
+
|
|
1857
|
+
def is_same(src:typing.Any, dst:typing.Any) -> builtins.bool:
|
|
1858
|
+
r"""
|
|
1859
|
+
Return `true` if `src` and `dst` are the same object defined by Jijmodeling.
|
|
1860
|
+
|
|
1861
|
+
|
|
1862
|
+
Args
|
|
1863
|
+
-----
|
|
1864
|
+
- `src`: An object defined by Jijmodeling module, or an iterable of Jijmodeling objects.
|
|
1865
|
+
- `dst`: An object defined by Jijmodeling module, or an iterable of Jijmodeling objects.
|
|
1866
|
+
|
|
1867
|
+
Returns
|
|
1868
|
+
--------
|
|
1869
|
+
`bool`: `true` if `src` and `dst` is the same object. Otherwise `false`.
|
|
1870
|
+
|
|
1871
|
+
Examples
|
|
1872
|
+
---------
|
|
1873
|
+
Check if the two placeholders are the same.
|
|
1874
|
+
|
|
1875
|
+
```python
|
|
1876
|
+
>>> import jijmodeling as jm
|
|
1877
|
+
>>> problem = jm.Problem("problem")
|
|
1878
|
+
>>> a = problem.Placeholder("name")
|
|
1879
|
+
>>> b = problem.Placeholder("name")
|
|
1880
|
+
>>> assert jm.is_same(a, b)
|
|
1881
|
+
>>> c = problem.Placeholder("name", ndim=2)
|
|
1882
|
+
>>> assert not jm.is_same(a, c) # the value of `ndim` is different
|
|
1883
|
+
```
|
|
1884
|
+
|
|
1885
|
+
Raises
|
|
1886
|
+
-------
|
|
1887
|
+
`TypeError`: Raises if
|
|
1888
|
+
- `src` and `dst` are of different types which are not iterable
|
|
1889
|
+
- called on a type not defined by Jijmodeling (e.g. `str`)
|
|
1890
|
+
|
|
1891
|
+
Note
|
|
1892
|
+
-----
|
|
1893
|
+
This function does not check the following attributes:
|
|
1894
|
+
- `description`
|
|
1895
|
+
- `latex`
|
|
1896
|
+
|
|
1897
|
+
For example,
|
|
1898
|
+
|
|
1899
|
+
```python
|
|
1900
|
+
>>> import jijmodeling as jm
|
|
1901
|
+
>>> problem = jm.Problem("problem")
|
|
1902
|
+
>>> src = problem.Placeholder("placeholder", latex="src")
|
|
1903
|
+
>>> dst = problem.Placeholder("placeholder", latex="dst")
|
|
1904
|
+
>>> assert jm.is_same(src, dst)
|
|
1905
|
+
```
|
|
1906
|
+
|
|
1907
|
+
this code works without any exception.
|
|
1908
|
+
"""
|
|
1909
|
+
|
|
1910
|
+
def items(dict:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1911
|
+
|
|
1912
|
+
def keys(dict:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1913
|
+
|
|
1914
|
+
def ln(expr:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1915
|
+
|
|
1916
|
+
def log10(expr:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1917
|
+
|
|
1918
|
+
def log2(expr:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1919
|
+
|
|
1920
|
+
def map(func:typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any], arg:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1921
|
+
|
|
1922
|
+
def map_or_else(option:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict, default:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict, mapper:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression:
|
|
1923
|
+
r"""
|
|
1924
|
+
If option is `Some(value)`, applies `mapper(value)`, otherwise returns default.
|
|
1925
|
+
"""
|
|
1926
|
+
|
|
1927
|
+
@typing.overload
|
|
1928
|
+
def max(operand:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression:
|
|
1929
|
+
r"""
|
|
1930
|
+
Return the maximum element of a list or tensor expression.
|
|
1931
|
+
"""
|
|
1932
|
+
|
|
1933
|
+
@typing.overload
|
|
1934
|
+
def max(lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression:
|
|
1935
|
+
r"""
|
|
1936
|
+
Return the larger of two expressions.
|
|
1937
|
+
"""
|
|
1938
|
+
|
|
1939
|
+
@typing.overload
|
|
1940
|
+
def min(operand:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression:
|
|
1941
|
+
r"""
|
|
1942
|
+
Return the minimum element of a list or tensor expression
|
|
1943
|
+
"""
|
|
1944
|
+
|
|
1945
|
+
@typing.overload
|
|
1946
|
+
def min(lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression:
|
|
1947
|
+
r"""
|
|
1948
|
+
Return the smaller of two expressions.
|
|
1949
|
+
"""
|
|
1950
|
+
|
|
1951
|
+
def neg(expr:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1952
|
+
|
|
1953
|
+
def or_else(option:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict, default:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression:
|
|
1954
|
+
r"""
|
|
1955
|
+
Returns the value inside option if Some, otherwise returns default.
|
|
1956
|
+
"""
|
|
1957
|
+
|
|
1958
|
+
@typing.overload
|
|
1959
|
+
def prod(index:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict, operand:typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any]) -> Expression:
|
|
1960
|
+
r"""
|
|
1961
|
+
Takes an index and an operand representing the product operation in positional style. Eg. `jm.prod(N, lambda i: x[i])`
|
|
1962
|
+
"""
|
|
1963
|
+
|
|
1964
|
+
@typing.overload
|
|
1965
|
+
def prod(operand:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict, axis:typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]=None) -> Expression:
|
|
1966
|
+
r"""
|
|
1967
|
+
Takes the product of a set or tensor-like expression. You can use `axis` to partially reducing the tensor along specified axes. Eg. `jm.prod(N.map(lambda i: x[i]))`
|
|
1968
|
+
"""
|
|
1969
|
+
|
|
1970
|
+
@typing.overload
|
|
1971
|
+
def prod(x:typing.Generator[Expression]) -> Expression:
|
|
1972
|
+
r"""
|
|
1973
|
+
Comprehension syntax for jm.prod (NOTE: only works with decorated API!)
|
|
1974
|
+
"""
|
|
1975
|
+
|
|
1976
|
+
def product(*sets) -> Expression:
|
|
1977
|
+
r"""
|
|
1978
|
+
Takes the cartesian product of given set-like expressions.
|
|
1979
|
+
"""
|
|
1980
|
+
|
|
1981
|
+
def roll(operand:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict, shift:typing.Any, *, axis:typing.Optional[builtins.int]=None) -> Expression: ...
|
|
1982
|
+
|
|
1983
|
+
def rows(array:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1984
|
+
|
|
1985
|
+
def set(operand:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1986
|
+
|
|
1987
|
+
def sin(expr:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1988
|
+
|
|
1989
|
+
def sinh(expr:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1990
|
+
|
|
1991
|
+
def sqrt(expr:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
1992
|
+
|
|
1993
|
+
@typing.overload
|
|
1994
|
+
def sum(index:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict, operand:typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any]) -> Expression:
|
|
1995
|
+
r"""
|
|
1996
|
+
Takes an index and an operand representing the summation operation in positional style. Eg. `jm.sum(N, lambda i: x[i])`
|
|
1997
|
+
"""
|
|
1998
|
+
|
|
1999
|
+
@typing.overload
|
|
2000
|
+
def sum(operand:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict, axis:typing.Optional[Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict]=None) -> Expression:
|
|
2001
|
+
r"""
|
|
2002
|
+
Takes the summation of set or tensor-like expression. You can use `axis` to partially reducing the tensor along specified axes. Eg. `jm.sum(N.map(lambda i: x[i]))`
|
|
2003
|
+
"""
|
|
2004
|
+
|
|
2005
|
+
@typing.overload
|
|
2006
|
+
def sum(x:typing.Generator[Expression]) -> Expression:
|
|
2007
|
+
r"""
|
|
2008
|
+
Comprehension syntax for jm.sum (NOTE: only works with decorated API!)
|
|
2009
|
+
"""
|
|
2010
|
+
|
|
2011
|
+
def tan(expr:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
2012
|
+
|
|
2013
|
+
def tanh(expr:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
2014
|
+
|
|
2015
|
+
def values(dict:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
2016
|
+
|
|
2017
|
+
def xor(lhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict, rhs:Expression | builtins.int | builtins.float | DecisionVar | Placeholder | list | tuple | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any] | dict) -> Expression: ...
|
|
2018
|
+
|