A novel discrete whale optimization algorithm for solving knapsack problems


Whale optimization algorithm (WOA) is a recently proposed meta-heuristic algorithm which imitates the hunting behavior of humpback whales. Due to its characteristic advantages, it has found its place in the mature population-based methods in many scientific and engineering fields. Because WOA was proposed for continuous optimization, it cannot be directly used to solve discrete optimization problems. For this purpose, we first give a new V -shaped function by drawing lesson from the existing discretization methods, which transfer a real vector to an integer vector. On this basis, we propose a novel discrete whale optimization algorithm (DWOA). DWOA uses the new proposed V -shaped function to generate an integer vector, and it can be used to solve discrete optimization problems with solution space {0,1,…,m1}×{0,1,…,m2}×… ×{0,1,…,mn}. To verify effectiveness of DWOA for the 0-1 knapsack problem and the discount {0-1} knapsack problem, we solve their benchmark instances from published literature and compare with the state-of-the-art algorithms. The comparison results show that the DWOA has more superiority than existing algorithms for the two kinds of knapsack problems.

This is a preview of subscription content, log in to check access.

Fig. 1
Fig. 2
Fig. 3
Fig. 4
Fig. 5
Fig. 6
Fig. 7
Fig. 8
Fig. 9
Fig. 10


  1. 1.

    Kellerer H, Pferschy U, Pisinger D (2004) Knapsack problems. Berlin, Springer

    Google Scholar 

  2. 2.

    Karp RM (1972) Reducibility among combinatorial problems. In: Miller REThatcher JW (ed) Proc. of the complexity of computer computations. Plenum Press, New York, pp 110–137

  3. 3.

    Martello S, Toth P (1990) Knapsack problems: algorithms and computer implementations. Wiley, New York

    Google Scholar 

  4. 4.

    Wang L, Zheng XL, Wang SY (2013) A novel binary fruit fly optimization algorithm for solving the multidimensional knapsack problem. Knowledge-Based Systems 48(2):17–23

    Article  Google Scholar 

  5. 5.

    Patvardhan C, Bansal S, Srivastav A (2016) Parallel improved quantum inspired evolutionary algorithm to solve large size Quadratic Knapsack Problems. Swarm & Evolutionary Computation 26:175–190

    Article  Google Scholar 

  6. 6.

    Yichao H, Haoran X, Tak-Lam W, Xizhao W (2018) A novel binary artificial bee colony algorithm for the set-union knapsack problem. Future Generation Computer Systems 78(1):77–86

    Google Scholar 

  7. 7.

    Pisinger DA (1995) Minimal algorithm for the bounded knapsack problem, integer programming and combinatorial optimization. Springer, Berlin

    Google Scholar 

  8. 8.

    Guldan B (2007) Heuristic and exact algorithms for discounted knapsack problems. Master thesis, University of Erlangen-Nnberg, Germany

  9. 9.

    Mathews GB (1988) On the partition of numbers. Proceedings of the London Mathematical Society s1-28 (1):256–282

    MathSciNet  Google Scholar 

  10. 10.

    Yichao H, Xizhao W, Wenbin L, Xinlu Z, YiYing C (2016) Research on genetic algorithm for discounted {0-1} knapsack problem. Chinese Journal of Computers 12:2614–2630

    MathSciNet  Google Scholar 

  11. 11.

    JinSong H, GuoLiang C, GuangCan G (1999) Solving the 0/1-knapsack problem on quantum computer. Chinese Journal of Computers 12:1314–1316

    MathSciNet  Google Scholar 

  12. 12.

    Cormen TH, Leiserson CE, Rivest RL, Stein C (2001) Introduction to algorithms, 2nd edn. Cambridge, MIT Press, pp 359–403

    Google Scholar 

  13. 13.

    Ibarra OH, Kim CE (1975) Fast approximation algorithms for the knapsack and sum of subset problems. Journal of the ACM 22(4):463–468

    MathSciNet  MATH  Article  Google Scholar 

  14. 14.

    Rajeev AMH (1995) Randomized algorithms. Cambridge University Press, Cambridge

    Google Scholar 

  15. 15.

    Du D-Z, Ko K-I, Hu X (2012) Design and analysis of approximation algorithms. Springer, New York

    Google Scholar 

  16. 16.

    Darehmiraki M, Nehi HM (2007) Molecular solution to the 0-1 knapsack problem based on DNA computing. Applied Mathematics & Computation 187(2):1033–1037

    MathSciNet  MATH  Article  Google Scholar 

  17. 17.

    Zhu Y, Ren LH, Ding YS, et al. (2009) DNA ligation design and biological realization of knapsack problem. Chinese Journal of Computers 31(12):2207–2214

    MathSciNet  Article  Google Scholar 

  18. 18.

    Michalewicz Z, Schoenauer M (2014) Evolutionary algorithms for constrained parameter optimization problems. Evol Comput 4(1):1–32

    Article  Google Scholar 

  19. 19.

    Goldberg DE (1989) Genetic algorithms in search. Optimization and Machine Learning xiii(7):2104–2116

    Google Scholar 

  20. 20.

    Michalewicz Z (1996) Genetic algorithm + data structure = evolution programs. Springer, Berlin, pp 631–653

    Google Scholar 

  21. 21.

    Kennedy J, Eberhart R (1995) Particle swarm optimization. In: IEEE international conference on neural networks, 1995. Proceedings, vol 4, pp 1942–1948

  22. 22.

    Bansal JC, Deep K (2012) A modified binary particle swarm optimization for knapsack problems. Applied Mathematics & Computation 218(22):11042–11061

    MathSciNet  MATH  Article  Google Scholar 

  23. 23.

    Storn R, Price K (1997) Differential evolution - a simple and efficient heuristic for global optimization over continuous spaces. J Glob Optim 11(4):341–359

    MathSciNet  MATH  Article  Google Scholar 

  24. 24.

    Yichao H (2007) A binary differential evolution algorithm with hybrid encoding. Journal of Computer Research & Development 44(9):1476–1484

    Article  Google Scholar 

  25. 25.

    Dorigo M, Birattari M, Stutzle T (2007) Ant colony optimization. IEEE Comput Intell Mag 1(4):28–39

    Article  Google Scholar 

  26. 26.

    Hanxiao S (2006) Solution to 0/1 knapsack problem based on improved ant colony algorithm. IEEE International Conference on Information Acquisition, pp 1062–1066

  27. 27.

    Karaboga D, Basturk B (2007) A powerful and efficient algorithm for numerical function optimization: artificial bee colony (ABC) algorithm[J]. J Glob Optim 39(3):459–471

    MathSciNet  MATH  Article  Google Scholar 

  28. 28.

    Mirjalili S, Lewis A (2016) The whale optimization algorithm. Adv Eng Softw 95:51–67

    Article  Google Scholar 

  29. 29.

    Aziz MAE, Ewees AA, Hassanien AE (2017) Whale optimization algorithm and moth-flame optimization for multilevel thresholding image segmentation. Expert Syst Appl 83:242–256

    Article  Google Scholar 

  30. 30.

    Mafarja MM, Mirjalili S (2017) Hybrid whale optimization algorithm with simulated annealing for feature selection[J]. Neurocomputing 260:302–312

    Article  Google Scholar 

  31. 31.

    Nazari-Heris M, Mehdinejad M, Mohammadi-Ivatloo B, et al. (2017) Combined heat and power economic dispatch problem solution by implementation of whale optimization method. Neural Computing & Applications, pp 1–16

  32. 32.

    Trivedi I, Bhoye N, Bhesdadiya M, An RH, et al. (2017) An emission constraint environment dispatch problem solution with microgrid using whale optimization algorithm. In: Power systems conference. IEEE

  33. 33.

    Aljarah I, Faris H, Mirjalili S (2016) Optimizing connection weights in neural networks using the whale optimization algorithm. Soft Comput 22(1):1–15

    Article  Google Scholar 

  34. 34.

    Prakash DB, Lakshminarayana C (2016) Optimal siting of capacitors in radial distribution network using whale optimization algorithm. Alexandria Engineering Journal 56(4):499–509

    Article  Google Scholar 

  35. 35.

    Ying L, Zhou Y, Luo Q (2017) Levy flight trajectory-based whale optimization algorithm for global optimization. IEEE Access 5(99):6168–6186

    Google Scholar 

  36. 36.

    Laskar NM, Guha K, Chatterjee I, Chanda S, Baishnab KL, Paul PK (2018) HWPSO: a new hybrid whale-particle swarm optimization algorithm and its application in electronic design optimization problems. Applied Intelligence, pp 1–27

  37. 37.

    Abdel-Basset M, Gunasekaran M, El-Shahat D, et al. (2018) A hybrid whale optimization algorithm based on local search strategy for the permutation flow shop scheduling problem. Futur Gener Comput Syst, pp 85

  38. 38.

    Xu Z, Yu Y, Yachi H, Ji J, Todo Y, Gao S (2018) A novel memetic whale optimization algorithm for optimization, international conference on swarm intelligence. ICSI 2018: Advances in Swarm Intelligence 10941:384–396

    Google Scholar 

  39. 39.

    Zamani H, Nadimi-Shahraki MH (2016) Feature selection based on whale optimization algorithm for diseases diagnosis. International Journal of Computer Science and Information Security (IJCSIS) 14(9):1243–1247

    Google Scholar 

  40. 40.

    Abdel-Basset M, El-Shahat D, Sangaiah AK (2017) A modified nature inspired meta-heuristic whale optimization algorithm for solving 0-1 knapsack problem. International Journal of Machine Learning & Cybernetics 1: 1–20

  41. 41.

    Mafarja MM, Mirjalili S (2017) Hybrid whale optimization algorithm with simulated annealing for feature selection. Neurocomputing 260:302–312

    Article  Google Scholar 

  42. 42.

    Hussien AG, Houssein EH, Hassanien AE (2018) A binary whale optimization algorithm with hyperbolic tangent fitness function for feature selection. In: Eighth international conference on intelligent computing and information systems. IEEE, pp 166– 172

  43. 43.

    Reddy KS, Panwar L, Panigrahi BK, et al. (2018) Binary whale optimization algorithm: a new metaheuristic approach for profit-based unit commitment problems in competitive electricity markets. Eng Optim, pp 1–21

  44. 44.

    Hussien AG, Hassanien AE, Houssein EH, et al. (2019) S-shaped binary whale optimization algorithm for feature selection. in press, https://doi.org/10.1007/978-981-10-8863-6_9

  45. 45.

    Shao-Yan WU, Zhuo-Qun XU (1998) A heuristic policy for constructing crossover in genetic algorithms. Chinese Journal of Computers 21(11):1003–1008

    Google Scholar 

  46. 46.

    Li Z, Li N (2009) A novel multi-mutation binary particle swarm optimization for 0/1 knapsack problem. Chinese Control and Decision Conference 2009(2):3090–3095

    Google Scholar 

  47. 47.

    Zou D, Gao L, Li S, et al. (2011) Solving 0-1 knapsack problem by a novel global harmony search algorithm. Appl Soft Comput 11(2):1556–1564

    Article  Google Scholar 

  48. 48.

    Zhou Y, Chen X, Zhou G (2016) An improved monkey algorithm for a 0-1 knapsack problem. Elsevier Science Publishers B. V., Amsterdam, pp 817–830

    Google Scholar 

  49. 49.

    Zhang XF, Wang JC, Mu L (2007) A parallel hybrid genetic algorithm of sovling knapsack problem. Journal of Xian University of Engineering Science and Technology 21(1):83– 87

    Google Scholar 

  50. 50.

    Sonuc E, Sen B, Bayir S (2016) A parallel approach for solving 0/1 knapsack problem using simulated annealing algorithm on CUDA platform. Int J Comput Sci Inf Sec 14(12):1096

    Google Scholar 

  51. 51.

    Rong A, Figueira JR, Klamroth K (2012) Dynamic programming based algorithms for the discounted {0-1} knapsackproblem. Appl Math Comput 218(12):6921–6933

    MathSciNet  MATH  Google Scholar 

  52. 52.

    Congcong W, Yichao H, Yiying C (2017) Mutated bat algorithm for solving discounted {0-1} knapsack problem. Journal of Computer Applications 37(5):1292–1299

    Google Scholar 

  53. 53.

    Xuejing L, Yichao H, Fengjia L, et al. (2018) Chaotic crow search algorithm based on differential evolution strategy for solving discount {0-1} knapsack problem. Journal of Computer Applications 38(1):137–145

    Google Scholar 

  54. 54.

    Zhu H, He Y, Wang X, Tang ECC (2017) Discrete differential evolutions for the discounted {0C1} knapsack problem. Int J Bio-Inspired Computation 10(4):219–238

    Article  Google Scholar 

  55. 55.

    Niu P, Wu Z, Ma Y, Shi C, Li J (2017) Prediction of steam turbine heat consumption rate based on whale optimization. CIESC Journal 68(3):1049–1057

    Google Scholar 

  56. 56.

    Kennedy J, Eberhart R (1997) A discrete binary version of the particle swarm algorithm. In: Proc 1997 conf. on systems, man, and cybernetics. IEEE Service Center, Piscataway, pp 4104–4109

  57. 57.

    Sundar S, Singh A, Andr Rossi (2010) An artificial bee colony algorithm for the 0-1 multidimensional knapsack problem[C]. International Symposium on Innovations in Intelligent Systems & Applications, IEEE

  58. 58.

    Wang L, Fu X, Mao Y, Menhas MI, Fei M (2012) A novel modified binary differential evolution algorithm and its applications. Neurocomput 98:55–75

    Article  Google Scholar 

  59. 59.

    Nakamura RYM, Pereira LAM, Costa KA, et al. (2012) BBA: a binary bat algorithm for feature selection[C]. In: 2012 25th SIBGRAPI conference on graphics, patterns and images, IEEE

  60. 60.

    Mirjalili S, Lewis A (2013) S-shaped versus v-shaped transfer functions for binary particle swarm optimization. Swarm & Evolutionary Computation 9:1–14

    Article  Google Scholar 

  61. 61.

    Mafarja M, Eleyan D, Abdullah S, et al. (2017) S-shaped vs. v-shaped transfer functions for ant lion optimization algorithm in feature selection problem. In: International conference on future networks and distributed systems. ACM, pp 1–7

  62. 62.

    Yichao H, Xizhao W, Shuling Z, Xinlu Z (2018) Design and applications of discrete evolutionary algorithm based on encoding transformation. Journal of Software 29(9):2580–2594. https://doi.org/10.13328/j.cnki.jos.005400

    Article  MATH  Google Scholar 

  63. 63.

    Zewen L, Yichao H, Huanzhe L, Ya L, Xiaohu G (2019) A novel discrete grey wolf optimizer for solving the bounded knapsack problem. In: Peng H, Deng C, Wu Z, Liu Y (eds) Computational intelligence and intelligent systems. ISICA 2018. Communications in computer and information science, vol 986. Springer, Singapore

  64. 64.

    He YC, Wang XZ, Li WB, Zhao SL (2016) Exact algorithms and evolutionary algorithms for randomized time-varying knapsack problem. Ruan Jian Xue Bao/Journal of Software. (in Chinese with English abstract). https://doi.org/10.13328/j.cnki.jos.004937. http://www.jos.org.cn/1000-9825/4937.htm

  65. 65.

    Wang XZ, Yi-Chao HE (2017) Evolutionary algorithms for knapsack problems. Journal of Software 28 (1):1–16

    MathSciNet  Google Scholar 

  66. 66.

    Zou D, Gao L, Li S, et al. (2011) Solving 0-1 knapsack problem by a novel global harmony search algorithm. Appl Soft Comput 11(2):1556–1564

    Article  Google Scholar 

  67. 67.

    Azad MAK, Rocha AMAC, Fernandes EMGP (2014) A simplified binary artificial fish swarm algorithm for 0-1 quadratic knapsack problems. Journal of Computational and Applied Mathematics 259:897–904

    MathSciNet  MATH  Article  Google Scholar 

  68. 68.

    Zhou Y, Chen X, Zhou G (2016) An improved monkey algorithm for a 0-1 knapsack problem. Elsevier Science Publishers B.V., Amsterdam, pp 817–830

    Google Scholar 

Download references


This article was supported by Scientific Research Project Program of Colleges and Universities in Hebei Province (ZD2016005), and Natural Science Foundation of Hebei Province (F2016403055).

Author information



Corresponding author

Correspondence to Yichao He.

Additional information

Publisher’s note

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.


Appendix: A

The pseudo code of algorithm GROA [64, 65] is shown below, and its time complexity is O(n).


Appendix: B

The pseudo code of algorithm NROA [10] is shown below, and its time complexity is O(n).


Rights and permissions

Reprints and Permissions

About this article

Verify currency and authenticity via CrossMark

Cite this article

Li, Y., He, Y., Liu, X. et al. A novel discrete whale optimization algorithm for solving knapsack problems. Appl Intell (2020). https://doi.org/10.1007/s10489-020-01722-3

Download citation


  • Whale optimization algorithm
  • Meta-heuristic algorithm
  • V -shaped function
  • 0-1knapsack problem
  • Discounted {0-1} knapsack problem