jijmodeling 1.12.3__cp38-abi3-win_amd64.whl → 2.0.0b4__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.
- jijmodeling/_jijmodeling.pyd +0 -0
- jijmodeling/_jijmodeling.pyi +4150 -0
- {jijmodeling-1.12.3.dist-info → jijmodeling-2.0.0b4.dist-info}/METADATA +8 -9
- jijmodeling-2.0.0b4.dist-info/RECORD +8 -0
- {jijmodeling-1.12.3.dist-info → jijmodeling-2.0.0b4.dist-info}/WHEEL +1 -1
- {jijmodeling-1.12.3.dist-info → jijmodeling-2.0.0b4.dist-info}/licenses/LICENSE.txt +3 -2
- jijmodeling/__init__.pyi +0 -5152
- jijmodeling/dataset.py +0 -5
- jijmodeling/dataset.pyi +0 -106
- jijmodeling/experimental.py +0 -13
- jijmodeling/experimental.pyi +0 -302
- jijmodeling/range/__init__.py +0 -14
- jijmodeling/range/__init__.pyi +0 -56
- jijmodeling/range/size.py +0 -14
- jijmodeling/range/size.pyi +0 -54
- jijmodeling/range/value.py +0 -14
- jijmodeling/range/value.pyi +0 -54
- jijmodeling-1.12.3.dist-info/RECORD +0 -18
|
@@ -0,0 +1,4150 @@
|
|
|
1
|
+
# This file is automatically generated by pyo3_stub_gen
|
|
2
|
+
# ruff: noqa: E501, F401
|
|
3
|
+
|
|
4
|
+
import builtins
|
|
5
|
+
import enum
|
|
6
|
+
import numpy
|
|
7
|
+
import numpy.typing
|
|
8
|
+
import ommx.v1
|
|
9
|
+
import typing
|
|
10
|
+
|
|
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 __eq__(self, other: typing.Any) -> Expression: ... # type: ignore[reportIncompatibleMethodOverride]
|
|
23
|
+
def __ne__(self, other: typing.Any) -> Expression: ... # type: ignore[reportIncompatibleMethodOverride]
|
|
24
|
+
def __lt__(self, other: typing.Any) -> Expression: ...
|
|
25
|
+
def __le__(self, other: typing.Any) -> Expression: ...
|
|
26
|
+
def __gt__(self, other: typing.Any) -> Expression: ...
|
|
27
|
+
def __ge__(self, other: typing.Any) -> Expression: ...
|
|
28
|
+
def bnot(self) -> Expression: ...
|
|
29
|
+
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: ...
|
|
30
|
+
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: ...
|
|
31
|
+
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: ...
|
|
32
|
+
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: ...
|
|
33
|
+
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: ...
|
|
34
|
+
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: ...
|
|
35
|
+
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: ...
|
|
36
|
+
def name(self) -> builtins.str: ...
|
|
37
|
+
def description(self) -> typing.Optional[builtins.str]: ...
|
|
38
|
+
def custom_latex(self) -> typing.Optional[builtins.str]: ...
|
|
39
|
+
def __next__(self) -> Expression:
|
|
40
|
+
r"""
|
|
41
|
+
A dummy implementation to make CategoryLabel usable in comprehension syntax with Decorator API.
|
|
42
|
+
Do not call this directly.
|
|
43
|
+
"""
|
|
44
|
+
def __iter__(self) -> CategoryLabel:
|
|
45
|
+
r"""
|
|
46
|
+
A dummy implementation to make CategoryLabel usable in comprehension syntax with Decorator API.
|
|
47
|
+
Do not call this directly.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
class CompileError(builtins.Exception):
|
|
51
|
+
...
|
|
52
|
+
|
|
53
|
+
@typing.final
|
|
54
|
+
class Compiler:
|
|
55
|
+
r"""
|
|
56
|
+
A compiler that converts 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 __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: ...
|
|
86
|
+
@staticmethod
|
|
87
|
+
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:
|
|
88
|
+
r"""
|
|
89
|
+
Creates a :class:`Compiler` object from a :class:`Problem` object and instance data.
|
|
90
|
+
|
|
91
|
+
See :class:`Compiler` constructor for details about `instance_data`.
|
|
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 get_decision_variable_by_name(self, name: str, subscript: typing.Optional[typing.Sequence[builtins.int | builtins.str | CategoryLabel]] = None) -> ommx.v1.DecisionVariable:
|
|
97
|
+
r"""
|
|
98
|
+
Retrieves an OMMX decision variable by its name and optional subscript.
|
|
99
|
+
"""
|
|
100
|
+
def get_constraint_id_by_name(self, name: builtins.str) -> dict:
|
|
101
|
+
r"""
|
|
102
|
+
Obtains a dictionary from subscript to constraint Id.
|
|
103
|
+
"""
|
|
104
|
+
|
|
105
|
+
@typing.final
|
|
106
|
+
class Constraint:
|
|
107
|
+
r"""
|
|
108
|
+
A constraint in the mathematical optimization model.
|
|
109
|
+
|
|
110
|
+
Constraints represent restrictions on the valid values for decision
|
|
111
|
+
variables in the mathematical model. Constraints wrap around a valid
|
|
112
|
+
comparison expression (using `==`, `<=` or `>=`), often featuring decision
|
|
113
|
+
variables on one side.
|
|
114
|
+
|
|
115
|
+
In JijModeling, `Constraints` exist within a :class:`Problem`'s namespace,
|
|
116
|
+
and cannot be defined outside of a problem. So to define a constraint, you
|
|
117
|
+
must use :meth:`Problem.Constraint` on a :class:`Problem` instance.
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
Created `Constraints` must then be explicitly added to a problem using the
|
|
121
|
+
`+=` operator, for example:
|
|
122
|
+
```python
|
|
123
|
+
>>> problem = jm.Problem("problem")
|
|
124
|
+
>>> x = problem.BinaryVar("x", shape=(10,))
|
|
125
|
+
>>> problem += problem.Constraint("constr", x.sum() == 1)
|
|
126
|
+
```
|
|
127
|
+
"""
|
|
128
|
+
@property
|
|
129
|
+
def name(self) -> builtins.str: ...
|
|
130
|
+
@property
|
|
131
|
+
def sense(self) -> ConstraintSense:
|
|
132
|
+
r"""
|
|
133
|
+
An enum representing the comparison involved in this constraint: whether it's
|
|
134
|
+
equality (==), greater-than (>=), or lesser-than (<=).
|
|
135
|
+
|
|
136
|
+
Constraints can be
|
|
137
|
+
- `lhs == rhs` Equalities: `ConstraintSense.EQUAL`
|
|
138
|
+
- `lhs <= rhs` Inequalities: `ConstraintSense.LESS_THAN_EQUAL
|
|
139
|
+
- `lhs >= rhs` Inequalities: `ConstraintSense.GREATER_THAN_EQUAL`
|
|
140
|
+
"""
|
|
141
|
+
@property
|
|
142
|
+
def left(self) -> Expression:
|
|
143
|
+
r"""
|
|
144
|
+
The left-hand side expression of the equality/inequality this constraint represents.
|
|
145
|
+
"""
|
|
146
|
+
@property
|
|
147
|
+
def right(self) -> Expression:
|
|
148
|
+
r"""
|
|
149
|
+
The right-hand side expression of the equality/inequality this constraint represents.
|
|
150
|
+
"""
|
|
151
|
+
@property
|
|
152
|
+
def expression(self) -> Expression:
|
|
153
|
+
r"""
|
|
154
|
+
The full expression of the equality/inequality this constraint represents.
|
|
155
|
+
"""
|
|
156
|
+
@property
|
|
157
|
+
def is_equality(self) -> builtins.bool:
|
|
158
|
+
r"""
|
|
159
|
+
Returns true if the constraint is an equality constraint.
|
|
160
|
+
|
|
161
|
+
Returns
|
|
162
|
+
--------
|
|
163
|
+
`bool`: True if the constraint is an equality constraint. Otherwise, False.
|
|
164
|
+
|
|
165
|
+
Examples
|
|
166
|
+
---------
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
>>> import jijmodeling as jm
|
|
170
|
+
>>> N = jm.Placeholder("N")
|
|
171
|
+
>>> i = jm.Element("i", belong_to=N)
|
|
172
|
+
>>> x = jm.BinaryVar("x", shape=(N,))
|
|
173
|
+
>>> constraint = jm.Constraint("constraint", jm.sum(i, x[i]) == 1)
|
|
174
|
+
>>> assert constraint.is_equality()
|
|
175
|
+
```
|
|
176
|
+
"""
|
|
177
|
+
@property
|
|
178
|
+
def is_inequality(self) -> builtins.bool:
|
|
179
|
+
r"""
|
|
180
|
+
Returns true if the constraint is an inequality constraint.
|
|
181
|
+
|
|
182
|
+
Returns
|
|
183
|
+
--------
|
|
184
|
+
`bool`: True if the constraint is an inequality constraint. Otherwise, False.
|
|
185
|
+
|
|
186
|
+
Examples
|
|
187
|
+
---------
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
>>> import jijmodeling as jm
|
|
191
|
+
>>> N = jm.Placeholder("N")
|
|
192
|
+
>>> i = jm.Element("i", belong_to=N)
|
|
193
|
+
>>> x = jm.BinaryVar("x", shape=(N,))
|
|
194
|
+
>>> constraint = jm.Constraint("constraint", jm.sum(i, x[i]) <= 1)
|
|
195
|
+
>>> assert constraint.is_inequality()
|
|
196
|
+
```
|
|
197
|
+
"""
|
|
198
|
+
def __repr__(self) -> builtins.str: ...
|
|
199
|
+
def _repr_latex_(self) -> builtins.str: ...
|
|
200
|
+
|
|
201
|
+
@typing.final
|
|
202
|
+
class ConstraintDetectionConfig:
|
|
203
|
+
@property
|
|
204
|
+
def constraint_hints(self) -> builtins.list[ConstraintHintName]: ...
|
|
205
|
+
@property
|
|
206
|
+
def max_iter(self) -> typing.Optional[builtins.int]: ...
|
|
207
|
+
@property
|
|
208
|
+
def max_hints(self) -> typing.Optional[builtins.int]: ...
|
|
209
|
+
@property
|
|
210
|
+
def ban_length(self) -> typing.Optional[builtins.int]: ...
|
|
211
|
+
@property
|
|
212
|
+
def num_simplification(self) -> typing.Optional[builtins.int]: ...
|
|
213
|
+
@property
|
|
214
|
+
def match_limit(self) -> typing.Optional[builtins.int]: ...
|
|
215
|
+
def __new__(cls, *, max_iter: typing.Optional[builtins.int] = None, max_hints: typing.Optional[builtins.int] = None, constraint_hints: typing.Optional[typing.Sequence[ConstraintHintName]] = None, num_simplification: typing.Optional[builtins.int] = None, match_limit: typing.Optional[builtins.int] = None, ban_length: typing.Optional[builtins.int] = None) -> ConstraintDetectionConfig: ...
|
|
216
|
+
@staticmethod
|
|
217
|
+
def default_hints() -> builtins.list[ConstraintHintName]: ...
|
|
218
|
+
|
|
219
|
+
@typing.final
|
|
220
|
+
class DecisionVar:
|
|
221
|
+
r"""
|
|
222
|
+
A decision variable in a mathematical model.
|
|
223
|
+
|
|
224
|
+
Decision variables are fundamental parts of mathematical optimization,
|
|
225
|
+
representing the values the solver can change to attempt to optimize the
|
|
226
|
+
objective function. As such, they will likely show up in
|
|
227
|
+
:class:`Expression`s throughout your model. `DecisionVar` should generally
|
|
228
|
+
work where `Expression` is expected and operations will automatically
|
|
229
|
+
convert as needed.
|
|
230
|
+
|
|
231
|
+
Decision variables must belong to some namespace, ie. a :class:`Problem`, so
|
|
232
|
+
you CANNOT construct one directly. Use :meth:`Problem.DecisionVar` or
|
|
233
|
+
shorthand methods (eg. :meth:`Problem.BinaryVar`,
|
|
234
|
+
:meth:`Problem.IntegerVar`, etc.) to define decision variables.
|
|
235
|
+
|
|
236
|
+
Decision variables can be defined and used as scalars (unit variables),
|
|
237
|
+
n-dimensional arrays, or as dictionaries. In the latter two cases, a single
|
|
238
|
+
`DecisionVariable` object represents multiple variables in the model, and
|
|
239
|
+
requires subscripting to access individual variables. This is similar to how
|
|
240
|
+
in a mathematical formula you may call a whole set of variables $x$ made up
|
|
241
|
+
of $x_0, x_1, ...$. More details on these is provided in later sections.
|
|
242
|
+
|
|
243
|
+
## Upper and lower bounds.
|
|
244
|
+
|
|
245
|
+
Decision variables must have well-defined upper and lower bounds. These can
|
|
246
|
+
be specified through any valid expression but **CANNOT** contain decision
|
|
247
|
+
variables. What counts as a valid expression depends the decision variable
|
|
248
|
+
but should be intuitive.
|
|
249
|
+
|
|
250
|
+
For all types of decision variable, a number literal, scalar
|
|
251
|
+
:class:`Placeholder`s, or expressions that evaluate to scalars can be used
|
|
252
|
+
as bounds. When this is used with array or dictionary variables, this sets
|
|
253
|
+
the same bounds for _all_ variables the object represents.
|
|
254
|
+
|
|
255
|
+
For array variables, you can set the bounds separately for each individual
|
|
256
|
+
variable by passing in a matching array expression (eg. an array of numbers
|
|
257
|
+
or an array placeholder). The shape of the decision variable and the bound
|
|
258
|
+
expression must match (eg. a 2x2 decision variable likewise requires a 2x2
|
|
259
|
+
matrix of bounds) and otherwise will cause errors. Due to how placeholders
|
|
260
|
+
may have vaguely-defined shapes, some errors may only happen when evaluating
|
|
261
|
+
the model with actual data.
|
|
262
|
+
|
|
263
|
+
For dictionary variables, you can set the bounds separately by passing in
|
|
264
|
+
a matching dictionary placeholder. The keys of the placeholder must matcha
|
|
265
|
+
the decision variable, and so partial dictionaries cannot be used.
|
|
266
|
+
|
|
267
|
+
For both array and dictionary variables, you can also set each bound
|
|
268
|
+
separately by passing a function (usually a lambda). When evaluating your
|
|
269
|
+
problem, each valid index for that variable (be it a natural number or a key
|
|
270
|
+
from the appropriate category label) will be passed to the function, and the
|
|
271
|
+
returned value must be a scalar that will be used as that variable's bound.
|
|
272
|
+
|
|
273
|
+
Using functions to set bounds is considered a more niche operation you will
|
|
274
|
+
often not need, but it can be useful when there is some operation on the
|
|
275
|
+
instance data you want to use to define the bounds (eg. the upper bound is
|
|
276
|
+
lower bound + 10); or when you want to do some index manipulation (eg.
|
|
277
|
+
setting the bound to an inverse matrix by doing `lambda i,j: V[j,i]`).
|
|
278
|
+
|
|
279
|
+
Binary decision variables should have upper and lower bounds defined as
|
|
280
|
+
`1` and `0` and using other bounds will lead to an error when evaluating
|
|
281
|
+
your model into an OMMX instance. The :meth:`Problem.BinaryVar` method sets
|
|
282
|
+
the correct bounds automatically.
|
|
283
|
+
|
|
284
|
+
## Array decision variables and `shape`
|
|
285
|
+
|
|
286
|
+
You can define `DecisionVar`s as n-dimensional arrays (aka. matrix, tensors,
|
|
287
|
+
etc.) of decision variables. While some operations can work on arrays
|
|
288
|
+
directly, in general this means you'll have to use subscripts (ie. indexing
|
|
289
|
+
with `[]`) to get individual decision variables when writing expressions.
|
|
290
|
+
|
|
291
|
+
Array variables are defined by specifying a `shape` in the constructor method. Shapes are tuples
|
|
292
|
+
or lists of expressions, where each entry specifies the number of decision variables in a given dimension. For example:
|
|
293
|
+
- a `10` shape represents a 1-dimensional array with 10 variables. (Defining the shape as `(10,)` would be equivalent)
|
|
294
|
+
- a `(2, 2)` shape represents a 2-dimensional array with 2 variables in each dimension (a 2x2 matrix)
|
|
295
|
+
|
|
296
|
+
Scalar variables have a shape of `()` (an empty tuple), which is also the
|
|
297
|
+
default value of `shape` when none is specified.
|
|
298
|
+
|
|
299
|
+
Unlike :class:`Placeholder`, decision variables _must_ have a defined shape.
|
|
300
|
+
You cannot simply specify "2-dimensional", for example. As an alternative
|
|
301
|
+
you _can_ define the shape using scalar placeholders or the length of
|
|
302
|
+
placeholders, allowing you to still define decision variable arrays with
|
|
303
|
+
size parametrized on the instance data.
|
|
304
|
+
|
|
305
|
+
## Dictionary decision variables
|
|
306
|
+
|
|
307
|
+
As an alternative to the array-like interface, decision variables can also
|
|
308
|
+
be used in a style closer to python dictionaries: an unordered collection
|
|
309
|
+
indexed by a set of labels. This is recommended mostly when you're focused
|
|
310
|
+
on string-based labels or want non-contiguous indices.
|
|
311
|
+
|
|
312
|
+
To use variables this way, you must first define a set of labels through
|
|
313
|
+
:meth:`Problem.CategoryLabel`s. This is a special kind of placeholder which
|
|
314
|
+
will represent the keys to dictionaries, and can be reused throughout your
|
|
315
|
+
model (eg. to define matching dictionary-like `Placeholder`s).
|
|
316
|
+
|
|
317
|
+
This `CategoryLabel` instance is then passed to the `dict_keys` parameter in
|
|
318
|
+
the appropriate constructor (:meth:`Problem.DecisionVar`, etc.). Tuples of
|
|
319
|
+
category labels can be passed to define dictionaries which use multiple
|
|
320
|
+
keys.
|
|
321
|
+
|
|
322
|
+
The array and dictionary representations are mutually exclusive, and you
|
|
323
|
+
**cannot** set both `shape` and `dict_keys` together. Doing so will lead to
|
|
324
|
+
an exception.
|
|
325
|
+
|
|
326
|
+
Unlike :class:`Placeholder`s, decision variables can only be used as total
|
|
327
|
+
dictionaries over the entire category domain. You cannot define them as
|
|
328
|
+
partial dictionaries, and there is no `partial_dict` parameter.
|
|
329
|
+
|
|
330
|
+
Attributes
|
|
331
|
+
-----------
|
|
332
|
+
- `name` (`str`): A name of the continuous variable.
|
|
333
|
+
- `kind` (`DecisionVarKind`): The kind of the decision variable, which can be one of the following:
|
|
334
|
+
- `BINARY`: A binary variable.
|
|
335
|
+
- `INTEGER`: An integer variable.
|
|
336
|
+
- `CONTINUOUS`: A continuous variable.
|
|
337
|
+
- `SEMI_INTEGER`: A semi-integer variable.
|
|
338
|
+
- `SEMI_CONTINUOUS`: A semi-continuous variable.
|
|
339
|
+
- `shape` (`tuple`): A tuple with the size of each dimension of the integer variable. Empty if the variable is not multi-dimensional.
|
|
340
|
+
- `lower_bound`: The lower bound of the variable.
|
|
341
|
+
- `upper_bound`: The upper bound of the variable.
|
|
342
|
+
- `description` (`str`): A description of the continuous variable.
|
|
343
|
+
|
|
344
|
+
Examples
|
|
345
|
+
---------
|
|
346
|
+
Create a scalar continuous variable whose name is "z" and is bounded to `[-1, 1]`.
|
|
347
|
+
|
|
348
|
+
```python
|
|
349
|
+
>>> import jijmodeling as jm
|
|
350
|
+
>>> problem = jm.Problem("example")
|
|
351
|
+
>>> z = problem.DecisionVar(
|
|
352
|
+
>>> "z",
|
|
353
|
+
>>> kind=jm.DecisionVarKind.CONTINUOUS,
|
|
354
|
+
>>> lower_bound=-1, upper_bound=1
|
|
355
|
+
>>> )
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
or equivalently:
|
|
359
|
+
|
|
360
|
+
```python
|
|
361
|
+
>>> import jijmodeling as jm
|
|
362
|
+
>>> problem = jm.Problem("example")
|
|
363
|
+
>>> z = problem.ContinuousVar("z", lower_bound=-1, upper_bound=1)
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
Create a 2-dimensional integer variable...
|
|
367
|
+
- whose name is "x".
|
|
368
|
+
- whose domain is [0, 2].
|
|
369
|
+
- where each dimension has length 2 (making this a 2x2 matrix).
|
|
370
|
+
|
|
371
|
+
```python
|
|
372
|
+
>>> import jijmodeling as jm
|
|
373
|
+
>>> problem = jm.Problem("example")
|
|
374
|
+
>>> x = problem.IntegerVar("x", shape=[2, 2], lower_bound=0, upper_bound=2)
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
Create a 1-dimensional continuous variable, and construct an expression
|
|
378
|
+
accessing the 123rd component of it..
|
|
379
|
+
|
|
380
|
+
```python
|
|
381
|
+
>>> import jijmodeling as jm
|
|
382
|
+
>>> problem = jm.Problem("example")
|
|
383
|
+
>>> x = problem.ContinuousVar("x", shape=[124], lower_bound=0, upper_bound=2)
|
|
384
|
+
>>> x[123]
|
|
385
|
+
x[123]
|
|
386
|
+
```
|
|
387
|
+
"""
|
|
388
|
+
@property
|
|
389
|
+
def name(self) -> builtins.str: ...
|
|
390
|
+
@property
|
|
391
|
+
def kind(self) -> DecisionVarKind: ...
|
|
392
|
+
@property
|
|
393
|
+
def description(self) -> typing.Optional[builtins.str]: ...
|
|
394
|
+
@property
|
|
395
|
+
def ndim(self) -> typing.Optional[builtins.int]:
|
|
396
|
+
r"""
|
|
397
|
+
The number of dimensions this decision variable represents.
|
|
398
|
+
|
|
399
|
+
This is 0 for scalar variables, and None for dictionary variables.
|
|
400
|
+
"""
|
|
401
|
+
@property
|
|
402
|
+
def shape(self) -> typing.Optional[tuple]:
|
|
403
|
+
r"""
|
|
404
|
+
The shape tuple of the decision variable, consisting of `Expression`s
|
|
405
|
+
that define the size of each dimension.
|
|
406
|
+
|
|
407
|
+
This is an empty tuple if the variable is a scalar, and None if it's a
|
|
408
|
+
dictionary variable.
|
|
409
|
+
"""
|
|
410
|
+
@property
|
|
411
|
+
def lower_bound(self) -> Expression | builtins.list[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]: ...
|
|
412
|
+
@property
|
|
413
|
+
def upper_bound(self) -> Expression | builtins.list[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]: ...
|
|
414
|
+
@property
|
|
415
|
+
def custom_latex(self) -> typing.Optional[builtins.str]:
|
|
416
|
+
r"""
|
|
417
|
+
The custom latex representation of this decision variable, if defined.
|
|
418
|
+
|
|
419
|
+
When no custom latex is defined, the default representation is to use the variable name.
|
|
420
|
+
"""
|
|
421
|
+
@typing.overload
|
|
422
|
+
def min(self) -> Expression:
|
|
423
|
+
r"""
|
|
424
|
+
Creates an expression which refers to the smallest value in `self`.
|
|
425
|
+
|
|
426
|
+
This method works only on valid sequence expressions, where the resulting
|
|
427
|
+
expression is a scalar representing the smallest among all values in the sequence.
|
|
428
|
+
"""
|
|
429
|
+
@typing.overload
|
|
430
|
+
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:
|
|
431
|
+
r"""
|
|
432
|
+
Creates an expression representing the smaller value between `self` and `rhs`.
|
|
433
|
+
|
|
434
|
+
This is a method-based alternative to :func:`jijmodeling.min`.
|
|
435
|
+
"""
|
|
436
|
+
@typing.overload
|
|
437
|
+
def max(self) -> Expression:
|
|
438
|
+
r"""
|
|
439
|
+
Creates an expression which refers to the largest value in `self`.
|
|
440
|
+
|
|
441
|
+
This method works only on valid sequence expressions, where the resulting
|
|
442
|
+
expression is a scalar representing the largest among all values in the sequence.
|
|
443
|
+
"""
|
|
444
|
+
@typing.overload
|
|
445
|
+
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:
|
|
446
|
+
r"""
|
|
447
|
+
Creates an expression representing the larger value between `self` and `rhs`.
|
|
448
|
+
|
|
449
|
+
This is a method-based alternative to :func:`jijmodeling.max`.
|
|
450
|
+
"""
|
|
451
|
+
def __eq__(self, other: typing.Any) -> Expression: ... # type: ignore[reportIncompatibleMethodOverride]
|
|
452
|
+
def __ne__(self, other: typing.Any) -> Expression: ... # type: ignore[reportIncompatibleMethodOverride]
|
|
453
|
+
def __lt__(self, other: typing.Any) -> Expression: ...
|
|
454
|
+
def __le__(self, other: typing.Any) -> Expression: ...
|
|
455
|
+
def __gt__(self, other: typing.Any) -> Expression: ...
|
|
456
|
+
def __ge__(self, other: typing.Any) -> Expression: ...
|
|
457
|
+
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:
|
|
458
|
+
r"""
|
|
459
|
+
Creates an expression representing the summation of `self`.
|
|
460
|
+
|
|
461
|
+
This is an alternative to using :func:`jijmodeling.sum`, where
|
|
462
|
+
a method call on an expression may be more convenient/readable.
|
|
463
|
+
|
|
464
|
+
If `self` isn't a valid sequence which can be summed, you will get an
|
|
465
|
+
error when the resulting expression is added to a :class:`Problem` and is
|
|
466
|
+
type-checked.
|
|
467
|
+
|
|
468
|
+
The optional `axis` parameter allows you to specify one axis of a
|
|
469
|
+
multi-dimensional expression across which to perform the operation.
|
|
470
|
+
|
|
471
|
+
Examples
|
|
472
|
+
------
|
|
473
|
+
|
|
474
|
+
Simple sum of decision variables.
|
|
475
|
+
|
|
476
|
+
```python
|
|
477
|
+
>>> import jijmodeling as jm
|
|
478
|
+
>>> problem = jm.Problem("MyProblem")
|
|
479
|
+
>>> N = problem.Natural("N")
|
|
480
|
+
>>> x = problem.IntegerVar("x", shape=N)
|
|
481
|
+
>>> problem += x.sum()
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
Performing a weighted sum. Note that this sort of usage may lead to errors
|
|
485
|
+
when the shapes don't match. In this case we guarantee that `x` has the
|
|
486
|
+
same shape as `W` through its definition.
|
|
487
|
+
|
|
488
|
+
```python
|
|
489
|
+
>>> import jijmodeling as jm
|
|
490
|
+
>>> problem = jm.Problem("MyProblem")
|
|
491
|
+
>>> W = problem.Float("W", ndim=1)
|
|
492
|
+
>>> N = a.len_at(0)
|
|
493
|
+
>>> x = problem.BinaryVar("x", shape=N)
|
|
494
|
+
>>> problem += (W * x).sum()
|
|
495
|
+
```
|
|
496
|
+
"""
|
|
497
|
+
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:
|
|
498
|
+
r"""
|
|
499
|
+
Creates an expression representing the multiplication of `self`.
|
|
500
|
+
|
|
501
|
+
This is an alternative to using :func:`jijmodeling.prod`, where
|
|
502
|
+
a method call on an expression may be more convenient/readable.
|
|
503
|
+
|
|
504
|
+
If `self` isn't a valid sequence which can be multiplied, you will get an
|
|
505
|
+
error when the resulting expression is added to a :class:`Problem` and is
|
|
506
|
+
type-checked.
|
|
507
|
+
|
|
508
|
+
The optional `axis` parameter allows you to specify one axis of a
|
|
509
|
+
multi-dimensional expression across which to perform the operation.
|
|
510
|
+
|
|
511
|
+
Examples
|
|
512
|
+
------
|
|
513
|
+
|
|
514
|
+
Simple product of decision variables
|
|
515
|
+
|
|
516
|
+
```python
|
|
517
|
+
>>> import jijmodeling as jm
|
|
518
|
+
>>> problem = jm.Problem("MyProblem")
|
|
519
|
+
>>> N = problem.Natural("N")
|
|
520
|
+
>>> x = problem.IntegerVar("x", shape=N)
|
|
521
|
+
>>> problem += x.prod()
|
|
522
|
+
```
|
|
523
|
+
"""
|
|
524
|
+
def __getitem__(self, subscripts: typing.Any) -> Expression: ...
|
|
525
|
+
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:
|
|
526
|
+
r"""
|
|
527
|
+
Creates an expression that maps the values in `self` to `func`.
|
|
528
|
+
|
|
529
|
+
This is an alternative to :func:`jijmodeling.map` which allows you
|
|
530
|
+
to place the indexing expression first.
|
|
531
|
+
|
|
532
|
+
When called on valid scalar scalars, each number from 0 to this `self`
|
|
533
|
+
will be passed to `func`. When called on a sequence expression (eg. a
|
|
534
|
+
1-dimensional placeholder, or the result of functions like
|
|
535
|
+
:func:`jijmodeling.product` or :func:`jijmodeling.items`), each element
|
|
536
|
+
in the sequence is passed to `func`.
|
|
537
|
+
|
|
538
|
+
This is mostly used alongside lambdas as a way to access individual values
|
|
539
|
+
within array-like or dictionary-like :class:`Placeholder`s and
|
|
540
|
+
:class:`DecisionVar`s. The resulting expression is then usually passed to a
|
|
541
|
+
reducer, like :func:`jijmodeling.sum` (or :meth:`Expression.sum` is called
|
|
542
|
+
on it), to form part of a constraint or the objective function.
|
|
543
|
+
|
|
544
|
+
Examples
|
|
545
|
+
------
|
|
546
|
+
|
|
547
|
+
Indexing by values from 0 to N. In this example we define N as the length of
|
|
548
|
+
another placeholder, but a scalar Natural placeholder would work as well.
|
|
549
|
+
|
|
550
|
+
```python
|
|
551
|
+
>>> import jijmodeling as jm
|
|
552
|
+
>>> problem = jm.Problem("MyProblem")
|
|
553
|
+
>>> W = problem.Float("W", ndim=1)
|
|
554
|
+
>>> N = W.len_at(0)
|
|
555
|
+
>>> x = problem.BinaryVar("x", shape=N)
|
|
556
|
+
>>> problem += N.map(lambda i: W[i] * x[i]).sum()
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
Indexing by specific values from instance data. In this example only the
|
|
560
|
+
indices present in `C` in the instance data will be used in this constraint.
|
|
561
|
+
|
|
562
|
+
```python
|
|
563
|
+
>>> import jijmodeling as jm
|
|
564
|
+
>>> problem = jm.Problem("MyProblem")
|
|
565
|
+
>>> N = problem.Natural("N")
|
|
566
|
+
>>> x = problem.IntegerVar("x", shape=N, lower_bound=0, upper_bound=10)
|
|
567
|
+
>>> C = problem.Natural("C", ndim=1)
|
|
568
|
+
>>> problem += problem.Constraint("constr", C.map(lambda i: x[i]).sum() <= 100)
|
|
569
|
+
```
|
|
570
|
+
"""
|
|
571
|
+
def roll(self, shift: typing.Any, *, axis: typing.Optional[builtins.int] = None) -> Expression: ...
|
|
572
|
+
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:
|
|
573
|
+
r"""
|
|
574
|
+
Creates an expression that filters the values of this sequence.
|
|
575
|
+
|
|
576
|
+
`predicate` will be called on each element in `self`. The resulting
|
|
577
|
+
expression represents only the values for which `predicate` is true.
|
|
578
|
+
|
|
579
|
+
This is an alternative to :func:`jijmodeling.filter` which allows
|
|
580
|
+
you to place the indexing expression first.
|
|
581
|
+
|
|
582
|
+
This is often useful when trying to create summations which only include
|
|
583
|
+
a subset of potential indices.The resulting expression is usually used as the
|
|
584
|
+
basis for :func:`jijmodeling.map`, :func:`jijmodeling.sum`, etc., or a
|
|
585
|
+
method equivalent.
|
|
586
|
+
|
|
587
|
+
Examples
|
|
588
|
+
------
|
|
589
|
+
|
|
590
|
+
Using only variables with even indices as part of a constraint.
|
|
591
|
+
|
|
592
|
+
```python
|
|
593
|
+
>>> import jijmodeling as jm
|
|
594
|
+
>>> problem = jm.Problem("MyProblem")
|
|
595
|
+
>>> N = jm.Natural("N")
|
|
596
|
+
>>> x = problem.BinaryVar("x", shape=(N, N))
|
|
597
|
+
>>> even_xs = N.filter(lambda i: i % 2 == 0).map(lambda i: x[i])
|
|
598
|
+
>>> problem += problem.Constraint("constr", even_xs.sum() <= 10)
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
Using only non-diagonal indices of an NxN matrix as part of a constraint, using the method version of `filter`.
|
|
602
|
+
|
|
603
|
+
```python
|
|
604
|
+
>>> import jijmodeling as jm
|
|
605
|
+
>>> problem = jm.Problem("MyProblem")
|
|
606
|
+
>>> N = jm.Natural("N")
|
|
607
|
+
>>> x = problem.BinaryVar("x", shape=(N, N))
|
|
608
|
+
>>> W = problem.Float("W", shape=(N, N))
|
|
609
|
+
>>> non_diagonals = jm.product(N, N).filter(lambda i, j: i != j)
|
|
610
|
+
>>> problem += problem.Constraint("constr", lambda i, j: W[i, j] * x[i, j], domain=non_diagonals)
|
|
611
|
+
```
|
|
612
|
+
"""
|
|
613
|
+
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:
|
|
614
|
+
r"""
|
|
615
|
+
Creates an expression which works like :meth:`map`, but flattens nested structure.
|
|
616
|
+
|
|
617
|
+
This is an alternative to :func:`jijmodeling.flat_map` which allows you to
|
|
618
|
+
place the indexing expression first.
|
|
619
|
+
|
|
620
|
+
`map` is useful when `func` returns scalar values, but in some
|
|
621
|
+
situations one wants to write a `func` that returns other
|
|
622
|
+
mappings/sequences instead. That is where `flat_map` should be used,
|
|
623
|
+
"flattening" all sequences/iterators into a single linear sequence
|
|
624
|
+
(which can then be reduced with :meth:`sum`, etc.)
|
|
625
|
+
|
|
626
|
+
You can also compare `flat_map` to a nested for-loop, or a generator
|
|
627
|
+
expression that uses two `for` clauses. Indeed when using the decorated API
|
|
628
|
+
(see tutorials or :meth:`Problem.update`), you can use a generator
|
|
629
|
+
expression-like syntax instead.
|
|
630
|
+
|
|
631
|
+
Examples
|
|
632
|
+
------
|
|
633
|
+
|
|
634
|
+
Using only non-diagonal indices of an NxN matrix.
|
|
635
|
+
```python
|
|
636
|
+
>>> import jijmodeling as jm
|
|
637
|
+
>>> problem = jm.Problem("MyProblem")
|
|
638
|
+
>>> N = jm.Natural("N")
|
|
639
|
+
>>> x = problem.BinaryVar("x", shape=(N, N))
|
|
640
|
+
>>> W = problem.Float("W", shape=(N, N))
|
|
641
|
+
>>> objective = N.flat_map(
|
|
642
|
+
... lambda i: N.filter(lambda j: i != j).map(lambda j: W[i, j] * x[i, j])
|
|
643
|
+
... ).sum()
|
|
644
|
+
>>> problem += objective
|
|
645
|
+
```
|
|
646
|
+
"""
|
|
647
|
+
def rows(self) -> Expression:
|
|
648
|
+
r"""
|
|
649
|
+
Creates a sequence over the rows of this multi-dimensional array expression.
|
|
650
|
+
|
|
651
|
+
That is, each element will be a whole row (itself containing multiple
|
|
652
|
+
values), which can then be operated on like other sequences (eg. using
|
|
653
|
+
:func:`jijmodelng.sum` or :func:`jijmodeling.map`).
|
|
654
|
+
|
|
655
|
+
If the array is 3-dimensional or higher, rows will iterate over the first
|
|
656
|
+
dimension/axis. For example, in a 3D matrix, the first element would be a
|
|
657
|
+
2D matrix representing all values `x[0, _, _]`
|
|
658
|
+
|
|
659
|
+
Examples
|
|
660
|
+
------
|
|
661
|
+
|
|
662
|
+
Create an objective function that multiplies each variable in a row, and
|
|
663
|
+
then sums each row. In this case we have a 2x3 matrix, so the final expression is
|
|
664
|
+
`x[0, 0] * x[0, 1] * x[0, 2] + x[1, 0] * x[1, 1] * x[1, 2]`. Using
|
|
665
|
+
placeholders instead of literals in `shape` would allow this to be written
|
|
666
|
+
for matrices of arbitrary size.
|
|
667
|
+
```python
|
|
668
|
+
>>> import jijmodeling as jm
|
|
669
|
+
>>> problem = jm.Problem("MyProblem")
|
|
670
|
+
>>> d = problem.BinaryVar("d", shape=(2, 3))
|
|
671
|
+
>>> problem += d.rows().map(lambda xs: xs.prod()).sum()
|
|
672
|
+
```
|
|
673
|
+
|
|
674
|
+
If the number of elements in the row can be guaranteed, the elements can be
|
|
675
|
+
destructured as separate arguments in a lambda expression:
|
|
676
|
+
|
|
677
|
+
```python
|
|
678
|
+
>>> import jijmodeling as jm
|
|
679
|
+
>>> problem = jm.Problem("MyProblem")
|
|
680
|
+
>>> N = problem.Natural("N")
|
|
681
|
+
>>> V = problem.Natural("V")
|
|
682
|
+
>>> E = problem.Natural("E", shape=(N, 2))
|
|
683
|
+
>>> x = problem.BinaryVar("x", shape=V)
|
|
684
|
+
>>> problem += jm.map(lambda i, j: x[i] * x[j], E.rows()).sum()
|
|
685
|
+
```
|
|
686
|
+
"""
|
|
687
|
+
def indices(self) -> Expression:
|
|
688
|
+
r"""
|
|
689
|
+
Get the set of indices of given array or jagged array.
|
|
690
|
+
|
|
691
|
+
Will throw type error when called on non-array type.
|
|
692
|
+
"""
|
|
693
|
+
def keys(self) -> Expression:
|
|
694
|
+
r"""
|
|
695
|
+
Returns an expression representing this dictionary-like object's keys.
|
|
696
|
+
|
|
697
|
+
In other words, this is the JijModeling equivalent of the `keys()`
|
|
698
|
+
method on Python dictionaries, used when creating JijModeling
|
|
699
|
+
expressions.
|
|
700
|
+
|
|
701
|
+
While it's possible to call this on any :class:`Expression`, this is
|
|
702
|
+
intended for dictionary-like :class:`Placeholder`s and
|
|
703
|
+
:class:`DecisionVar`s. Using this with an invalid object will lead
|
|
704
|
+
to an error when the resulting expression is added to a
|
|
705
|
+
:class:`Problem` and is type-checked.
|
|
706
|
+
|
|
707
|
+
See also :meth:`Expression.values` and :meth:`Expression.items`.
|
|
708
|
+
|
|
709
|
+
Examples
|
|
710
|
+
------
|
|
711
|
+
Refer to a dictionary-like placeholder's keys when
|
|
712
|
+
creating other objects or writing summations:
|
|
713
|
+
|
|
714
|
+
```python
|
|
715
|
+
>>> import jijmodeling as jm
|
|
716
|
+
>>> problem = jm.Problem("MyProblem")
|
|
717
|
+
>>> I = problem.CategoryLabel("I")
|
|
718
|
+
>>> W = problem.Float("W", dict_keys=I)
|
|
719
|
+
>>> x = problem.BinaryVar("x", dict_keys=W.keys())
|
|
720
|
+
>>> problem += jm.sum(W.keys(), lambda i: W[i] * x[i])
|
|
721
|
+
```
|
|
722
|
+
"""
|
|
723
|
+
def values(self) -> Expression:
|
|
724
|
+
r"""
|
|
725
|
+
Returns an expression representing this dictionary-like object's values.
|
|
726
|
+
|
|
727
|
+
In other words, this is the JijModeling equivalent of the `values()`
|
|
728
|
+
method on Python dictionaries, used when creating JijModeling
|
|
729
|
+
expressions.
|
|
730
|
+
|
|
731
|
+
While it's possible to call this on any :class:`Expression`, this is
|
|
732
|
+
intended for dictionary-like :class:`Placeholder`s and
|
|
733
|
+
:class:`DecisionVar`s. Using this with an invalid object will lead
|
|
734
|
+
to an error when the resulting expression is added to a
|
|
735
|
+
:class:`Problem` and is type-checked.
|
|
736
|
+
|
|
737
|
+
See also :meth:`Expression.keys` and :meth:`Expression.items`.
|
|
738
|
+
|
|
739
|
+
Examples
|
|
740
|
+
------
|
|
741
|
+
Defining a simple objective function which just sums a dictionary-based decision variable.
|
|
742
|
+
|
|
743
|
+
```python
|
|
744
|
+
>>> problem = jm.Problem("MyProblem")
|
|
745
|
+
>>> I = problem.CategoryLabel("I")
|
|
746
|
+
>>> x = problem.IntegerVar("x", dict_keys=I, lower_bound=0, upper_bound=100)
|
|
747
|
+
>>> problem += x.values().sum()
|
|
748
|
+
```
|
|
749
|
+
"""
|
|
750
|
+
def items(self) -> Expression:
|
|
751
|
+
r"""
|
|
752
|
+
Returns an expression representing this object's `(key,value)` pairs.
|
|
753
|
+
|
|
754
|
+
In other words, this is the JijModeling equivalent of the `items()`
|
|
755
|
+
method on Python dictionaries, used when creating JijModeling
|
|
756
|
+
expressions.
|
|
757
|
+
|
|
758
|
+
While it's possible to call this on any :class:`Expression`, this is
|
|
759
|
+
intended for dictionary-like :class:`Placeholder`s and
|
|
760
|
+
:class:`DecisionVar`s. Using this with an invalid object will lead
|
|
761
|
+
to an error when the resulting expression is added to a
|
|
762
|
+
:class:`Problem` and is type-checked.
|
|
763
|
+
|
|
764
|
+
See also :meth:`Expression.keys` and :meth:`Expression.values`.
|
|
765
|
+
|
|
766
|
+
Examples
|
|
767
|
+
------
|
|
768
|
+
Simple matching of weights to their respective variables, as an alternative to just using `keys()` or the `CategoryLabel`:
|
|
769
|
+
|
|
770
|
+
```python
|
|
771
|
+
>>> problem = jm.Problem("MyProblem")
|
|
772
|
+
>>> I = problem.CategoryLabel("I")
|
|
773
|
+
>>> weights = problem.Float("W", dict_keys=I)
|
|
774
|
+
>>> x = problem.BinaryVar("x", dict_keys=I)
|
|
775
|
+
>>> problem += jm.sum(weights.items(), lambda i, w: w * x[i])
|
|
776
|
+
```
|
|
777
|
+
|
|
778
|
+
Same as above, but using the decorated API:
|
|
779
|
+
```python
|
|
780
|
+
>>> @problem.update
|
|
781
|
+
... def _(problem):
|
|
782
|
+
... I = problem.CategoryLabel()
|
|
783
|
+
... W = problem.Float(dict_keys=I)
|
|
784
|
+
... x = problem.BinaryVar(dict_keys=I)
|
|
785
|
+
... problem += jm.sum(w * x[i] for i, w in W.items())
|
|
786
|
+
```
|
|
787
|
+
"""
|
|
788
|
+
def __neg__(self) -> Expression: ...
|
|
789
|
+
def abs(self) -> Expression:
|
|
790
|
+
r"""
|
|
791
|
+
Returns an expression representing the absolute value of the given expression.
|
|
792
|
+
|
|
793
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
794
|
+
"""
|
|
795
|
+
def sqrt(self) -> Expression:
|
|
796
|
+
r"""
|
|
797
|
+
Returns an expression representing the square root of the given expression.
|
|
798
|
+
|
|
799
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
800
|
+
"""
|
|
801
|
+
def sin(self) -> Expression:
|
|
802
|
+
r"""
|
|
803
|
+
Returns an expression representing the sine of the given expression.
|
|
804
|
+
|
|
805
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
806
|
+
"""
|
|
807
|
+
def cos(self) -> Expression:
|
|
808
|
+
r"""
|
|
809
|
+
Returns an expression representing the cosine of the given expression.
|
|
810
|
+
|
|
811
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
812
|
+
"""
|
|
813
|
+
def tan(self) -> Expression:
|
|
814
|
+
r"""
|
|
815
|
+
Returns an expression representing the tangent of the given expression.
|
|
816
|
+
|
|
817
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
818
|
+
"""
|
|
819
|
+
def asin(self) -> Expression:
|
|
820
|
+
r"""
|
|
821
|
+
Returns an expression representing the arcsine of the given expression.
|
|
822
|
+
|
|
823
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
824
|
+
"""
|
|
825
|
+
def acos(self) -> Expression:
|
|
826
|
+
r"""
|
|
827
|
+
Returns an expression representing the arccosine of the given expression.
|
|
828
|
+
|
|
829
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
830
|
+
"""
|
|
831
|
+
def atan(self) -> Expression:
|
|
832
|
+
r"""
|
|
833
|
+
Returns an expression representing the arctangent of the given expression.
|
|
834
|
+
|
|
835
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
836
|
+
"""
|
|
837
|
+
def sinh(self) -> Expression:
|
|
838
|
+
r"""
|
|
839
|
+
Returns an expression representing the hyperbolic sine of the given expression.
|
|
840
|
+
|
|
841
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
842
|
+
"""
|
|
843
|
+
def cosh(self) -> Expression:
|
|
844
|
+
r"""
|
|
845
|
+
Returns an expression representing the hyperbolic cosine of the given expression.
|
|
846
|
+
|
|
847
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
848
|
+
"""
|
|
849
|
+
def tanh(self) -> Expression:
|
|
850
|
+
r"""
|
|
851
|
+
Returns an expression representing the hyperbolic tangent of the given expression.
|
|
852
|
+
|
|
853
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
854
|
+
"""
|
|
855
|
+
def asinh(self) -> Expression:
|
|
856
|
+
r"""
|
|
857
|
+
Returns an expression representing the hyperbolic arcsine of the given expression.
|
|
858
|
+
|
|
859
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
860
|
+
"""
|
|
861
|
+
def acosh(self) -> Expression:
|
|
862
|
+
r"""
|
|
863
|
+
Returns an expression representing the hyperbolic arccosine of the given expression.
|
|
864
|
+
|
|
865
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
866
|
+
"""
|
|
867
|
+
def atanh(self) -> Expression:
|
|
868
|
+
r"""
|
|
869
|
+
Returns an expression representing the hyperbolic arctangent of the given expression.
|
|
870
|
+
|
|
871
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
872
|
+
"""
|
|
873
|
+
def exp(self) -> Expression:
|
|
874
|
+
r"""
|
|
875
|
+
Returns an expression representing the application of the exponential function on the given expression.
|
|
876
|
+
|
|
877
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
878
|
+
"""
|
|
879
|
+
def ln(self) -> Expression:
|
|
880
|
+
r"""
|
|
881
|
+
Returns an expression representing the natural logarithm of the given expression.
|
|
882
|
+
|
|
883
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
884
|
+
"""
|
|
885
|
+
def log10(self) -> Expression:
|
|
886
|
+
r"""
|
|
887
|
+
Returns an expression representing the decimal logarithm of the given expression.
|
|
888
|
+
|
|
889
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
890
|
+
"""
|
|
891
|
+
def log2(self) -> Expression:
|
|
892
|
+
r"""
|
|
893
|
+
Returns an expression representing the binary logarithm of the given expression.
|
|
894
|
+
|
|
895
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
896
|
+
"""
|
|
897
|
+
def ceil(self) -> Expression:
|
|
898
|
+
r"""
|
|
899
|
+
Returns an expression which rounds down to the nearest whole number.
|
|
900
|
+
|
|
901
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
902
|
+
"""
|
|
903
|
+
def floor(self) -> Expression: ...
|
|
904
|
+
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: ...
|
|
905
|
+
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: ...
|
|
906
|
+
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: ...
|
|
907
|
+
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: ...
|
|
908
|
+
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: ...
|
|
909
|
+
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: ...
|
|
910
|
+
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: ...
|
|
911
|
+
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: ...
|
|
912
|
+
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: ...
|
|
913
|
+
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: ...
|
|
914
|
+
def __pow__(self, exponent: typing.Any, modulo: typing.Optional[typing.Any] = None) -> Expression: ...
|
|
915
|
+
def __rpow__(self, base: typing.Any, modulo: typing.Optional[typing.Any] = None) -> Expression: ...
|
|
916
|
+
def __repr__(self) -> builtins.str: ...
|
|
917
|
+
def _repr_latex_(self) -> builtins.str: ...
|
|
918
|
+
|
|
919
|
+
@typing.final
|
|
920
|
+
class DecoratedProblem(typing.Protocol):
|
|
921
|
+
r"""
|
|
922
|
+
A variant of `Problem` that is only available in Decorator API provided by `Problem.update`.
|
|
923
|
+
See `Problem` for more details.
|
|
924
|
+
"""
|
|
925
|
+
@property
|
|
926
|
+
def objective(self) -> Expression: ...
|
|
927
|
+
@property
|
|
928
|
+
def description(self) -> builtins.str:
|
|
929
|
+
r"""
|
|
930
|
+
The problem description.
|
|
931
|
+
|
|
932
|
+
An empty string if no description was defined.
|
|
933
|
+
"""
|
|
934
|
+
@property
|
|
935
|
+
def constraints(self) -> builtins.dict[builtins.str, builtins.list[Constraint]]:
|
|
936
|
+
r"""
|
|
937
|
+
Returns a dictionary of the constraints in the problem.
|
|
938
|
+
|
|
939
|
+
Returns
|
|
940
|
+
--------
|
|
941
|
+
`dict[str, [Constraint]]`: Dictionary mapping constraint names to Constraint objects.
|
|
942
|
+
"""
|
|
943
|
+
@typing.overload
|
|
944
|
+
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:
|
|
945
|
+
r"""
|
|
946
|
+
Constructs `Constraint` object from comparison expression, __WITHOUT__ registering it to the problem.
|
|
947
|
+
Use `+=` operator to register the constraint to the problem.
|
|
948
|
+
"""
|
|
949
|
+
@typing.overload
|
|
950
|
+
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:
|
|
951
|
+
r"""
|
|
952
|
+
Constructs ``Constraint`` family with the index set ``domain`` and function ``expression`` to build comparison expression from each index, __WITHOUT__ registering it to the problem.
|
|
953
|
+
Use `+=` operator to register the constraint to the problem.
|
|
954
|
+
"""
|
|
955
|
+
@typing.overload
|
|
956
|
+
def Constraint(self, name: str, expressions: typing.Generator[Expression, None, None], description: typing.Optional[builtins.str] = None) -> Constraint:
|
|
957
|
+
r"""
|
|
958
|
+
Comprehension syntax for jm.prod (NOTE: only works with decorated API!)
|
|
959
|
+
"""
|
|
960
|
+
def used_placeholders(self) -> builtins.list[Placeholder]: ...
|
|
961
|
+
def get_problem_schema(self) -> dict:
|
|
962
|
+
r"""
|
|
963
|
+
Returns the schema of the problem.
|
|
964
|
+
|
|
965
|
+
Returns
|
|
966
|
+
--------
|
|
967
|
+
- `schema`: The dictionary containing the schema of the problem.
|
|
968
|
+
"""
|
|
969
|
+
def generate_random_dataset(self, _default: typing.Any, _options: typing.Any, _seed: typing.Optional[builtins.int]) -> typing.Any:
|
|
970
|
+
r"""
|
|
971
|
+
Generates a dictionary of random `InstanceDataValue` for a given problem.
|
|
972
|
+
To generate `ommx.v1.Instance` object directly, use `InstanceDataValue.generate_random_instance` instead.
|
|
973
|
+
|
|
974
|
+
Args
|
|
975
|
+
-----
|
|
976
|
+
- `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).
|
|
977
|
+
- `default` (optional): default range parameters for placeholders which is not specified in `options`.
|
|
978
|
+
- `seed` (optional): seed for random number generation.
|
|
979
|
+
|
|
980
|
+
Returns
|
|
981
|
+
--------
|
|
982
|
+
`dict`: The dictionary from the name of placeholders to the generated `InstanceDataValue` objects. To be fed to `Interpreter.eval_problem`.
|
|
983
|
+
|
|
984
|
+
Range Parameters and Range Syntax
|
|
985
|
+
----------------------------------
|
|
986
|
+
A range parameter is a dictionary consisting of the following fields:
|
|
987
|
+
- `size` (optional): interval of natural numbers for the size of each array dimension (default: `range(1, 6)`)
|
|
988
|
+
- `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]$).
|
|
989
|
+
|
|
990
|
+
Example range parameter config:
|
|
991
|
+
|
|
992
|
+
```python
|
|
993
|
+
{"size": range(2, 10), "value": jm.range.value.closed(100.0, 200.0)}
|
|
994
|
+
```
|
|
995
|
+
|
|
996
|
+
Intervals are expressed as a range object.
|
|
997
|
+
Currently, the following syntax is supported for range objects:
|
|
998
|
+
|
|
999
|
+
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.
|
|
1000
|
+
2. Use the functions from `jijmodeling.range`, `jijmodeling.range.size`, or `jijmodeling.range.value` modules.
|
|
1001
|
+
- 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.
|
|
1002
|
+
- These three modules provides the following combinators (see the module documents for more details.):
|
|
1003
|
+
- `closed(a, b)`: a closed interval $[a, b]$
|
|
1004
|
+
- `open(a, b)`: an open interval $(a, b)$
|
|
1005
|
+
- `closed_open(a, b)`: an upper half-open interval $[a, b)$
|
|
1006
|
+
- `open_closed(a, b)`: a lower half-open interval $(a, b]$
|
|
1007
|
+
- `greater_than(a)`: an open interval $(a, \infty)$
|
|
1008
|
+
- `at_least(a)`: a closed interval $[a, \infty)$
|
|
1009
|
+
- `less_than(a)`: an open interval $(-\infty, a)$
|
|
1010
|
+
- `at_most(a)`: a closed interval $(-\infty, a]$
|
|
1011
|
+
3. Use `range` builtin function: this is equivalent to `jijmodeling.range.value.closed_open(a, b)`.
|
|
1012
|
+
- Any python range object with `step = 1` can be used as a size range; otherwise it results in runtime error.
|
|
1013
|
+
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`.
|
|
1014
|
+
- You can also use bound object as a tuple component; in such case, both tuple components must be one of the following:
|
|
1015
|
+
|
|
1016
|
+
1. A string `"Unbounded"` means $-\infty$ (in the first component) or $\infty$ (the second).
|
|
1017
|
+
2. A dictionary `{"Included": a}` means the endpoint is inclusive.
|
|
1018
|
+
3. A dictionary `{"Excluded": a}` means the endpoint is exclusive.
|
|
1019
|
+
- Examples:
|
|
1020
|
+
- `(1.2, 4)` is equivalent to `closed_open(1.2, 4)`,
|
|
1021
|
+
- `(-1, {"Included": 1})` is equivalent to `closed(-1, 1)`,
|
|
1022
|
+
- `(-5, {"Excluded": 4})` is equivalent to `closed_open(-5, 4)` and built in function `range(-5, 4)`,
|
|
1023
|
+
- `({"Excluded": 1}, {"Excluded": 2.5})` is equivalent to `open(1, 2.5)`,
|
|
1024
|
+
- `({"Included": -1}, "Unbounded")` is equivalent to `at_least(-1)`.
|
|
1025
|
+
- `(5, "Unbounded")` is **INVALID**; `5` must be bound object.
|
|
1026
|
+
5. The range object: A dictionary of form `{"start": lb, "end": ub}`, where both `lb` and `ub` are the bound object described as above.
|
|
1027
|
+
|
|
1028
|
+
Examples
|
|
1029
|
+
---------
|
|
1030
|
+
```python
|
|
1031
|
+
>>> import jijmodeling as jm
|
|
1032
|
+
>>> import builtins
|
|
1033
|
+
>>> N = jm.Placeholder("N", dtype=jm.DataType.INTEGER)
|
|
1034
|
+
>>> c = jm.Placeholder("c", dtype=jm.DataType.FLOAT, shape=(N,))
|
|
1035
|
+
>>> x = jm.BinaryVar("x", shape=(N,))
|
|
1036
|
+
>>> i = jm.Element("i", belong_to=N)
|
|
1037
|
+
|
|
1038
|
+
>>> problem = jm.Problem("problem")
|
|
1039
|
+
>>> problem += jm.sum(i, c[i] * x[i])
|
|
1040
|
+
|
|
1041
|
+
>>> inputs = problem.generate_random_dataset(
|
|
1042
|
+
... options={
|
|
1043
|
+
... 'N': {"value": builtins.range(10, 20)},
|
|
1044
|
+
... 'c': {"value": jm.range.value.closed(-1.0, 1.0)}
|
|
1045
|
+
... # You can also specify "size" for the range of jagged array dimension size.
|
|
1046
|
+
... },
|
|
1047
|
+
... seed=123 # omittable
|
|
1048
|
+
... )
|
|
1049
|
+
>>> assert set(inputs.keys()) == {"N", "c"}
|
|
1050
|
+
>>> inputs
|
|
1051
|
+
{'N': 11.0, 'c': array([ 0.93914459, -0.06511935, -0.7460324 , -0.32443706, 0.99981451,
|
|
1052
|
+
-0.24407535, 0.31329469, 0.52206453, -0.1291936 , 0.30443087,
|
|
1053
|
+
0.53125838])}
|
|
1054
|
+
|
|
1055
|
+
```
|
|
1056
|
+
"""
|
|
1057
|
+
def generate_random_instance(self, _default: typing.Any, _options: typing.Any, _seed: typing.Optional[builtins.int], _hints: typing.Optional[typing.Any]) -> typing.Any:
|
|
1058
|
+
r"""
|
|
1059
|
+
Generates random `ommx.v1.Instance` for a given problem.
|
|
1060
|
+
See also `InstanceDataValue.generate_random_dataset`.
|
|
1061
|
+
|
|
1062
|
+
Args
|
|
1063
|
+
-----
|
|
1064
|
+
- `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`).
|
|
1065
|
+
- `default` (optional): default range parameters for placeholders which is not specified in `options`.
|
|
1066
|
+
- `seed` (optional): seed for random number generation.
|
|
1067
|
+
- `hints` (optional): the hints to be detected during compilation see `Interpreter.eval_problem` for more details.
|
|
1068
|
+
|
|
1069
|
+
Returns
|
|
1070
|
+
--------
|
|
1071
|
+
`instance`: The OMMX v1 instance object.
|
|
1072
|
+
|
|
1073
|
+
Examples
|
|
1074
|
+
---------
|
|
1075
|
+
```python
|
|
1076
|
+
>>> import jijmodeling as jm
|
|
1077
|
+
>>> import builtins
|
|
1078
|
+
>>> import ommx.v1
|
|
1079
|
+
>>> N = jm.Placeholder("N", dtype=jm.DataType.INTEGER)
|
|
1080
|
+
>>> c = jm.Placeholder("c", dtype=jm.DataType.FLOAT, shape=(N,))
|
|
1081
|
+
>>> x = jm.BinaryVar("x", shape=(N,))
|
|
1082
|
+
>>> i = jm.Element("i", belong_to=N)
|
|
1083
|
+
|
|
1084
|
+
>>> problem = jm.Problem("problem")
|
|
1085
|
+
>>> problem += jm.sum(i, c[i] * x[i])
|
|
1086
|
+
|
|
1087
|
+
>>> instance = problem.generate_random_instance(
|
|
1088
|
+
... options={
|
|
1089
|
+
... 'N': {"value": builtins.range(10, 20)},
|
|
1090
|
+
... 'c': {"value": jm.range.value.closed(-1.0, 1.0)}
|
|
1091
|
+
... },
|
|
1092
|
+
... seed=123
|
|
1093
|
+
... )
|
|
1094
|
+
>>> assert type(instance) is ommx.v1.Instance
|
|
1095
|
+
|
|
1096
|
+
```
|
|
1097
|
+
"""
|
|
1098
|
+
def type_of(self, name: builtins.str) -> Type:
|
|
1099
|
+
r"""
|
|
1100
|
+
Returns the type associated with a given name (eg. of a placeholder or decision variable).
|
|
1101
|
+
|
|
1102
|
+
This is mostly inteded for testing purposes, and not as part of standard model writing.
|
|
1103
|
+
|
|
1104
|
+
:raises ModelingError: If the name is undefined in this problem's namespace.
|
|
1105
|
+
"""
|
|
1106
|
+
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:
|
|
1107
|
+
r"""
|
|
1108
|
+
Infers the resulting type of an expression using this problem as a namespace.
|
|
1109
|
+
|
|
1110
|
+
This is mostly intended for testing purposes, and not as part of standard model writing.
|
|
1111
|
+
|
|
1112
|
+
Examples
|
|
1113
|
+
===
|
|
1114
|
+
```python
|
|
1115
|
+
>>> problem = jm.Problem("MyProblem")
|
|
1116
|
+
>>> N = problem.Length(name="N")
|
|
1117
|
+
>>> x = problem.BinaryVar("x", shape=(N,))
|
|
1118
|
+
>>> y = problem.IntegerVar("y", shape=(N,), lower_bound=0,upper_bound=10)
|
|
1119
|
+
>>> problem.infer(jm.sum(x))
|
|
1120
|
+
binary!
|
|
1121
|
+
>>> problem.infer(jm.sum(y))
|
|
1122
|
+
int!
|
|
1123
|
+
```
|
|
1124
|
+
"""
|
|
1125
|
+
def decision_vars(self) -> builtins.dict[builtins.str, DecisionVar]:
|
|
1126
|
+
r"""
|
|
1127
|
+
Returns a dictionary of decision variables in the problem.
|
|
1128
|
+
|
|
1129
|
+
Returns
|
|
1130
|
+
--------
|
|
1131
|
+
`dict[str, DecisionVar]`: Dictionary mapping variable names to DecisionVar objects.
|
|
1132
|
+
"""
|
|
1133
|
+
def placeholders(self) -> builtins.dict[builtins.str, Placeholder]:
|
|
1134
|
+
r"""
|
|
1135
|
+
Returns a dictionary of placeholders in the problem.
|
|
1136
|
+
The dictionary may contain placeholders that are not used in the problem;
|
|
1137
|
+
to get only used placeholders, use `used_placeholders` method.
|
|
1138
|
+
|
|
1139
|
+
Returns
|
|
1140
|
+
--------
|
|
1141
|
+
`dict[str, Placeholder]`: Dictionary mapping placeholder names to Placeholder objects.
|
|
1142
|
+
"""
|
|
1143
|
+
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:
|
|
1144
|
+
r"""
|
|
1145
|
+
Defines a :class:`Placeholder` in this problem's namespace.
|
|
1146
|
+
|
|
1147
|
+
Placeholders can be a scalar, multi-dimensional array (representing arrays and
|
|
1148
|
+
matrices), or dictionary keyed by integers or strings.
|
|
1149
|
+
|
|
1150
|
+
When calling `DecoratedProblem.Placehoder`, you must specify `dtype` explicitly to indicate the type of data the placeholder holds.
|
|
1151
|
+
Alternative shorthand methods like `DecoratedProblem.Integer`, `DecoratedProblem.Binary`,
|
|
1152
|
+
or `DecoratedProblem.Natural` are recommended for convenience in their specific
|
|
1153
|
+
use cases.
|
|
1154
|
+
|
|
1155
|
+
Representation
|
|
1156
|
+
--------------
|
|
1157
|
+
Depending on the arguments described below, the representation of the placeholder will be determined as follows:
|
|
1158
|
+
|
|
1159
|
+
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).
|
|
1160
|
+
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.
|
|
1161
|
+
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).
|
|
1162
|
+
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`.
|
|
1163
|
+
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`.
|
|
1164
|
+
6. Otherwise, an error is raised.
|
|
1165
|
+
|
|
1166
|
+
Args
|
|
1167
|
+
-----
|
|
1168
|
+
- `name` (`str | None`): The placeholder's name. If omitted, the local variable name is used.
|
|
1169
|
+
- `dtype` (`DataType`): The type of data this placeholder holds (integer, floating point, etc.).
|
|
1170
|
+
- `ndim` (`int`): The number of dimensions in this placeholder. Defaults to 0 (a scalar value).
|
|
1171
|
+
- `shape` (`list | tuple`): A sequence with the size of each dimension of the placeholder. Defaults to an empty tuple (a scalar value).
|
|
1172
|
+
- Each item in `shape` must be a valid expression evaluating to a non-negative scalar.
|
|
1173
|
+
- There is no need to provide `ndim` if `shape` is specified, but they must not conflict if both specified.
|
|
1174
|
+
- `jagged` (`bool`): Whether this placeholder represents a jagged array (ie. a non-square matrix). Ignored if scalar.
|
|
1175
|
+
- `dict_keys` (`tuple[Expression, ...]`, optional): If provided, specifies that this placeholder represents a dictionary-like structure with keys `dict_keys`.
|
|
1176
|
+
- `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`.
|
|
1177
|
+
- `latex` (`str`, optional): An optional LaTeX representation to be used in Jupyter notebook.
|
|
1178
|
+
- When not provided, `name` is used by default.
|
|
1179
|
+
- `description` (`str`, optional): An optional description for user reference.
|
|
1180
|
+
|
|
1181
|
+
Examples
|
|
1182
|
+
---------
|
|
1183
|
+
Create a scalar integer placeholder whose name is "a".
|
|
1184
|
+
|
|
1185
|
+
```python
|
|
1186
|
+
>>> import jijmodeling as jm
|
|
1187
|
+
>>> problem = jm.Problem("my_problem")
|
|
1188
|
+
>>> @problem.update
|
|
1189
|
+
>>> def _(problem: jm.DecoratedProblem)
|
|
1190
|
+
>>> a = problem.Placeholder("a", dtype=jm.DataType.INTEGER)
|
|
1191
|
+
```
|
|
1192
|
+
"""
|
|
1193
|
+
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:
|
|
1194
|
+
r"""
|
|
1195
|
+
Defines a :class:`Placeholder` representing an integer in this problem's namespace.
|
|
1196
|
+
|
|
1197
|
+
A shorthand for `DecoratedProblem.Placeholder(dtype=DataType.INTEGER)`, provided for clarity and convenience.
|
|
1198
|
+
See `DecoratedProblem.Placeholder` for more details on placeholders.
|
|
1199
|
+
"""
|
|
1200
|
+
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:
|
|
1201
|
+
r"""
|
|
1202
|
+
Defines a :class:`Placeholder` representing a floating-point (real) number in this problem's namespace.
|
|
1203
|
+
|
|
1204
|
+
A shorthand for `DecoratedProblem.Placeholder(dtype=DataType.FLOAT)`, provided for clarity and convenience.
|
|
1205
|
+
See `DecoratedProblem.Placeholder` for more details on placeholders.
|
|
1206
|
+
"""
|
|
1207
|
+
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:
|
|
1208
|
+
r"""
|
|
1209
|
+
Defines a :class:`Placeholder` representing a natural number in this problem's namespace.
|
|
1210
|
+
|
|
1211
|
+
A shorthand for `DecoratedProblem.Placeholder(dtype=DataType.NATURAL)`, provided for clarity and convenience.
|
|
1212
|
+
See `DecoratedProblem.Placeholder` for more details on placeholders.
|
|
1213
|
+
"""
|
|
1214
|
+
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:
|
|
1215
|
+
r"""
|
|
1216
|
+
Defines a :class:`Placeholder` representing a natural number in this problem's namespace.
|
|
1217
|
+
|
|
1218
|
+
This is just a shorthand for `DecoratedProblem.Natural(ndim=0)` and effectively the same as any other natural
|
|
1219
|
+
placeholder for practical purposes. The use of `Length` is recommended just for clarity when
|
|
1220
|
+
defining a placeholder which will be used to define the length of multi-dimensional objects.
|
|
1221
|
+
|
|
1222
|
+
See `DecoratedProblem.Placeholder` for more details on placeholders.
|
|
1223
|
+
"""
|
|
1224
|
+
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:
|
|
1225
|
+
r"""
|
|
1226
|
+
Defines a :class:`Placeholder` representing a natural number in this problem's namespace.
|
|
1227
|
+
|
|
1228
|
+
This is just a shorthand for `DecoratedProblem.Natural(ndim=0)` and effectively the same as any other natural
|
|
1229
|
+
placeholder for practical purposes. The use of `Dim` is recommended just for clarity when
|
|
1230
|
+
defining a placeholder which will be used to define the length of multi-dimensional objects.
|
|
1231
|
+
|
|
1232
|
+
See `DecoratedProblem.Placeholder` for more details on placeholders.
|
|
1233
|
+
"""
|
|
1234
|
+
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:
|
|
1235
|
+
r"""
|
|
1236
|
+
Defines a `Placeholder` representing a binary number in this problem's namespace.
|
|
1237
|
+
|
|
1238
|
+
A shorthand for `DecoratedProblem.Placeholder(dtype=DataType.BINARY)`, provided for clarity and convenience.
|
|
1239
|
+
See `DecoratedProblem.Placeholder` for more details on placeholders.
|
|
1240
|
+
"""
|
|
1241
|
+
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:
|
|
1242
|
+
r"""
|
|
1243
|
+
A shorthand for creating a partial dictionary placeholder with key type
|
|
1244
|
+
"""
|
|
1245
|
+
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:
|
|
1246
|
+
r"""
|
|
1247
|
+
A shorthand for creating a total dictionary placeholder with key type
|
|
1248
|
+
"""
|
|
1249
|
+
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:
|
|
1250
|
+
r"""
|
|
1251
|
+
A placeholder expressing a directed graph with vertices of type `dtype` (without edge weights), represented by a 1-dimensional array of tuples.
|
|
1252
|
+
|
|
1253
|
+
A shorthand for `DecoratedProblem.Placeholder(dtype=(dtype, dtype), ndim=1)`.
|
|
1254
|
+
By default `dtype` is `DataType.Natural` but can be specified.
|
|
1255
|
+
"""
|
|
1256
|
+
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] | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any], 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] | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any], latex: typing.Optional[builtins.str] = None, description: typing.Optional[builtins.str] = None) -> DecisionVar:
|
|
1257
|
+
r"""
|
|
1258
|
+
Defines a :class:`DecisionVar` and registers it to the problem namespace.
|
|
1259
|
+
|
|
1260
|
+
Decision variables can be scalars, multi-dimensional arrays (eg. representing
|
|
1261
|
+
arrays and matrices of variables), or total dictionaries.
|
|
1262
|
+
|
|
1263
|
+
Variables must have a `DecisionVarKind` (such as `BINARY`, `INTEGER`, `CONTINUOUS`),
|
|
1264
|
+
as well as defined lower and upper bounds.
|
|
1265
|
+
|
|
1266
|
+
We recommend using alternative convenience methods which predefine the
|
|
1267
|
+
decision variable's kind, such as `DecoratedProblem.IntegerVar` for integers, or
|
|
1268
|
+
`DecoratedProblem.BinaryVar` for binary variables.
|
|
1269
|
+
|
|
1270
|
+
Representation
|
|
1271
|
+
--------------
|
|
1272
|
+
Depending on the arguments described below, the representation of the decision variable will be determined as follows:
|
|
1273
|
+
|
|
1274
|
+
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).
|
|
1275
|
+
2. If `shape` is provided and `dict_keys` is not provided, DecisionVar will be considered as a multi-dimensional array with fixed shape.
|
|
1276
|
+
3. If `dict_keys` is provided without `shape`, DecisionVar will be considered as a dictionary-like structure with keys specified by `dict_keys`.
|
|
1277
|
+
4. Otherwise, an error is raised.
|
|
1278
|
+
|
|
1279
|
+
Args
|
|
1280
|
+
-----
|
|
1281
|
+
- `name` (`str | None`): A name for the binary variable. If omitted, local variable name is used.
|
|
1282
|
+
- `kind` (`DecisionVarKind`): A kind of the decision variable.
|
|
1283
|
+
- `shape` (`list | tuple`): A sequence with the size of each dimension of the variable. Defaults to an empty tuple (a scalar value).
|
|
1284
|
+
- Each item in `shape` must be a valid expression evaluating to a non-negative scalar.
|
|
1285
|
+
- `dict_keys` (`tuple[Expression, ...]`, optional): If provided, specifies that this variable represents a dictionary-like structure with keys `dict_keys`.
|
|
1286
|
+
- `lower_bound` and `upper_bound` (`jijmodeling.Expression`): A lower and upper bounds of the variable.
|
|
1287
|
+
- `kind` (`DecisionVarKind`): The kind of the decision variable.
|
|
1288
|
+
- `latex` (`str`, optional): An optional LaTeX representation to be used in Jupyter notebook.
|
|
1289
|
+
- It is set to be the same as `name` by default.
|
|
1290
|
+
- `description` (`str`, optional): An optional description, for user reference.
|
|
1291
|
+
|
|
1292
|
+
Examples
|
|
1293
|
+
---------
|
|
1294
|
+
Create a scalar binary variable whose name is "z".
|
|
1295
|
+
|
|
1296
|
+
```python
|
|
1297
|
+
>>> import jijmodeling as jm
|
|
1298
|
+
>>> problem = jm.Problem("my_problem")
|
|
1299
|
+
>>> @problem.update
|
|
1300
|
+
>>> def update(problem: DecoratedProblem):
|
|
1301
|
+
>>> z = problem.DecisionVar(kind=jm.DecisionVarKind.BINARY, lower_bound=0, upper_bound=1)
|
|
1302
|
+
|
|
1303
|
+
```
|
|
1304
|
+
|
|
1305
|
+
Create a 2-dimensional binary variable whose name is "x" and has a 2x2 shape.
|
|
1306
|
+
|
|
1307
|
+
```python
|
|
1308
|
+
>>> import jijmodeling as jm
|
|
1309
|
+
>>> problem = jm.Problem("my_problem")
|
|
1310
|
+
>>> @problem.update
|
|
1311
|
+
>>> def update(problem: DecoratedProblem):
|
|
1312
|
+
>>> z = problem.BinaryVar(shape=[2, 2])
|
|
1313
|
+
|
|
1314
|
+
```
|
|
1315
|
+
|
|
1316
|
+
Create a total dictionary of integer variables with the keys `(I, J, 5)`
|
|
1317
|
+
|
|
1318
|
+
```python
|
|
1319
|
+
>>> import jijmodeling as jm
|
|
1320
|
+
>>> problem = jm.Problem("my_problem")
|
|
1321
|
+
>>> @problem.update
|
|
1322
|
+
>>> def update(problem: DecoratedProblem):
|
|
1323
|
+
>>> w = problem.IntegerVar(
|
|
1324
|
+
>>> lower_bound=l,
|
|
1325
|
+
>>> upper_bound=u,
|
|
1326
|
+
>>> dict_keys=(I, J, 5)
|
|
1327
|
+
>>> )
|
|
1328
|
+
|
|
1329
|
+
```
|
|
1330
|
+
"""
|
|
1331
|
+
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:
|
|
1332
|
+
r"""
|
|
1333
|
+
Defines a binary decision variable and registers it to the problem namespace. See `DecoratedProblem.DecisionVariable` for more details.
|
|
1334
|
+
|
|
1335
|
+
A shorthand for `DecoratedProblem.DecisionVariable(dtype=DecisionVarKind.BINARY,
|
|
1336
|
+
lower_bound=0, upper_bound=1)`, provided for clarity and convenience.
|
|
1337
|
+
|
|
1338
|
+
Args
|
|
1339
|
+
-----
|
|
1340
|
+
- `name` (`str | None`): A name for the binary variable. If omitted, local variable name is used.
|
|
1341
|
+
- `shape` (`list | tuple`): A sequence with the size of each dimension of the binary variable. Defaults to an empty tuple (a scalar value).
|
|
1342
|
+
- Each item in `shape` must be a valid expression evaluating to a non-negative scalar.
|
|
1343
|
+
- `dict_keys` (`tuple[Expression, ...]`, optional): If provided, specifies that this variable represents a dictionary-like structure with keys `dict_keys`.
|
|
1344
|
+
- `latex` (`str`, optional): A LaTeX-name of the binary variable to be represented in Jupyter notebook.
|
|
1345
|
+
- It is set to `name` by default.
|
|
1346
|
+
- `description` (`str`, optional): A description of the binary variable.
|
|
1347
|
+
"""
|
|
1348
|
+
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] | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any], 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] | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any], latex: typing.Optional[builtins.str] = None, description: typing.Optional[builtins.str] = None) -> DecisionVar:
|
|
1349
|
+
r"""
|
|
1350
|
+
Defines an integer decision variable and registers it to the problem namespace. See `DecoratedProblem.DecisionVar` for more details.
|
|
1351
|
+
|
|
1352
|
+
This is shorthand for `Problem.DecisionVariable(kind=DecisionVarKind.INTEGER)`.
|
|
1353
|
+
|
|
1354
|
+
Args
|
|
1355
|
+
-----
|
|
1356
|
+
- `name` (`str | None`): A name for the binary variable. If omitted, local variable name is used.
|
|
1357
|
+
- `shape` (`list | tuple`): A sequence with the size of each dimension of the integer variable. Defaults to an empty tuple (a scalar value).
|
|
1358
|
+
- Each item in `shape` must be a valid expression evaluating to a non-negative scalar.
|
|
1359
|
+
- `dict_keys` (`tuple[Expression, ...]`, optional): If provided, specifies that this variable represents a dictionary-like structure with keys `dict_keys`.
|
|
1360
|
+
- `lower_bound`: The lower bound of the variable.
|
|
1361
|
+
- `upper_bound`: The upper bound of the variable.
|
|
1362
|
+
- `latex` (`str`, optional): A LaTeX-name of the integer variable to be represented in Jupyter notebook.
|
|
1363
|
+
- It is set to `name` by default.
|
|
1364
|
+
- `description` (`str`, optional): A description of the integer variable.
|
|
1365
|
+
|
|
1366
|
+
Raises
|
|
1367
|
+
-------
|
|
1368
|
+
`ModelingError`: Raises if a bound is a `Placeholder` or `Subscript` object whose `ndim`
|
|
1369
|
+
is neither `0` nor the same value as `ndim` of the integer variable.
|
|
1370
|
+
"""
|
|
1371
|
+
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] | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any], 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] | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any], latex: typing.Optional[builtins.str] = None, description: typing.Optional[builtins.str] = None) -> DecisionVar:
|
|
1372
|
+
r"""
|
|
1373
|
+
Defines a semi-integer decision variable and registers it to the problem namespace. See `DecoratedProblem.DecisionVar` for more details.
|
|
1374
|
+
|
|
1375
|
+
This is shorthand for `problem.DecisionVariable(kind=DecisionVarKind.SEMI_INTEGER)`.
|
|
1376
|
+
"""
|
|
1377
|
+
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] | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any], 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] | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any], latex: typing.Optional[builtins.str] = None, description: typing.Optional[builtins.str] = None) -> DecisionVar:
|
|
1378
|
+
r"""
|
|
1379
|
+
Defines a continuous decision variable and registers it to the problem namespace. See `Problem.DecisionVar` for more details.
|
|
1380
|
+
|
|
1381
|
+
This is shorthand for `problem.DecisionVariable(dtype=DecisionVarKind.CONTINUOUS)`.
|
|
1382
|
+
|
|
1383
|
+
Args
|
|
1384
|
+
-----
|
|
1385
|
+
- `name` (`str | None`): A name for the binary variable. If omitted, local variable name is used.
|
|
1386
|
+
- `shape` (`list | tuple`): A sequence with the size of each dimension of the continuous variable. Defaults to an empty tuple (a scalar value).
|
|
1387
|
+
- Each item in `shape` must be a valid expression evaluating to a non-negative scalar.
|
|
1388
|
+
- `dict_keys` (`tuple[Expression, ...]`, optional): If provided, specifies that this variable represents a dictionary-like structure with keys `dict_keys`.
|
|
1389
|
+
- `lower_bound`: The lower bound of the variable.
|
|
1390
|
+
- `upper_bound`: The upper bound of the variable.
|
|
1391
|
+
- `latex` (`str`, optional): A LaTeX-name of the continuous variable to be represented in Jupyter notebook.
|
|
1392
|
+
- It is set to `name` by default.
|
|
1393
|
+
- `description` (`str`, optional): A description of the continuous variable.
|
|
1394
|
+
|
|
1395
|
+
Raises
|
|
1396
|
+
-------
|
|
1397
|
+
`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.
|
|
1398
|
+
"""
|
|
1399
|
+
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] | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any], 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] | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any], latex: typing.Optional[builtins.str] = None, description: typing.Optional[builtins.str] = None) -> DecisionVar: ...
|
|
1400
|
+
def CategoryLabel(self, name: typing.Optional[builtins.str] = None, *, latex: typing.Optional[builtins.str] = None, description: typing.Optional[builtins.str] = None) -> CategoryLabel:
|
|
1401
|
+
r"""
|
|
1402
|
+
Add a new opaque category label to the namespace.
|
|
1403
|
+
|
|
1404
|
+
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).
|
|
1405
|
+
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.
|
|
1406
|
+
|
|
1407
|
+
:class:`CategoryLabel` objects can be created via :meth:`Problem.CategoryLabel`.
|
|
1408
|
+
The concrete values should be given in `instance_data` dictionary together with placeholder values when creating a :class:`Compiler` object or in `Problem.eval`.
|
|
1409
|
+
In `instance_data`, category label should be given a list of either strings or integers.
|
|
1410
|
+
///
|
|
1411
|
+
Args
|
|
1412
|
+
----
|
|
1413
|
+
- `name` (`str | None`): A name for the category label. If omitted, local variable name is used.
|
|
1414
|
+
- `latex` (`str`, optional): An optional LaTeX representation to be used in Jupyter notebook.
|
|
1415
|
+
- When not provided, `name` is used by default.
|
|
1416
|
+
- `description` (`str`, optional): An optional description for user reference.
|
|
1417
|
+
"""
|
|
1418
|
+
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:
|
|
1419
|
+
r"""
|
|
1420
|
+
Compiles and evaluates the problem given the specified instance data, returning an OMMX instance.
|
|
1421
|
+
|
|
1422
|
+
A short-hand of `Compiler.from_problem(self, data).eval_problem(self)`.
|
|
1423
|
+
|
|
1424
|
+
Args
|
|
1425
|
+
----
|
|
1426
|
+
- `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`.
|
|
1427
|
+
"""
|
|
1428
|
+
@typing.overload
|
|
1429
|
+
def __iadd__(self, other: Constraint) -> DecoratedProblem:
|
|
1430
|
+
r"""
|
|
1431
|
+
Add constraint to the problem.
|
|
1432
|
+
"""
|
|
1433
|
+
@typing.overload
|
|
1434
|
+
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:
|
|
1435
|
+
r"""
|
|
1436
|
+
Add an expression as a term to the objective function of the problem.
|
|
1437
|
+
"""
|
|
1438
|
+
|
|
1439
|
+
@typing.final
|
|
1440
|
+
class DesugaredProblemBuilder:
|
|
1441
|
+
def __call__(self) -> None: ...
|
|
1442
|
+
|
|
1443
|
+
@typing.final
|
|
1444
|
+
class Expression:
|
|
1445
|
+
r"""
|
|
1446
|
+
Any expression in Python.
|
|
1447
|
+
"""
|
|
1448
|
+
@typing.overload
|
|
1449
|
+
def min(self) -> Expression:
|
|
1450
|
+
r"""
|
|
1451
|
+
Creates an expression which refers to the smallest value in `self`.
|
|
1452
|
+
|
|
1453
|
+
This method works only on valid sequence expressions, where the resulting
|
|
1454
|
+
expression is a scalar representing the smallest among all values in the sequence.
|
|
1455
|
+
"""
|
|
1456
|
+
@typing.overload
|
|
1457
|
+
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:
|
|
1458
|
+
r"""
|
|
1459
|
+
Creates an expression representing the smaller value between `self` and `rhs`.
|
|
1460
|
+
|
|
1461
|
+
This is a method-based alternative to :func:`jijmodeling.min`.
|
|
1462
|
+
"""
|
|
1463
|
+
@typing.overload
|
|
1464
|
+
def max(self) -> Expression:
|
|
1465
|
+
r"""
|
|
1466
|
+
Creates an expression which refers to the largest value in `self`.
|
|
1467
|
+
|
|
1468
|
+
This method works only on valid sequence expressions, where the resulting
|
|
1469
|
+
expression is a scalar representing the largest among all values in the sequence.
|
|
1470
|
+
"""
|
|
1471
|
+
@typing.overload
|
|
1472
|
+
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:
|
|
1473
|
+
r"""
|
|
1474
|
+
Creates an expression representing the larger value between `self` and `rhs`.
|
|
1475
|
+
|
|
1476
|
+
This is a method-based alternative to :func:`jijmodeling.max`.
|
|
1477
|
+
"""
|
|
1478
|
+
def __eq__(self, other: typing.Any) -> Expression: ... # type: ignore[reportIncompatibleMethodOverride]
|
|
1479
|
+
def __ne__(self, other: typing.Any) -> Expression: ... # type: ignore[reportIncompatibleMethodOverride]
|
|
1480
|
+
def __lt__(self, other: typing.Any) -> Expression: ...
|
|
1481
|
+
def __le__(self, other: typing.Any) -> Expression: ...
|
|
1482
|
+
def __gt__(self, other: typing.Any) -> Expression: ...
|
|
1483
|
+
def __ge__(self, other: typing.Any) -> Expression: ...
|
|
1484
|
+
def bnot(self) -> Expression: ...
|
|
1485
|
+
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: ...
|
|
1486
|
+
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: ...
|
|
1487
|
+
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: ...
|
|
1488
|
+
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: ...
|
|
1489
|
+
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: ...
|
|
1490
|
+
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: ...
|
|
1491
|
+
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: ...
|
|
1492
|
+
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:
|
|
1493
|
+
r"""
|
|
1494
|
+
Creates an expression representing the summation of `self`.
|
|
1495
|
+
|
|
1496
|
+
This is an alternative to using :func:`jijmodeling.sum`, where
|
|
1497
|
+
a method call on an expression may be more convenient/readable.
|
|
1498
|
+
|
|
1499
|
+
If `self` isn't a valid sequence which can be summed, you will get an
|
|
1500
|
+
error when the resulting expression is added to a :class:`Problem` and is
|
|
1501
|
+
type-checked.
|
|
1502
|
+
|
|
1503
|
+
The optional `axis` parameter allows you to specify one axis of a
|
|
1504
|
+
multi-dimensional expression across which to perform the operation.
|
|
1505
|
+
|
|
1506
|
+
Examples
|
|
1507
|
+
------
|
|
1508
|
+
|
|
1509
|
+
Simple sum of decision variables.
|
|
1510
|
+
|
|
1511
|
+
```python
|
|
1512
|
+
>>> import jijmodeling as jm
|
|
1513
|
+
>>> problem = jm.Problem("MyProblem")
|
|
1514
|
+
>>> N = problem.Natural("N")
|
|
1515
|
+
>>> x = problem.IntegerVar("x", shape=N)
|
|
1516
|
+
>>> problem += x.sum()
|
|
1517
|
+
```
|
|
1518
|
+
|
|
1519
|
+
Performing a weighted sum. Note that this sort of usage may lead to errors
|
|
1520
|
+
when the shapes don't match. In this case we guarantee that `x` has the
|
|
1521
|
+
same shape as `W` through its definition.
|
|
1522
|
+
|
|
1523
|
+
```python
|
|
1524
|
+
>>> import jijmodeling as jm
|
|
1525
|
+
>>> problem = jm.Problem("MyProblem")
|
|
1526
|
+
>>> W = problem.Float("W", ndim=1)
|
|
1527
|
+
>>> N = a.len_at(0)
|
|
1528
|
+
>>> x = problem.BinaryVar("x", shape=N)
|
|
1529
|
+
>>> problem += (W * x).sum()
|
|
1530
|
+
```
|
|
1531
|
+
"""
|
|
1532
|
+
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:
|
|
1533
|
+
r"""
|
|
1534
|
+
Creates an expression representing the multiplication of `self`.
|
|
1535
|
+
|
|
1536
|
+
This is an alternative to using :func:`jijmodeling.prod`, where
|
|
1537
|
+
a method call on an expression may be more convenient/readable.
|
|
1538
|
+
|
|
1539
|
+
If `self` isn't a valid sequence which can be multiplied, you will get an
|
|
1540
|
+
error when the resulting expression is added to a :class:`Problem` and is
|
|
1541
|
+
type-checked.
|
|
1542
|
+
|
|
1543
|
+
The optional `axis` parameter allows you to specify one axis of a
|
|
1544
|
+
multi-dimensional expression across which to perform the operation.
|
|
1545
|
+
|
|
1546
|
+
Examples
|
|
1547
|
+
------
|
|
1548
|
+
|
|
1549
|
+
Simple product of decision variables
|
|
1550
|
+
|
|
1551
|
+
```python
|
|
1552
|
+
>>> import jijmodeling as jm
|
|
1553
|
+
>>> problem = jm.Problem("MyProblem")
|
|
1554
|
+
>>> N = problem.Natural("N")
|
|
1555
|
+
>>> x = problem.IntegerVar("x", shape=N)
|
|
1556
|
+
>>> problem += x.prod()
|
|
1557
|
+
```
|
|
1558
|
+
"""
|
|
1559
|
+
def __getitem__(self, subscripts: typing.Any) -> Expression: ...
|
|
1560
|
+
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:
|
|
1561
|
+
r"""
|
|
1562
|
+
Creates an expression that maps the values in `self` to `func`.
|
|
1563
|
+
|
|
1564
|
+
This is an alternative to :func:`jijmodeling.map` which allows you
|
|
1565
|
+
to place the indexing expression first.
|
|
1566
|
+
|
|
1567
|
+
When called on valid scalar scalars, each number from 0 to this `self`
|
|
1568
|
+
will be passed to `func`. When called on a sequence expression (eg. a
|
|
1569
|
+
1-dimensional placeholder, or the result of functions like
|
|
1570
|
+
:func:`jijmodeling.product` or :func:`jijmodeling.items`), each element
|
|
1571
|
+
in the sequence is passed to `func`.
|
|
1572
|
+
|
|
1573
|
+
This is mostly used alongside lambdas as a way to access individual values
|
|
1574
|
+
within array-like or dictionary-like :class:`Placeholder`s and
|
|
1575
|
+
:class:`DecisionVar`s. The resulting expression is then usually passed to a
|
|
1576
|
+
reducer, like :func:`jijmodeling.sum` (or :meth:`Expression.sum` is called
|
|
1577
|
+
on it), to form part of a constraint or the objective function.
|
|
1578
|
+
|
|
1579
|
+
Examples
|
|
1580
|
+
------
|
|
1581
|
+
|
|
1582
|
+
Indexing by values from 0 to N. In this example we define N as the length of
|
|
1583
|
+
another placeholder, but a scalar Natural placeholder would work as well.
|
|
1584
|
+
|
|
1585
|
+
```python
|
|
1586
|
+
>>> import jijmodeling as jm
|
|
1587
|
+
>>> problem = jm.Problem("MyProblem")
|
|
1588
|
+
>>> W = problem.Float("W", ndim=1)
|
|
1589
|
+
>>> N = W.len_at(0)
|
|
1590
|
+
>>> x = problem.BinaryVar("x", shape=N)
|
|
1591
|
+
>>> problem += N.map(lambda i: W[i] * x[i]).sum()
|
|
1592
|
+
```
|
|
1593
|
+
|
|
1594
|
+
Indexing by specific values from instance data. In this example only the
|
|
1595
|
+
indices present in `C` in the instance data will be used in this constraint.
|
|
1596
|
+
|
|
1597
|
+
```python
|
|
1598
|
+
>>> import jijmodeling as jm
|
|
1599
|
+
>>> problem = jm.Problem("MyProblem")
|
|
1600
|
+
>>> N = problem.Natural("N")
|
|
1601
|
+
>>> x = problem.IntegerVar("x", shape=N, lower_bound=0, upper_bound=10)
|
|
1602
|
+
>>> C = problem.Natural("C", ndim=1)
|
|
1603
|
+
>>> problem += problem.Constraint("constr", C.map(lambda i: x[i]).sum() <= 100)
|
|
1604
|
+
```
|
|
1605
|
+
"""
|
|
1606
|
+
def roll(self, shift: typing.Any, *, axis: typing.Optional[builtins.int] = None) -> Expression: ...
|
|
1607
|
+
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:
|
|
1608
|
+
r"""
|
|
1609
|
+
Creates an expression that filters the values of this sequence.
|
|
1610
|
+
|
|
1611
|
+
`predicate` will be called on each element in `self`. The resulting
|
|
1612
|
+
expression represents only the values for which `predicate` is true.
|
|
1613
|
+
|
|
1614
|
+
This is an alternative to :func:`jijmodeling.filter` which allows
|
|
1615
|
+
you to place the indexing expression first.
|
|
1616
|
+
|
|
1617
|
+
This is often useful when trying to create summations which only include
|
|
1618
|
+
a subset of potential indices.The resulting expression is usually used as the
|
|
1619
|
+
basis for :func:`jijmodeling.map`, :func:`jijmodeling.sum`, etc., or a
|
|
1620
|
+
method equivalent.
|
|
1621
|
+
|
|
1622
|
+
Examples
|
|
1623
|
+
------
|
|
1624
|
+
|
|
1625
|
+
Using only variables with even indices as part of a constraint.
|
|
1626
|
+
|
|
1627
|
+
```python
|
|
1628
|
+
>>> import jijmodeling as jm
|
|
1629
|
+
>>> problem = jm.Problem("MyProblem")
|
|
1630
|
+
>>> N = jm.Natural("N")
|
|
1631
|
+
>>> x = problem.BinaryVar("x", shape=(N, N))
|
|
1632
|
+
>>> even_xs = N.filter(lambda i: i % 2 == 0).map(lambda i: x[i])
|
|
1633
|
+
>>> problem += problem.Constraint("constr", even_xs.sum() <= 10)
|
|
1634
|
+
```
|
|
1635
|
+
|
|
1636
|
+
Using only non-diagonal indices of an NxN matrix as part of a constraint, using the method version of `filter`.
|
|
1637
|
+
|
|
1638
|
+
```python
|
|
1639
|
+
>>> import jijmodeling as jm
|
|
1640
|
+
>>> problem = jm.Problem("MyProblem")
|
|
1641
|
+
>>> N = jm.Natural("N")
|
|
1642
|
+
>>> x = problem.BinaryVar("x", shape=(N, N))
|
|
1643
|
+
>>> W = problem.Float("W", shape=(N, N))
|
|
1644
|
+
>>> non_diagonals = jm.product(N, N).filter(lambda i, j: i != j)
|
|
1645
|
+
>>> problem += problem.Constraint("constr", lambda i, j: W[i, j] * x[i, j], domain=non_diagonals)
|
|
1646
|
+
```
|
|
1647
|
+
"""
|
|
1648
|
+
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:
|
|
1649
|
+
r"""
|
|
1650
|
+
Creates an expression which works like :meth:`map`, but flattens nested structure.
|
|
1651
|
+
|
|
1652
|
+
This is an alternative to :func:`jijmodeling.flat_map` which allows you to
|
|
1653
|
+
place the indexing expression first.
|
|
1654
|
+
|
|
1655
|
+
`map` is useful when `func` returns scalar values, but in some
|
|
1656
|
+
situations one wants to write a `func` that returns other
|
|
1657
|
+
mappings/sequences instead. That is where `flat_map` should be used,
|
|
1658
|
+
"flattening" all sequences/iterators into a single linear sequence
|
|
1659
|
+
(which can then be reduced with :meth:`sum`, etc.)
|
|
1660
|
+
|
|
1661
|
+
You can also compare `flat_map` to a nested for-loop, or a generator
|
|
1662
|
+
expression that uses two `for` clauses. Indeed when using the decorated API
|
|
1663
|
+
(see tutorials or :meth:`Problem.update`), you can use a generator
|
|
1664
|
+
expression-like syntax instead.
|
|
1665
|
+
|
|
1666
|
+
Examples
|
|
1667
|
+
------
|
|
1668
|
+
|
|
1669
|
+
Using only non-diagonal indices of an NxN matrix.
|
|
1670
|
+
```python
|
|
1671
|
+
>>> import jijmodeling as jm
|
|
1672
|
+
>>> problem = jm.Problem("MyProblem")
|
|
1673
|
+
>>> N = jm.Natural("N")
|
|
1674
|
+
>>> x = problem.BinaryVar("x", shape=(N, N))
|
|
1675
|
+
>>> W = problem.Float("W", shape=(N, N))
|
|
1676
|
+
>>> objective = N.flat_map(
|
|
1677
|
+
... lambda i: N.filter(lambda j: i != j).map(lambda j: W[i, j] * x[i, j])
|
|
1678
|
+
... ).sum()
|
|
1679
|
+
>>> problem += objective
|
|
1680
|
+
```
|
|
1681
|
+
"""
|
|
1682
|
+
def rows(self) -> Expression:
|
|
1683
|
+
r"""
|
|
1684
|
+
Creates a sequence over the rows of this multi-dimensional array expression.
|
|
1685
|
+
|
|
1686
|
+
That is, each element will be a whole row (itself containing multiple
|
|
1687
|
+
values), which can then be operated on like other sequences (eg. using
|
|
1688
|
+
:func:`jijmodelng.sum` or :func:`jijmodeling.map`).
|
|
1689
|
+
|
|
1690
|
+
If the array is 3-dimensional or higher, rows will iterate over the first
|
|
1691
|
+
dimension/axis. For example, in a 3D matrix, the first element would be a
|
|
1692
|
+
2D matrix representing all values `x[0, _, _]`
|
|
1693
|
+
|
|
1694
|
+
Examples
|
|
1695
|
+
------
|
|
1696
|
+
|
|
1697
|
+
Create an objective function that multiplies each variable in a row, and
|
|
1698
|
+
then sums each row. In this case we have a 2x3 matrix, so the final expression is
|
|
1699
|
+
`x[0, 0] * x[0, 1] * x[0, 2] + x[1, 0] * x[1, 1] * x[1, 2]`. Using
|
|
1700
|
+
placeholders instead of literals in `shape` would allow this to be written
|
|
1701
|
+
for matrices of arbitrary size.
|
|
1702
|
+
```python
|
|
1703
|
+
>>> import jijmodeling as jm
|
|
1704
|
+
>>> problem = jm.Problem("MyProblem")
|
|
1705
|
+
>>> d = problem.BinaryVar("d", shape=(2, 3))
|
|
1706
|
+
>>> problem += d.rows().map(lambda xs: xs.prod()).sum()
|
|
1707
|
+
```
|
|
1708
|
+
|
|
1709
|
+
If the number of elements in the row can be guaranteed, the elements can be
|
|
1710
|
+
destructured as separate arguments in a lambda expression:
|
|
1711
|
+
|
|
1712
|
+
```python
|
|
1713
|
+
>>> import jijmodeling as jm
|
|
1714
|
+
>>> problem = jm.Problem("MyProblem")
|
|
1715
|
+
>>> N = problem.Natural("N")
|
|
1716
|
+
>>> V = problem.Natural("V")
|
|
1717
|
+
>>> E = problem.Natural("E", shape=(N, 2))
|
|
1718
|
+
>>> x = problem.BinaryVar("x", shape=V)
|
|
1719
|
+
>>> problem += jm.map(lambda i, j: x[i] * x[j], E.rows()).sum()
|
|
1720
|
+
```
|
|
1721
|
+
"""
|
|
1722
|
+
def indices(self) -> Expression:
|
|
1723
|
+
r"""
|
|
1724
|
+
Get the set of indices of given array or jagged array.
|
|
1725
|
+
|
|
1726
|
+
Will throw type error when called on non-array type.
|
|
1727
|
+
"""
|
|
1728
|
+
def keys(self) -> Expression:
|
|
1729
|
+
r"""
|
|
1730
|
+
Returns an expression representing this dictionary-like object's keys.
|
|
1731
|
+
|
|
1732
|
+
In other words, this is the JijModeling equivalent of the `keys()`
|
|
1733
|
+
method on Python dictionaries, used when creating JijModeling
|
|
1734
|
+
expressions.
|
|
1735
|
+
|
|
1736
|
+
While it's possible to call this on any :class:`Expression`, this is
|
|
1737
|
+
intended for dictionary-like :class:`Placeholder`s and
|
|
1738
|
+
:class:`DecisionVar`s. Using this with an invalid object will lead
|
|
1739
|
+
to an error when the resulting expression is added to a
|
|
1740
|
+
:class:`Problem` and is type-checked.
|
|
1741
|
+
|
|
1742
|
+
See also :meth:`Expression.values` and :meth:`Expression.items`.
|
|
1743
|
+
|
|
1744
|
+
Examples
|
|
1745
|
+
------
|
|
1746
|
+
Refer to a dictionary-like placeholder's keys when
|
|
1747
|
+
creating other objects or writing summations:
|
|
1748
|
+
|
|
1749
|
+
```python
|
|
1750
|
+
>>> import jijmodeling as jm
|
|
1751
|
+
>>> problem = jm.Problem("MyProblem")
|
|
1752
|
+
>>> I = problem.CategoryLabel("I")
|
|
1753
|
+
>>> W = problem.Float("W", dict_keys=I)
|
|
1754
|
+
>>> x = problem.BinaryVar("x", dict_keys=W.keys())
|
|
1755
|
+
>>> problem += jm.sum(W.keys(), lambda i: W[i] * x[i])
|
|
1756
|
+
```
|
|
1757
|
+
"""
|
|
1758
|
+
def values(self) -> Expression:
|
|
1759
|
+
r"""
|
|
1760
|
+
Returns an expression representing this dictionary-like object's values.
|
|
1761
|
+
|
|
1762
|
+
In other words, this is the JijModeling equivalent of the `values()`
|
|
1763
|
+
method on Python dictionaries, used when creating JijModeling
|
|
1764
|
+
expressions.
|
|
1765
|
+
|
|
1766
|
+
While it's possible to call this on any :class:`Expression`, this is
|
|
1767
|
+
intended for dictionary-like :class:`Placeholder`s and
|
|
1768
|
+
:class:`DecisionVar`s. Using this with an invalid object will lead
|
|
1769
|
+
to an error when the resulting expression is added to a
|
|
1770
|
+
:class:`Problem` and is type-checked.
|
|
1771
|
+
|
|
1772
|
+
See also :meth:`Expression.keys` and :meth:`Expression.items`.
|
|
1773
|
+
|
|
1774
|
+
Examples
|
|
1775
|
+
------
|
|
1776
|
+
Defining a simple objective function which just sums a dictionary-based decision variable.
|
|
1777
|
+
|
|
1778
|
+
```python
|
|
1779
|
+
>>> problem = jm.Problem("MyProblem")
|
|
1780
|
+
>>> I = problem.CategoryLabel("I")
|
|
1781
|
+
>>> x = problem.IntegerVar("x", dict_keys=I, lower_bound=0, upper_bound=100)
|
|
1782
|
+
>>> problem += x.values().sum()
|
|
1783
|
+
```
|
|
1784
|
+
"""
|
|
1785
|
+
def items(self) -> Expression:
|
|
1786
|
+
r"""
|
|
1787
|
+
Returns an expression representing this object's `(key,value)` pairs.
|
|
1788
|
+
|
|
1789
|
+
In other words, this is the JijModeling equivalent of the `items()`
|
|
1790
|
+
method on Python dictionaries, used when creating JijModeling
|
|
1791
|
+
expressions.
|
|
1792
|
+
|
|
1793
|
+
While it's possible to call this on any :class:`Expression`, this is
|
|
1794
|
+
intended for dictionary-like :class:`Placeholder`s and
|
|
1795
|
+
:class:`DecisionVar`s. Using this with an invalid object will lead
|
|
1796
|
+
to an error when the resulting expression is added to a
|
|
1797
|
+
:class:`Problem` and is type-checked.
|
|
1798
|
+
|
|
1799
|
+
See also :meth:`Expression.keys` and :meth:`Expression.values`.
|
|
1800
|
+
|
|
1801
|
+
Examples
|
|
1802
|
+
------
|
|
1803
|
+
Simple matching of weights to their respective variables, as an alternative to just using `keys()` or the `CategoryLabel`:
|
|
1804
|
+
|
|
1805
|
+
```python
|
|
1806
|
+
>>> problem = jm.Problem("MyProblem")
|
|
1807
|
+
>>> I = problem.CategoryLabel("I")
|
|
1808
|
+
>>> weights = problem.Float("W", dict_keys=I)
|
|
1809
|
+
>>> x = problem.BinaryVar("x", dict_keys=I)
|
|
1810
|
+
>>> problem += jm.sum(weights.items(), lambda i, w: w * x[i])
|
|
1811
|
+
```
|
|
1812
|
+
|
|
1813
|
+
Same as above, but using the decorated API:
|
|
1814
|
+
```python
|
|
1815
|
+
>>> @problem.update
|
|
1816
|
+
... def _(problem):
|
|
1817
|
+
... I = problem.CategoryLabel()
|
|
1818
|
+
... W = problem.Float(dict_keys=I)
|
|
1819
|
+
... x = problem.BinaryVar(dict_keys=I)
|
|
1820
|
+
... problem += jm.sum(w * x[i] for i, w in W.items())
|
|
1821
|
+
```
|
|
1822
|
+
"""
|
|
1823
|
+
def __neg__(self) -> Expression: ...
|
|
1824
|
+
def abs(self) -> Expression:
|
|
1825
|
+
r"""
|
|
1826
|
+
Returns an expression representing the absolute value of the given expression.
|
|
1827
|
+
|
|
1828
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
1829
|
+
"""
|
|
1830
|
+
def sqrt(self) -> Expression:
|
|
1831
|
+
r"""
|
|
1832
|
+
Returns an expression representing the square root of the given expression.
|
|
1833
|
+
|
|
1834
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
1835
|
+
"""
|
|
1836
|
+
def sin(self) -> Expression:
|
|
1837
|
+
r"""
|
|
1838
|
+
Returns an expression representing the sine of the given expression.
|
|
1839
|
+
|
|
1840
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
1841
|
+
"""
|
|
1842
|
+
def cos(self) -> Expression:
|
|
1843
|
+
r"""
|
|
1844
|
+
Returns an expression representing the cosine of the given expression.
|
|
1845
|
+
|
|
1846
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
1847
|
+
"""
|
|
1848
|
+
def tan(self) -> Expression:
|
|
1849
|
+
r"""
|
|
1850
|
+
Returns an expression representing the tangent of the given expression.
|
|
1851
|
+
|
|
1852
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
1853
|
+
"""
|
|
1854
|
+
def asin(self) -> Expression:
|
|
1855
|
+
r"""
|
|
1856
|
+
Returns an expression representing the arcsine of the given expression.
|
|
1857
|
+
|
|
1858
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
1859
|
+
"""
|
|
1860
|
+
def acos(self) -> Expression:
|
|
1861
|
+
r"""
|
|
1862
|
+
Returns an expression representing the arccosine of the given expression.
|
|
1863
|
+
|
|
1864
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
1865
|
+
"""
|
|
1866
|
+
def atan(self) -> Expression:
|
|
1867
|
+
r"""
|
|
1868
|
+
Returns an expression representing the arctangent of the given expression.
|
|
1869
|
+
|
|
1870
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
1871
|
+
"""
|
|
1872
|
+
def sinh(self) -> Expression:
|
|
1873
|
+
r"""
|
|
1874
|
+
Returns an expression representing the hyperbolic sine of the given expression.
|
|
1875
|
+
|
|
1876
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
1877
|
+
"""
|
|
1878
|
+
def cosh(self) -> Expression:
|
|
1879
|
+
r"""
|
|
1880
|
+
Returns an expression representing the hyperbolic cosine of the given expression.
|
|
1881
|
+
|
|
1882
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
1883
|
+
"""
|
|
1884
|
+
def tanh(self) -> Expression:
|
|
1885
|
+
r"""
|
|
1886
|
+
Returns an expression representing the hyperbolic tangent of the given expression.
|
|
1887
|
+
|
|
1888
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
1889
|
+
"""
|
|
1890
|
+
def asinh(self) -> Expression:
|
|
1891
|
+
r"""
|
|
1892
|
+
Returns an expression representing the hyperbolic arcsine of the given expression.
|
|
1893
|
+
|
|
1894
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
1895
|
+
"""
|
|
1896
|
+
def acosh(self) -> Expression:
|
|
1897
|
+
r"""
|
|
1898
|
+
Returns an expression representing the hyperbolic arccosine of the given expression.
|
|
1899
|
+
|
|
1900
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
1901
|
+
"""
|
|
1902
|
+
def atanh(self) -> Expression:
|
|
1903
|
+
r"""
|
|
1904
|
+
Returns an expression representing the hyperbolic arctangent of the given expression.
|
|
1905
|
+
|
|
1906
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
1907
|
+
"""
|
|
1908
|
+
def exp(self) -> Expression:
|
|
1909
|
+
r"""
|
|
1910
|
+
Returns an expression representing the application of the exponential function on the given expression.
|
|
1911
|
+
|
|
1912
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
1913
|
+
"""
|
|
1914
|
+
def ln(self) -> Expression:
|
|
1915
|
+
r"""
|
|
1916
|
+
Returns an expression representing the natural logarithm of the given expression.
|
|
1917
|
+
|
|
1918
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
1919
|
+
"""
|
|
1920
|
+
def log10(self) -> Expression:
|
|
1921
|
+
r"""
|
|
1922
|
+
Returns an expression representing the decimal logarithm of the given expression.
|
|
1923
|
+
|
|
1924
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
1925
|
+
"""
|
|
1926
|
+
def log2(self) -> Expression:
|
|
1927
|
+
r"""
|
|
1928
|
+
Returns an expression representing the binary logarithm of the given expression.
|
|
1929
|
+
|
|
1930
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
1931
|
+
"""
|
|
1932
|
+
def ceil(self) -> Expression:
|
|
1933
|
+
r"""
|
|
1934
|
+
Returns an expression which rounds down to the nearest whole number.
|
|
1935
|
+
|
|
1936
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
1937
|
+
"""
|
|
1938
|
+
def floor(self) -> Expression: ...
|
|
1939
|
+
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: ...
|
|
1940
|
+
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: ...
|
|
1941
|
+
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: ...
|
|
1942
|
+
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: ...
|
|
1943
|
+
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: ...
|
|
1944
|
+
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: ...
|
|
1945
|
+
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: ...
|
|
1946
|
+
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: ...
|
|
1947
|
+
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: ...
|
|
1948
|
+
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: ...
|
|
1949
|
+
def __pow__(self, exponent: typing.Any, modulo: typing.Optional[typing.Any] = None) -> Expression: ...
|
|
1950
|
+
def __rpow__(self, base: typing.Any, modulo: typing.Optional[typing.Any] = None) -> Expression: ...
|
|
1951
|
+
def _repr_latex_(self) -> builtins.str: ...
|
|
1952
|
+
def __call__(self, *args: typing.Any) -> Expression: ...
|
|
1953
|
+
def shape(self) -> Expression:
|
|
1954
|
+
r"""
|
|
1955
|
+
Returns an expression which represents the shape of this expression.
|
|
1956
|
+
|
|
1957
|
+
Unlike the attributes in :class:`DecisionVar` and :class:`Placeholder`,
|
|
1958
|
+
this expression is opaque and abstract -- but can still be used to define
|
|
1959
|
+
the shape of new objects according to the shape of arbitrary expressions.
|
|
1960
|
+
"""
|
|
1961
|
+
def len_at(self, axis: builtins.int) -> Expression:
|
|
1962
|
+
r"""
|
|
1963
|
+
Returns an expression which represents the length (number of values) of this expression at a given dimension (0-indexed).
|
|
1964
|
+
|
|
1965
|
+
This can be used, for example, when trying to match the shape of
|
|
1966
|
+
an object to the number of values in an array.
|
|
1967
|
+
"""
|
|
1968
|
+
def __repr__(self) -> builtins.str: ...
|
|
1969
|
+
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:
|
|
1970
|
+
r"""
|
|
1971
|
+
Returns the value inside `option` if `Some`, otherwise returns `default`.
|
|
1972
|
+
"""
|
|
1973
|
+
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:
|
|
1974
|
+
r"""
|
|
1975
|
+
If self is `Some(value)`, applies `mapper(value)`, otherwise returns `default`.
|
|
1976
|
+
"""
|
|
1977
|
+
|
|
1978
|
+
class ModelingError(builtins.Exception):
|
|
1979
|
+
...
|
|
1980
|
+
|
|
1981
|
+
@typing.final
|
|
1982
|
+
class Namespace:
|
|
1983
|
+
def __new__(cls) -> Namespace: ...
|
|
1984
|
+
@staticmethod
|
|
1985
|
+
def from_problem(problem: Problem) -> Namespace: ...
|
|
1986
|
+
def add_category_label(self, label: CategoryLabel) -> None:
|
|
1987
|
+
r"""
|
|
1988
|
+
Add a new opaque category label to the namespace.
|
|
1989
|
+
"""
|
|
1990
|
+
def add_placeholder(self, placeholder: Placeholder) -> None: ...
|
|
1991
|
+
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: ...
|
|
1992
|
+
def add_decision_var(self, var: DecisionVar) -> None: ...
|
|
1993
|
+
def type_of(self, name: builtins.str) -> typing.Optional[Type]: ...
|
|
1994
|
+
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: ...
|
|
1995
|
+
|
|
1996
|
+
@typing.final
|
|
1997
|
+
class Placeholder:
|
|
1998
|
+
r"""
|
|
1999
|
+
A placeholder for instance-specific parameters.
|
|
2000
|
+
|
|
2001
|
+
This class represents a symbol of unspecified value, which is to be replaced
|
|
2002
|
+
by numerical values when you evaluate an optimization problem, before
|
|
2003
|
+
solving it. Think of it like a instance-specific constant/parameters you
|
|
2004
|
+
want to abstract in your model (for examples, the weights of different
|
|
2005
|
+
objects/nodes).
|
|
2006
|
+
|
|
2007
|
+
Like decision variables, `Placeholder`s are often used throughout your model
|
|
2008
|
+
within :class:`Expression`s, and should generally work wherever an
|
|
2009
|
+
`Expression` is expected. Operations will automatically convert as needed.
|
|
2010
|
+
|
|
2011
|
+
Placeholders must belong to some namespace, i.e. a :class:`Problem`, so you
|
|
2012
|
+
cannot construct one directly. Use `Problem.Placeholder` or shorthand
|
|
2013
|
+
methods shorthands (e.g., `Problem.Integer`, `Problem.Float`, etc.) to
|
|
2014
|
+
define placeholders.
|
|
2015
|
+
|
|
2016
|
+
Placeholders can be defined and used as scalars (unit values), n-dimensional
|
|
2017
|
+
arrays, or as dictionaries. In the latter two cases, a single `Placeholder`
|
|
2018
|
+
object represents multiple values in the model, and requires subscripting
|
|
2019
|
+
to access individual values. This is similar to how in a mathematical
|
|
2020
|
+
formula you may call a whole set by a symbol $W$, made up of $W_0, W_1,
|
|
2021
|
+
...$. More details on these usages is provided in the following sections.
|
|
2022
|
+
|
|
2023
|
+
## Array placeholders, `shape` and `ndim`
|
|
2024
|
+
|
|
2025
|
+
You can define `Placeholder`s as n-dimensional arrays (aka. matrix, tensors,
|
|
2026
|
+
etc.). While some operations can work on arrays directly, in general this
|
|
2027
|
+
means you'll have to use subscripts (ie. indexing with `[]`) to refer to
|
|
2028
|
+
individual values writing expressions.
|
|
2029
|
+
|
|
2030
|
+
Array placeholders are defined by specifying either `ndim` or `shape` in the
|
|
2031
|
+
constructor method. `ndim` simply states the number of dimensions a
|
|
2032
|
+
placeholder will have. Shapes are tuples or lists of expressions, where each
|
|
2033
|
+
entry specifies the number of values in a given dimension. For example:
|
|
2034
|
+
- a `10` shape represents a 1-dimensional array with 10 values. (Defining the shape as `(10,)` would be equivalent)
|
|
2035
|
+
- a `(2, 2)` shape represents a 2-dimensional array with 2 values in each dimension (a 2x2 matrix)
|
|
2036
|
+
|
|
2037
|
+
Only one of `ndim` or `shape` is required to define an array placeholder,
|
|
2038
|
+
but if both are provided they must be consistent with eachother.
|
|
2039
|
+
|
|
2040
|
+
When only `ndim` is provided, the shape of the placeholder is not yet
|
|
2041
|
+
defined but it still has one in an abstract sense (which will be defined by
|
|
2042
|
+
the instance data), and :meth:`Placeholder.shape` will return a tuple of "length
|
|
2043
|
+
at" expressions.
|
|
2044
|
+
|
|
2045
|
+
Scalar placeholders have a shape of `()` (an empty tuple) and 0 dimensions.
|
|
2046
|
+
|
|
2047
|
+
## Dictionary placeholders
|
|
2048
|
+
|
|
2049
|
+
As an alternative to the array-like interface, placeholders can also be used
|
|
2050
|
+
in a style closer to python dictionaries: an unordered collection indexed by
|
|
2051
|
+
a set of labels. This is recommended mostly when you're focused on
|
|
2052
|
+
string-based labels or want non-contiguous indices.
|
|
2053
|
+
|
|
2054
|
+
To use variables this way, you must first define a set of labels through
|
|
2055
|
+
:meth:`Problem.CategoryLabel`s. This is a special kind of placeholder which
|
|
2056
|
+
will represent the keys to dictionaries, and can be reused throughout your
|
|
2057
|
+
model (eg. to define matching dictionary-like `DecisionVar`s).
|
|
2058
|
+
|
|
2059
|
+
This `CategoryLabel` instance is then passed to the `dict_keys` parameter in
|
|
2060
|
+
the appropriate constructor (:meth:`Problem.Placeholder`, etc.). Tuples of
|
|
2061
|
+
category labels can be passed to define dictionaries which use multiple
|
|
2062
|
+
keys.
|
|
2063
|
+
|
|
2064
|
+
By default, dictionary placeholders are "total", that is, each label given
|
|
2065
|
+
by the `CategoryLabel` must have a corresponding value in the data. If you
|
|
2066
|
+
wish to create a partial dictionary, when only certain keys will have data,
|
|
2067
|
+
you must define `partial_dict` as `True` when creating the placeholder.
|
|
2068
|
+
|
|
2069
|
+
The array and dictionary representations are mutually exclusive, and you
|
|
2070
|
+
**cannot** set `dict_keys` alongside `shape`/`ndim`. Doing so will lead to
|
|
2071
|
+
an exception.
|
|
2072
|
+
|
|
2073
|
+
Attributes
|
|
2074
|
+
-----------
|
|
2075
|
+
- `name` (`str`): A name of the placeholder.
|
|
2076
|
+
- `dtype` (`DataType`, optional): The data type (eg. `DataType.INT` or `DataType.FLOAT`) of the placeholder.
|
|
2077
|
+
- `ndim` (`int`): The number of dimensions of the placeholder.
|
|
2078
|
+
- `shape` (`tuple` of `Optional[Expression]`, optional): The (partial) shape of the placeholder if given.
|
|
2079
|
+
- `jagged` (`boolean`, defaut: `False`): `True` if the placeholder will be treated as a jagged array in random data generation. Ignored for scalars.
|
|
2080
|
+
- `dict_keys` (`DictKeySpec`): The specification of dictionary keys if the placeholder is a dictionary type.
|
|
2081
|
+
- `partial_dict` (`bool`, default: `False`): `True` if the placeholder is a partial dictionary. Ignored if `dict_keys` is not given.
|
|
2082
|
+
- `description` (`str`, optional): A description for user reference.
|
|
2083
|
+
|
|
2084
|
+
Raises
|
|
2085
|
+
-------
|
|
2086
|
+
- `TypeError`: Raises if set a float value to `ndim`.
|
|
2087
|
+
- `OverflowError`: Raises if set a negative value to `ndim`.
|
|
2088
|
+
|
|
2089
|
+
Examples
|
|
2090
|
+
---------
|
|
2091
|
+
Create a scalar (or `ndim` is `0`) placeholder whose name is "a".
|
|
2092
|
+
|
|
2093
|
+
```python
|
|
2094
|
+
>>> import jijmodeling as jm
|
|
2095
|
+
>>> problem = jm.Problem("example")
|
|
2096
|
+
>>> a = problem.Placeholder("a", dtype=float)
|
|
2097
|
+
|
|
2098
|
+
```
|
|
2099
|
+
|
|
2100
|
+
Create a 2-dimensional integer placeholder whose name is "m".
|
|
2101
|
+
|
|
2102
|
+
```python
|
|
2103
|
+
>>> import jijmodeling as jm
|
|
2104
|
+
>>> problem = jm.Problem("example")
|
|
2105
|
+
>>> m = problem.Integer("m", ndim=2)
|
|
2106
|
+
|
|
2107
|
+
```
|
|
2108
|
+
|
|
2109
|
+
Create a 1-dimensional natural number placeholder with the index of `123`.
|
|
2110
|
+
|
|
2111
|
+
```python
|
|
2112
|
+
>>> import jijmodeling as jm
|
|
2113
|
+
>>> problem = jm.Problem("example")
|
|
2114
|
+
>>> a = problem.Natural("a", ndim=2)
|
|
2115
|
+
>>> a[123]
|
|
2116
|
+
a[123]
|
|
2117
|
+
>>> problem.get_placeholder("a")
|
|
2118
|
+
Placeholder(name='a', ndim=2, shape=None, dtype=typing.float, jagged=False)
|
|
2119
|
+
```
|
|
2120
|
+
"""
|
|
2121
|
+
@property
|
|
2122
|
+
def name(self) -> builtins.str: ...
|
|
2123
|
+
@property
|
|
2124
|
+
def ndim(self) -> typing.Optional[builtins.int]:
|
|
2125
|
+
r"""
|
|
2126
|
+
The number of dimensions this decision variable represents.
|
|
2127
|
+
|
|
2128
|
+
This is 0 for scalar variables, and None for dictionary variables.
|
|
2129
|
+
"""
|
|
2130
|
+
@property
|
|
2131
|
+
def shape(self) -> typing.Optional[typing.Tuple[Expression,...]]:
|
|
2132
|
+
r"""
|
|
2133
|
+
The shape tuple of the placeholder, consisting of `Expression`s
|
|
2134
|
+
that define the size of each dimension.
|
|
2135
|
+
|
|
2136
|
+
This is an empty tuple if the placeholder is a scalar, and `None` if it's a
|
|
2137
|
+
dictionary placeholder.
|
|
2138
|
+
|
|
2139
|
+
See also `Placeholder.shape_spec` property to get the original value
|
|
2140
|
+
given at the declaration time.
|
|
2141
|
+
|
|
2142
|
+
## Difference between `Placeholder.shape` and `Placeholder.shape_spec`
|
|
2143
|
+
|
|
2144
|
+
- `Placeholder.shape` property always returns a tuple of `Expression`s,
|
|
2145
|
+
filling `None` with `len_at` expressions so that i-th component
|
|
2146
|
+
coincides with the value of `ph.len_at(i)`
|
|
2147
|
+
- `Placeholder.shape_spec` just returns the original `shape` definition,
|
|
2148
|
+
hence the spec itself can be `None` or contain `None` components.
|
|
2149
|
+
|
|
2150
|
+
## Use cases
|
|
2151
|
+
|
|
2152
|
+
- use `Placeholder.shape` property if you want to construct expressions involving the shape of the placeholder.
|
|
2153
|
+
- use `Placeholder.shape_spec` property if you want to inspect the very definition of the placeholder.
|
|
2154
|
+
"""
|
|
2155
|
+
@property
|
|
2156
|
+
def shape_spec(self) -> typing.Optional[typing.Tuple[typing.Optional[Expression],...]]:
|
|
2157
|
+
r"""
|
|
2158
|
+
Get the original definition of shape given at the declaration time, possibly `None` if omitted.
|
|
2159
|
+
See also `Placeholder.shape` property to get the shape as `Expression`s.
|
|
2160
|
+
|
|
2161
|
+
## Difference between `Placeholder.shape` and `Placeholder.shape_spec`
|
|
2162
|
+
|
|
2163
|
+
- `Placeholder.shape` property always returns a tuple of `Expression`s,
|
|
2164
|
+
filling `None` with `len_at` expressions so that i-th component
|
|
2165
|
+
coincides with the value of `ph.len_at(i)`
|
|
2166
|
+
- `Placeholder.shape_spec` just returns the original `shape` definition,
|
|
2167
|
+
hence the spec itself can be `None` or contain `None` components.
|
|
2168
|
+
|
|
2169
|
+
## Use cases
|
|
2170
|
+
|
|
2171
|
+
- use `Placeholder.shape_spec` property if you want to inspect the very definition of the placeholder.
|
|
2172
|
+
- use `Placeholder.shape` property if you want to construct expressions involving the shape of the placeholder.
|
|
2173
|
+
"""
|
|
2174
|
+
@property
|
|
2175
|
+
def dtype(self) -> DataType | type | tuple:
|
|
2176
|
+
r"""
|
|
2177
|
+
This placeholder's data type (natural, integer, float, etc.)
|
|
2178
|
+
"""
|
|
2179
|
+
@property
|
|
2180
|
+
def jagged(self) -> builtins.bool: ...
|
|
2181
|
+
@property
|
|
2182
|
+
def description(self) -> typing.Optional[builtins.str]: ...
|
|
2183
|
+
@property
|
|
2184
|
+
def custom_latex(self) -> typing.Optional[builtins.str]:
|
|
2185
|
+
r"""
|
|
2186
|
+
The custom latex representation of this placeholder, if defined.
|
|
2187
|
+
|
|
2188
|
+
When no custom latex is defined, the default representation is to use the placeholder name.
|
|
2189
|
+
"""
|
|
2190
|
+
@typing.overload
|
|
2191
|
+
def min(self) -> Expression:
|
|
2192
|
+
r"""
|
|
2193
|
+
Creates an expression which refers to the smallest value in `self`.
|
|
2194
|
+
|
|
2195
|
+
This method works only on valid sequence expressions, where the resulting
|
|
2196
|
+
expression is a scalar representing the smallest among all values in the sequence.
|
|
2197
|
+
"""
|
|
2198
|
+
@typing.overload
|
|
2199
|
+
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:
|
|
2200
|
+
r"""
|
|
2201
|
+
Creates an expression representing the smaller value between `self` and `rhs`.
|
|
2202
|
+
|
|
2203
|
+
This is a method-based alternative to :func:`jijmodeling.min`.
|
|
2204
|
+
"""
|
|
2205
|
+
@typing.overload
|
|
2206
|
+
def max(self) -> Expression:
|
|
2207
|
+
r"""
|
|
2208
|
+
Creates an expression which refers to the largest value in `self`.
|
|
2209
|
+
|
|
2210
|
+
This method works only on valid sequence expressions, where the resulting
|
|
2211
|
+
expression is a scalar representing the largest among all values in the sequence.
|
|
2212
|
+
"""
|
|
2213
|
+
@typing.overload
|
|
2214
|
+
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:
|
|
2215
|
+
r"""
|
|
2216
|
+
Creates an expression representing the larger value between `self` and `rhs`.
|
|
2217
|
+
|
|
2218
|
+
This is a method-based alternative to :func:`jijmodeling.max`.
|
|
2219
|
+
"""
|
|
2220
|
+
def __eq__(self, other: typing.Any) -> Expression: ... # type: ignore[reportIncompatibleMethodOverride]
|
|
2221
|
+
def __ne__(self, other: typing.Any) -> Expression: ... # type: ignore[reportIncompatibleMethodOverride]
|
|
2222
|
+
def __lt__(self, other: typing.Any) -> Expression: ...
|
|
2223
|
+
def __le__(self, other: typing.Any) -> Expression: ...
|
|
2224
|
+
def __gt__(self, other: typing.Any) -> Expression: ...
|
|
2225
|
+
def __ge__(self, other: typing.Any) -> Expression: ...
|
|
2226
|
+
def bnot(self) -> Expression: ...
|
|
2227
|
+
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: ...
|
|
2228
|
+
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: ...
|
|
2229
|
+
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: ...
|
|
2230
|
+
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: ...
|
|
2231
|
+
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: ...
|
|
2232
|
+
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: ...
|
|
2233
|
+
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: ...
|
|
2234
|
+
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:
|
|
2235
|
+
r"""
|
|
2236
|
+
Creates an expression representing the summation of `self`.
|
|
2237
|
+
|
|
2238
|
+
This is an alternative to using :func:`jijmodeling.sum`, where
|
|
2239
|
+
a method call on an expression may be more convenient/readable.
|
|
2240
|
+
|
|
2241
|
+
If `self` isn't a valid sequence which can be summed, you will get an
|
|
2242
|
+
error when the resulting expression is added to a :class:`Problem` and is
|
|
2243
|
+
type-checked.
|
|
2244
|
+
|
|
2245
|
+
The optional `axis` parameter allows you to specify one axis of a
|
|
2246
|
+
multi-dimensional expression across which to perform the operation.
|
|
2247
|
+
|
|
2248
|
+
Examples
|
|
2249
|
+
------
|
|
2250
|
+
|
|
2251
|
+
Simple sum of decision variables.
|
|
2252
|
+
|
|
2253
|
+
```python
|
|
2254
|
+
>>> import jijmodeling as jm
|
|
2255
|
+
>>> problem = jm.Problem("MyProblem")
|
|
2256
|
+
>>> N = problem.Natural("N")
|
|
2257
|
+
>>> x = problem.IntegerVar("x", shape=N)
|
|
2258
|
+
>>> problem += x.sum()
|
|
2259
|
+
```
|
|
2260
|
+
|
|
2261
|
+
Performing a weighted sum. Note that this sort of usage may lead to errors
|
|
2262
|
+
when the shapes don't match. In this case we guarantee that `x` has the
|
|
2263
|
+
same shape as `W` through its definition.
|
|
2264
|
+
|
|
2265
|
+
```python
|
|
2266
|
+
>>> import jijmodeling as jm
|
|
2267
|
+
>>> problem = jm.Problem("MyProblem")
|
|
2268
|
+
>>> W = problem.Float("W", ndim=1)
|
|
2269
|
+
>>> N = a.len_at(0)
|
|
2270
|
+
>>> x = problem.BinaryVar("x", shape=N)
|
|
2271
|
+
>>> problem += (W * x).sum()
|
|
2272
|
+
```
|
|
2273
|
+
"""
|
|
2274
|
+
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:
|
|
2275
|
+
r"""
|
|
2276
|
+
Creates an expression representing the multiplication of `self`.
|
|
2277
|
+
|
|
2278
|
+
This is an alternative to using :func:`jijmodeling.prod`, where
|
|
2279
|
+
a method call on an expression may be more convenient/readable.
|
|
2280
|
+
|
|
2281
|
+
If `self` isn't a valid sequence which can be multiplied, you will get an
|
|
2282
|
+
error when the resulting expression is added to a :class:`Problem` and is
|
|
2283
|
+
type-checked.
|
|
2284
|
+
|
|
2285
|
+
The optional `axis` parameter allows you to specify one axis of a
|
|
2286
|
+
multi-dimensional expression across which to perform the operation.
|
|
2287
|
+
|
|
2288
|
+
Examples
|
|
2289
|
+
------
|
|
2290
|
+
|
|
2291
|
+
Simple product of decision variables
|
|
2292
|
+
|
|
2293
|
+
```python
|
|
2294
|
+
>>> import jijmodeling as jm
|
|
2295
|
+
>>> problem = jm.Problem("MyProblem")
|
|
2296
|
+
>>> N = problem.Natural("N")
|
|
2297
|
+
>>> x = problem.IntegerVar("x", shape=N)
|
|
2298
|
+
>>> problem += x.prod()
|
|
2299
|
+
```
|
|
2300
|
+
"""
|
|
2301
|
+
def __getitem__(self, subscripts: typing.Any) -> Expression: ...
|
|
2302
|
+
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:
|
|
2303
|
+
r"""
|
|
2304
|
+
Creates an expression that maps the values in `self` to `func`.
|
|
2305
|
+
|
|
2306
|
+
This is an alternative to :func:`jijmodeling.map` which allows you
|
|
2307
|
+
to place the indexing expression first.
|
|
2308
|
+
|
|
2309
|
+
When called on valid scalar scalars, each number from 0 to this `self`
|
|
2310
|
+
will be passed to `func`. When called on a sequence expression (eg. a
|
|
2311
|
+
1-dimensional placeholder, or the result of functions like
|
|
2312
|
+
:func:`jijmodeling.product` or :func:`jijmodeling.items`), each element
|
|
2313
|
+
in the sequence is passed to `func`.
|
|
2314
|
+
|
|
2315
|
+
This is mostly used alongside lambdas as a way to access individual values
|
|
2316
|
+
within array-like or dictionary-like :class:`Placeholder`s and
|
|
2317
|
+
:class:`DecisionVar`s. The resulting expression is then usually passed to a
|
|
2318
|
+
reducer, like :func:`jijmodeling.sum` (or :meth:`Expression.sum` is called
|
|
2319
|
+
on it), to form part of a constraint or the objective function.
|
|
2320
|
+
|
|
2321
|
+
Examples
|
|
2322
|
+
------
|
|
2323
|
+
|
|
2324
|
+
Indexing by values from 0 to N. In this example we define N as the length of
|
|
2325
|
+
another placeholder, but a scalar Natural placeholder would work as well.
|
|
2326
|
+
|
|
2327
|
+
```python
|
|
2328
|
+
>>> import jijmodeling as jm
|
|
2329
|
+
>>> problem = jm.Problem("MyProblem")
|
|
2330
|
+
>>> W = problem.Float("W", ndim=1)
|
|
2331
|
+
>>> N = W.len_at(0)
|
|
2332
|
+
>>> x = problem.BinaryVar("x", shape=N)
|
|
2333
|
+
>>> problem += N.map(lambda i: W[i] * x[i]).sum()
|
|
2334
|
+
```
|
|
2335
|
+
|
|
2336
|
+
Indexing by specific values from instance data. In this example only the
|
|
2337
|
+
indices present in `C` in the instance data will be used in this constraint.
|
|
2338
|
+
|
|
2339
|
+
```python
|
|
2340
|
+
>>> import jijmodeling as jm
|
|
2341
|
+
>>> problem = jm.Problem("MyProblem")
|
|
2342
|
+
>>> N = problem.Natural("N")
|
|
2343
|
+
>>> x = problem.IntegerVar("x", shape=N, lower_bound=0, upper_bound=10)
|
|
2344
|
+
>>> C = problem.Natural("C", ndim=1)
|
|
2345
|
+
>>> problem += problem.Constraint("constr", C.map(lambda i: x[i]).sum() <= 100)
|
|
2346
|
+
```
|
|
2347
|
+
"""
|
|
2348
|
+
def roll(self, shift: typing.Any, *, axis: typing.Optional[builtins.int] = None) -> Expression: ...
|
|
2349
|
+
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:
|
|
2350
|
+
r"""
|
|
2351
|
+
Creates an expression that filters the values of this sequence.
|
|
2352
|
+
|
|
2353
|
+
`predicate` will be called on each element in `self`. The resulting
|
|
2354
|
+
expression represents only the values for which `predicate` is true.
|
|
2355
|
+
|
|
2356
|
+
This is an alternative to :func:`jijmodeling.filter` which allows
|
|
2357
|
+
you to place the indexing expression first.
|
|
2358
|
+
|
|
2359
|
+
This is often useful when trying to create summations which only include
|
|
2360
|
+
a subset of potential indices.The resulting expression is usually used as the
|
|
2361
|
+
basis for :func:`jijmodeling.map`, :func:`jijmodeling.sum`, etc., or a
|
|
2362
|
+
method equivalent.
|
|
2363
|
+
|
|
2364
|
+
Examples
|
|
2365
|
+
------
|
|
2366
|
+
|
|
2367
|
+
Using only variables with even indices as part of a constraint.
|
|
2368
|
+
|
|
2369
|
+
```python
|
|
2370
|
+
>>> import jijmodeling as jm
|
|
2371
|
+
>>> problem = jm.Problem("MyProblem")
|
|
2372
|
+
>>> N = jm.Natural("N")
|
|
2373
|
+
>>> x = problem.BinaryVar("x", shape=(N, N))
|
|
2374
|
+
>>> even_xs = N.filter(lambda i: i % 2 == 0).map(lambda i: x[i])
|
|
2375
|
+
>>> problem += problem.Constraint("constr", even_xs.sum() <= 10)
|
|
2376
|
+
```
|
|
2377
|
+
|
|
2378
|
+
Using only non-diagonal indices of an NxN matrix as part of a constraint, using the method version of `filter`.
|
|
2379
|
+
|
|
2380
|
+
```python
|
|
2381
|
+
>>> import jijmodeling as jm
|
|
2382
|
+
>>> problem = jm.Problem("MyProblem")
|
|
2383
|
+
>>> N = jm.Natural("N")
|
|
2384
|
+
>>> x = problem.BinaryVar("x", shape=(N, N))
|
|
2385
|
+
>>> W = problem.Float("W", shape=(N, N))
|
|
2386
|
+
>>> non_diagonals = jm.product(N, N).filter(lambda i, j: i != j)
|
|
2387
|
+
>>> problem += problem.Constraint("constr", lambda i, j: W[i, j] * x[i, j], domain=non_diagonals)
|
|
2388
|
+
```
|
|
2389
|
+
"""
|
|
2390
|
+
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:
|
|
2391
|
+
r"""
|
|
2392
|
+
Creates an expression which works like :meth:`map`, but flattens nested structure.
|
|
2393
|
+
|
|
2394
|
+
This is an alternative to :func:`jijmodeling.flat_map` which allows you to
|
|
2395
|
+
place the indexing expression first.
|
|
2396
|
+
|
|
2397
|
+
`map` is useful when `func` returns scalar values, but in some
|
|
2398
|
+
situations one wants to write a `func` that returns other
|
|
2399
|
+
mappings/sequences instead. That is where `flat_map` should be used,
|
|
2400
|
+
"flattening" all sequences/iterators into a single linear sequence
|
|
2401
|
+
(which can then be reduced with :meth:`sum`, etc.)
|
|
2402
|
+
|
|
2403
|
+
You can also compare `flat_map` to a nested for-loop, or a generator
|
|
2404
|
+
expression that uses two `for` clauses. Indeed when using the decorated API
|
|
2405
|
+
(see tutorials or :meth:`Problem.update`), you can use a generator
|
|
2406
|
+
expression-like syntax instead.
|
|
2407
|
+
|
|
2408
|
+
Examples
|
|
2409
|
+
------
|
|
2410
|
+
|
|
2411
|
+
Using only non-diagonal indices of an NxN matrix.
|
|
2412
|
+
```python
|
|
2413
|
+
>>> import jijmodeling as jm
|
|
2414
|
+
>>> problem = jm.Problem("MyProblem")
|
|
2415
|
+
>>> N = jm.Natural("N")
|
|
2416
|
+
>>> x = problem.BinaryVar("x", shape=(N, N))
|
|
2417
|
+
>>> W = problem.Float("W", shape=(N, N))
|
|
2418
|
+
>>> objective = N.flat_map(
|
|
2419
|
+
... lambda i: N.filter(lambda j: i != j).map(lambda j: W[i, j] * x[i, j])
|
|
2420
|
+
... ).sum()
|
|
2421
|
+
>>> problem += objective
|
|
2422
|
+
```
|
|
2423
|
+
"""
|
|
2424
|
+
def rows(self) -> Expression:
|
|
2425
|
+
r"""
|
|
2426
|
+
Creates a sequence over the rows of this multi-dimensional array expression.
|
|
2427
|
+
|
|
2428
|
+
That is, each element will be a whole row (itself containing multiple
|
|
2429
|
+
values), which can then be operated on like other sequences (eg. using
|
|
2430
|
+
:func:`jijmodelng.sum` or :func:`jijmodeling.map`).
|
|
2431
|
+
|
|
2432
|
+
If the array is 3-dimensional or higher, rows will iterate over the first
|
|
2433
|
+
dimension/axis. For example, in a 3D matrix, the first element would be a
|
|
2434
|
+
2D matrix representing all values `x[0, _, _]`
|
|
2435
|
+
|
|
2436
|
+
Examples
|
|
2437
|
+
------
|
|
2438
|
+
|
|
2439
|
+
Create an objective function that multiplies each variable in a row, and
|
|
2440
|
+
then sums each row. In this case we have a 2x3 matrix, so the final expression is
|
|
2441
|
+
`x[0, 0] * x[0, 1] * x[0, 2] + x[1, 0] * x[1, 1] * x[1, 2]`. Using
|
|
2442
|
+
placeholders instead of literals in `shape` would allow this to be written
|
|
2443
|
+
for matrices of arbitrary size.
|
|
2444
|
+
```python
|
|
2445
|
+
>>> import jijmodeling as jm
|
|
2446
|
+
>>> problem = jm.Problem("MyProblem")
|
|
2447
|
+
>>> d = problem.BinaryVar("d", shape=(2, 3))
|
|
2448
|
+
>>> problem += d.rows().map(lambda xs: xs.prod()).sum()
|
|
2449
|
+
```
|
|
2450
|
+
|
|
2451
|
+
If the number of elements in the row can be guaranteed, the elements can be
|
|
2452
|
+
destructured as separate arguments in a lambda expression:
|
|
2453
|
+
|
|
2454
|
+
```python
|
|
2455
|
+
>>> import jijmodeling as jm
|
|
2456
|
+
>>> problem = jm.Problem("MyProblem")
|
|
2457
|
+
>>> N = problem.Natural("N")
|
|
2458
|
+
>>> V = problem.Natural("V")
|
|
2459
|
+
>>> E = problem.Natural("E", shape=(N, 2))
|
|
2460
|
+
>>> x = problem.BinaryVar("x", shape=V)
|
|
2461
|
+
>>> problem += jm.map(lambda i, j: x[i] * x[j], E.rows()).sum()
|
|
2462
|
+
```
|
|
2463
|
+
"""
|
|
2464
|
+
def indices(self) -> Expression:
|
|
2465
|
+
r"""
|
|
2466
|
+
Get the set of indices of given array or jagged array.
|
|
2467
|
+
|
|
2468
|
+
Will throw type error when called on non-array type.
|
|
2469
|
+
"""
|
|
2470
|
+
def keys(self) -> Expression:
|
|
2471
|
+
r"""
|
|
2472
|
+
Returns an expression representing this dictionary-like object's keys.
|
|
2473
|
+
|
|
2474
|
+
In other words, this is the JijModeling equivalent of the `keys()`
|
|
2475
|
+
method on Python dictionaries, used when creating JijModeling
|
|
2476
|
+
expressions.
|
|
2477
|
+
|
|
2478
|
+
While it's possible to call this on any :class:`Expression`, this is
|
|
2479
|
+
intended for dictionary-like :class:`Placeholder`s and
|
|
2480
|
+
:class:`DecisionVar`s. Using this with an invalid object will lead
|
|
2481
|
+
to an error when the resulting expression is added to a
|
|
2482
|
+
:class:`Problem` and is type-checked.
|
|
2483
|
+
|
|
2484
|
+
See also :meth:`Expression.values` and :meth:`Expression.items`.
|
|
2485
|
+
|
|
2486
|
+
Examples
|
|
2487
|
+
------
|
|
2488
|
+
Refer to a dictionary-like placeholder's keys when
|
|
2489
|
+
creating other objects or writing summations:
|
|
2490
|
+
|
|
2491
|
+
```python
|
|
2492
|
+
>>> import jijmodeling as jm
|
|
2493
|
+
>>> problem = jm.Problem("MyProblem")
|
|
2494
|
+
>>> I = problem.CategoryLabel("I")
|
|
2495
|
+
>>> W = problem.Float("W", dict_keys=I)
|
|
2496
|
+
>>> x = problem.BinaryVar("x", dict_keys=W.keys())
|
|
2497
|
+
>>> problem += jm.sum(W.keys(), lambda i: W[i] * x[i])
|
|
2498
|
+
```
|
|
2499
|
+
"""
|
|
2500
|
+
def values(self) -> Expression:
|
|
2501
|
+
r"""
|
|
2502
|
+
Returns an expression representing this dictionary-like object's values.
|
|
2503
|
+
|
|
2504
|
+
In other words, this is the JijModeling equivalent of the `values()`
|
|
2505
|
+
method on Python dictionaries, used when creating JijModeling
|
|
2506
|
+
expressions.
|
|
2507
|
+
|
|
2508
|
+
While it's possible to call this on any :class:`Expression`, this is
|
|
2509
|
+
intended for dictionary-like :class:`Placeholder`s and
|
|
2510
|
+
:class:`DecisionVar`s. Using this with an invalid object will lead
|
|
2511
|
+
to an error when the resulting expression is added to a
|
|
2512
|
+
:class:`Problem` and is type-checked.
|
|
2513
|
+
|
|
2514
|
+
See also :meth:`Expression.keys` and :meth:`Expression.items`.
|
|
2515
|
+
|
|
2516
|
+
Examples
|
|
2517
|
+
------
|
|
2518
|
+
Defining a simple objective function which just sums a dictionary-based decision variable.
|
|
2519
|
+
|
|
2520
|
+
```python
|
|
2521
|
+
>>> problem = jm.Problem("MyProblem")
|
|
2522
|
+
>>> I = problem.CategoryLabel("I")
|
|
2523
|
+
>>> x = problem.IntegerVar("x", dict_keys=I, lower_bound=0, upper_bound=100)
|
|
2524
|
+
>>> problem += x.values().sum()
|
|
2525
|
+
```
|
|
2526
|
+
"""
|
|
2527
|
+
def items(self) -> Expression:
|
|
2528
|
+
r"""
|
|
2529
|
+
Returns an expression representing this object's `(key,value)` pairs.
|
|
2530
|
+
|
|
2531
|
+
In other words, this is the JijModeling equivalent of the `items()`
|
|
2532
|
+
method on Python dictionaries, used when creating JijModeling
|
|
2533
|
+
expressions.
|
|
2534
|
+
|
|
2535
|
+
While it's possible to call this on any :class:`Expression`, this is
|
|
2536
|
+
intended for dictionary-like :class:`Placeholder`s and
|
|
2537
|
+
:class:`DecisionVar`s. Using this with an invalid object will lead
|
|
2538
|
+
to an error when the resulting expression is added to a
|
|
2539
|
+
:class:`Problem` and is type-checked.
|
|
2540
|
+
|
|
2541
|
+
See also :meth:`Expression.keys` and :meth:`Expression.values`.
|
|
2542
|
+
|
|
2543
|
+
Examples
|
|
2544
|
+
------
|
|
2545
|
+
Simple matching of weights to their respective variables, as an alternative to just using `keys()` or the `CategoryLabel`:
|
|
2546
|
+
|
|
2547
|
+
```python
|
|
2548
|
+
>>> problem = jm.Problem("MyProblem")
|
|
2549
|
+
>>> I = problem.CategoryLabel("I")
|
|
2550
|
+
>>> weights = problem.Float("W", dict_keys=I)
|
|
2551
|
+
>>> x = problem.BinaryVar("x", dict_keys=I)
|
|
2552
|
+
>>> problem += jm.sum(weights.items(), lambda i, w: w * x[i])
|
|
2553
|
+
```
|
|
2554
|
+
|
|
2555
|
+
Same as above, but using the decorated API:
|
|
2556
|
+
```python
|
|
2557
|
+
>>> @problem.update
|
|
2558
|
+
... def _(problem):
|
|
2559
|
+
... I = problem.CategoryLabel()
|
|
2560
|
+
... W = problem.Float(dict_keys=I)
|
|
2561
|
+
... x = problem.BinaryVar(dict_keys=I)
|
|
2562
|
+
... problem += jm.sum(w * x[i] for i, w in W.items())
|
|
2563
|
+
```
|
|
2564
|
+
"""
|
|
2565
|
+
def __neg__(self) -> Expression: ...
|
|
2566
|
+
def abs(self) -> Expression:
|
|
2567
|
+
r"""
|
|
2568
|
+
Returns an expression representing the absolute value of the given expression.
|
|
2569
|
+
|
|
2570
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
2571
|
+
"""
|
|
2572
|
+
def sqrt(self) -> Expression:
|
|
2573
|
+
r"""
|
|
2574
|
+
Returns an expression representing the square root of the given expression.
|
|
2575
|
+
|
|
2576
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
2577
|
+
"""
|
|
2578
|
+
def sin(self) -> Expression:
|
|
2579
|
+
r"""
|
|
2580
|
+
Returns an expression representing the sine of the given expression.
|
|
2581
|
+
|
|
2582
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
2583
|
+
"""
|
|
2584
|
+
def cos(self) -> Expression:
|
|
2585
|
+
r"""
|
|
2586
|
+
Returns an expression representing the cosine of the given expression.
|
|
2587
|
+
|
|
2588
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
2589
|
+
"""
|
|
2590
|
+
def tan(self) -> Expression:
|
|
2591
|
+
r"""
|
|
2592
|
+
Returns an expression representing the tangent of the given expression.
|
|
2593
|
+
|
|
2594
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
2595
|
+
"""
|
|
2596
|
+
def asin(self) -> Expression:
|
|
2597
|
+
r"""
|
|
2598
|
+
Returns an expression representing the arcsine of the given expression.
|
|
2599
|
+
|
|
2600
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
2601
|
+
"""
|
|
2602
|
+
def acos(self) -> Expression:
|
|
2603
|
+
r"""
|
|
2604
|
+
Returns an expression representing the arccosine of the given expression.
|
|
2605
|
+
|
|
2606
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
2607
|
+
"""
|
|
2608
|
+
def atan(self) -> Expression:
|
|
2609
|
+
r"""
|
|
2610
|
+
Returns an expression representing the arctangent of the given expression.
|
|
2611
|
+
|
|
2612
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
2613
|
+
"""
|
|
2614
|
+
def sinh(self) -> Expression:
|
|
2615
|
+
r"""
|
|
2616
|
+
Returns an expression representing the hyperbolic sine of the given expression.
|
|
2617
|
+
|
|
2618
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
2619
|
+
"""
|
|
2620
|
+
def cosh(self) -> Expression:
|
|
2621
|
+
r"""
|
|
2622
|
+
Returns an expression representing the hyperbolic cosine of the given expression.
|
|
2623
|
+
|
|
2624
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
2625
|
+
"""
|
|
2626
|
+
def tanh(self) -> Expression:
|
|
2627
|
+
r"""
|
|
2628
|
+
Returns an expression representing the hyperbolic tangent of the given expression.
|
|
2629
|
+
|
|
2630
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
2631
|
+
"""
|
|
2632
|
+
def asinh(self) -> Expression:
|
|
2633
|
+
r"""
|
|
2634
|
+
Returns an expression representing the hyperbolic arcsine of the given expression.
|
|
2635
|
+
|
|
2636
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
2637
|
+
"""
|
|
2638
|
+
def acosh(self) -> Expression:
|
|
2639
|
+
r"""
|
|
2640
|
+
Returns an expression representing the hyperbolic arccosine of the given expression.
|
|
2641
|
+
|
|
2642
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
2643
|
+
"""
|
|
2644
|
+
def atanh(self) -> Expression:
|
|
2645
|
+
r"""
|
|
2646
|
+
Returns an expression representing the hyperbolic arctangent of the given expression.
|
|
2647
|
+
|
|
2648
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
2649
|
+
"""
|
|
2650
|
+
def exp(self) -> Expression:
|
|
2651
|
+
r"""
|
|
2652
|
+
Returns an expression representing the application of the exponential function on the given expression.
|
|
2653
|
+
|
|
2654
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
2655
|
+
"""
|
|
2656
|
+
def ln(self) -> Expression:
|
|
2657
|
+
r"""
|
|
2658
|
+
Returns an expression representing the natural logarithm of the given expression.
|
|
2659
|
+
|
|
2660
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
2661
|
+
"""
|
|
2662
|
+
def log10(self) -> Expression:
|
|
2663
|
+
r"""
|
|
2664
|
+
Returns an expression representing the decimal logarithm of the given expression.
|
|
2665
|
+
|
|
2666
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
2667
|
+
"""
|
|
2668
|
+
def log2(self) -> Expression:
|
|
2669
|
+
r"""
|
|
2670
|
+
Returns an expression representing the binary logarithm of the given expression.
|
|
2671
|
+
|
|
2672
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
2673
|
+
"""
|
|
2674
|
+
def ceil(self) -> Expression:
|
|
2675
|
+
r"""
|
|
2676
|
+
Returns an expression which rounds down to the nearest whole number.
|
|
2677
|
+
|
|
2678
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
2679
|
+
"""
|
|
2680
|
+
def floor(self) -> Expression: ...
|
|
2681
|
+
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: ...
|
|
2682
|
+
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: ...
|
|
2683
|
+
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: ...
|
|
2684
|
+
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: ...
|
|
2685
|
+
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: ...
|
|
2686
|
+
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: ...
|
|
2687
|
+
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: ...
|
|
2688
|
+
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: ...
|
|
2689
|
+
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: ...
|
|
2690
|
+
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: ...
|
|
2691
|
+
def __pow__(self, exponent: typing.Any, modulo: typing.Optional[typing.Any] = None) -> Expression: ...
|
|
2692
|
+
def __rpow__(self, base: typing.Any, modulo: typing.Optional[typing.Any] = None) -> Expression: ...
|
|
2693
|
+
def __repr__(self) -> builtins.str: ...
|
|
2694
|
+
def _repr_latex_(self) -> builtins.str: ...
|
|
2695
|
+
def len_at(self, index: builtins.int) -> Expression:
|
|
2696
|
+
r"""
|
|
2697
|
+
Returns an expression representing the length (number of values) a
|
|
2698
|
+
placeholder has at a given dimension (0-indexed).
|
|
2699
|
+
|
|
2700
|
+
This can be used, for example, when trying to match the shape of
|
|
2701
|
+
an object to the number of values in an array.
|
|
2702
|
+
|
|
2703
|
+
Examples
|
|
2704
|
+
------
|
|
2705
|
+
|
|
2706
|
+
```python
|
|
2707
|
+
>>> problem = jm.Problem("MyProblem")
|
|
2708
|
+
>>> V = problem.Integer(name="V", ndim=1)
|
|
2709
|
+
>>> N = V.len_at(0)
|
|
2710
|
+
>>> x = problem.BinaryVar("x", shape=(N,))
|
|
2711
|
+
```
|
|
2712
|
+
"""
|
|
2713
|
+
|
|
2714
|
+
@typing.final
|
|
2715
|
+
class Problem:
|
|
2716
|
+
r"""
|
|
2717
|
+
A class for creating an optimization problem.
|
|
2718
|
+
|
|
2719
|
+
Attributes
|
|
2720
|
+
-----------
|
|
2721
|
+
- `name` (`str`): A name of the optimization problem.
|
|
2722
|
+
- `sense` (`ProblemSense`): Sense of the optimization problem.
|
|
2723
|
+
- `objective`: The objective function of the optimization problem.
|
|
2724
|
+
- `constraints` (`dict`): A dictionary that stores constraints.
|
|
2725
|
+
- A key is the name of a constraint and the value is the constraint object.
|
|
2726
|
+
|
|
2727
|
+
Args
|
|
2728
|
+
-----
|
|
2729
|
+
- `name` (`str`): A name of the optimization problem.
|
|
2730
|
+
- `sense` (optional): Sense of the optimization problem. Defaults to `ProblemSense.MINIMIZE`.
|
|
2731
|
+
- `description` (`str`, optional): An optional description of the problem, for user reference.
|
|
2732
|
+
"""
|
|
2733
|
+
@property
|
|
2734
|
+
def objective(self) -> Expression: ...
|
|
2735
|
+
@property
|
|
2736
|
+
def description(self) -> builtins.str:
|
|
2737
|
+
r"""
|
|
2738
|
+
The problem description.
|
|
2739
|
+
|
|
2740
|
+
An empty string if no description was defined.
|
|
2741
|
+
"""
|
|
2742
|
+
@property
|
|
2743
|
+
def constraints(self) -> builtins.dict[builtins.str, builtins.list[Constraint]]:
|
|
2744
|
+
r"""
|
|
2745
|
+
Returns a dictionary of the constraints in the problem.
|
|
2746
|
+
|
|
2747
|
+
Returns
|
|
2748
|
+
--------
|
|
2749
|
+
`dict[str, [Constraint]]`: Dictionary mapping constraint names to Constraint objects.
|
|
2750
|
+
"""
|
|
2751
|
+
@property
|
|
2752
|
+
def used_placeholders(self) -> builtins.list[Placeholder]:
|
|
2753
|
+
r"""
|
|
2754
|
+
A list of the :class:`Placeholder`s used in expressions composing this problem (objective function and constraints).
|
|
2755
|
+
|
|
2756
|
+
This does not include placeholders which have been created but never used.
|
|
2757
|
+
"""
|
|
2758
|
+
@property
|
|
2759
|
+
def decision_vars(self) -> builtins.dict[builtins.str, DecisionVar]:
|
|
2760
|
+
r"""
|
|
2761
|
+
Returns a dictionary of decision variables in the problem.
|
|
2762
|
+
The dictionary may contain decision variables that are not used in the problem.
|
|
2763
|
+
|
|
2764
|
+
Returns
|
|
2765
|
+
--------
|
|
2766
|
+
`dict[str, DecisionVar]`: Dictionary mapping variable names to DecisionVar objects.
|
|
2767
|
+
"""
|
|
2768
|
+
@property
|
|
2769
|
+
def placeholders(self) -> builtins.dict[builtins.str, Placeholder]:
|
|
2770
|
+
r"""
|
|
2771
|
+
Returns a dictionary of placeholders in the problem.
|
|
2772
|
+
The dictionary may contain placeholders that are not used in the problem;
|
|
2773
|
+
to get only used placeholders, use `used_placeholders` method.
|
|
2774
|
+
|
|
2775
|
+
Returns
|
|
2776
|
+
--------
|
|
2777
|
+
`dict[str, Placeholder]`: Dictionary mapping placeholder names to Placeholder objects.
|
|
2778
|
+
"""
|
|
2779
|
+
def __new__(cls, name: builtins.str, *, sense: ProblemSense = ProblemSense.MINIMIZE, description: typing.Optional[builtins.str] = None) -> Problem: ...
|
|
2780
|
+
@typing.overload
|
|
2781
|
+
def Constraint(self, name: 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:
|
|
2782
|
+
r"""
|
|
2783
|
+
Constructs `Constraint` object from comparison expression, __WITHOUT__ registering it to the problem.
|
|
2784
|
+
Use `+=` operator to register the constraint to the problem.
|
|
2785
|
+
"""
|
|
2786
|
+
@typing.overload
|
|
2787
|
+
def Constraint(self, name: 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:
|
|
2788
|
+
r"""
|
|
2789
|
+
Constructs ``Constraint`` family with the index set ``domain`` and function ``expression`` to build comparison expression from each index, __WITHOUT__ registering it to the problem.
|
|
2790
|
+
Use `+=` operator to register the constraint to the problem.
|
|
2791
|
+
"""
|
|
2792
|
+
def get_problem_schema(self) -> dict:
|
|
2793
|
+
r"""
|
|
2794
|
+
Returns the schema of the problem.
|
|
2795
|
+
|
|
2796
|
+
Returns
|
|
2797
|
+
--------
|
|
2798
|
+
- `schema`: The dictionary containing the schema of the problem.
|
|
2799
|
+
"""
|
|
2800
|
+
def generate_random_dataset(self, _default: typing.Any, _options: typing.Any, _seed: typing.Optional[builtins.int]) -> typing.Any:
|
|
2801
|
+
r"""
|
|
2802
|
+
Generates a dictionary of random `InstanceDataValue` for a given problem.
|
|
2803
|
+
To generate `ommx.v1.Instance` object directly, use `InstanceDataValue.generate_random_instance` instead.
|
|
2804
|
+
|
|
2805
|
+
Args
|
|
2806
|
+
-----
|
|
2807
|
+
- `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).
|
|
2808
|
+
- `default` (optional): default range parameters for placeholders which is not specified in `options`.
|
|
2809
|
+
- `seed` (optional): seed for random number generation.
|
|
2810
|
+
|
|
2811
|
+
Returns
|
|
2812
|
+
--------
|
|
2813
|
+
`dict`: The dictionary from the name of placeholders to the generated `InstanceDataValue` objects. To be fed to `Interpreter.eval_problem`.
|
|
2814
|
+
|
|
2815
|
+
Range Parameters and Range Syntax
|
|
2816
|
+
----------------------------------
|
|
2817
|
+
A range parameter is a dictionary consisting of the following fields:
|
|
2818
|
+
- `size` (optional): interval of natural numbers for the size of each array dimension (default: `range(1, 6)`)
|
|
2819
|
+
- `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]$).
|
|
2820
|
+
|
|
2821
|
+
Example range parameter config:
|
|
2822
|
+
|
|
2823
|
+
```python
|
|
2824
|
+
{"size": range(2, 10), "value": jm.range.value.closed(100.0, 200.0)}
|
|
2825
|
+
```
|
|
2826
|
+
|
|
2827
|
+
Intervals are expressed as a range object.
|
|
2828
|
+
Currently, the following syntax is supported for range objects:
|
|
2829
|
+
|
|
2830
|
+
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.
|
|
2831
|
+
2. Use the functions from `jijmodeling.range`, `jijmodeling.range.size`, or `jijmodeling.range.value` modules.
|
|
2832
|
+
- 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.
|
|
2833
|
+
- These three modules provides the following combinators (see the module documents for more details.):
|
|
2834
|
+
- `closed(a, b)`: a closed interval $[a, b]$
|
|
2835
|
+
- `open(a, b)`: an open interval $(a, b)$
|
|
2836
|
+
- `closed_open(a, b)`: an upper half-open interval $[a, b)$
|
|
2837
|
+
- `open_closed(a, b)`: a lower half-open interval $(a, b]$
|
|
2838
|
+
- `greater_than(a)`: an open interval $(a, \infty)$
|
|
2839
|
+
- `at_least(a)`: a closed interval $[a, \infty)$
|
|
2840
|
+
- `less_than(a)`: an open interval $(-\infty, a)$
|
|
2841
|
+
- `at_most(a)`: a closed interval $(-\infty, a]$
|
|
2842
|
+
3. Use `range` builtin function: this is equivalent to `jijmodeling.range.value.closed_open(a, b)`.
|
|
2843
|
+
- Any python range object with `step = 1` can be used as a size range; otherwise it results in runtime error.
|
|
2844
|
+
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`.
|
|
2845
|
+
- You can also use bound object as a tuple component; in such case, both tuple components must be one of the following:
|
|
2846
|
+
|
|
2847
|
+
1. A string `"Unbounded"` means $-\infty$ (in the first component) or $\infty$ (the second).
|
|
2848
|
+
2. A dictionary `{"Included": a}` means the endpoint is inclusive.
|
|
2849
|
+
3. A dictionary `{"Excluded": a}` means the endpoint is exclusive.
|
|
2850
|
+
- Examples:
|
|
2851
|
+
- `(1.2, 4)` is equivalent to `closed_open(1.2, 4)`,
|
|
2852
|
+
- `(-1, {"Included": 1})` is equivalent to `closed(-1, 1)`,
|
|
2853
|
+
- `(-5, {"Excluded": 4})` is equivalent to `closed_open(-5, 4)` and built in function `range(-5, 4)`,
|
|
2854
|
+
- `({"Excluded": 1}, {"Excluded": 2.5})` is equivalent to `open(1, 2.5)`,
|
|
2855
|
+
- `({"Included": -1}, "Unbounded")` is equivalent to `at_least(-1)`.
|
|
2856
|
+
- `(5, "Unbounded")` is **INVALID**; `5` must be bound object.
|
|
2857
|
+
5. The range object: A dictionary of form `{"start": lb, "end": ub}`, where both `lb` and `ub` are the bound object described as above.
|
|
2858
|
+
|
|
2859
|
+
Examples
|
|
2860
|
+
---------
|
|
2861
|
+
```python
|
|
2862
|
+
>>> import jijmodeling as jm
|
|
2863
|
+
>>> import builtins
|
|
2864
|
+
>>> N = jm.Placeholder("N", dtype=jm.DataType.INTEGER)
|
|
2865
|
+
>>> c = jm.Placeholder("c", dtype=jm.DataType.FLOAT, shape=(N,))
|
|
2866
|
+
>>> x = jm.BinaryVar("x", shape=(N,))
|
|
2867
|
+
>>> i = jm.Element("i", belong_to=N)
|
|
2868
|
+
|
|
2869
|
+
>>> problem = jm.Problem("problem")
|
|
2870
|
+
>>> problem += jm.sum(i, c[i] * x[i])
|
|
2871
|
+
|
|
2872
|
+
>>> inputs = problem.generate_random_dataset(
|
|
2873
|
+
... options={
|
|
2874
|
+
... 'N': {"value": builtins.range(10, 20)},
|
|
2875
|
+
... 'c': {"value": jm.range.value.closed(-1.0, 1.0)}
|
|
2876
|
+
... # You can also specify "size" for the range of jagged array dimension size.
|
|
2877
|
+
... },
|
|
2878
|
+
... seed=123 # omittable
|
|
2879
|
+
... )
|
|
2880
|
+
>>> assert set(inputs.keys()) == {"N", "c"}
|
|
2881
|
+
>>> inputs
|
|
2882
|
+
{'N': 11.0, 'c': array([ 0.93914459, -0.06511935, -0.7460324 , -0.32443706, 0.99981451,
|
|
2883
|
+
-0.24407535, 0.31329469, 0.52206453, -0.1291936 , 0.30443087,
|
|
2884
|
+
0.53125838])}
|
|
2885
|
+
|
|
2886
|
+
```
|
|
2887
|
+
"""
|
|
2888
|
+
def generate_random_instance(self, _default: typing.Any, _options: typing.Any, _seed: typing.Optional[builtins.int], _hints: typing.Optional[typing.Any]) -> typing.Any:
|
|
2889
|
+
r"""
|
|
2890
|
+
Generates random `ommx.v1.Instance` for a given problem.
|
|
2891
|
+
See also `InstanceDataValue.generate_random_dataset`.
|
|
2892
|
+
|
|
2893
|
+
Args
|
|
2894
|
+
-----
|
|
2895
|
+
- `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`).
|
|
2896
|
+
- `default` (optional): default range parameters for placeholders which is not specified in `options`.
|
|
2897
|
+
- `seed` (optional): seed for random number generation.
|
|
2898
|
+
- `hints` (optional): the hints to be detected during compilation see `Interpreter.eval_problem` for more details.
|
|
2899
|
+
|
|
2900
|
+
Returns
|
|
2901
|
+
--------
|
|
2902
|
+
`instance`: The OMMX v1 instance object.
|
|
2903
|
+
|
|
2904
|
+
Examples
|
|
2905
|
+
---------
|
|
2906
|
+
```python
|
|
2907
|
+
>>> import jijmodeling as jm
|
|
2908
|
+
>>> import builtins
|
|
2909
|
+
>>> import ommx.v1
|
|
2910
|
+
>>> N = jm.Placeholder("N", dtype=jm.DataType.INTEGER)
|
|
2911
|
+
>>> c = jm.Placeholder("c", dtype=jm.DataType.FLOAT, shape=(N,))
|
|
2912
|
+
>>> x = jm.BinaryVar("x", shape=(N,))
|
|
2913
|
+
>>> i = jm.Element("i", belong_to=N)
|
|
2914
|
+
|
|
2915
|
+
>>> problem = jm.Problem("problem")
|
|
2916
|
+
>>> problem += jm.sum(i, c[i] * x[i])
|
|
2917
|
+
|
|
2918
|
+
>>> instance = problem.generate_random_instance(
|
|
2919
|
+
... options={
|
|
2920
|
+
... 'N': {"value": builtins.range(10, 20)},
|
|
2921
|
+
... 'c': {"value": jm.range.value.closed(-1.0, 1.0)}
|
|
2922
|
+
... },
|
|
2923
|
+
... seed=123
|
|
2924
|
+
... )
|
|
2925
|
+
>>> assert type(instance) is ommx.v1.Instance
|
|
2926
|
+
|
|
2927
|
+
```
|
|
2928
|
+
"""
|
|
2929
|
+
def type_of(self, name: builtins.str) -> typing.Optional[Type]:
|
|
2930
|
+
r"""
|
|
2931
|
+
Returns the type associated with a given name (eg. of a placeholder or decision variable).
|
|
2932
|
+
|
|
2933
|
+
This is mostly inteded for testing purposes, and not as part of standard model writing.
|
|
2934
|
+
|
|
2935
|
+
:raises ModelingError: If the name is undefined in this problem's namespace.
|
|
2936
|
+
"""
|
|
2937
|
+
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:
|
|
2938
|
+
r"""
|
|
2939
|
+
Infers the resulting type of an expression using this problem as a namespace.
|
|
2940
|
+
|
|
2941
|
+
This is mostly intended for testing purposes, and not as part of standard model writing.
|
|
2942
|
+
|
|
2943
|
+
Examples
|
|
2944
|
+
===
|
|
2945
|
+
```python
|
|
2946
|
+
>>> problem = jm.Problem("MyProblem")
|
|
2947
|
+
>>> N = problem.Length(name="N")
|
|
2948
|
+
>>> x = problem.BinaryVar("x", shape=(N,))
|
|
2949
|
+
>>> y = problem.IntegerVar("y", shape=(N,), lower_bound=0,upper_bound=10)
|
|
2950
|
+
>>> problem.infer(jm.sum(x))
|
|
2951
|
+
binary!
|
|
2952
|
+
>>> problem.infer(jm.sum(y))
|
|
2953
|
+
int!
|
|
2954
|
+
```
|
|
2955
|
+
"""
|
|
2956
|
+
@typing.overload
|
|
2957
|
+
def Placeholder(self, name: 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: bool = False, description: typing.Optional[builtins.str] = None, latex: typing.Optional[builtins.str] = None) -> Placeholder: ...
|
|
2958
|
+
@typing.overload
|
|
2959
|
+
def Placeholder(self, name: str, *, dtype: DataType | type | tuple, dict_keys: 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, description: typing.Optional[builtins.str] = None, latex: typing.Optional[builtins.str] = None) -> Placeholder: ...
|
|
2960
|
+
@typing.overload
|
|
2961
|
+
def Placeholder(self, name: str, *, dtype: DataType | type | tuple, dict_keys: 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, partial_dict: typing.Literal[False], description: typing.Optional[builtins.str] = None, latex: typing.Optional[builtins.str] = None) -> Placeholder: ...
|
|
2962
|
+
@typing.overload
|
|
2963
|
+
def Placeholder(self, name: 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, partial_dict: typing.Literal[True], description: typing.Optional[builtins.str] = None, latex: typing.Optional[builtins.str] = None) -> Placeholder: ...
|
|
2964
|
+
@typing.overload
|
|
2965
|
+
def Placeholder(self, name: 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, partial_dict: builtins.bool, description: typing.Optional[builtins.str] = None, latex: typing.Optional[builtins.str] = None) -> Placeholder: ...
|
|
2966
|
+
@typing.overload
|
|
2967
|
+
def Placeholder(self, name: 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: 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, description: typing.Optional[builtins.str] = None, latex: typing.Optional[builtins.str] = None) -> Placeholder:
|
|
2968
|
+
r"""
|
|
2969
|
+
Defines a :class:`Placeholder` in this problem's namespace.
|
|
2970
|
+
|
|
2971
|
+
Placeholders can be a scalar, multi-dimensional array (representing arrays and
|
|
2972
|
+
matrices), or dictionary keyed by integers or strings.
|
|
2973
|
+
|
|
2974
|
+
When calling `Problem.Placehoder`, you must specify `dtype` explicitly to indicate the type of data the placeholder holds.
|
|
2975
|
+
Alternative shorthand methods like `Problem.Integer`, `Problem.Binary`,
|
|
2976
|
+
or `Problem.Natural` are recommended for convenience in their specific
|
|
2977
|
+
use cases.
|
|
2978
|
+
|
|
2979
|
+
Representation
|
|
2980
|
+
--------------
|
|
2981
|
+
Depending on the arguments described below, the representation of the placeholder will be determined as follows:
|
|
2982
|
+
|
|
2983
|
+
1. If 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).
|
|
2984
|
+
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.
|
|
2985
|
+
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).
|
|
2986
|
+
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`.
|
|
2987
|
+
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`.
|
|
2988
|
+
6. Otherwise, an error is raised.
|
|
2989
|
+
|
|
2990
|
+
Args
|
|
2991
|
+
-----
|
|
2992
|
+
- `name` (`str`): The placeholder's name
|
|
2993
|
+
- `dtype` (`DataType`): The type of data this placeholder holds (integer, floating point, etc.).
|
|
2994
|
+
- `ndim` (`int`): The number of dimensions in this placeholder. Defaults to 0 (a scalar value).
|
|
2995
|
+
- `shape` (`list | tuple`): A sequence with the size of each dimension of the placeholder. Defaults to an empty tuple (a scalar value).
|
|
2996
|
+
- Each item in `shape` must be a valid expression evaluating to a non-negative scalar.
|
|
2997
|
+
- There is no need to provide `ndim` if `shape` is specified, but they must not conflict if both specified.
|
|
2998
|
+
- `jagged` (`bool`): Whether this placeholder represents a jagged array (ie. a non-square matrix). Ignored if scalar.
|
|
2999
|
+
- `dict_keys` (`tuple[Expression, ...]`, optional): If provided, specifies that this placeholder represents a dictionary-like structure with keys `dict_keys`.
|
|
3000
|
+
- `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`.
|
|
3001
|
+
- `latex` (`str`, optional): An optional LaTeX representation to be used in Jupyter notebook.
|
|
3002
|
+
- When not provided, `name` is used by default.
|
|
3003
|
+
- `description` (`str`, optional): An optional description for user reference.
|
|
3004
|
+
|
|
3005
|
+
Examples
|
|
3006
|
+
---------
|
|
3007
|
+
Create a scalar integer placeholder whose name is "a".
|
|
3008
|
+
|
|
3009
|
+
```python
|
|
3010
|
+
>>> import jijmodeling as jm
|
|
3011
|
+
>>> problem = jm.Problem("my_problem")
|
|
3012
|
+
>>> a = problem.Placeholder("a", dtype=jm.DataType.INTEGER)
|
|
3013
|
+
```
|
|
3014
|
+
|
|
3015
|
+
Create a 2-dimensional floating-point placeholder whose name is "y" and has a 2x2 shape.
|
|
3016
|
+
|
|
3017
|
+
```python
|
|
3018
|
+
>>> import jijmodeling as jm
|
|
3019
|
+
>>> problem = jm.Problem("my_problem")
|
|
3020
|
+
>>> y = problem.Float("x", shape=(2, 2))
|
|
3021
|
+
```
|
|
3022
|
+
"""
|
|
3023
|
+
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:
|
|
3024
|
+
r"""
|
|
3025
|
+
Defines a :class:`Placeholder` representing an integer in this problem's namespace.
|
|
3026
|
+
|
|
3027
|
+
A shorthand for `Problem.Placeholder(dtype=DataType.INTEGER)`, provided for clarity and convenience.
|
|
3028
|
+
See `Problem.Placeholder` for more details on placeholders.
|
|
3029
|
+
"""
|
|
3030
|
+
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:
|
|
3031
|
+
r"""
|
|
3032
|
+
Defines a :class:`Placeholder` representing a floating-point (real) number in this problem's namespace.
|
|
3033
|
+
|
|
3034
|
+
A shorthand for `Problem.Placeholder(dtype=DataType.FLOAT)`, provided for clarity and convenience.
|
|
3035
|
+
See `Problem.Placeholder` for more details on placeholders.
|
|
3036
|
+
"""
|
|
3037
|
+
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:
|
|
3038
|
+
r"""
|
|
3039
|
+
Defines a :class:`Placeholder` representing a natural number in this problem's namespace.
|
|
3040
|
+
|
|
3041
|
+
A shorthand for `Problem.Placeholder(dtype=DataType.NATURAL)`, provided for clarity and convenience.
|
|
3042
|
+
See `Problem.Placeholder` for more details on placeholders.
|
|
3043
|
+
"""
|
|
3044
|
+
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:
|
|
3045
|
+
r"""
|
|
3046
|
+
Defines a :class:`Placeholder` representing a natural number in this problem's namespace.
|
|
3047
|
+
|
|
3048
|
+
This is just a shorthand for `Problem.Natural(ndim=0)` and effectively the same as any other natural
|
|
3049
|
+
placeholder for practical purposes. The use of `Length` is recommended just for clarity when
|
|
3050
|
+
defining a placeholder which will be used to define the length of multi-dimensional objects.
|
|
3051
|
+
|
|
3052
|
+
See `Problem.Placeholder` for more details on placeholders.
|
|
3053
|
+
"""
|
|
3054
|
+
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:
|
|
3055
|
+
r"""
|
|
3056
|
+
Defines a :class:`Placeholder` representing a natural number in this problem's namespace.
|
|
3057
|
+
|
|
3058
|
+
This is just a shorthand for `Problem.Natural(ndim=0)` and effectively the same as any other natural
|
|
3059
|
+
placeholder for practical purposes. The use of `Dim` is recommended just for clarity when
|
|
3060
|
+
defining a placeholder which will be used to define the length of multi-dimensional objects.
|
|
3061
|
+
|
|
3062
|
+
See `Problem.Placeholder` for more details on placeholders.
|
|
3063
|
+
"""
|
|
3064
|
+
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:
|
|
3065
|
+
r"""
|
|
3066
|
+
Defines a `Placeholder` representing a binary number in this problem's namespace.
|
|
3067
|
+
|
|
3068
|
+
A shorthand for `Problem.Placeholder(dtype=DataType.BINARY)`, provided for clarity and convenience.
|
|
3069
|
+
See `Problem.Placeholder` for more details on placeholders.
|
|
3070
|
+
"""
|
|
3071
|
+
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:
|
|
3072
|
+
r"""
|
|
3073
|
+
A shorthand for creating a partial dictionary placeholder with key type
|
|
3074
|
+
"""
|
|
3075
|
+
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:
|
|
3076
|
+
r"""
|
|
3077
|
+
A shorthand for creating a total dictionary placeholder with key type
|
|
3078
|
+
"""
|
|
3079
|
+
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:
|
|
3080
|
+
r"""
|
|
3081
|
+
A placeholder expressing a directed graph (without edge weights), represented by a 1-dimensional array of tuples.
|
|
3082
|
+
|
|
3083
|
+
A shorthand for `Problem.Placeholder(dtype=(vertex, vertex), ndim=1)`.
|
|
3084
|
+
By default `vertex` is `DataType.Natural` but can be specified.
|
|
3085
|
+
"""
|
|
3086
|
+
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] | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any], 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] | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any], latex: typing.Optional[builtins.str] = None, description: typing.Optional[builtins.str] = None) -> DecisionVar:
|
|
3087
|
+
r"""
|
|
3088
|
+
Defines a :class:`DecisionVar` and registers it to the problem namespace.
|
|
3089
|
+
|
|
3090
|
+
Decision variables can be scalars, multi-dimensional arrays (eg.
|
|
3091
|
+
representing arrays and matrices of variables), or total dictionaries.
|
|
3092
|
+
Variables must have a `DecisionVarKind` (such as `BINARY`, `INTEGER`,
|
|
3093
|
+
`CONTINUOUS`), as well as defined lower and upper bounds.
|
|
3094
|
+
|
|
3095
|
+
See :class:`DecisionVar` documentation for more general info on decision
|
|
3096
|
+
variables, their representation, and bounds.
|
|
3097
|
+
|
|
3098
|
+
We recommend using alternative convenience methods which predefine the
|
|
3099
|
+
decision variable's kind, such as `Problem.IntegerVar` for integers, or
|
|
3100
|
+
`Problem.BinaryVar` for binary variables.
|
|
3101
|
+
|
|
3102
|
+
Representation
|
|
3103
|
+
--------------
|
|
3104
|
+
Depending on the arguments described below, the representation of the decision variable will be determined as follows:
|
|
3105
|
+
|
|
3106
|
+
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).
|
|
3107
|
+
2. If `shape` is provided and `dict_keys` is not provided, DecisionVar will be considered as a multi-dimensional array with fixed shape.
|
|
3108
|
+
3. If `dict_keys` is provided without `shape`, DecisionVar will be considered as a dictionary-like structure with keys specified by `dict_keys`.
|
|
3109
|
+
4. Otherwise, an error is raised.
|
|
3110
|
+
|
|
3111
|
+
Args
|
|
3112
|
+
-----
|
|
3113
|
+
- `name` (`str`): A name for the binary variable.
|
|
3114
|
+
- `kind` (`DecisionVarKind`): A kind of the decision variable.
|
|
3115
|
+
- `shape` (`list | tuple`): A sequence with the size of each dimension of the variable. Defaults to an empty tuple (a scalar value).
|
|
3116
|
+
- Each item in `shape` must be a valid expression evaluating to a non-negative scalar.
|
|
3117
|
+
- `dict_keys` (`tuple[Expression, ...]`, optional): If provided, specifies that this variable represents a dictionary-like structure with keys `dict_keys`.
|
|
3118
|
+
- `lower_bound` and `upper_bound` (`jijmodeling.Expression`): A lower and upper bounds of the variable.
|
|
3119
|
+
- `kind` (`DecisionVarKind`): The kind of the decision variable.
|
|
3120
|
+
- `latex` (`str`, optional): An optional LaTeX representation to be used in Jupyter notebook.
|
|
3121
|
+
- It is set to be the same as `name` by default.
|
|
3122
|
+
- `description` (`str`, optional): An optional description, for user reference.
|
|
3123
|
+
|
|
3124
|
+
Examples
|
|
3125
|
+
---------
|
|
3126
|
+
Create a scalar binary variable whose name is "z".
|
|
3127
|
+
|
|
3128
|
+
```python
|
|
3129
|
+
>>> import jijmodeling as jm
|
|
3130
|
+
>>> problem = jm.Problem("my_problem")
|
|
3131
|
+
>>> z = problem.DecisionVar("z", kind=jm.DecisionVarKind.BINARY, lower_bound=0, upper_bound=1)
|
|
3132
|
+
|
|
3133
|
+
```
|
|
3134
|
+
|
|
3135
|
+
Create a 2-dimensional binary variable whose name is "x" and has a 2x2 shape.
|
|
3136
|
+
|
|
3137
|
+
```python
|
|
3138
|
+
>>> import jijmodeling as jm
|
|
3139
|
+
>>> problem = jm.Problem("my_problem")
|
|
3140
|
+
>>> x = problem.BinaryVar("x", shape=[2, 2])
|
|
3141
|
+
|
|
3142
|
+
```
|
|
3143
|
+
|
|
3144
|
+
Create a 1-dimensional binary variable with the index of `123`.
|
|
3145
|
+
|
|
3146
|
+
```python
|
|
3147
|
+
>>> import jijmodeling as jm
|
|
3148
|
+
>>> problem = jm.Problem("my_problem")
|
|
3149
|
+
>>> x = jm.BinaryVar("x", shape=[124])
|
|
3150
|
+
>>> x[123]
|
|
3151
|
+
BinaryVar(name='x', shape=[NumberLit(value=124)])[NumberLit(value=123)]
|
|
3152
|
+
|
|
3153
|
+
```
|
|
3154
|
+
"""
|
|
3155
|
+
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:
|
|
3156
|
+
r"""
|
|
3157
|
+
Defines a binary decision variable and registers it to the problem namespace. See `Problem.DecisionVar` for more details.
|
|
3158
|
+
|
|
3159
|
+
A shorthand for `Problem.DecisionVariable(dtype=DecisionVarKind.BINARY,
|
|
3160
|
+
lower_bound=0, upper_bound=1)`, provided for clarity and convenience.
|
|
3161
|
+
|
|
3162
|
+
Args
|
|
3163
|
+
-----
|
|
3164
|
+
- `name` (`str`): A name of the binary variable.
|
|
3165
|
+
- `shape` (`list | tuple`): A sequence with the size of each dimension of the binary variable. Defaults to an empty tuple (a scalar value).
|
|
3166
|
+
- Each item in `shape` must be a valid expression evaluating to a non-negative scalar.
|
|
3167
|
+
- `dict_keys` (`tuple[Expression, ...]`, optional): If provided, specifies that this variable represents a dictionary-like structure with keys `dict_keys`.
|
|
3168
|
+
- `latex` (`str`, optional): A LaTeX-name of the binary variable to be represented in Jupyter notebook.
|
|
3169
|
+
- It is set to `name` by default.
|
|
3170
|
+
- `description` (`str`, optional): A description of the binary variable.
|
|
3171
|
+
"""
|
|
3172
|
+
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] | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any], 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] | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any], latex: typing.Optional[builtins.str] = None, description: typing.Optional[builtins.str] = None) -> DecisionVar:
|
|
3173
|
+
r"""
|
|
3174
|
+
Defines an integer decision variable and registers it to the problem namespace. See `Problem.DecisionVar` for more details.
|
|
3175
|
+
|
|
3176
|
+
This is shorthand for `Problem.DecisionVariable(kind=DecisionVarKind.INTEGER)`.
|
|
3177
|
+
|
|
3178
|
+
Args
|
|
3179
|
+
-----
|
|
3180
|
+
- `name` (`str): A name of the integer variable.
|
|
3181
|
+
- `shape` (`list | tuple`): A sequence with the size of each dimension of the integer variable. Defaults to an empty tuple (a scalar value).
|
|
3182
|
+
- Each item in `shape` must be a valid expression evaluating to a non-negative scalar.
|
|
3183
|
+
- `dict_keys` (`tuple[Expression, ...]`, optional): If provided, specifies that this variable represents a dictionary-like structure with keys `dict_keys`.
|
|
3184
|
+
- `lower_bound`: The lower bound of the variable.
|
|
3185
|
+
- `upper_bound`: The upper bound of the variable.
|
|
3186
|
+
- `latex` (`str`, optional): A LaTeX-name of the integer variable to be represented in Jupyter notebook.
|
|
3187
|
+
- It is set to `name` by default.
|
|
3188
|
+
- `description` (`str`, optional): A description of the integer variable.
|
|
3189
|
+
|
|
3190
|
+
Raises
|
|
3191
|
+
-------
|
|
3192
|
+
`ModelingError`: Raises if a bound is a `Placeholder` or `Subscript` object whose `ndim`
|
|
3193
|
+
is neither `0` nor the same value as `ndim` of the integer variable.
|
|
3194
|
+
"""
|
|
3195
|
+
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] | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any], 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] | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any], latex: typing.Optional[builtins.str] = None, description: typing.Optional[builtins.str] = None) -> DecisionVar:
|
|
3196
|
+
r"""
|
|
3197
|
+
Defines a semi-integer decision variable and registers it to the problem namespace. See :class:`DecisionVar` for more details.
|
|
3198
|
+
|
|
3199
|
+
This is shorthand for `Problem.DecisionVariable(kind=DecisionVarKind.SEMI_INTEGER)`.
|
|
3200
|
+
"""
|
|
3201
|
+
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] | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any], 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] | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any], latex: typing.Optional[builtins.str] = None, description: typing.Optional[builtins.str] = None) -> DecisionVar:
|
|
3202
|
+
r"""
|
|
3203
|
+
Defines a continuous decision variable and registers it to the problem namespace. See `Problem.DecisionVar` for more details.
|
|
3204
|
+
|
|
3205
|
+
This is shorthand for `problem.DecisionVariable(dtype=DecisionVarKind.CONTINUOUS)`.
|
|
3206
|
+
|
|
3207
|
+
Args
|
|
3208
|
+
-----
|
|
3209
|
+
- `name` (`str`): A name of the continuous variable.
|
|
3210
|
+
- `shape` (`list | tuple`): A sequence with the size of each dimension of the continuous variable. Defaults to an empty tuple (a scalar value).
|
|
3211
|
+
- Each item in `shape` must be a valid expression evaluating to a non-negative scalar.
|
|
3212
|
+
- `dict_keys` (`tuple[Expression, ...]`, optional): If provided, specifies that this variable represents a dictionary-like structure with keys `dict_keys`.
|
|
3213
|
+
- `lower_bound`: The lower bound of the variable.
|
|
3214
|
+
- `upper_bound`: The upper bound of the variable.
|
|
3215
|
+
- `latex` (`str`, optional): A LaTeX-name of the continuous variable to be represented in Jupyter notebook.
|
|
3216
|
+
- It is set to `name` by default.
|
|
3217
|
+
- `description` (`str`, optional): A description of the continuous variable.
|
|
3218
|
+
|
|
3219
|
+
Raises
|
|
3220
|
+
-------
|
|
3221
|
+
`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.
|
|
3222
|
+
"""
|
|
3223
|
+
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] | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any], 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] | typing.Callable[[Expression], typing.Any] | typing.Callable[[Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression], typing.Any] | typing.Callable[[Expression, Expression, Expression, Expression, Expression], typing.Any], latex: typing.Optional[builtins.str] = None, description: typing.Optional[builtins.str] = None) -> DecisionVar: ...
|
|
3224
|
+
def namespace(self) -> Namespace:
|
|
3225
|
+
r"""
|
|
3226
|
+
Access to the internal `Namespace` associated with this problem.
|
|
3227
|
+
|
|
3228
|
+
Accessing this directly is not normally necessary for regular users.
|
|
3229
|
+
"""
|
|
3230
|
+
def CategoryLabel(self, name: builtins.str, *, latex: typing.Optional[builtins.str] = None, description: typing.Optional[builtins.str] = None) -> CategoryLabel:
|
|
3231
|
+
r"""
|
|
3232
|
+
Add a new opaque category label to the namespace.
|
|
3233
|
+
|
|
3234
|
+
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).
|
|
3235
|
+
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.
|
|
3236
|
+
|
|
3237
|
+
:class:`CategoryLabel` objects can be created via :meth:`Problem.CategoryLabel`.
|
|
3238
|
+
The concrete values should be given in `instance_data` dictionary together with placeholder values when creating a :class:`Compiler` object or in `Problem.eval`.
|
|
3239
|
+
In `instance_data`, category label should be given a list of either strings or integers.
|
|
3240
|
+
|
|
3241
|
+
Args
|
|
3242
|
+
----
|
|
3243
|
+
- `name` (`str`): The name of the category label.
|
|
3244
|
+
- `latex` (`str`, optional): An optional LaTeX representation to be used in Jupyter notebook.
|
|
3245
|
+
- When not provided, `name` is used by default.
|
|
3246
|
+
- `description` (`str`, optional): An optional description for user reference.
|
|
3247
|
+
"""
|
|
3248
|
+
def update(self, func: typing.Callable[[DecoratedProblem]]) -> DesugaredProblemBuilder:
|
|
3249
|
+
r"""
|
|
3250
|
+
A function decorator to modify an existing `Problem` using the decorated API.
|
|
3251
|
+
|
|
3252
|
+
This must be decorated to a function that takes `DecoratedProblem` as
|
|
3253
|
+
the only argument and returns None. You can call `update` multiple
|
|
3254
|
+
times.
|
|
3255
|
+
|
|
3256
|
+
The given function will automatically be evaluated exactly once by the
|
|
3257
|
+
decocrator, so you DO NOT need to call the original function again.
|
|
3258
|
+
|
|
3259
|
+
Example
|
|
3260
|
+
-------
|
|
3261
|
+
|
|
3262
|
+
```python
|
|
3263
|
+
>>> import jijmodeling as jm
|
|
3264
|
+
>>> problem = jm.Problem("Knapsack Problem", sense=jm.ProblemSense.MAXIMIZE)
|
|
3265
|
+
>>>
|
|
3266
|
+
>>> @problem.update
|
|
3267
|
+
>>> def my_updater(problem: jm.DecoratedProblem):
|
|
3268
|
+
>>> w = problem.Float(ndim=1, description="Weights of the items")
|
|
3269
|
+
>>> N = w.len_at(0)
|
|
3270
|
+
>>> v = problem.Float(ndim=1, description="Values of the items")
|
|
3271
|
+
>>> W = problem.Float(description="Total weight")
|
|
3272
|
+
>>> x = problem.BinaryVar(shape=(N,), description="Selected items")
|
|
3273
|
+
>>>
|
|
3274
|
+
>>> problem += problem.Constraint("weight", jm.sum(w * x) <= W)
|
|
3275
|
+
>>> problem += jm.sum(v * x)
|
|
3276
|
+
>>>
|
|
3277
|
+
>>> w_data = [10, 20, 30]
|
|
3278
|
+
>>> v_data = [60, 100, 120]
|
|
3279
|
+
>>> instance_data = {"w": w_data, "v": v_data, "W": 50}
|
|
3280
|
+
>>> instance = problem.eval(instance_data)
|
|
3281
|
+
```
|
|
3282
|
+
"""
|
|
3283
|
+
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], *, constraint_hints: typing.Optional[ConstraintDetectionConfig] = None) -> ommx.v1.Instance:
|
|
3284
|
+
r"""
|
|
3285
|
+
Compiles and evaluates the problem given the specified instance data, returning an OMMX instance.
|
|
3286
|
+
|
|
3287
|
+
A short-hand of `Compiler.from_problem(self, data).eval_problem(self)`.
|
|
3288
|
+
|
|
3289
|
+
Args
|
|
3290
|
+
----
|
|
3291
|
+
- `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`.
|
|
3292
|
+
"""
|
|
3293
|
+
def __repr__(self) -> builtins.str: ...
|
|
3294
|
+
def _repr_latex_(self) -> builtins.str: ...
|
|
3295
|
+
@typing.overload
|
|
3296
|
+
def __iadd__(self, other: Constraint) -> Problem:
|
|
3297
|
+
r"""
|
|
3298
|
+
Add constraint to the problem.
|
|
3299
|
+
"""
|
|
3300
|
+
@typing.overload
|
|
3301
|
+
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:
|
|
3302
|
+
r"""
|
|
3303
|
+
Add an expression as a term to the objective function of the problem.
|
|
3304
|
+
"""
|
|
3305
|
+
|
|
3306
|
+
@typing.final
|
|
3307
|
+
class Type:
|
|
3308
|
+
def __eq__(self, other: builtins.object) -> builtins.bool: ...
|
|
3309
|
+
|
|
3310
|
+
class TypeError(builtins.Exception):
|
|
3311
|
+
...
|
|
3312
|
+
|
|
3313
|
+
@typing.final
|
|
3314
|
+
class ConstraintHintName(enum.Enum):
|
|
3315
|
+
OneHot = ...
|
|
3316
|
+
|
|
3317
|
+
@typing.final
|
|
3318
|
+
class ConstraintSense(enum.Enum):
|
|
3319
|
+
r"""
|
|
3320
|
+
Classification of a constraint based on the comparison used.
|
|
3321
|
+
|
|
3322
|
+
Constraints can be
|
|
3323
|
+
- `lhs == rhs` Equalities: `ConstraintSense.EQUAL`
|
|
3324
|
+
- `lhs <= rhs` Inequalities: `ConstraintSense.LESS_THAN_EQUAL
|
|
3325
|
+
- `lhs >= rhs` Inequalities: `ConstraintSense.GREATER_THAN_EQUAL`
|
|
3326
|
+
"""
|
|
3327
|
+
EQUAL = ...
|
|
3328
|
+
LESS_THAN_EQUAL = ...
|
|
3329
|
+
GREATER_THAN_EQUAL = ...
|
|
3330
|
+
|
|
3331
|
+
@typing.final
|
|
3332
|
+
class DataType(enum.Enum):
|
|
3333
|
+
r"""
|
|
3334
|
+
The type of values in the instance data.
|
|
3335
|
+
|
|
3336
|
+
Used to specify the types of values :class:`Placeholder` will be able to
|
|
3337
|
+
hold. This type is used for type checking and error detection, particularly
|
|
3338
|
+
when compiling models into ommx instances -- not allowing data of the wrong
|
|
3339
|
+
kind to be used in a given placeholder. This is also used when trying to
|
|
3340
|
+
generate random instances from a model.
|
|
3341
|
+
|
|
3342
|
+
Placeholders may also have tuples of `DataType`s as their types, eg.
|
|
3343
|
+
`(DataType.NATURAL, DataType.NATURAL)` for representing edges in a graph.
|
|
3344
|
+
"""
|
|
3345
|
+
INTEGER = ...
|
|
3346
|
+
FLOAT = ...
|
|
3347
|
+
BINARY = ...
|
|
3348
|
+
NATURAL = ...
|
|
3349
|
+
|
|
3350
|
+
@typing.final
|
|
3351
|
+
class DecisionVarKind(enum.Enum):
|
|
3352
|
+
r"""
|
|
3353
|
+
The type of values a decision variable may have.
|
|
3354
|
+
|
|
3355
|
+
The larger domain, before being restricted by the upper and lower bounds
|
|
3356
|
+
|
|
3357
|
+
- Binary variables may only be either 1 or 0. (other bounds will lead to errors).
|
|
3358
|
+
- Integer variables can only be discrete integers withing the upper/lower bound range.
|
|
3359
|
+
- Continuous variables can be any real number within the bounded range.
|
|
3360
|
+
- Semi-Integer and Semi-Continuous are like the above, but always accept "0" as a value. Support for these in tooling is limited.
|
|
3361
|
+
"""
|
|
3362
|
+
BINARY = ...
|
|
3363
|
+
INTEGER = ...
|
|
3364
|
+
CONTINUOUS = ...
|
|
3365
|
+
SEMI_INTEGER = ...
|
|
3366
|
+
SEMI_CONTINUOUS = ...
|
|
3367
|
+
|
|
3368
|
+
@typing.final
|
|
3369
|
+
class ProblemSense(enum.Enum):
|
|
3370
|
+
r"""
|
|
3371
|
+
An optimization sense
|
|
3372
|
+
|
|
3373
|
+
Specifies whether the problem is a minization or maximization problem.
|
|
3374
|
+
Mostly used in the constructor for :class:`Problem`, or obtained from
|
|
3375
|
+
an existing problem through `Problem.sense()`
|
|
3376
|
+
"""
|
|
3377
|
+
MINIMIZE = ...
|
|
3378
|
+
MAXIMIZE = ...
|
|
3379
|
+
|
|
3380
|
+
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: ...
|
|
3381
|
+
|
|
3382
|
+
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:
|
|
3383
|
+
r"""
|
|
3384
|
+
Returns an expression representing the absolute value of the given expression.
|
|
3385
|
+
|
|
3386
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
3387
|
+
"""
|
|
3388
|
+
|
|
3389
|
+
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:
|
|
3390
|
+
r"""
|
|
3391
|
+
Returns an expression representing the arccosine of the given expression.
|
|
3392
|
+
|
|
3393
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
3394
|
+
"""
|
|
3395
|
+
|
|
3396
|
+
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:
|
|
3397
|
+
r"""
|
|
3398
|
+
Returns an expression representing the hyperbolic arccosine of the given expression.
|
|
3399
|
+
|
|
3400
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
3401
|
+
"""
|
|
3402
|
+
|
|
3403
|
+
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:
|
|
3404
|
+
r"""
|
|
3405
|
+
Returns an expression representing the arcsine of the given expression.
|
|
3406
|
+
|
|
3407
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
3408
|
+
"""
|
|
3409
|
+
|
|
3410
|
+
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:
|
|
3411
|
+
r"""
|
|
3412
|
+
Returns an expression representing the hyperbolic arcsine of the given expression.
|
|
3413
|
+
|
|
3414
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
3415
|
+
"""
|
|
3416
|
+
|
|
3417
|
+
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:
|
|
3418
|
+
r"""
|
|
3419
|
+
Returns an expression representing the arctangent of the given expression.
|
|
3420
|
+
|
|
3421
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
3422
|
+
"""
|
|
3423
|
+
|
|
3424
|
+
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:
|
|
3425
|
+
r"""
|
|
3426
|
+
Returns an expression representing the hyperbolic arctangent of the given expression.
|
|
3427
|
+
|
|
3428
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
3429
|
+
"""
|
|
3430
|
+
|
|
3431
|
+
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: ...
|
|
3432
|
+
|
|
3433
|
+
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: ...
|
|
3434
|
+
|
|
3435
|
+
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: ...
|
|
3436
|
+
|
|
3437
|
+
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:
|
|
3438
|
+
r"""
|
|
3439
|
+
Returns an expression which rounds down to the nearest whole number.
|
|
3440
|
+
|
|
3441
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
3442
|
+
"""
|
|
3443
|
+
|
|
3444
|
+
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:
|
|
3445
|
+
r"""
|
|
3446
|
+
Returns an expression representing the cosine of the given expression.
|
|
3447
|
+
|
|
3448
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
3449
|
+
"""
|
|
3450
|
+
|
|
3451
|
+
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:
|
|
3452
|
+
r"""
|
|
3453
|
+
Returns an expression representing the hyperbolic cosine of the given expression.
|
|
3454
|
+
|
|
3455
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
3456
|
+
"""
|
|
3457
|
+
|
|
3458
|
+
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: ...
|
|
3459
|
+
|
|
3460
|
+
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:
|
|
3461
|
+
r"""
|
|
3462
|
+
Returns an expression representing the application of the exponential function on the given expression.
|
|
3463
|
+
|
|
3464
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
3465
|
+
"""
|
|
3466
|
+
|
|
3467
|
+
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:
|
|
3468
|
+
r"""
|
|
3469
|
+
Creates an expression that filters the values of another sequence expression.
|
|
3470
|
+
|
|
3471
|
+
`predicate` will be called on each element in `operand`. The resulting
|
|
3472
|
+
expression represents only the values for which `predicate` is true.
|
|
3473
|
+
|
|
3474
|
+
This parallels python's built-in `filter()` function, but made to work with
|
|
3475
|
+
JijModeling sequence expressions.
|
|
3476
|
+
|
|
3477
|
+
This is often useful when trying to create summations which only include a
|
|
3478
|
+
subset of potential indices. The resulting expression is usually used as the
|
|
3479
|
+
basis for :func:`jijmodeling.map`, :func:`jijmodeling.sum`, etc., or a
|
|
3480
|
+
method equivalent.
|
|
3481
|
+
|
|
3482
|
+
See also the method equivalents: :meth:`Placeholder.filter`,
|
|
3483
|
+
:meth:`DecisionVar.filter` and :meth:`Expression.filter`.
|
|
3484
|
+
|
|
3485
|
+
Examples
|
|
3486
|
+
------
|
|
3487
|
+
|
|
3488
|
+
Using only variables with even indices as part of a constraint.
|
|
3489
|
+
|
|
3490
|
+
```python
|
|
3491
|
+
>>> import jijmodeling as jm
|
|
3492
|
+
>>> problem = jm.Problem("MyProblem")
|
|
3493
|
+
>>> N = jm.Natural("N")
|
|
3494
|
+
>>> x = problem.BinaryVar("x", shape=(N, N))
|
|
3495
|
+
>>> even_xs = jm.filter(lambda i: i % 2 == 0, N).map(lambda i: x[i])
|
|
3496
|
+
>>> problem += problem.Constraint("constr", even_xs.sum() < 10)
|
|
3497
|
+
```
|
|
3498
|
+
|
|
3499
|
+
Using only non-diagonal indices of an NxN matrix as part of a constraint, using the method version of `filter`.
|
|
3500
|
+
|
|
3501
|
+
```python
|
|
3502
|
+
>>> import jijmodeling as jm
|
|
3503
|
+
>>> problem = jm.Problem("MyProblem")
|
|
3504
|
+
>>> N = jm.Natural("N")
|
|
3505
|
+
>>> x = problem.BinaryVar("x", shape=(N, N))
|
|
3506
|
+
>>> W = problem.Float("W", shape=(N, N))
|
|
3507
|
+
>>> non_diagonals = jm.product(N, N).filter(lambda i, j: i != j)
|
|
3508
|
+
>>> problem += problem.Constraint("constr", lambda i, j: W[i, j] * x[i, j] <= 100, domain=non_diagonals)
|
|
3509
|
+
```
|
|
3510
|
+
"""
|
|
3511
|
+
|
|
3512
|
+
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:
|
|
3513
|
+
r"""
|
|
3514
|
+
Creates an expression which works like :func:`jijmodeling.map`, but flattens nested structure.
|
|
3515
|
+
|
|
3516
|
+
`map` is useful when `func` returns scalar values, but in some situations
|
|
3517
|
+
one wants to write a `func` that returns other mappings/sequences instead.
|
|
3518
|
+
That is where `flat_map` should be used, "flattening" all
|
|
3519
|
+
sequences/iterators into a single linear sequence (which can then be reduced
|
|
3520
|
+
with :func:`jijmodeling.sum`, etc.)
|
|
3521
|
+
|
|
3522
|
+
You can also compare `flat_map` to a nested for-loop, or a generator
|
|
3523
|
+
expression that uses two `for` clauses. Indeed when using the decorated API
|
|
3524
|
+
(see tutorials or :meth:`Problem.update`), you can use a generator
|
|
3525
|
+
expression-like syntax instead.
|
|
3526
|
+
|
|
3527
|
+
See also the method equivalents: :meth:`Placeholder.flat_map`,
|
|
3528
|
+
:meth:`DecisionVar.flat_map` and :meth:`Expression.flat_map`. Using the
|
|
3529
|
+
methods often leads to code that is easier to read. Note that the method is
|
|
3530
|
+
not available for number literals.
|
|
3531
|
+
|
|
3532
|
+
Examples
|
|
3533
|
+
------
|
|
3534
|
+
|
|
3535
|
+
Using only non-diagonal indices of an NxN matrix.
|
|
3536
|
+
```python
|
|
3537
|
+
>>> import jijmodeling as jm
|
|
3538
|
+
>>> problem = jm.Problem("MyProblem")
|
|
3539
|
+
>>> N = jm.Natural("N")
|
|
3540
|
+
>>> x = problem.BinaryVar("x", shape=(N, N))
|
|
3541
|
+
>>> W = problem.Float("W", shape=(N, N))
|
|
3542
|
+
>>> objective = jm.flat_map(
|
|
3543
|
+
... lambda i: N.filter(lambda j: i != j).map(lambda j: W[i, j] * x[i, j]), N
|
|
3544
|
+
... ).sum()
|
|
3545
|
+
>>> problem += objective
|
|
3546
|
+
```
|
|
3547
|
+
"""
|
|
3548
|
+
|
|
3549
|
+
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: ...
|
|
3550
|
+
|
|
3551
|
+
def indices(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:
|
|
3552
|
+
r"""
|
|
3553
|
+
Get the set of indices of given array or jagged array.
|
|
3554
|
+
|
|
3555
|
+
Will throw type error when called on non-array type.
|
|
3556
|
+
"""
|
|
3557
|
+
|
|
3558
|
+
def is_same(src: typing.Any, dst: typing.Any) -> builtins.bool:
|
|
3559
|
+
r"""
|
|
3560
|
+
Return `true` if `src` and `dst` are the same object defined by Jijmodeling.
|
|
3561
|
+
|
|
3562
|
+
|
|
3563
|
+
Args
|
|
3564
|
+
-----
|
|
3565
|
+
- `src`: An object defined by Jijmodeling module, or an iterable of Jijmodeling objects.
|
|
3566
|
+
- `dst`: An object defined by Jijmodeling module, or an iterable of Jijmodeling objects.
|
|
3567
|
+
|
|
3568
|
+
Returns
|
|
3569
|
+
--------
|
|
3570
|
+
`bool`: `true` if `src` and `dst` is the same object. Otherwise `false`.
|
|
3571
|
+
|
|
3572
|
+
Examples
|
|
3573
|
+
---------
|
|
3574
|
+
Check if the two placeholders are the same.
|
|
3575
|
+
|
|
3576
|
+
```python
|
|
3577
|
+
>>> import jijmodeling as jm
|
|
3578
|
+
>>> problem = jm.Problem("problem")
|
|
3579
|
+
>>> a = problem.Placeholder("name")
|
|
3580
|
+
>>> b = problem.Placeholder("name")
|
|
3581
|
+
>>> assert jm.is_same(a, b)
|
|
3582
|
+
>>> c = problem.Placeholder("name", ndim=2)
|
|
3583
|
+
>>> assert not jm.is_same(a, c) # the value of `ndim` is different
|
|
3584
|
+
```
|
|
3585
|
+
|
|
3586
|
+
Raises
|
|
3587
|
+
-------
|
|
3588
|
+
`TypeError`: Raises if
|
|
3589
|
+
- `src` and `dst` are of different types which are not iterable
|
|
3590
|
+
- called on a type not defined by Jijmodeling (e.g. `str`)
|
|
3591
|
+
|
|
3592
|
+
Note
|
|
3593
|
+
-----
|
|
3594
|
+
This function does not check the following attributes:
|
|
3595
|
+
- `description`
|
|
3596
|
+
- `latex`
|
|
3597
|
+
|
|
3598
|
+
For example,
|
|
3599
|
+
|
|
3600
|
+
```python
|
|
3601
|
+
>>> import jijmodeling as jm
|
|
3602
|
+
>>> problem = jm.Problem("problem")
|
|
3603
|
+
>>> src = problem.Placeholder("placeholder", latex="src")
|
|
3604
|
+
>>> dst = problem.Placeholder("placeholder", latex="dst")
|
|
3605
|
+
>>> assert jm.is_same(src, dst)
|
|
3606
|
+
```
|
|
3607
|
+
|
|
3608
|
+
this code works without any exception.
|
|
3609
|
+
"""
|
|
3610
|
+
|
|
3611
|
+
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:
|
|
3612
|
+
r"""
|
|
3613
|
+
Returns an expression representing the `(key,value)` pairs of a
|
|
3614
|
+
dictionary-like :class:`Expression`.
|
|
3615
|
+
|
|
3616
|
+
In other words, this is the JijModeling equivalent of the `items()` method on Python dictionaries,
|
|
3617
|
+
used when creating JijModeling expressions.
|
|
3618
|
+
|
|
3619
|
+
While it's possible to call this on any :class:`Expression`, this is
|
|
3620
|
+
intended for dictionary-like :class:`Placeholder`s and
|
|
3621
|
+
:class:`DecisionVar`s. Using this with an invalid object will lead to an
|
|
3622
|
+
error when the resulting expression is added to a :class:`Problem` and is
|
|
3623
|
+
type-checked.
|
|
3624
|
+
|
|
3625
|
+
See also :meth:`Placeholder.items`, :meth:`DecisionVar.items`, and
|
|
3626
|
+
:meth:`Expression.items` to achieve this with methods, which are recommended
|
|
3627
|
+
for clarity.
|
|
3628
|
+
|
|
3629
|
+
If you want to refer to the keys used in the dictionary, use
|
|
3630
|
+
:func:`jijmodeling.keys` or its method equivalents. If you want the
|
|
3631
|
+
dictionary's values, use :func:`jijmodeling.values` or its method
|
|
3632
|
+
equivalents instead.
|
|
3633
|
+
"""
|
|
3634
|
+
|
|
3635
|
+
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:
|
|
3636
|
+
r"""
|
|
3637
|
+
Returns an expression representing the keys of a dictionary-like
|
|
3638
|
+
:class:`Expression`.
|
|
3639
|
+
|
|
3640
|
+
In other words, this is the JijModeling equivalent of the `keys()` method on
|
|
3641
|
+
Python dictionaries, used when creating JijModeling expressions.
|
|
3642
|
+
|
|
3643
|
+
While it's possible to call this on any :class:`Expression`, this is
|
|
3644
|
+
intended for dictionary-like :class:`Placeholder`s and
|
|
3645
|
+
:class:`DecisionVar`s. Using this with an invalid object will lead to an
|
|
3646
|
+
error when the resulting expression is added to a :class:`Problem` and is
|
|
3647
|
+
type-checked.
|
|
3648
|
+
|
|
3649
|
+
See also :meth:`Placeholder.keys`, :meth:`DecisionVar.keys`, and
|
|
3650
|
+
:meth:`Expression.keys` to achieve this with methods, which is recommended for
|
|
3651
|
+
clarity.
|
|
3652
|
+
|
|
3653
|
+
If you want to refer to the dictionary's values, use
|
|
3654
|
+
:func:`jijmodeling.values` or its method equivalents. If you want key-value
|
|
3655
|
+
pairs, use :func:`jijmodeling.items` or its method equivalents instead.
|
|
3656
|
+
"""
|
|
3657
|
+
|
|
3658
|
+
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:
|
|
3659
|
+
r"""
|
|
3660
|
+
Returns an expression representing the natural logarithm of the given expression.
|
|
3661
|
+
|
|
3662
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
3663
|
+
"""
|
|
3664
|
+
|
|
3665
|
+
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:
|
|
3666
|
+
r"""
|
|
3667
|
+
Returns an expression representing the decimal logarithm of the given expression.
|
|
3668
|
+
|
|
3669
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
3670
|
+
"""
|
|
3671
|
+
|
|
3672
|
+
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:
|
|
3673
|
+
r"""
|
|
3674
|
+
Returns an expression representing the binary logarithm of the given expression.
|
|
3675
|
+
|
|
3676
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
3677
|
+
"""
|
|
3678
|
+
|
|
3679
|
+
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:
|
|
3680
|
+
r"""
|
|
3681
|
+
Creates an expression that maps `func` to a sequence of values.
|
|
3682
|
+
|
|
3683
|
+
This parallels python's built-in `map()` function, but made to work with
|
|
3684
|
+
and create JijModeling expressions.
|
|
3685
|
+
|
|
3686
|
+
If `arg` is a number literal or scalar placeholder, each number from 0 to
|
|
3687
|
+
`arg` will be passed to `func`. If `arg` is a sequence expression (eg. a
|
|
3688
|
+
1-dimensional placeholder, or the result of functions like
|
|
3689
|
+
:func:`jijmodeling.product` or :func:`jijmodeling.items`), each element in
|
|
3690
|
+
the sequence is passed to `func`.
|
|
3691
|
+
|
|
3692
|
+
This is mostly used alongside lambdas as a way to access individual values
|
|
3693
|
+
within array-like or dictionary-like :class:`Placeholder`s and
|
|
3694
|
+
:class:`DecisionVar`s. The resulting expression is then usually passed to a
|
|
3695
|
+
reducer, like :func:`jijmodeling.sum` (or :meth:`Expression.sum` is called
|
|
3696
|
+
on it), to form part of a constraint or the objective function.
|
|
3697
|
+
|
|
3698
|
+
See also the method equivalents: :meth:`Placeholder.map`,
|
|
3699
|
+
:meth:`DecisionVar.map` and :meth:`Expression.map`. Using the methods often
|
|
3700
|
+
leads to code that is easier to read. Note that the method is not available
|
|
3701
|
+
for number literals.
|
|
3702
|
+
|
|
3703
|
+
Examples
|
|
3704
|
+
------
|
|
3705
|
+
|
|
3706
|
+
Indexing by values from 0 to N. In this example we define N as the length of
|
|
3707
|
+
another placeholder, but a scalar Natural placeholder would work as well.
|
|
3708
|
+
|
|
3709
|
+
```python
|
|
3710
|
+
>>> import jijmodeling as jm
|
|
3711
|
+
>>> problem = jm.Problem("MyProblem")
|
|
3712
|
+
>>> W = problem.Float("W", ndim=1)
|
|
3713
|
+
>>> N = W.len_at(0)
|
|
3714
|
+
>>> x = problem.BinaryVar("x", shape=N)
|
|
3715
|
+
>>> problem += jm.sum(jm.map(lambda i: W[i] * x[i], N))
|
|
3716
|
+
>>> # or, same as above
|
|
3717
|
+
>>> problem += jm.map(lambda i: W[i] * x[i], N).sum()
|
|
3718
|
+
>>> # same as above but using method on N instead of this function:
|
|
3719
|
+
>>> problem += N.map(lambda i: W[i] * x[i]).sum()
|
|
3720
|
+
```
|
|
3721
|
+
|
|
3722
|
+
Indexing by specific values from instance data. In this example only the
|
|
3723
|
+
indices present in `C` in the instance data will be used in this constraint.
|
|
3724
|
+
|
|
3725
|
+
```python
|
|
3726
|
+
>>> import jijmodeling as jm
|
|
3727
|
+
>>> problem = jm.Problem("MyProblem")
|
|
3728
|
+
>>> N = problem.Natural("N")
|
|
3729
|
+
>>> x = problem.IntegerVar("x", shape=N, lower_bound=0, upper_bound=10)
|
|
3730
|
+
>>> C = problem.Natural("C", ndim=1)
|
|
3731
|
+
>>> problem += problem.Constraint("constr", jm.map(lambda i: x[i], C).sum() <= 100)
|
|
3732
|
+
```
|
|
3733
|
+
|
|
3734
|
+
Accessing category label keys. Dictionary-like placeholders &
|
|
3735
|
+
decision-variables require keys from the appropriate :class:`CategoryLabel`,
|
|
3736
|
+
which are accessed by mapping.
|
|
3737
|
+
|
|
3738
|
+
```python
|
|
3739
|
+
>>> import jijmodeling as jm
|
|
3740
|
+
>>> problem = jm.Problem("MyProblem")
|
|
3741
|
+
>>> I = problem.CategoryLabel("I")
|
|
3742
|
+
>>> W = problem.Float("W", dict_keys=I)
|
|
3743
|
+
>>> x = problem.BinaryVar("x", dict_keys=I)
|
|
3744
|
+
>>> problem += jm.sum(jm.map(lambda i: W[i] * x[i], I))
|
|
3745
|
+
```
|
|
3746
|
+
|
|
3747
|
+
Or, using `items()` on a dictionary placeholder:
|
|
3748
|
+
```python
|
|
3749
|
+
>>> problem = jm.Problem("MyProblem")
|
|
3750
|
+
>>> I = problem.CategoryLabel("I")
|
|
3751
|
+
>>> W = problem.Float("W", dict_keys=I)
|
|
3752
|
+
>>> x = problem.BinaryVar("x", dict_keys=I)
|
|
3753
|
+
>>> problem += jm.map(lambda i, w: w * x[i], W.items())
|
|
3754
|
+
```
|
|
3755
|
+
"""
|
|
3756
|
+
|
|
3757
|
+
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:
|
|
3758
|
+
r"""
|
|
3759
|
+
If option is `Some(value)`, applies `mapper(value)`, otherwise returns default.
|
|
3760
|
+
"""
|
|
3761
|
+
|
|
3762
|
+
@typing.overload
|
|
3763
|
+
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:
|
|
3764
|
+
r"""
|
|
3765
|
+
Creates an expression that refers to the largest value among `lhs` and `rhs`.
|
|
3766
|
+
|
|
3767
|
+
See also the method equivalents :meth:`Placeholder.max`, :meth:`DecisionVar.max`, and :meth:`Expresion.max`.
|
|
3768
|
+
"""
|
|
3769
|
+
|
|
3770
|
+
@typing.overload
|
|
3771
|
+
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:
|
|
3772
|
+
r"""
|
|
3773
|
+
Creates an expression which refers to the largest of several values.
|
|
3774
|
+
|
|
3775
|
+
This overload variant accepts a single sequence expression (eg. a one-dimensional placeholder
|
|
3776
|
+
or a :func:`map`ping) as an argument, and the resulting expression is a scalar representing
|
|
3777
|
+
the largest among all values in the sequence.
|
|
3778
|
+
|
|
3779
|
+
See also the method equivalents :meth:`Placeholder.max`, :meth:`DecisionVar.max`, and :meth:`Expresion.max`.
|
|
3780
|
+
"""
|
|
3781
|
+
|
|
3782
|
+
@typing.overload
|
|
3783
|
+
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:
|
|
3784
|
+
r"""
|
|
3785
|
+
Creates an expression that refers to the smallest value among `lhs` and `rhs`.
|
|
3786
|
+
|
|
3787
|
+
See also the method equivalents :meth:`Placeholder.min`, :meth:`DecisionVar.min`, and :meth:`Expresion.min`.
|
|
3788
|
+
"""
|
|
3789
|
+
|
|
3790
|
+
@typing.overload
|
|
3791
|
+
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:
|
|
3792
|
+
r"""
|
|
3793
|
+
Creates an expression which refers to the smallest of several values.
|
|
3794
|
+
|
|
3795
|
+
This overload variant accepts a single sequence expression (eg. a one-dimensional placeholder
|
|
3796
|
+
or a :func:`map`ping) as an argument, and the resulting expression is a scalar representing
|
|
3797
|
+
the smallest among all values in the sequence.
|
|
3798
|
+
|
|
3799
|
+
See also the method equivalents :meth:`Placeholder.min`, :meth:`DecisionVar.min`, and :meth:`Expresion.min`.
|
|
3800
|
+
"""
|
|
3801
|
+
|
|
3802
|
+
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: ...
|
|
3803
|
+
|
|
3804
|
+
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:
|
|
3805
|
+
r"""
|
|
3806
|
+
Returns the value inside option if Some, otherwise returns default.
|
|
3807
|
+
"""
|
|
3808
|
+
|
|
3809
|
+
@typing.overload
|
|
3810
|
+
def prod(x: typing.Generator["Expression", None, None]) -> Expression:
|
|
3811
|
+
r"""
|
|
3812
|
+
Comprehension syntax for :func:`jijmodeling.prod`, for use with decorated API.
|
|
3813
|
+
|
|
3814
|
+
When using the decorated API, you are allowed to use a comprehension/generator
|
|
3815
|
+
expression directly inside `prod`, using `for` clauses to mark the index.
|
|
3816
|
+
|
|
3817
|
+
NOTE: do not confuse with :func:`jijmodeling.product`. This is a sequence
|
|
3818
|
+
multiplication (like capital-PI notation). `product` is the cartesian product.
|
|
3819
|
+
|
|
3820
|
+
NOTE: this variant only works with decorated API!
|
|
3821
|
+
|
|
3822
|
+
See :meth:`Problem.update` or the cheatsheet for more information on the decorated API.
|
|
3823
|
+
|
|
3824
|
+
Examples
|
|
3825
|
+
------
|
|
3826
|
+
|
|
3827
|
+
```python
|
|
3828
|
+
>>> problem = jm.Problem("MyProblem", sense=jm.ProblemSense.MINIMIZE)
|
|
3829
|
+
>>> @problem.update
|
|
3830
|
+
>>> def _(problem: jm.DecoratedProblem):
|
|
3831
|
+
... N = problem.Placeholder(dtype=jm.DataType.NATURAL)
|
|
3832
|
+
... x = problem.BinaryVar(shape=N)
|
|
3833
|
+
... C = problem.Placeholder(ndim=1, dtype=np.uint64)
|
|
3834
|
+
... problem += jm.prod(x[i] for i in C)
|
|
3835
|
+
>>>
|
|
3836
|
+
```
|
|
3837
|
+
"""
|
|
3838
|
+
|
|
3839
|
+
@typing.overload
|
|
3840
|
+
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:
|
|
3841
|
+
r"""
|
|
3842
|
+
Creates an expression representing the multiplication of a sequence expression.
|
|
3843
|
+
|
|
3844
|
+
`prod`, though less common than `sum` is a fundamental part of building models,
|
|
3845
|
+
used as a reducer to collapse multiple values into a single value. Everything
|
|
3846
|
+
that applies to `sum` applies to `prod`, they simply represent different mathematical
|
|
3847
|
+
operations.
|
|
3848
|
+
|
|
3849
|
+
NOTE: do not confuse with :func:`jijmodeling.product`. This is a sequence
|
|
3850
|
+
multiplication (like capital-PI notation). `product` is the cartesian product.
|
|
3851
|
+
|
|
3852
|
+
While it's possible to call this on any :class:`Expression`, using this with an invalid object will lead to an
|
|
3853
|
+
error when the resulting expression is added to a :class:`Problem` and is
|
|
3854
|
+
type-checked.
|
|
3855
|
+
|
|
3856
|
+
In this overload variant, `operand` must be a linear sequence expression.
|
|
3857
|
+
That is, it could be, for example:
|
|
3858
|
+
- A one-dimensional array :class:`Placeholder` or :class:`DecisionVariable`
|
|
3859
|
+
- The result of another sequence function/method, like :func:`jijmodeling.map`, :func:`jijmodeling.filter`
|
|
3860
|
+
- An expression that is a supported operation on the above two categories.
|
|
3861
|
+
|
|
3862
|
+
Due to many binary operations on two one-dimensional arrays being supported,
|
|
3863
|
+
use of :func`jijmodeling.map` on an index is often not required for simple
|
|
3864
|
+
products (note that for illustrative purposes the documentation examples
|
|
3865
|
+
on the relevant functions may use `map` when not strictly required). `map`
|
|
3866
|
+
is often required when doing more complex indexing.
|
|
3867
|
+
|
|
3868
|
+
The optional `axis` parameter allows you to specify one axis of a
|
|
3869
|
+
multi-dimensional expression across which to perform the operation.
|
|
3870
|
+
|
|
3871
|
+
See also the method equivalent :meth:`Expression.prod`, which is often more
|
|
3872
|
+
convenient and clearer.
|
|
3873
|
+
|
|
3874
|
+
Examples
|
|
3875
|
+
------
|
|
3876
|
+
Performing a simple product.
|
|
3877
|
+
|
|
3878
|
+
```python
|
|
3879
|
+
>>> import jijmodeling as jm
|
|
3880
|
+
>>> problem = jm.Problem("MyProblem")
|
|
3881
|
+
>>> N = problem.Natural("N")
|
|
3882
|
+
>>> x = problem.IntegerVar("x", shape=N)
|
|
3883
|
+
>>> problem += jm.prod(x)
|
|
3884
|
+
```
|
|
3885
|
+
|
|
3886
|
+
Same as above, but using map for indexing. This allows flexibility
|
|
3887
|
+
on how the index is used, including mapping multiple indices, or filtering before mapping.
|
|
3888
|
+
The other overload variant allows you to do this without explicitly calling `map`.
|
|
3889
|
+
|
|
3890
|
+
```python
|
|
3891
|
+
>>> import jijmodeling as jm
|
|
3892
|
+
>>> problem = jm.Problem("MyProblem")
|
|
3893
|
+
>>> N = problem.Natural("N")
|
|
3894
|
+
>>> x = problem.IntegerVar("x", shape=N)
|
|
3895
|
+
>>> problem += jm.prod(N.map(lambda i: x[i])
|
|
3896
|
+
```
|
|
3897
|
+
"""
|
|
3898
|
+
|
|
3899
|
+
@typing.overload
|
|
3900
|
+
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:
|
|
3901
|
+
r"""
|
|
3902
|
+
Creates a multiplication expression based on an index and an operand function.
|
|
3903
|
+
|
|
3904
|
+
This overload variant can be thought of as a convenient shorthand for
|
|
3905
|
+
`jm.prod(jm.map(operand, index))`. Each element in `index` will be passed
|
|
3906
|
+
to the `operand` function for indexing, and multiplication will be performed on
|
|
3907
|
+
the results. See :func:`jijmodeling.map` and the other overload of
|
|
3908
|
+
:func:`jijmodeling.prod` for more information.
|
|
3909
|
+
|
|
3910
|
+
Examples
|
|
3911
|
+
------
|
|
3912
|
+
|
|
3913
|
+
```python
|
|
3914
|
+
>>> import jijmodeling as jm
|
|
3915
|
+
>>> problem = jm.Problem("MyProblem")
|
|
3916
|
+
>>> N = problem.Natural("N")
|
|
3917
|
+
>>> x = problem.IntegerVar("x", shape=N)
|
|
3918
|
+
>>> problem += jm.prod(N, lambda i: x[i])
|
|
3919
|
+
```
|
|
3920
|
+
"""
|
|
3921
|
+
|
|
3922
|
+
def product(*sets: typing.Any) -> Expression:
|
|
3923
|
+
r"""
|
|
3924
|
+
Returns an expression representing the cartesian product of two :class:`Expression`s.
|
|
3925
|
+
|
|
3926
|
+
For example `product(10,10)` represents all pairs `(0,0),(0,1),...,(1,0),(1,1),...,(10, 10)`.
|
|
3927
|
+
This can then be :func:`map`ped to access these pairs of values, or :func:`filter`ed to remove unwanted values.
|
|
3928
|
+
|
|
3929
|
+
Do not confuse with :func:`jijmodeling.prod`, which represents the
|
|
3930
|
+
multiplication of a sequence of values.
|
|
3931
|
+
"""
|
|
3932
|
+
|
|
3933
|
+
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: ...
|
|
3934
|
+
|
|
3935
|
+
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:
|
|
3936
|
+
r"""
|
|
3937
|
+
Creates a sequence over the rows of a multi-dimensional array expression.
|
|
3938
|
+
|
|
3939
|
+
That is, each element will be a whole row (itself containing multiple
|
|
3940
|
+
values), which can then be operated on like other sequences (eg. using
|
|
3941
|
+
:func:`jijmodelng.sum` or :func:`jijmodeling.map`).
|
|
3942
|
+
|
|
3943
|
+
If the array is 3-dimensional or higher, rows will iterate over the first
|
|
3944
|
+
dimension/axis. For example, in a 3D matrix, the first element would be a
|
|
3945
|
+
2D matrix representing all values `x[0, _, _]`
|
|
3946
|
+
|
|
3947
|
+
See also the method equivalents: :meth:`Placeholder.rows`,
|
|
3948
|
+
:meth:`DecisionVar.rows` and :meth:`Expression.rows`. Using the
|
|
3949
|
+
methods often leads to code that is easier to read.
|
|
3950
|
+
|
|
3951
|
+
Examples
|
|
3952
|
+
------
|
|
3953
|
+
|
|
3954
|
+
Create an objective function that multiplies each variable in a row, and
|
|
3955
|
+
then sums each row. In this case we have a 2x3 matrix, so the final expression is
|
|
3956
|
+
`x[0, 0] * x[0, 1] * x[0, 2] + x[1, 0] * x[1, 1] * x[1, 2]`. Using
|
|
3957
|
+
placeholders instead of literals in `shape` would allow this to be written
|
|
3958
|
+
for matrices of arbitrary size.
|
|
3959
|
+
```python
|
|
3960
|
+
>>> import jijmodeling as jm
|
|
3961
|
+
>>> problem = jm.Problem("MyProblem")
|
|
3962
|
+
>>> d = problem.BinaryVar("d", shape=(2, 3))
|
|
3963
|
+
>>> problem += jm.rows(d).map(lambda xs: xs.prod()).sum()
|
|
3964
|
+
```
|
|
3965
|
+
|
|
3966
|
+
If the number of elements in the row can be guaranteed, the elements can be
|
|
3967
|
+
destructured as separate arguments in a lambda expression:
|
|
3968
|
+
|
|
3969
|
+
```python
|
|
3970
|
+
>>> import jijmodeling as jm
|
|
3971
|
+
>>> problem = jm.Problem("MyProblem")
|
|
3972
|
+
>>> N = problem.Natural("N")
|
|
3973
|
+
>>> V = problem.Natural("V")
|
|
3974
|
+
>>> E = problem.Natural("E", shape=(N, 2))
|
|
3975
|
+
>>> x = problem.BinaryVar("x", shape=V)
|
|
3976
|
+
>>> problem += jm.map(lambda i, j: x[i] * x[j], jm.rows(E)).sum()
|
|
3977
|
+
```
|
|
3978
|
+
"""
|
|
3979
|
+
|
|
3980
|
+
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: ...
|
|
3981
|
+
|
|
3982
|
+
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:
|
|
3983
|
+
r"""
|
|
3984
|
+
Returns an expression representing the sine of the given expression.
|
|
3985
|
+
|
|
3986
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
3987
|
+
"""
|
|
3988
|
+
|
|
3989
|
+
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:
|
|
3990
|
+
r"""
|
|
3991
|
+
Returns an expression representing the hyperbolic sine of the given expression.
|
|
3992
|
+
|
|
3993
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
3994
|
+
"""
|
|
3995
|
+
|
|
3996
|
+
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:
|
|
3997
|
+
r"""
|
|
3998
|
+
Returns an expression representing the square root of the given expression.
|
|
3999
|
+
|
|
4000
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
4001
|
+
"""
|
|
4002
|
+
|
|
4003
|
+
@typing.overload
|
|
4004
|
+
def sum(x: typing.Generator["Expression", None, None]) -> Expression:
|
|
4005
|
+
r"""
|
|
4006
|
+
Comprehension syntax for :func:`jijmodeling.sum` for use with decorated API.
|
|
4007
|
+
|
|
4008
|
+
When using the decorated API, you are allowed to use a comprehension/generator
|
|
4009
|
+
expression directly inside `sum`, using `for` clauses to mark the index.
|
|
4010
|
+
|
|
4011
|
+
NOTE: only works with decorated API!
|
|
4012
|
+
|
|
4013
|
+
See :meth:`Problem.update` or the cheatsheet for more information on the decorated API.
|
|
4014
|
+
|
|
4015
|
+
Examples
|
|
4016
|
+
------
|
|
4017
|
+
```python
|
|
4018
|
+
>>> problem = jm.Problem("MyProblem", sense=jm.ProblemSense.MINIMIZE)
|
|
4019
|
+
>>> @problem.update
|
|
4020
|
+
>>> def _(problem: jm.DecoratedProblem):
|
|
4021
|
+
... N = problem.Placeholder(dtype=jm.DataType.NATURAL)
|
|
4022
|
+
... x = problem.BinaryVar(shape=N)
|
|
4023
|
+
... C = problem.Placeholder(ndim=1, dtype=np.uint64)
|
|
4024
|
+
... problem += jm.sum(x[i] for i in C)
|
|
4025
|
+
>>>
|
|
4026
|
+
```
|
|
4027
|
+
"""
|
|
4028
|
+
|
|
4029
|
+
@typing.overload
|
|
4030
|
+
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:
|
|
4031
|
+
r"""
|
|
4032
|
+
Creates an expression representing the summation of a sequence expression.
|
|
4033
|
+
|
|
4034
|
+
`sum` is a fundamental part of building models, used as a reducer to collapse
|
|
4035
|
+
multiple values into a single value.
|
|
4036
|
+
|
|
4037
|
+
While it's possible to call this on any :class:`Expression`, using this with an invalid object will lead to an
|
|
4038
|
+
error when the resulting expression is added to a :class:`Problem` and is
|
|
4039
|
+
type-checked.
|
|
4040
|
+
|
|
4041
|
+
In this overload variant, `operand` must be a linear sequence expression.
|
|
4042
|
+
That is, it could be, for example:
|
|
4043
|
+
- A one-dimensional array :class:`Placeholder` or :class:`DecisionVariable`
|
|
4044
|
+
- The result of another sequence function/method, like :func:`jijmodeling.map`, :func:`jijmodeling.filter`
|
|
4045
|
+
- An expression that is a supported operation on the above two categories.
|
|
4046
|
+
|
|
4047
|
+
Due to many binary operations on two one-dimensional arrays being supported,
|
|
4048
|
+
use of :func`jijmodeling.map` on an index is often not required for simple
|
|
4049
|
+
summations (note that for illustrative purposes the documentation examples
|
|
4050
|
+
on the relevant functions may use `map` when not strictly required). `map`
|
|
4051
|
+
is often required when doing more complex indexing.
|
|
4052
|
+
|
|
4053
|
+
The optional `axis` parameter allows you to specify one axis of a
|
|
4054
|
+
multi-dimensional expression across which to perform the operation.
|
|
4055
|
+
|
|
4056
|
+
See also the method equivalent :meth:`Expression.sum`, which is often more
|
|
4057
|
+
convenient and clearer.
|
|
4058
|
+
|
|
4059
|
+
Examples
|
|
4060
|
+
------
|
|
4061
|
+
Performing a weighted sum. Note that this sort of usage may lead to errors
|
|
4062
|
+
when the shapes don't match. In this case we guarantee that `x` has the
|
|
4063
|
+
same shape as `W` through its definition.
|
|
4064
|
+
|
|
4065
|
+
```python
|
|
4066
|
+
>>> import jijmodeling as jm
|
|
4067
|
+
>>> problem = jm.Problem("MyProblem")
|
|
4068
|
+
>>> W = problem.Float("W", ndim=1)
|
|
4069
|
+
>>> N = a.len_at(0)
|
|
4070
|
+
>>> x = problem.BinaryVar("x", shape=N)
|
|
4071
|
+
>>> problem += jm.sum(W * x)
|
|
4072
|
+
```
|
|
4073
|
+
|
|
4074
|
+
Same as above, but using map for indexing. This allows flexibility
|
|
4075
|
+
on how the index is used, including mapping multiple indices, or filtering before mapping.
|
|
4076
|
+
The other overload variant allows you to do this without explicitly calling `map`.
|
|
4077
|
+
|
|
4078
|
+
```python
|
|
4079
|
+
>>> import jijmodeling as jm
|
|
4080
|
+
>>> problem = jm.Problem("MyProblem")
|
|
4081
|
+
>>> W = problem.Float("W", ndim=1)
|
|
4082
|
+
>>> N = a.len_at(0)
|
|
4083
|
+
>>> x = problem.BinaryVar("x", shape=N)
|
|
4084
|
+
>>> problem += jm.sum(N.map(lambda i: W[i] * x[i])
|
|
4085
|
+
```
|
|
4086
|
+
"""
|
|
4087
|
+
|
|
4088
|
+
@typing.overload
|
|
4089
|
+
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:
|
|
4090
|
+
r"""
|
|
4091
|
+
Creates a summation based on an index and an operand function.
|
|
4092
|
+
|
|
4093
|
+
This overload variant can be thought of as a convenient shorthand for
|
|
4094
|
+
`jm.sum(jm.map(operand, index))`. Each element in `index` will be passed
|
|
4095
|
+
to the `operand` function for indexing, and summation will be performed on
|
|
4096
|
+
the results. See :func:`jijmodeling.map` and the other overload of
|
|
4097
|
+
:func:`jijmodeling.sum` for more information.
|
|
4098
|
+
|
|
4099
|
+
Examples
|
|
4100
|
+
------
|
|
4101
|
+
|
|
4102
|
+
```python
|
|
4103
|
+
>>> import jijmodeling as jm
|
|
4104
|
+
>>> problem = jm.Problem("MyProblem")
|
|
4105
|
+
>>> W = problem.Float("W", ndim=1)
|
|
4106
|
+
>>> N = a.len_at(0)
|
|
4107
|
+
>>> x = problem.BinaryVar("x", shape=N)
|
|
4108
|
+
>>> problem += jm.sum(N, lambda i: W[i] * x[i])
|
|
4109
|
+
```
|
|
4110
|
+
"""
|
|
4111
|
+
|
|
4112
|
+
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:
|
|
4113
|
+
r"""
|
|
4114
|
+
Returns an expression representing the tangent of the given expression.
|
|
4115
|
+
|
|
4116
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
4117
|
+
"""
|
|
4118
|
+
|
|
4119
|
+
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:
|
|
4120
|
+
r"""
|
|
4121
|
+
Returns an expression representing the hyperbolic tangent of the given expression.
|
|
4122
|
+
|
|
4123
|
+
Note that `expr` must be a scalar. Also, evaluating models where this operation is performed on decision variables is currently unsupported.
|
|
4124
|
+
"""
|
|
4125
|
+
|
|
4126
|
+
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:
|
|
4127
|
+
r"""
|
|
4128
|
+
Returns an expression representing the values of a dictionary-like
|
|
4129
|
+
:class:`Expression`.
|
|
4130
|
+
|
|
4131
|
+
In other words, this is the JijModeling equivalent of the `values()` method
|
|
4132
|
+
on Python dictionaries, used when creating JijModeling expressions.
|
|
4133
|
+
|
|
4134
|
+
While it's possible to call this on any :class:`Expression`, this is
|
|
4135
|
+
intended for dictionary-like :class:`Placeholder`s and
|
|
4136
|
+
:class:`DecisionVar`s. Using this with an invalid object will lead to an
|
|
4137
|
+
error when the resulting expression is added to a :class:`Problem` and is
|
|
4138
|
+
type-checked.
|
|
4139
|
+
|
|
4140
|
+
See also :meth:`Placeholder.values`, :meth:`DecisionVar.values`, and
|
|
4141
|
+
:meth:`Expression.values` to achieve this with methods, which is recommended for
|
|
4142
|
+
clarity.
|
|
4143
|
+
|
|
4144
|
+
If you want to refer to the keys used in the dictionary, use
|
|
4145
|
+
:func:`jijmodeling.keys` or its method equivalents. If you want key-value
|
|
4146
|
+
pairs, use :func:`jijmodeling.items` or its method equivalents instead.
|
|
4147
|
+
"""
|
|
4148
|
+
|
|
4149
|
+
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: ...
|
|
4150
|
+
|