Generate random integer samples within problem bounds. Args: problem: Optimization problem. n_samples: Number of samples. *args: Additional positional arguments. random_state: Random state for reproducibility. **kwargs: Additional
( # type: ignore[override]
self, problem, n_samples: int, *args, random_state=None, **kwargs
)
| 82 | """Random sampling operator for integer variables.""" |
| 83 | |
| 84 | def _do( # type: ignore[override] |
| 85 | self, problem, n_samples: int, *args, random_state=None, **kwargs |
| 86 | ) -> np.ndarray: |
| 87 | """Generate random integer samples within problem bounds. |
| 88 | |
| 89 | Args: |
| 90 | problem: Optimization problem. |
| 91 | n_samples: Number of samples. |
| 92 | *args: Additional positional arguments. |
| 93 | random_state: Random state for reproducibility. |
| 94 | **kwargs: Additional keyword arguments. |
| 95 | |
| 96 | Returns: |
| 97 | Sample matrix of shape (n_samples, n_var) with integer values. |
| 98 | """ |
| 99 | n, (xl, xu) = problem.n_var, problem.bounds() |
| 100 | return np.column_stack( |
| 101 | [random_state.integers(xl[k], xu[k] + 1, size=n_samples) for k in range(n)] |
| 102 | ) |
| 103 | |
| 104 | |
| 105 | class PermutationRandomSampling(Sampling): |