pykp.sampler.Sampler#

class pykp.sampler.Sampler(num_items: int, normalised_capacity: float, weight_dist: ~typing.Tuple[<MagicMock name='mock.random.Generator' id='139960639512144'>, dict] = (<MagicMock name='mock.random.default_rng().uniform' id='139960639964992'>, {'high': 1, 'low': 0.001}), value_dist: ~typing.Tuple[<MagicMock name='mock.random.Generator' id='139960639512144'>, dict] = (<MagicMock name='mock.random.default_rng().uniform' id='139960639964992'>, {'high': 1, 'low': 0.001}))#

Bases: object

Methods

sample()

Samples a knapsack instance using the sampling criteria provided to the sampler.

__init__(num_items: int, normalised_capacity: float, weight_dist: ~typing.Tuple[<MagicMock name='mock.random.Generator' id='139960639512144'>, dict] = (<MagicMock name='mock.random.default_rng().uniform' id='139960639964992'>, {'high': 1, 'low': 0.001}), value_dist: ~typing.Tuple[<MagicMock name='mock.random.Generator' id='139960639512144'>, dict] = (<MagicMock name='mock.random.default_rng().uniform' id='139960639964992'>, {'high': 1, 'low': 0.001}))#

A class for sampling knapsack instances.

Parameters:
  • num_items (int) – The number of items to sample.

  • normalised_capacity (float) – The normalised capacity of the knapsack (sum of weights / capacity constraint).

  • weight_dist (Tuple[np.random.Generator, dict], optional) – The distribution to sample weights from. The argument should be a tuple where the first element is the generator function, and the second element is a dictionary of keyword arguments to the generator. Defaults to random uniform over open interval (0, 1).

  • value_dist (Tuple[np.random.Generator, dict], optional) – The distribution to sample weights from. The argument should be a tuple where the first element is the generator function, and the second element is a dictionary of keyword arguments to the generator. Defaults to random uniform over open interval (0, 1).

Methods

__init__(num_items, normalised_capacity[, ...])

A class for sampling knapsack instances.

sample()

Samples a knapsack instance using the sampling criteria provided to the sampler.

sample() Knapsack#

Samples a knapsack instance using the sampling criteria provided to the sampler.

Returns:

The sampled knapsack instance.

Return type:

Knapsack