problems: Allow correlated arguments in random problem generators

This commit is contained in:
2025-12-08 16:08:05 -06:00
parent 485625e07f
commit 9f0fa0e500
9 changed files with 133 additions and 30 deletions

View File

@@ -3,9 +3,11 @@
# Released under the modified BSD license. See COPYING.md for more details.
import numpy as np
from scipy.stats import randint, uniform
from miplearn.problems.setpack import (
SetPackData,
SetPackGenerator,
build_setpack_model_gurobipy,
)
@@ -24,3 +26,19 @@ def test_setpack() -> None:
model = build_setpack_model_gurobipy(data)
model.optimize()
assert model.inner.objval == -22.0
def test_set_pack_generator_callable() -> None:
np.random.seed(42)
gen = SetPackGenerator(
n_elements=randint(low=4, high=5),
n_sets=lambda n: n * 2,
costs=uniform(loc=10.0, scale=0.0),
density=uniform(loc=0.5, scale=0),
K=uniform(loc=0, scale=0),
)
data = gen.generate(1)
n_elements, n_sets = data[0].incidence_matrix.shape
assert n_elements == 4
assert n_sets == 8
assert len(data[0].costs) == 8