Skip to main content

QMKPy: A Python Testbed for the Quadratic Multiple Knapsack Problem

Pytest codecov Read the docs status PyPI License status

This software package primarily aims at research in the areas of operations research and optimization. It serves as a testbed that provides a way of quickly implementing and testing new algorithms to solve the quadratic multiple knapsack problem (QMKP) and compare it with existing solutions.

The goal is to encourage researchers and developers to share their algorithms and make them publicly available.

Problem Description

The QMKP is defined as the following combinatorial optimization problem

$$ \begin{alignat}{3} \max\quad & \sum_{u\in\mathcal{K}}\Bigg(\sum_{i\in\mathcal{A}(u)} p_{i} &+&\sum_{\substack{j\in\mathcal{A}(u), \ j\neq i}} p_{ij}\Bigg)\ \mathrm{s.t.}\quad & \sum_{i\in\mathcal{A}(u)} w_{i} \leq c_u & \quad & \forall u\in\mathcal{K} \ & \sum_{u=1}^{K} a_{iu} \leq 1 & & \forall i \in {1, 2, \dots, N} \end{alignat} $$

This describes an assignment problem where one wants to assign $N\in\mathbb{N}$ items to $K\in\mathbb{N}$ knapsacks, which are described by the index set $\mathcal{K}={1, 2, \dots, K}$. Item $i$ has the weight $w_i\in\mathbb{R_+}$ and knapsack $u$ has the weight capacity $c_u\mathbb{R_+}$. If item $i$ is assigned to a knapsack, it yields the (non-negative) profit $p_i\in\mathbb{R_+}$. If item $j$ (with $j\neq i$ ) is assigned to the same knapsack, we get the additional joint profit $p_{ij}\in\mathbb{R_+}$.

The set of items which are assigned to knapsack $u$ is denoted by $\mathcal{A}(u)$ and $a_{iu}\in{0, 1}$ is an indicator whether item $i$ is assigned to knapsack $u$.

The objective of the above problem is to maximize the total profit such that each item is assigned to at most one knapsack and such that the weight capacity constraints of the knapsacks are not violated.

Remark: The profits $p$ are also referred to as "values" in the literature.

Features

  • Quick and simple creation of QMKP instances
  • Saving/loading of problem instances for a simple creation and use of reference datasets
  • Easy implementation of novel algorithms to solve the QMKP
  • High reproducibility and direct comparison between different algorithms

The benefit of enabling a simple and direct way of implementing novel algorithms is highlighted by an example in the provided Jupyter notebook in examples/Custom Algorithm.ipynb.
Binder

Installation

The package can easily be installed via pip. Either from the PyPI

pip3 install qmkpy

or from the GitHub repository

git clone https://github.com/klb2/qmkpy.git
cd qmkpy
git checkout dev  # optional for the latest development version
pip3 install -r requirements.txt
pip3 install .
pip3 install pytest  # optional if you want to run the unit tests

Usage

In order to test the installation and get an idea of how to use the QMKPy package, you can take a look at the examples/ directory. It contains some standalone scripts that can be executed and perform some simple tasks.

More detailed descriptions of the implemented algorithms and a documentation of the API can be found in the documentation.

A collection of reference datasets can be found at https://github.com/klb2/qmkpy-datasets.

Contributing

Please see CONTRIBUTING.md for guidelines on how to contribute to this project. In particular, novel algorithms are always welcome. Please check out the documentation for a brief overview on how to implement new algorithms for the QMKPy framework.

Release files for qmkpy 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qmkpy 1.2.0
File Size Uploaded
qmkpy-1.2.0.tar.gz 51.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for qmkpy 1.2.0
File Interpreter ABI Platform
qmkpy-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 81.0 kB

Release files / qmkpy-1.2.0.tar.gz

Download URL qmkpy-1.2.0.tar.gz
Size 51.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8baa911b3cac7ecb1b20be4f9f4e859d6a9d723ab94b61abcb0c563e30970ec5
BLAKE2b-256 checksum
How to use checksums
abe1ba8fc5e5626fd60940ea0209ee8d1026eea0b428e805c6592b38e195f487
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.8

Release files / qmkpy-1.2.0-py3-none-any.whl

Download URL qmkpy-1.2.0-py3-none-any.whl
Size 29.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
27751f071307739a3b838ad78c7ab976390d8a9840a0d7b4b1594c6569d63f5c
BLAKE2b-256 checksum
How to use checksums
0006384c274ec5e6e1346068f0ed60edce1343ee45e77af09407f22d8d962f4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.8

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page