knapsack problem solved by genetic algorithms

20
Computational intelligence Stavros Charitakis MTP 112 Stelios Krasadakis MTP 117 Knapsack Problem solved by Genetic Algorithms Supervisor : Professor G. Papadourakis 1/11/2015 Project: Evolutionary Computation

Upload: stelios-krasadakis

Post on 06-Apr-2017

350 views

Category:

Education


4 download

TRANSCRIPT

Page 1: Knapsack problem solved by Genetic Algorithms

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

Page 2: Knapsack problem solved by Genetic Algorithms

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.

Page 3: Knapsack problem solved by Genetic Algorithms

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.

Page 4: Knapsack problem solved by Genetic Algorithms

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

Page 5: Knapsack problem solved by Genetic Algorithms

Genetic vs Dynamic

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

Knapsack Problem NP problem

Page 6: Knapsack problem solved by Genetic Algorithms

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.

Page 7: Knapsack problem solved by Genetic Algorithms

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

Page 8: Knapsack problem solved by Genetic Algorithms

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

Page 9: Knapsack problem solved by Genetic Algorithms

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.

Page 10: Knapsack problem solved by Genetic Algorithms

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.

Page 11: Knapsack problem solved by Genetic Algorithms

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

Page 12: Knapsack problem solved by Genetic Algorithms

Output and Results

Optimal list

Criterion met

Page 13: Knapsack problem solved by Genetic Algorithms

Basic EA Code (1)Initialize Population

Page 14: Knapsack problem solved by Genetic Algorithms

Basic EA Code (2)Evaluate Population – Fitness Function

Page 15: Knapsack problem solved by Genetic Algorithms

Basic EA Code (3)Breed Population

Page 16: Knapsack problem solved by Genetic Algorithms

Basic EA Code (4)Crossover

Page 17: Knapsack problem solved by Genetic Algorithms

Basic EA Code (5)Mutation

Page 18: Knapsack problem solved by Genetic Algorithms

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

Page 19: Knapsack problem solved by Genetic Algorithms

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.

Page 20: Knapsack problem solved by Genetic Algorithms