knapsack problem solved by genetic algorithms

Post on 06-Apr-2017

350 Views

Category:

Education

4 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Computational intelligence

Stavros Charitakis MTP 112Stelios Krasadakis MTP 117

Knapsack Problem solved by Genetic Algorithms

Supervisor : Professor G. Papadourakis

1/11/2015

Project: Evolutionary Computation

HistoryKnapsack problem first studied by Tobias Dantzig in 1897.

• 1950s First Dynamic programming algorithm, R. Bellman• 1960s First Branch and Bound algorithm• 1970s First Polynomial Approximation Schemes, Sahni• 1990s First Genetic Algorithms implementations, Chu and Beasly

A 1998 study of the Stony Brook University showed, that the knapsack problem was the 18th most popular algorithmic problem.

Problem DefinitionThe knapsack problem is a problem in combinatorial optimization:Given a set of items (N), each with a weight (Vi) and a value (Bi), determine the number of each item (i) to include in a collection so that the total weight is less than or equal to a given limit (V) and the total value is as large as possible. It derives its name from the problem faced by someone who is constrained by a fixed-size knapsack and must fill it with the most useful items.

Real World Examples Luggage Having a Journey with a low cost company like Ryanair with a limitation at your handbag at 10 Kg. What items should you take?

Burglar’s Dilemma The burglar is facing a challenge. There are many items to choose between, each with different value and weight. The burglar wants to maximize the sum of the values of the objects, but the sum of the weight has to be less than 20

Genetic vs Dynamic

Dynamic Programming number of items and the capacityGenetic Algorithm number of items and number of population

Knapsack Problem NP problem

Software DesignI. User inputs the number of items he wants.

II. User inputs the name, the weight and the value of each item.

III. User inputs population, generation, crossover, mutation .

IV. Program is running till conditions meet (3 generations without better evolution).

V. Results indicate the whole process and inform the user about the itemshe should take to maximize his value.

Fitness Function

Item Weight

Value

Laptop 6 340Television 21 560Painting 10 380Total knapsack capacity = 28

The fitness function sums the corresponding weights and values for each population member one by one.  It then compares the population member’s total weight to the knapsack capacity. if(knapsack capacity >= population’s member total weight)fitness value = population’s member total valueelsefitness value = 0 A/A Populatio

n (individuals)

Fitness

1 010 5602 101 7203 011 04 110 900

Application DevelopmentProgramming Language: JavaEnvironment: Eclipse

Building code from scratch based on other free source code:• https://gist.github.com/NilsHaldenwang/972159 Ruby Programming Language• https://github.com/mmmayo13/knapsack-problem-ga

Graphical User Interface Design (1)

Textbox outputs:1) Population and Fitness over generations.2) Best solution and mean Fitness over each generation3) If crossover and mutation was implemented and how many times occurred.4) Informs the user with the items he should take.

User setting the number of items he wants to take with him.

Graphical User Interface Design (2)User

setting the number of items he wants to take with him.

Program informs the user, how many items are left to input.

Input dialog pop up in order to take user inputs for each item with 3 elements, item name, item value and item weight.

Graphical User Interface Design (3)

Text fields unlock, user just configured 10 for capacity, 100 population, 200 generations, crossover prob. 80% and mutation prob. 1%.

Finally he’s ready for execution.

Calculate optimal list of items

Output and Results

Optimal list

Criterion met

Basic EA Code (1)Initialize Population

Basic EA Code (2)Evaluate Population – Fitness Function

Basic EA Code (3)Breed Population

Basic EA Code (4)Crossover

Basic EA Code (5)Mutation

References[1] M. Lagoudakis, “The 0-1 knapsack problem—An introductory survey,” Citeseer.

Nj. Nec. Com/151553. Html, 1996.

[2] M. Hristakeva and D. Shrestha, “Solving the 0-1 knapsack problem with genetic algorithms,” Midwest Instr. Comput. …, 2004.

[3] M. Hristakeva and D. Shrestha, “Different Approaches to Solve the 0/1 Knapsack Problem,” Retrieved Novemb., pp. 0–14, 2004.

[4] J. J. Bartholdi, “Building Intuition,” vol. 115, 2008.

[5] http://www.nils-haldenwang.de/computer-science/computational-intelligence/genetic-algorithm-vs-0-1-knapsack

[6] https://github.com/mmmayo13/knapsack-problem-ga

References (2)[7] L. S. - and M. L. -, “Comparative Study on the Knapsack problem based on PAR

Method and other Methods,” Int. J. Digit. Content Technol. its Appl., vol. 6, no. 18, pp. 211–218, 2012.

[8] C. H. Papadimitriou, “On the Complexity of Integer Programming,” vol. 28, no. 4, pp. 765–768, 1981.

[9] R. C. Eberhart and Y. Shi, Computational Intelligence: Concepts to Implementations, no. March. 2007.[10] M. Melanie, “An introduction to genetic algorithms,” Cambridge, Massachusetts

London, England, …, p. 162, 1996.[11] L. S. - and M. L. -, “Comparative Study on the Knapsack problem based on PAR

Method and other Methods,” Int. J. Digit. Content Technol. its Appl., vol. 6, no. 18, pp. 211–218, 2012.

top related