A Genetic Algorithm to Solve the Multidimensional Knapsack Problem

In this paper, The Multidimensional Knapsack Problem (MKP) which occurs in many different applications is studied and a genetic algorithm to solve the MKP is proposed. Unlike the technique of the classical genetic algorithm, initial population is not randomly generated in the proposed algorithm, thus the solution space is scanned more efficiently. Moreover, the algorithm is written in C programming language and is tested on randomly generated instances. It is seen that the algorithm yields optimal solutions for all instances.


INTRODUCTION
Knapsack problems have been intensively studied recently due to its simple structure and the more complex problems can be solved through knapsack problems.The problems such as capital budgeting, cargo loading and project selection problem can be modeled by knapsack problems [4].The multidimensional knapsack problem (MKP) is special case of the classical 0-1 knapsack problem, and it has more than one constraint.The MKP is a well-studied, NP-hard combinatorial optimization problem occurring in many different applications and there is no FPTAS for two dimensional knapsack problem unless P=NP, [9].
The MKP can be stated as follows: Consider a set of projects (j = 1,...,n) and a set of resources (i = 1,...,m).Each project has assigned a profit 0 j p  and resource consumption values 0 ij w  .The problem is to find a subset of all projects that leads to the maximum possible profit and not exceeding given resource limits i c [13].
It is seen that there are more constraints unlike the general KP.The problem cen be defined by the following integer linear programming:    , whereas finding a feasible solution can be as hard as finding an optimal solution in general integer programming [11].
The first examples have been exhibited by Lorie and Savage and by Manne and Markowitz as a capital budgeting model.There is a comprehensive overview of the results for the MKP by Kellerer et al. [9].A recent review of the MKP was given by Fr´eville [3].Besides the method currently yielding the best results, at least for commonly used benchmark instances, was described by Vasquez and Hao [16] and has recently been refined by Vasquez and Vimont [17].It is a hybrid approach based on tabu search.Moreover, there are studies of Gilmore and Gomory [9]; Weingartner and Ness [9]; Shih [9]; Gavish and Pirkul [5]; Glover and Kochenberger [9]; Chu and Beasley [2], Raidl and Gottlieb [7,14] and Puchinger et al. [12] in the litarature.

GENETIC ALGORITHMS FOR MKP
Genetic Algorithms (GA), which find application in bioinformatics, phylogenetics, computational science, engineering, economics, chemistry, manufacturing, mathematics, physics, pharmacometrics and other fields are search algorithms based on natural selection and genetics.These algorithms belong to the larger class of evolutionary algorithms (EA), that generate solutions to optimization problems using techniques inspired by natural evolution, such as inheritance, mutation, selection, and crossover.It can be said that the strongest individuals in a population will have a better chance to transfer their genes to the next generation.
In a genetic algorithm, a population of candidate solutions to an optimization problem is evolved toward better solutions.Each candidate solution has a set of properties which can be mutated and altered; traditionally, solutions are represented in binary as strings of 0s and 1s, but other encodings are also possible.
The evolution usually starts from a population of randomly generated individuals and happens in generations.In each generation, the fitness of every individual in the population is evaluated, the more fit individuals are stochastically selected from the current population, and each individual's genome is modified (recombined and possibly randomly mutated) to form a new population.The new population is then used in the next iteration of the algorithm.Commonly, the algorithm terminates when either a maximum number of generations has been produced, or a satisfactory fitness level has been reached for the population, [6].
The reproduction can be done in three ways :  Pure Reproduction -The individual is copied directly into the next generation  Crossover -Two individuals are selected and their genes are crossed at some point, as the first part of the new individual comes from one parent and the last part from the other. Mutation -An individual is selected, and one bit is changed.
Evolutionary algorithms is an important subject of metaheuristics.The early papers have not successfully proved that genetic algorithms were an effective heuristic tool for the MKP.Khuri et al. [10] extended previous work for the single constraint knapsack problem.A similar study is given in Battiti and Tecchioli [1].Thiel and Voss showed that a standard GA using a direct search in the complete search space is not able to obtain good solutions for the MKP, except for small problems [15].Moreover, they investigated the combination of GA with tabu search and obtained promising results.Chu and Beasley gave the first successful implementation of GA's by restricting the genetic algorithms to search only the feasible search space.Finally, Haul and Voβ enhanced the performance of GA's by using surrogate constraints [8].

A NEW GENETIC ALGORITHM FOR MKP
The steps of the algorithm are as follows: [GA1] Each of m constraints is handled seperately and its optimal solution is found by dynamic programming method.The total frequencies of occurrence of items that are located in the solution vectors are found, then they are sorted in descending order and index sequence I is obtained.
[GA2] The first n elements of the initial population are established in a way that the item concerning the current index is taken as long as it does not exceed knapsack capacities starting with the i th element of index sequence I (1 im  ) at each step.
[GA3] Each of m constraints is handled seperately and j ij pw , (1 im  ), values are calculated.The relaxed solutions of each constraint are found, then index sequence J is obtained by sorting the frequencies of entering the solution of each item in descending order.
[GA4] The other n elements of the initial population are established in a way that the item concerning the current index is taken as long as it does not exceed knapsack capacities starting with the j th element of index sequence J (1 jn ).
[GA5] The coefficients of the objective function, j p , are sorted in descending order and index sequence K is obtained.
[GA6] Each individual of the population consisting of 2*n elements is crossed with all other individuals.If there is an item which can be taken for the generated individual, the item concerning the current index is taken as long as it does not exceed knapsack capacities starting with the first element of index sequence K(1 kn ).The individual that has the maximum value of the objective function in the population is assigned as the record.

[GA7]
Step [GA6] is repeated until the iteration number is n.
[GA8] The record is written and the algorithm ends.
Unlike the technique of the classical genetic algorithm, initial population is not randomly generated in this algorithm through the steps [GA1]...[GA4], thus the solution space is scanned much more efficiently.

COMPUTATIONAL EXPERIMENTS
Computational experiments have been carried out generating random problems for The optimal values of the problems have been found by GAMS IDE and shown in Table 1.
The algorithm has been written in C language and it has been observed that the proposed algorithm yields optimal results when it is run for 100 problems.The solution times are given in Table 2.
The parameters which affect the running time of the algorithm are m, n and i c . Figure 1 shows the time increment with respect to parameter m, and Figure 2 shows the time increment with respect to parameter n.As it is seen in Table 2 and the figures, while parameter m affects the running time of the program linearly, parameter n affects the time 3rd degree parabolically.
In order to observe how the capacity of the knapsack affects the running time, computational experiments have been carried out for n=100, m:10,20,…100.The values of i c are determined by taking 25 percent, 45 percent, 55 percent, 75 percent off total weight of the items in i th constraint.The optimal values are shown in Table 3, and the running times are given in Table 4 and Figure 3.The properties of the computer that has been used in computational experiments are Intel CORE 2 CPU (2.8 GHz) and 3 GB RAM, besides all problems and source codes are available in the adress http://fen.ege.edu.tr/~murateb/mknapGA/.

CONCLUSION
In this paper, The Multidimensional Knapsack Problem (MKP) which occurs in many different applications such as capital budgeting, cargo loading, project selection and which is an NP-hard problem has been studied.A new genetic algorithm to solve the MKP has been proposed.Unlike the technique of the classical genetic algorithm, initial population is not randomly generated in the proposed algorithm, thus the solution space is scanned more efficiently.Moreover, the algorithm is written in C programming language and is tested on randomly generated instances.It is seen that the algorithm yields optimal solutions for all instances.The properties of the computer that has been used in computational experiments are Intel CORE 2 CPU (2.8 GHz) and 3 GB RAM.As it is seen in Table 2 and the figures, while parameter m affects the running time of the program linearly, parameter n affects the time parabolically.Furthermore, problems have been generated in order to observe how the capacity of the knapsack affects the running time and the results have been given in the tables and figures.

6.
of project j, ij w : consumption of project j from resource i, i c : capacity of resource i, 10,20,…,100 and n:10,20,…,100.In all instances, the capacity of each knapsack ( i c ) in each constraint is obtained by taking 25 percent off total weight of the items.

Figure 1 .Figure 2 .
Figure 1.The time increment with respect to parameter m