pyepo.data.knapsack

Synthetic data for knapsack problem

Functions

genData(→ tuple[numpy.ndarray, numpy.ndarray, ...)

Generate synthetic feature-cost pairs for the multi-dimensional knapsack.

Module Contents

pyepo.data.knapsack.genData(num_data: int, num_features: int, num_items: int, dim: int = 1, deg: int = 1, noise_width: float = 0, seed: int = 135) tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]

Generate synthetic feature-cost pairs for the multi-dimensional knapsack.

Item weights are fixed across instances; only the value (cost) of each item depends on features. Features are sampled from a standard Gaussian \(\mathcal{N}(0, \mathbf{I})\), mapped through a random Bernoulli(0.5) matrix \(\mathcal{B}\) and a polynomial of degree deg, then scaled by multiplicative uniform noise of half-width noise_width and rounded up to the nearest integer.

Parameters:
  • num_data – number of data points

  • num_features – dimension of features

  • num_items – number of items

  • dim – dimension of multi-dimensional knapsack

  • deg – polynomial degree of the feature-to-cost mapping

  • noise_width – half-width of the multiplicative uniform noise

  • seed – random state seed (default 135 for reproducibility)

Returns:

weights of items (np.ndarray), data features (np.ndarray), costs (np.ndarray)

Return type:

tuple