Latex 1
Latex 1
Latex 1
Abstract
During the last decades solving problem to accomplish the best opti-
mization using different algorithms has attracted the attention of many
researchers. In this paper we describe a research on solving 0/1 knapsack
problem using different algorithm .The Knapsack Problem is an exam-
ple of optimization problem,which seek the maximum object in knapsack
without exceeding its capacity,is defined to be is recognized to be NP-hard.
This paper describe aresearch project on using differant algorithm to
solve the 0-1 knapsack problem,Subsequently comparisons are made with
a these algorithm to decide which one is best in solving 0/1 knapsack
problem .
In this paper we use the same computational example to solve this prob-
lem using differant algorithem the output shows the behaviour of each
algorithm in the same problem space.
1 Introduction
This paper proposes different algorithms to solve 0/1 knapsack problem,we use
different Algorithms to solve the problem since we want to focus on how each
affects search behavior in the same problem space.The goals of the paper are to
provide additional insights into how each algorithm works,and to decide which
algorithm gives best performance in problem like 0/1knapsack problem.
The paper contains brief description of the basic idea and elements of the 0/1
Knapsack Problem ,implementation of the 0-1 Knapsack Problem using genetic
algorithm greedy and dynamic algorithm, finally computational results shows
the behaviour of each algorithm in the same problem space.
1
Genetic algorithm focus on probabilistic and stochastic basis to search through
a space of potential solutions using randomness as a major factor to make de-
cisions,since they can provide solutions to problems where often standard al-
gorithms have failed. In this paper we implemented Roulette-wheel selection
as a selection functions. The results from both of them differed depending on
whether we used elitism or not. Elitism significantly improved the performance
of the roulette-wheel function. Moreover, we tested the program with different
crossover ratios and single and double crossover points but the results given
were not that different.
2
2.1 Example of a 0-1 Knapsack
In this paper we solved a given knapsack problem in different algorithem ,given
some items, pack the knapsack to get the maximum total value,each item has
some weight and some value,and the total knapsack capacity is 10.In order to
find the best solution we have to identify a subset that meets the constraint and
has the maximum total benefit.
3 Implementation
3.1 Implementation of the 0-1 KP Using Genetic Algo-
rithm
Genetic algorithm are among search procedures based on natural selection and
natural genetics,they randomly create an initial population of individuals. Then
they use genetic operators to yield new offspring[*].
For this problem there are 24 possiblesubsetsof items :
A B C D weight of set benefit of set subset meets constraint
0 0 0 0 0 0 reject
0 0 0 1 3 50 reject
0 0 1 0 6 30 reject
0 0 1 1 9 80 accept
0 1 0 0 4 40 reject
0 1 0 1 7 90 accept
0 1 1 0 10 70 accept
0 1 1 1 15 120 reject
1 0 0 0 5 10 accept
1 0 0 1 8 60 accept
1 0 1 0 11 40 reject
1 0 1 1 14 90 reject
1 1 0 0 9 50 accept
1 1 0 1 12 100 reject
1 1 1 1 18 130 reject
subsetmeetsconstrain : meanmeetknapsackcapacity.
3
3.2 Representation Of Items And Encoding Of The Chro-
mosomes
We use a data structure, called cell, with two fields (Value and weight) to rep-
resent every item[*]. Then we use an array of type cell to store all items in it,
which looks as follows:
4
A B C D weight of set benefit of set
0 0 1 1 9 80
0 1 0 1 7 90
0 1 1 0 10 70
1 0 0 1 8 60
1 1 0 0 9 50
If yes select the chromosome with the most benefit in this example we
selecte chromosome with greater benefit.
6. Does 40% have the same fit value? and Is the number of generations greater
than the limit?
If not go to step 3 If yes exit.
5
3.5 Using Roulette-Wheel Selection As Selection Func-
tion
In this paper we use Roulette-wheel combined with elitism,roulette-wheel is a
simple method of implementing fitness-proportionate selection it is conceptually
equal to giving each individual a slice of a circular roulette wheel equal in area
to the individuals fitness.The wheel is spun N times, where N is the number
of the individuals in the population (in our case N = Size).On each spin, the
individual under wheels marker is selected to be in the pool of parents for the
next generation [*].
6
4.1 Main Operation
Step1: Structure: Characterize the structure of an optimal solution by decom-
pose the problem into smaller problems,and find a relation between the structure
of the optimal solution of the original problem and the solutions of the smaller
problems.
Step2:Principle of Optimality: Recursively define the value of an optimal so-
lution;express the solution of the original problem in terms of optimal solutions
for smaller problems.
Step 3:Bottom-up computation: Compute the value of an optimal solution
in a bottom-up fashion by using a table structure,using iteration not recursion.
Bottom: V[0,w]=0 0≤ w ≤ W
Bottomupcomputationmeancomputingthetableusing
V [i, w] = max(V [i − 1, w], vi + V [i − 1, W − wi])
rowbyrow.
Step4 : Construction of optimal solution:Constructoptimalsolutionf romcomputedinf ormation.
Steps 3 and 4 may often be combined.
v[i,w] 0 1 2 3 4 5 6 7 8 9 10
i=0 0 0 0 0 0 10 10 10 10 10 10
1 0 0 0 0 40 40 40 40 40 50 50
2 0 0 0 0 40 40 40 40 40 50 70
2 0 0 0 50 50 50 50 90 90 90 90
T hef inaloutputisv[4, 10] = 90
7
}
T imecomplexity : Clearly, O(nW )