-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'blank_slate' into vehicle_routing/advanced_routing
- Loading branch information
Showing
7 changed files
with
125 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,17 +41,17 @@ jobs: | |
- uses: dtolnay/rust-toolchain@stable | ||
with: | ||
targets: wasm32-wasi | ||
# - name: Install CUDA | ||
# if: env.SKIP_JOB != 'true' | ||
# uses: Jimver/[email protected] | ||
# id: cuda-toolkit | ||
# with: | ||
# cuda: '12.1.0' | ||
# method: network | ||
# sub-packages: '["nvcc"]' | ||
# - name: Cargo Build CUDA | ||
# if: env.SKIP_JOB != 'true' | ||
# run: cargo build -p tig-algorithms --release --features cuda | ||
- name: Install CUDA | ||
if: env.SKIP_JOB != 'true' | ||
uses: Jimver/[email protected] | ||
id: cuda-toolkit | ||
with: | ||
cuda: '12.1.0' | ||
method: network | ||
sub-packages: '["nvcc"]' | ||
- name: Cargo Build CUDA | ||
if: env.SKIP_JOB != 'true' | ||
run: cargo build -p tig-algorithms --release --features cuda | ||
- name: Cargo Build WASM | ||
if: env.SKIP_JOB != 'true' | ||
run: > | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,50 @@ | ||
# Knapsack Problem | ||
|
||
[The area of Knapsack problems is one of the most active research areas of combinatorial optimization](https://en.wikipedia.org/wiki/Knapsack_problem). The problem is to maximise the value of items placed in a knapsack given the constraint that the total weight of items cannot exceed some limit. | ||
The quadratic knapsack problem is one of the most popular variants of the single knapsack problem with applications in many optimization problems. The aim is to maximise the value of individual items placed in the knapsack while satisfying a weight constraint. However, pairs of items also have interaction values which may be negative or positive that are added to the total value within the knapsack. | ||
|
||
# Example | ||
|
||
For our challenge, we use a version of the knapsack problem with configurable difficulty, where the following two parameters can be adjusted in order to vary the difficulty of the challenge: | ||
For our challenge, we use a version of the quadratic knapsack problem with configurable difficulty, where the following two parameters can be adjusted in order to vary the difficulty of the challenge: | ||
|
||
- Parameter 1: $num\textunderscore{ }items$ is the number of items from which you need to select a subset to put in the knapsack. | ||
- Parameter 2: $better\textunderscore{ }than\textunderscore{ }baseline \geq 1$ is the factor by which a solution must be better than the baseline value [link TIG challenges for explanation of baseline value]. | ||
|
||
|
||
The larger the $num\textunderscore{ }items$, the more number of possible $S_{knapsack}$, making the challenge more difficult. Also, the higher $better\textunderscore{ }than\textunderscore{ }baseline$, the less likely a given $S_{knapsack}$ will be a solution, making the challenge more difficult. | ||
|
||
The weight $w_j$ of each of the $num\textunderscore{ }items$ is an integer, chosen independently, uniformly at random, and such that each of the item weights $1 <= w_j <= 50$, for $j=1,2,...,num\textunderscore{ }items$. The values of the items $v_j$ are similarly selected at random from the same distribution. | ||
The weight $w_i$ of each of the $num\textunderscore{ }items$ is an integer, chosen independently, uniformly at random, and such that each of the item weights $1 <= w_i <= 50$, for $i=1,2,...,num\textunderscore{ }items$. The individual values of the items $v_i$ are selected by random from the range $50 <= v_i <= 100$, and the interaction values of pairs of items $V_{ij}$ are selected by random from the range $-50 <= V_{ij} <= 50$. | ||
|
||
The total value of a knapsack is determined by summing up the individual values of items in the knapsack, as well as the interaction values of every pair of items $(i,j)$ where $i > j$ in the knapsack: | ||
|
||
$$V_{knapsack} = \sum_{i \in knapsack}{v_i} + \sum_{(i,j)\in knapsack}{V_{ij}}$$ | ||
|
||
We impose a weight constraint $W(S_{knapsack}) <= 0.5 \cdot W(S_{all})$, where the knapsack can hold at most half the total weight of all items. | ||
|
||
|
||
Consider an example of a challenge instance with `num_items=6` and `better_than_baseline = 1.09`. Let the baseline value be 100: | ||
Consider an example of a challenge instance with `num_items=4` and `better_than_baseline = 1.10`. Let the baseline value be 150: | ||
|
||
``` | ||
weights = [48, 20, 39, 13, 25, 16] | ||
values = [24, 42, 27, 31, 44, 31] | ||
max_weight = 80 | ||
min_value = baseline*better_than_baseline = 109 | ||
weights = [26, 20, 39, 13] | ||
individual_values = [63, 87, 52, 97] | ||
interaction_values = [ 0, 23, -18, -37 | ||
23, 0, 42, -28 | ||
-18, 42, 0, 32 | ||
-37, -28, 32, 0] | ||
max_weight = 60 | ||
min_value = baseline*better_than_baseline = 165 | ||
``` | ||
The objective is to find a set of items where the total weight is at most 80 but has a total value of at least 109. | ||
The objective is to find a set of items where the total weight is at most 60 but has a total value of at least 165. | ||
|
||
Now consider the following selection: | ||
|
||
``` | ||
selected_items = [1, 3, 4, 5] | ||
selected_items = [0, 1, 3] | ||
``` | ||
|
||
When evaluating this selection, we can confirm that the total weight is less than 80, and the total value is more than 109, thereby this selection of items is a solution: | ||
When evaluating this selection, we can confirm that the total weight is less than 60, and the total value is more than 165, thereby this selection of items is a solution: | ||
|
||
* Total weight = 20 + 13 + 25 + 16 = 74 | ||
* Total value = 42 + 31 + 44 + 31 = 148 | ||
* Total weight = 26 + 20 + 13 = 59 | ||
* Total value = 63 + 52 + 97 + 23 - 37 - 28 = 170 | ||
|
||
# Our Challenge | ||
In TIG, the baseline value is determined by a greedy algorithm that simply iterates through items sorted by value to weight ratio, adding them if knapsack is still below the weight constraint. | ||
|
||
# Applications | ||
|
||
The Knapsack problems have a wide variety of practical applications. The [use of knapsack in integer programming](https://www.sciencedirect.com/science/article/pii/0012365X71900057) led to break thoughs in several disciplines, including [energy management](https://www.sciencedirect.com/science/article/abs/pii/S0301421513003418) and [cellular network frequency planning](https://www.slideshare.net/deepakecrbs/gsm-frequency-planning). | ||
|
||
Although originally studied in the context of logistics, Knapsack problems appear regularly in diverse areas of science and technology. For example, in gene expression data, there are usually thousands of genes, but only a subset of them are informative for a specific problem. The Knapsack Problem can be used to select a subset of genes (items) that maximises the total information (value) without exceeding the limit of the number of genes that can be included in the analysis (weight limit). | ||
|
||
<img src="../images/gene_clustering.jfif" alt="Gene Clustering" width="100%"/> | ||
|
||
|
||
<figcaption>Figure 2: <a href="https://openres.ersjournals.com/content/4/4/00031-2018" target="_blank">Microarray clustering of differentially expressed genes in blood</a>. Genes are clustered in rows, with red indicating high expression, yellow intermediate expression and blue low expression. The Knapsack problem is <a href="https://www.sciencedirect.com/science/article/abs/pii/S0305054821003877" target="_blank">used to analyse</a> gene expression clustering.</figcaption> | ||
<br/> | ||
In TIG, the baseline value is determined by a greedy algorithm that simply iterates through items sorted by potential value to weight ratio, adding them if knapsack is still below the weight constraint. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters