This repository contains a Python implementation of a branch-and-bound approach (plus a simple greedy heuristic) to solve a variation of the Quadratic Multiple Knapsack Problem (QMKP) where items have both individual and pairwise benefits.
- 🧳Multiple knapsacks – each with a fixed capacity.
- 🤝Pairwise benefits – placing items (i,j) together yields an extra benefit.
- 🌲Branch-and-bound – systematically builds a search tree, with a simple bounding approach.
- ⚙️Greedy heuristic – as a fallback or initial solution (sort items by benefit/weight).
- ⏱️Time limit – automatically stops branching after the user-defined time in each instance.
Each instance file must have:
- First line:
I B C T
I
: number of itemsB
: number of backpacksC
: capacity per backpackT
: max time (seconds) for the search
- Second line: list of
I
item weights. - Third line: list of
I
item benefits. - Subsequent lines: the pairwise-benefits matrix, typically forming a triangular or row-based structure.
- Clone or Download the repository:
git clone https://github.com/RenatoMaynard/quadratic-multi-knapsack-b&b.py.git
Feel free to open issues or create pull requests:
- Fork the repository.
- Create a new branch.
- Commit changes.
- Push to the branch.
- Create a Pull Request.
This project is for educational purposes only. Errors may exist. Please report issues or contribute improvements via pull requests.
This project is open-sourced under the MIT license.