An efficient optimizer for the 0/1 knapsack problem using group counseling

The field of optimization is concerned with determining the optimal solution to a problem. It refers to the mathematical loss or gain of a given objective function. Optimization must reduce the given problem’s losses and disadvantages while maximizing its earnings and benefits. We all want optimal or, at the very least, suboptimal answers because we all want to live a better life. Group counseling optimizer (GCO) is an emerging evolutionary algorithm that simulates the human behavior of counseling within a group for solving problems. GCO has been successfully applied to single and multi-objective optimization problems. The 0/1 knapsack problem is also a combinatorial problem in which we can select an item entirely or drop it to fill a knapsack so that the total weight of selected items is less than or equal to the knapsack size and the value of all items is as significant as possible. Dynamic programming solves the 0/1 knapsack problem optimally, but the time complexity of dynamic programming is O(n3). In this article, we provide a feature analysis of GCO parameters and use it to solve the 0/1 knapsack problem (KP) using GCO. The results show that the GCO-based approach efficiently solves the 0/1 knapsack problem; therefore, it is a viable alternative to solving the 0/1 knapsack problem.


INTRODUCTION
Over the previous several decades, the use of evolutionary algorithms to solve optimization issues has increased. Single-objective and multi-objective are the two categories of optimization problems. Multi-objective optimization involves problems with multiple competing goals to be achieved. Problems that have only one goal are called single-objective optimization problems. Researchers have suggested several evolutionary optimization strategies for single-objective and multi-objective optimization problems (Steuer, 1986).
Since the 0/1 knapsack problem is a combinatorial problem, approaches such as branch and bound, backtracking, and dynamic programming are not very helpful in solving it. A multi-objective variant of GCO has been recently published that shows promise in solving multi-objective optimization problems. According to the results, group counseling optimizer is used in a real-world application to test its applicability and the proposed algorithm also outperforms well-known optimizers.
In this article, we use the GCO algorithm for the following: 1. to solve the 0/1 knapsack problem and 2. to analyze the various parameters to see how they affect the solution.
The experimental results show the significant role of parameters in GCO algorithms for solving the 0/1 knapsack problem.
The rest of the article is organized as follows: Section II describes the related work. In section III, we briefly discuss the group counseling optimizer. Sections IV and V describe the knapsack problem and experimental results, respectively. Section VI concludes the article. In Ezugwu et al. (2019), the authors proposed preliminary results from several memetics optimization procedures for solving the 0/1 knapsack problems, including simulated annealing, genetic algorithms, greedy search algorithm, dynamic programming, branch and bound, and simulated annealing using a hybrid genetic algorithm. During the optimization process, every computation punishes infeasible arrangements while optimizing the feasible ones. The authors of Abdel-Basset, Mohamed & Mirjalili (2021) suggested a binary version of equilibrium optimization (BEO). Transfer functions change the constant value from continuous to binary EO, converting it to the binary values 0, 1, and 0. Transfer functions come in two different shapes: V-shaped and S-shaped. This research demonstrates that the best transfer function among them is the V-Shaped V3. The sigmoid S3 transfer function is likewise more advantageous than V3. This new intelligent system builds on dragonfly foraging and predator evasion theory (Wang, Shi & Dong, 2021). When tackling continuous multi-modal functions and engineering issues, the dragonfly algorithm (DA) excels. This study offers an angle modulation technique on DA (AMDA). AMDA is used to produce bit strings to make this algorithm function in binary space. A modified AMDA, an improved angle-modulated dragonfly algorithm (IAMDA) is presented to increase algorithm stability and convergence speed by including one additional coefficient to control the vertical displacement of the cosine section of the original generating function. Hybrid rice optimization (HRO) (Shu et al., 2022) is a new optimization procedure stimulated through the upbringing method of Chinese three-line hybrid rice. The population of the algorithm is divided into three categories; restorer, maintainer, and sterile line, and other stages like hybridization, renewal, and selfing are applied. The proposed algorithm is integrated with another to develop a parallel and serial model using the binary ant colony optimization (BACO) technique to expand merging speed and search efficiency. The maintainer line is updated by BACO, which is incorporated in HRO as an operator.

RELATED WORK
The re-establishment plan presents an active step to adjust the investigation and misuse stages. All exploratory approaches were implemented using Python 3.6 on a Windows 10 Working Framework PC with an Intel(R) Core (TM) i7-8700 @ 3.2 GHz CPU and 16GB DDR3 RAM. In Moradi, Kayvanfar & Rafiee (2021), the authors develop and contrast a novel population-based SA (PSA) for the 0/1 knapsack problem and analyze and contrast the given and non-introduced single-solution SA-based computations for KP01. PSA is the most efficient optimization strategy for KP01 among the SA-based options. PSA's inquiry and abuse are far more capable than previous SA-based calculations since it generates multiple beginning arrangements rather than a single fair one. PSA employs transformation and hybrid administrators to investigate and misuse the arrangement space and the ravenous repair and improvement instrument to identify neighboring arrangements. In Abdollahzadeh et al. (2021), the authors solve the 0/1 knapsack problem using an extended binary slime mold algorithm (SMA) at various sizes. SMA has tested and analyzed eight distinct transfer functions. The transfer function that performed well is used to improve the performance of the proposed binary SMA, and the Bitwise and Gaussian mutation operators are applied. Punitive work and a repair computation are used to deal with infeasible arrangements. On typical datasets with various scales, performance was tested statistically. In Basheer & Algamal (2021), the authors proposed two new time-varying exchange functions to expand the biotic flower pollination algorithm BFPA's investigation and exploitation capacity with the best arrangement and shortest computation time. A bio-inspired algorithm called the flower pollination algorithm mimics the pollination characteristics of plants' blooms. It mimics the backpack issue's small, medium, and large-dimensional scales. Two efficient time-varying exchange functions are combined with the S-shaped and V-shaped functions with the time-varying notion. In , the authors provide a quantum-inspired differential advancement algorithm with a grey wolf optimizer (QDGWO) to make strides in differences and meet execution in high-dimensional situations. The suggested method uses quantum computing standards such as quantum superposition states and gates. It, too, uses flexible transformation operations of differential advancement, hybrid operations of differential advancement, and quantum perception to construct unique arrangements as trial persons. The superior arrangements between the stored individuals and the trial individuals formed by change and hybrid operations are determined using determination operations.

GROUP COUNSELING OPTIMIZER
As was previously said, the GCO draws inspiration from human behavior to solve real-world problems (Eita & Fahmy, 2010;Ali & Khan, 2013). Several parameters must be established, including the population size, generational age, generational size of the counselors, selfcounseling probability, and self-belief counseling probability (SBCP). Figure 1 describes the flowchart of the GCO algorithm.

Main algorithm
The outline of the GCO algorithm is given in algorithm 1:

Selection of individuals for counseling
The counseling process of each individual continues component-wise in each generation. The new value of each component is obtained from the previous values of the same component using one of the following three strategies: • Other-members counseling • Self-belief counseling (use self-best values) • Self-counseling To influence a person's decision, the creators of the original GCO algorithm (Eita & Fahmy, 2010) provide other members with counseling and self-counseling techniques. However, in Ali & Khan (2013), the authors add a third technique called self-belief coaching to help an individual stay current.
Strategy, i.e., self-belief counseling, illustrates an individual's self-experience in decisionmaking as we know that an individual's self-experience influences their decisions. This self-experience tries to limit any possible modification against what they believe based on their personal experience. Therefore, the authors introduce the self-belief counseling strategy into the algorithm to make the counseling process more realistic.
For each component, we generate a random number of self-counseling decisive coefficients (sdc) in the range [0, 1]. If ''sdc'' is less than self-counseling probability (scp), then we do self-counseling; else, we do self-belief or other-members counseling. Now we generate a random number self-belief counseling decisive coefficient ''scdc'' in the range [0, 1]. If ''scdc'' is less than the self-belief counseling probability (scdc), use the self-belief counseling strategy; otherwise, use other member counseling strategies. The self-counseling operator covers the whole range of each component at the start of the search and then uses a nonlinear function to limit the range covered over time. So, self-counseling produces a highly explorative behavior at the beginning of the search, and the influence of the self-counseling operator reduces as the number of generations grows.
The process of computing the new value of each component is given in algorithm 2. Where,

Updating individual best position
If the present position leads to the best value, replace the best position; otherwise, do not change the best position. If the current and best positions are the same, then we can randomly select any position.

KNAPSACK PROBLEM
The 0/1 knapsack problem is a combinatorial problem. 'W ' is the positive capacity of a knapsack. An individual can insert a set of S different items in the knapsack. The weight of item 'i' is a positive integer 'wi', while the value of item 'i' is a positive integer vi (Singh, 2011). The objective is to:

Example of 0/1 knapsack problem
Assume that there is a knapsack with a size of 15 and many objects of varying weights and values. Within the constraints of the knapsack's capacity, we wish to maximize the worth of goods contained in the knapsack. Four objects were used (A, B, C, and D). The following are their weights and values as shown in Table 1: We want to maximize the total value: There are 24 potential subsets of objects for this problem, as shown in Table 2: The best solution satisfies the constraint while also providing the highest total value. The rows in italics face meeting the condition in our situation. As a result, the best value for the given constraint (W = 15) is 90, which is reached with B and D items.

RESULTS AND DISCUSSION
The item representation, individual encoding, experimental setup, and conclusions are discussed in this section.

Representation of the items
To represent all items, we need a table with three rows, item #, weights, and values, as seen in Table 3:

Encoding an individual
An array of the same size represents an individual as the number of elements in the array. The item included in the knapsack is denoted by 1; if not included, indicated by 0, but the total weight is always less than or equal to the knapsack size. For example, the second and fourth items are packed in the knapsack, as shown in Table 4. A table called ''population'' is used to represent the entire population. The rows represent the number of individuals, and the columns represent the items that might be carried in the knapsack.

Fitness function
Each individual's fitness is equal to the sum of the values of selected items for the knapsack.

Termination condition
After achieving the provided criteria (maximum number of generations or maximum assigned profit value), the program will terminate. The whole process is given in Fig. 2.

Experimental setup
MATLAB R2018a has been used to develop the GCO algorithm-based solution to solve the 0/1 knapsack problem. A thorough analysis was performed on the performance impact of the parameters used in the GCO algorithm. The three knapsack problems with different weights are given in Tables 5 to 7. These problems were used for various experiments. Experiment 1: At the same time, we have changed the number of counselors. Analysis was performed by 1 to 5 counselors. The other settings were left alone and followed (Ali & Khan, 2013) exactly. Experiment 2: The number of function evaluations was changed from 200 to 1,000, as given in Tables 8 to 10. We changed the population sizes to 10, 20, 30, 40, and 50 while keeping the number of generations equal to 100. The other settings were left alone and followed (Ali & Khan, 2013) exactly. Experiment 3: The number of function evaluations was changed from 200 to 1,000, as given in Tables 11 to 13. We changed the number of generations to 20, 40, 60, 80, and 100 while keeping the population size equal to 100. The other settings were left alone and followed (Ali & Khan, 2013) exactly. Experiment 4: In this experiment, we changed the self-belief counseling probability. The results are produced by varying the self-belief counseling probability from 10% to 90%,  as given in Tables 14 to 16. The other settings were left alone and followed (Ali & Khan, 2013) exactly. Experiment 5: In this experiment, we changed the self-counseling probability. The results are produced by varying the self-counseling probability from 10% to 90%, as given in Tables 17 to 19. The other settings were left alone and followed (Ali & Khan, 2013) exactly.
The following subsections explain the findings.

Experiment 1
This experiment sought to determine how the GCO algorithm's use of counselors affected its ability to solve the 0/1 knapsack problem. We compare the GCO results by varying the number of counselors using three different knapsack problems. Tables 8 to 10 show that the average and standard deviation of results produced by varying the number of counselors are best when the number of counsellors is equal to 1 for all three knapsack problems. So we should use only one counselor for knapsack problems.

Experiment 2
This experiment was designed to find the impact of the number of function evaluations and population size in the GCO algorithm when solving the 0/1 knapsack problem. We compare the GCO results by varying the number of function evaluations using three different knapsack problems.
Tables 11 to 13 show that the error decreases as the number of function evaluations increases. Because the average and standard deviation of results produced by varying the number of function evaluations are minima when the number of functions is equal to 1,000 for all three knapsack problems, we can say that GCO does not trap knapsack problems at a local optimum.

Experiment 3
This experiment aimed to determine how the GCO algorithm's function evaluations and generation count affected its ability to solve the 0/1 knapsack problem. We compare the GCO results by varying the number of function evaluations using three different knapsack problems. Tables 14 to 16 show that the error decreases as the number of function evaluations increases. Because the average and standard deviation of results produced by varying the number of function evaluations are minima when functions are equal to 1,000 for all three knapsack problems, we can say that GCO is not a trap for knapsack problems at the local optimum.
Comparing the results produced in experiments 2 and 3 shows that increasing the number of generations is more effective than a population. So, we use more generations except for the population.

Experiment 4
This experiment aimed to determine how the self-belief counseling probability affected the GCO algorithm's capacity to solve the 0/1 knapsack problem. Compare the GCO results  19 show that the average and standard deviation results produced by varying the self-belief-counseling probability are best at 70% for two out of three knapsack problems. So we should use a 70% self-belief-counseling probability for knapsack problems.

Experiment 5
This experiment aimed to determine how the self-counseling probability affected the GCO algorithm's capacity to solve the 0/1 knapsack problem. We compare the GCO results by varying the self-counseling probability from 10% to 90% using three knapsack problems.
Tables 20 to 22 show that the average and standard deviation of results produced by varying the self-counseling probability is best at 50% for two out of three knapsack problems. So we should use a 50% self-belief-counselling probability for knapsack problems.
A proposed solution for the 0/1 knapsack problem based on GCO is implemented in MATLAB R2018a. GCO advanced parameter settings are initialized as follows: • The population size is equal to 50; • The maximum number of generations increases from 20 to 100; • The number of counselors is equal to 1; • self-belief-counseling probability is equal to 70%; • self-counseling probability is equal to 50%; • Max_mdf is equal to 0.5; In all experiments, we report results obtained from 100 independent runs. The best results are presented in all cases.

Results
Our experiments use the 0/1 knapsack problem with three different knapsack capacities. Details of the 0/1 knapsack problem are shown in Table 2 to Table 4.
Set the population size to 20 and vary the number of generations from 20 to 100 to generate results. Tables 5 to 7 show the maximum fit found after 100 runs of the algorithm in each generation. The results demonstrate the usefulness of GCO for the 0/1 knapsack problem. They show that for all numbers of function evaluations, it yields results close to those of the dynamic programming approach for all three problems. Diff = ((Optimal value -GCO Optimal value)/ Optimal value) *100 Various problem sizes are present in the test scenarios to examine the effectiveness of the proposed algorithm. The numbers of items that sizes are 20, 40, 60, and 80 having the size of knapsack 125, 400, 800, and 1,150 respectively. We apply the dynamic programming and GOC algorithm to know the optimal values of the given problem.
In Table 23, the number of items is 20, having a knapsack size of 125. The optimal value is 261 according to the dynamic programming technique, and the result produced by the GCO is also 261. So the difference between dynamic programming and the proposed algorithm is zero.
In Table 24, the number of items is 40, having a knapsack size of 400. The optimal value is 741 according to the dynamic programming technique, and the result produced by the GCO is also 735. So the difference between the dynamic programming and the proposed algorithm is 0.80%.