Minor updates to knapsack docs; add challenge

pull/1/head
Alinson S. Xavier 6 years ago
parent a3309aa4b2
commit 25ba23a58d

@ -73,25 +73,26 @@ Given a set of $n$ items and $m$ types of resources (also called *knapsacks*), t
The class `MultiKnapsackGenerator` can be used to generate random instances of this problem. The number of items $n$ and knapsacks $m$ are sampled from the user-provided probability distributions `n` and `m`. The weights $w_{ij}$ are sampled independently from the provided distribution `w`. The capacity of knapsack $i$ is set to The class `MultiKnapsackGenerator` can be used to generate random instances of this problem. The number of items $n$ and knapsacks $m$ are sampled from the user-provided probability distributions `n` and `m`. The weights $w_{ij}$ are sampled independently from the provided distribution `w`. The capacity of knapsack $i$ is set to
$$ $$
\alpha_i \sum_{j=1}^n w_{ij} b_i = \alpha_i \sum_{j=1}^n w_{ij}
$$ $$
where $\alpha_i$, the tightness ratio, is sampled from the provided probability where $\alpha_i$, the tightness ratio, is sampled from the provided probability
distribution `alpha`. To make the instances more challenging, the costs of the items distribution `alpha`. To make the instances more challenging, the costs of the items
are linearly correlated to their average weights. More specifically, the weight of each are linearly correlated to their average weights. More specifically, the price of each
item $j$ is set to: item $j$ is set to:
$$ $$
\sum_{i=1}^m \frac{w_{ij}}{m} + K u_j, p_j = \sum_{i=1}^m \frac{w_{ij}}{m} + K u_j,
$$ $$
where $K$, the correlation coefficient, and $u_j$, the correlation multiplier, are sampled where $K$, the correlation coefficient, and $u_j$, the correlation multiplier, are sampled
from the provided probability distributions `K` and `u`. Note that $K$ is only sample once for each generated instance. from the provided probability distributions `K` and `u`.
If `fix_w=True` is provided, then $w_{ij}$ are kept the same in all generated instances. This also implies that $n$ and $m$ are kept fixed. Although the prices and capacities are derived from $w_{ij}$, as long as `u` and `K` are not constants, the generated instances will still not be completely identical. If `fix_w=True` is provided, then $w_{ij}$ are kept the same in all generated instances. This also implies that $n$ and $m$ are kept fixed. Although the prices and capacities are derived from $w_{ij}$, as long as `u` and `K` are not constants, the generated instances will still not be completely identical.
If a probability distribution `w_jitter` is provided, then item weights will be set to $w_{ij} + \gamma_{ij}$ where $\gamma_{ij}$ is sampled from `w_jitter`. When combined with `fix_w=True`, this argument may be used to generate instances where the weight of each item is roughly the same, but not exactly identical, across all instances. The prices of the items and the capacities of the knapsacks will be calculated as above, but using these perturbed weights instead. If a probability distribution `w_jitter` is provided, then item weights will be set to $w_{ij} + \gamma_{ij}$ where $\gamma_{ij}$ is sampled from `w_jitter`. When combined with `fix_w=True`, this argument may be used to generate instances where the weight of each item is roughly the same, but not exactly identical, across all instances. The prices of the items and the capacities of the knapsacks will be calculated as above, but using these perturbed weights instead.
!!! note !!! note "References"
Random generator based on *A. Freville and G. Plateau, **An efficient preprocessing procedure for the multidimensional knapsack problem**, Discrete Applied Mathematics 49 (1994) 189212*. * Freville, Arnaud, and Gérard Plateau. *An efficient preprocessing procedure for the multidimensional 01 knapsack problem.* Discrete applied mathematics 49.1-3 (1994): 189-212.
* Fréville, Arnaud. *The multidimensional 01 knapsack problem: An overview.* European Journal of Operational Research 155.1 (2004): 1-21.

@ -39,10 +39,10 @@ class BranchPriorityComponent(Component):
"%s/scripts/branchpriority.jl" % src_dirname, "%s/scripts/branchpriority.jl" % src_dirname,
model_file.name, model_file.name,
priority_file.name], priority_file.name],
check=True) check=True,
capture_output=True)
self._merge(np.genfromtxt(priority_file.name, self._merge(np.genfromtxt(priority_file.name,
delimiter=',', delimiter=','))
dtype=int))
def fit(self, solver): def fit(self, solver):

@ -10,6 +10,22 @@ from scipy.stats import uniform, randint, bernoulli
from scipy.stats.distributions import rv_frozen from scipy.stats.distributions import rv_frozen
class ChallengeA:
def __init__(self, seed=0):
np.random.seed(seed)
self.gen = MultiKnapsackGenerator(n=randint(low=50, high=51),
m=randint(low=3, high=4),
w=uniform(loc=0.0, scale=200.0),
K=uniform(loc=1.0, scale=0.0),
u=uniform(loc=1.0, scale=0.0),
alpha=uniform(loc=0.25, scale=0.0),
fix_w=True,
w_jitter=uniform(loc=-10.0, scale=20.0),
)
self.training_instances = self.gen.generate(300)
self.test_instances = self.gen.generate(50)
class MultiKnapsackInstance(Instance): class MultiKnapsackInstance(Instance):
"""Representation of the Multidimensional 0-1 Knapsack Problem. """Representation of the Multidimensional 0-1 Knapsack Problem.
@ -74,6 +90,7 @@ class MultiKnapsackGenerator:
alpha=uniform(loc=0.25, scale=0.0), alpha=uniform(loc=0.25, scale=0.0),
fix_w=False, fix_w=False,
w_jitter=randint(low=0, high=1), w_jitter=randint(low=0, high=1),
seed=None,
): ):
"""Initialize the problem generator. """Initialize the problem generator.
@ -114,9 +131,9 @@ class MultiKnapsackGenerator:
Probability distribution for the number of items (or variables) Probability distribution for the number of items (or variables)
m: rv_discrete m: rv_discrete
Probability distribution for the number of knapsacks (or constraints) Probability distribution for the number of knapsacks (or constraints)
w: rv_discrete w: rv_continuous
Probability distribution for the item weights Probability distribution for the item weights
K: rv_discrete K: rv_continuous
Probability distribution for the profit correlation coefficient Probability distribution for the profit correlation coefficient
u: rv_continuous u: rv_continuous
Probability distribution for the profit multiplier Probability distribution for the profit multiplier

@ -1,6 +1,6 @@
site_name: MIPLearn site_name: MIPLearn
theme: cinder theme: cinder
copyright: Copyright (C) 2019-2020 Argonne National Laboratory. All rights reserved. copyright: Copyright (C) 2019-2020 Argonne National Laboratory
repo_url: https://github.com/iSoron/miplearn repo_url: https://github.com/iSoron/miplearn
nav: nav:
- Home: index.md - Home: index.md

Loading…
Cancel
Save