journal article·2025Open access

Reinforcement Learning for Solving the Knapsack Problem

Zhenfu Zhang, Haiyan Yin, Liudong Zuo, Pan Lai

Computers, Materials & Continua· Volume 84· Issue 1

Abstract

The knapsack problem is a classical combinatorial optimization problem widely encountered in areas such as logistics, resource allocation, and portfolio optimization. Traditional methods, including dynamic programming (DP) and greedy algorithms, have been effective in solving small problem instances but often struggle with scalability and efficiency as the problem size increases. DP, for instance, has exponential time complexity and can become computationally prohibitive for large problem instances. On the other hand, greedy algorithms offer faster solutions but may not always yield the optimal results, especially when the problem involves complex constraints or large numbers of items. This paper introduces a novel reinforcement learning (RL) approach to solve the knapsack problem by enhancing the state representation within the learning environment. We propose a representation where item weights and volumes are expressed as ratios relative to the knapsack’s capacity, and item values are normalized to represent their percentage of the total value across all items. This novel state modification leads to a 5% improvement in accuracy compared to the state-of-the-art RL-based algorithms, while significantly reducing execution time. Our RL-based method outperforms DP by over 9000 times in terms of speed, making it highly scalable for larger problem instances. Furthermore, we improve the performance of the RL model by incorporating Noisy layers into the neural network architecture. The addition of Noisy layers enhances the exploration capabilities of the agent, resulting in an additional accuracy boost of 0.2%–0.5%. The results demonstrate that our approach not only outperforms existing RL techniques, such as the Transformer model in terms of accuracy, but also provides a substantial improvement than DP in computational efficiency. This combination of enhanced accuracy and speed presents a promising solution for tackling large-scale optimization problems in real-world applications, where both precision and time are critical factors.
Source: openalex_inverted_index · Quality: baseline

Research context

OpenAlex topics: Advanced Manufacturing and Logistics Optimization · Optimization and Packing Problems · Scheduling and Optimization Algorithms

SciVX discovery tags are terminology-based. OpenAlex topics are source-provided classifications.

References (26)

Show source-provided references
1. Solving 0-1 knapsack problem using cohort intelligence algorithm10.1007/s13042-014-0272-y ↗
2. The polynomial robust knapsack problem10.1016/j.ejor.2022.06.029 ↗
3. Modeling and solving of knapsack problem with setup based on evolutionary algorithm10.1016/j.matcom.2023.12.033 ↗
4. The multidimensional 0–1 knapsack problem: an overview10.1016/S0377-2217(03)00274-1 ↗
5. Deep learning10.1038/nature14539 ↗
6. Sutton · Reinforcement learning: an introduction · 2018
7. Ernst · Introduction to reinforcement learning · 2024 · 111
8. Human-level control through deep reinforcement learning10.1038/nature14236 ↗
9. Mastering the game of Go with deep neural networks and tree search10.1038/nature16961 ↗
10. Universal intelligence: a definition of machine intelligence10.1007/s11023-007-9079-x ↗
11. Reinforcement learning using fully connected, attention, and transformer models in knapsack problem solving10.1002/cpe.6509 ↗
12. Martello · North-holland mathematics studies · 1987 · 21310.1016/S0304-0208(08)73237-7 ↗
13. On two-stage stochastic knapsack problems10.1016/j.dam.2010.04.006 ↗
14. A genetic algorithm for the multidimensional knapsack problem10.1023/A:1009642405419 ↗
15. Approximate algorithms for the 0/1 knapsack problem10.1145/321864.321873 ↗
16. Bello I, Pham H, Le QV, Norouzi M, Bengio S. Neural combinatorial optimization with reinforcement learning. arXiv:1611.09940. 2016.
17. Reinforcement learning for solving the vehicle routing problem
18. Learning combinatorial optimization algorithms over graphs
19. Stabilizing transformers for reinforcement learning
20. A pointer network based deep learning algorithm for 0–1 Knapsack Problem
21. Neuroevolution for solving multiobjective knapsack problems10.1016/j.eswa.2018.09.004 ↗
22. Noisy networks for exploration
23. Dueling network architectures for deep reinforcement learning
24. Zhang · Handbook of reinforcement learning and control · 2021 · 32110.1007/978-3-030-60990-0_12 ↗
25. Transfer learning in deep reinforcement learning: a survey10.1109/TPAMI.2023.3292075 ↗
26. Combining reinforcement learning with Lin-kernighan-helsgaun algorithm for the traveling salesman problem