Creates a new Problem object.
The problem is defined by its dimension and the bounds of each variable.
| Parameters: |
-
dimension
(int)
–
Number of variables in the problem
-
bounds
(Sequence[tuple])
–
Bounds of each variable in the problem
-
name
(str, default:
'Problem'
)
–
Name of the problem for printing and logging purposes. Defaults to "Problem".
-
dtype
(_type_, default:
float64
)
–
Type of the variables. Defaults to np.float64.
-
seed
(int, default:
None
)
–
Seed for the random number generation (_rng). Defaults to None.
|
Source code in digneapy/core/_problem.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 | def __init__(
self,
dimension: np.uint32 | int,
bounds: Sequence[Tuple],
name: str = "Problem",
dtype=np.float64,
seed: Optional[int | np.random.SeedSequence] = None,
*args,
**kwargs,
):
"""Creates a new Problem object.
The problem is defined by its dimension and the bounds of each variable.
Args:
dimension (int): Number of variables in the problem
bounds (Sequence[tuple]): Bounds of each variable in the problem
name (str, optional): Name of the problem for printing and logging purposes. Defaults to "Problem".
dtype (_type_, optional): Type of the variables. Defaults to np.float64.
seed (int, optional): Seed for the random number generation (_rng). Defaults to None.
"""
try:
self._dimension = int(dimension)
if dimension <= 0:
raise ValueError
except Exception as te:
te.add_note(f"Dimension must be a postive integer. Got: {dimension}")
raise te
self.__name__ = name
self._dimension = dimension
self._bounds = bounds
self._dtype = dtype
if len(self._bounds) != 0:
ranges = list(zip(*bounds))
self._lbs = np.asarray(ranges[0], dtype=dtype)
self._ubs = np.asarray(ranges[1], dtype=dtype)
self._seed = seed
self._rng = np.random.default_rng(seed)
|