Using Genetic Algorithms to Solve the Box Stacking Problem

Similar documents
Geometric Semantic Genetic Programming ~ Theory & Practice ~

Mutations for Permutations

Genetic Algorithms. Kang Zheng Karl Schober

implementing the breadth-first search algorithm implementing the depth-first search algorithm

Planning and Search. Genetic algorithms. Genetic algorithms 1

CS5401 FS2015 Exam 1 Key

MATLAB Based Optimization Techniques and Parallel Computing

CHAPTER 6 HYBRID AI BASED IMAGE CLASSIFICATION TECHNIQUES

Multi-objective Optimization

Suppose you have a problem You don t know how to solve it What can you do? Can you use a computer to somehow find a solution for you?

March 19, Heuristics for Optimization. Outline. Problem formulation. Genetic algorithms

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/27/17

The Genetic Algorithm for finding the maxima of single-variable functions

Neural Network Weight Selection Using Genetic Algorithms

A Genetic Algorithm Applied to Graph Problems Involving Subsets of Vertices

Chapter 14 Global Search Algorithms

Literature Review On Implementing Binary Knapsack problem

Escaping Local Optima: Genetic Algorithm

GENETIC ALGORITHM with Hands-On exercise

ARTIFICIAL INTELLIGENCE (CSCU9YE ) LECTURE 5: EVOLUTIONARY ALGORITHMS

Problem Set 6 Solutions

A Genetic Algorithm for Minimum Tetrahedralization of a Convex Polyhedron

Chapter 15 Introduction to Linear Programming

Catalan Numbers. Table 1: Balanced Parentheses

Genetic Algorithms for Vision and Pattern Recognition

EVOLVING LEGO. Exploring the impact of alternative encodings on the performance of evolutionary algorithms. 1. Introduction

Lecture 6: Genetic Algorithm. An Introduction to Meta-Heuristics, Produced by Qiangfu Zhao (Since 2012), All rights reserved

1 Probability Review. CS 124 Section #8 Hashing, Skip Lists 3/20/17. Expectation (weighted average): the expectation of a random quantity X is:

Adaptive Crossover in Genetic Algorithms Using Statistics Mechanism

Introduction to Genetic Algorithms. Based on Chapter 10 of Marsland Chapter 9 of Mitchell

Review: Final Exam CPSC Artificial Intelligence Michael M. Richter

3.6.2 Generating admissible heuristics from relaxed problems

Genetic programming. Lecture Genetic Programming. LISP as a GP language. LISP structure. S-expressions

Genetic Algorithms. Genetic Algorithms

Evolutionary Algorithms

Genetic Algorithms. PHY 604: Computational Methods in Physics and Astrophysics II

A New Selection Operator - CSM in Genetic Algorithms for Solving the TSP

Network Routing Protocol using Genetic Algorithms

Regression Test Case Prioritization using Genetic Algorithm

Bulgarian Math Olympiads with a Challenge Twist

4.1 COMPUTATIONAL THINKING AND PROBLEM-SOLVING

Job Shop Scheduling Problem (JSSP) Genetic Algorithms Critical Block and DG distance Neighbourhood Search

Evolutionary Linkage Creation between Information Sources in P2P Networks

Two Efficient Algorithms for VLSI Floorplanning. Chris Holmes Peter Sassone

Uninformed Search Methods. Informed Search Methods. Midterm Exam 3/13/18. Thursday, March 15, 7:30 9:30 p.m. room 125 Ag Hall

Midterm Examination CS540-2: Introduction to Artificial Intelligence

Spring 2007 Midterm Exam

CHAPTER 6 REAL-VALUED GENETIC ALGORITHMS

A GENETIC ALGORITHM FOR CLUSTERING ON VERY LARGE DATA SETS

Network Reconfiguration for Loss Reduction in Electrical Distribution System Using Genetic Algorithm

Balanced Binary Search Trees. Victor Gao

Chapter 4: Trees. 4.2 For node B :

Automata Construct with Genetic Algorithm

6.001 Notes: Section 6.1

OVERVIEW & RECAP COLE OTT MILESTONE WRITEUP GENERALIZABLE IMAGE ANALOGIES FOCUS

Topological Machining Fixture Layout Synthesis Using Genetic Algorithms

Evolutionary Computation Algorithms for Cryptanalysis: A Study

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays)

Genetic Algorithms Variations and Implementation Issues

CS301 - Data Structures Glossary By

Traffic Signal Control Based On Fuzzy Artificial Neural Networks With Particle Swarm Optimization

GENETIC ALGORITHM VERSUS PARTICLE SWARM OPTIMIZATION IN N-QUEEN PROBLEM

SIMULATION APPROACH OF CUTTING TOOL MOVEMENT USING ARTIFICIAL INTELLIGENCE METHOD

Genetic Algorithm for Seismic Velocity Picking

Genetic Algorithms. Chapter 3

5. Computational Geometry, Benchmarks and Algorithms for Rectangular and Irregular Packing. 6. Meta-heuristic Algorithms and Rectangular Packing

Algorithm Design (4) Metaheuristics

Introduction. A very important step in physical design cycle. It is the process of arranging a set of modules on the layout surface.

Optimization of Noisy Fitness Functions by means of Genetic Algorithms using History of Search with Test of Estimation

ISA[k] Trees: a Class of Binary Search Trees with Minimal or Near Minimal Internal Path Length

How Santa Fe Ants Evolve

Classification of Optimization Problems and the Place of Calculus of Variations in it

Evolutionary Computation

Parallelizing SAT Solver With specific application on solving Sudoku Puzzles

Hybridization EVOLUTIONARY COMPUTING. Reasons for Hybridization - 1. Naming. Reasons for Hybridization - 3. Reasons for Hybridization - 2

Multiobjective Job-Shop Scheduling With Genetic Algorithms Using a New Representation and Standard Uniform Crossover

Advanced Search Genetic algorithm

The Binary Genetic Algorithm. Universidad de los Andes-CODENSA

Introduction to Optimization

Subset sum problem and dynamic programming

Let the dynamic table support the operations TABLE-INSERT and TABLE-DELETE It is convenient to use the load factor ( )

Encoding Techniques in Genetic Algorithms

Optimization Methods in Management Science

Evolutionary Algorithms: Lecture 4. Department of Cybernetics, CTU Prague.

Introduction to Optimization

Introduction to Genetic Algorithms

COUPLING TRNSYS AND MATLAB FOR GENETIC ALGORITHM OPTIMIZATION IN SUSTAINABLE BUILDING DESIGN

Massively Parallel Approximation Algorithms for the Knapsack Problem

AIRFOIL SHAPE OPTIMIZATION USING EVOLUTIONARY ALGORITHMS

Lecture 4. Convexity Robust cost functions Optimizing non-convex functions. 3B1B Optimization Michaelmas 2017 A. Zisserman

UNIT 4 Branch and Bound

Practical 4: The Integrate & Fire neuron

ECE 242 Data Structures and Algorithms. Trees IV. Lecture 21. Prof.

Midterm Examination CS 540-2: Introduction to Artificial Intelligence

1. Introduction. 2. Motivation and Problem Definition. Volume 8 Issue 2, February Susmita Mohapatra

An Evolutionary Approximation to Contrastive Divergence in Convolutional Restricted Boltzmann Machines

Introduction to Homogeneous coordinates

A Genetic Algorithm for Graph Matching using Graph Node Characteristics 1 2

2. A Bernoulli distribution has the following likelihood function for a data set D: N 1 N 1 + N 0

Transcription:

Using Genetic Algorithms to Solve the Box Stacking Problem Jenniffer Estrada, Kris Lee, Ryan Edgar October 7th, 2010 Abstract The box stacking or strip stacking problem is exceedingly difficult to solve using conventional methods due to the size of the solution space. An alternative to conventional methods is to use a genetic algorithm. Genetic algorithms search the solution space using the concepts of evolution. The core of the problem relies on how the boxes are stacked. In this problem, a left to right bottom up minimum stacking algorithm was implemented. Using this algorithm with a sequential cross-over and mutation functions yielded good results. For a known object set the algorithm obtained the best stacking of objects. The effect of different parameter values on the obtained solution was also explored. The parameters were varied individually and included the probability of cross-over and mutation, population size and terminating condition. In the end, the algorithm obtained the best results by using the ideal for each of the four parameters that were varied. Introduction A genetic algorithm is a type of search algorithm that emulates the process of natural selection. In general, a genetic algorithm will begin with an initial population and, from this base population, generate a new population from the individuals from the initial population which had the best fitness. Genetic algorithms emulate reproduction and evolutionary mutation. For reproduction, a crossover technique is used in which the genotype of two parent individuals is combined to obtain two new individuals which are included in the population. Mutation, as in evolution, acts on the genotype of a single individual and creates a new genotype which replaces the original in the population. The mission of crossover and mutation is to introduce variations into the population which can be evaluated in hopes of finding the best individual. This process is repeated until a terminating condition is meet. Quite often, these algorithms prove to be useful for optimization or classification problems. Problem Statement One application of genetic algorithms is solving a box stacking or container loading problem. In this problem set, there is a set of objects which must be packed into a given space, or container. The objective is to find the optimum loading such that all the objects fit and occupy the least amount of space. In some situations the stipulation is that the objects must fit into a given space. In others the objective might be to load as many objects as possible. And in yet other formulations of the problem the mission is to find an arrangement that must use all the objects and occupies the least amount of space. This final variation is the one which is to be examined in more detail. The problem states that there is a set of predefined fixed rectangular objects which must be stacked in a strip. The 1

strip is two dimensional and has a fixed width. The height of the strip is allowed to go to infinity or has high as the stacking requires. Thus, the objective is to minimize the height of the strip. This variation of the container loading problem was solved using the Genetic Algorithm MATLAB toolbox. Genetic Algorithm Implementation The Genetic Algorithms Toolbox in MATLAB was developed by Prof. Michael G. Kay at North Carolina State University and is available to the public. The toolbox contains a variety of concepts used in genetic algorithms and several demonstration scripts. A combination of altered scripts from Kay s toolbox and our own implementations of certain aspects of genetic algorithms were used to address the two dimensional stacking problem. The alterations were used to address conflicts that arose from the specific constraints of the 2-D packing problem, such as cross-over when two elements cannot be repeated. Representing an Individual Individuals are represented using a string of alternating indexes and boolean rotation values. The indexes are into the static list of objects. The boolean rotation values indicate whether the object should be stacked as is, a value of zero, or rotated 90 degrees, a value of one. An individual is therefore composed of an array of 2 N where N is the number of objects. The array below is an individual in which there are five objects to be stacked. Population Initialization {1, 0, 3, 0, 5, 1, 2, 1, 4, 0} Given a population size P and a number of objects N, we generate a population of P individuals, each of who will be a 2 N row vector. This is done by taking the list S = {1,..., N} and randomly choosing a value, say m, and then randomly choosing either a 1 or a 0, say 1. This indicates the the first object in our individual is the mth object from the original list and it has been rotated by 90 degrees. This process is repeated until S is empty. Once S is empty, we have our first individual, hence we repeat this process to generate P 1 more individuals. For an example of an output, if we have 5 objects and want to generate a population of size 5, running the code yields: {5, 0, 3, 0, 4, 1, 1, 0, 2, 0} {4, 1, 5, 1, 1, 0, 3, 1, 2, 1} {1, 0, 5, 0, 2, 0, 3, 1, 4, 0} {1, 1, 3, 1, 4, 0, 5, 1, 2, 1} {5, 0, 3, 0, 4, 1, 2, 0, 1, 0} Fitness Function For an individual, we will use the amount of empty space left after packing as a means of determining our fitness. By empty space, we mean the amount of area that is not occupied by an object after packing. Note that if there is no empty space, this means that the objects were packed 2

perfectly into the strip. However, there are collection of objects such that, no matter how they are packed into the strip, will never yield an empty space of zero. For example, if we have N objects where the first N 1 objects perfectly pack into the square 20 20, then we will always have a positive empty space value for any orderings or rotations of the objects. To compute the empty space value of a given individual, we calculate STRIP WIDTH h - LEAST AREA where STRIP WIDTH is a global variable that contains the width of the strip we are placing the objects, LEAST AREA is a global variable that contains the sum of the areas of the objects we are packing, and h is the height of the tallest point of the objects after they have been packed. Hence, to calculate the amount of empty space, we need to devise a method to calculate h. In order to calculate h, we need to pack the objects as they are listed in the individual. We will pack objects by first placing the first object in the bottom left corner of the strip. Then we place objects to the right of each other until we can place no more objects in the strip. To recap, our first step is to as place as many objects as possible next to each other on the bottom of the strip. We then search for the minimum height of the packed objects and stack as many objects next to each other on top of this minimum height. If we could not pack anything into the space, we increment the minimum height by one, thus giving us either the same minimum or a new one. After this, we search for the minimum height again and repeat. This is repeated until either we run out of objects, or the minimum height is the same as the maximum height. In the event that the minimum matches the maximum, this means that either we have completely packed the area with objects or the current object cannot be place in between any of the objects that have already been packed. Thus, we pack objects next to each starting from the left side of the strip at the tallest point of the already packed objects. This process is carried out until there are no more objects to pack. During this process, we keep track of the tallest point of the already packed objects. Hence, once the process has ended, we will have calculated our h. Now that we have calculated our h, we can calculate the empty space of a given individual. Since the Genetic Algorithm Toolbox is designed to find a maximum of a fitness function, we cannot just use the empty space of an individual. This is because the smaller the empty space, the better we have packed the objects. In order to correct for this, we need to find a value from which we can subtract the empty space of an individual. Hence, if this difference maximizes, then it must be that the empty space of the individual minimized. The value we will use is what we will call the worst empty space. This value represents the empty space left by packing the object on top of each other, rotated so that their height is greater than or equal to their width, starting from the bottom left corner. We calculate this value by evaluating STRIP WIDTH WORST HEIGHT- LEAST AREA, where WORST HEIGHT is a global variable that contains the sum of the heights of the objects, after they have been rotated so that their height is greater than or equal to their width. Using this value, we can now define our fitness function for an individual: f(individual) = STRIP WIDTH WORST HEIGHT LEAST AREA (STRIP WIDTH h LEAST AREA) = STRIP WIDTH (WORST HEIGHT h). Thus, to calculate the fitness of an individual, we need only compute WORST HEIGHT and h. 3

For an example of how this entire process is carried out, suppose that we have the following objects {2, 4} {3, 2} {1, 2} {2, 3} and are trying to pack these objects as best we can in a strip that had a width of 5. In other words, STRIP WIDTH = 5. Moreover, note that WORST HEIGHT = 4 + 3 + 2 + 3 = 12. We will find the fitness of the individual {1, 0, 3, 1, 2, 0, 4, 1}. Note that this individual says to pack the objects in the following order: the first object, the third object rotated by 90 degrees, the second object, and the fourth object rotated by 90 degrees. We will now pack these four objects into our strip. To keep track of this process, we will represent the strip as a row vector of length 5 where the entries indicate the current height of the objects packed in the strip. We start out as follows: {0, 0, 0, 0, 0}. This represents the empty strip with no objects placed in it. The first object to be place is the first object with no rotation. We place this object in the bottom left corner. Upon doing so, our strip vector now looks like this: {4, 4, 0, 0, 0}. Next, we see if we can place next object in our individual next to this one. The next object to be place is the third object rotated by 90 degrees. This object has width 2 and height 1, so it does fit. Hence our strip vector is now: {4, 4, 1, 1, 0}. We have now reached the point where we can no longer put any objects in the strip. Thus, we need to search for the minimum height of the already packed objects and see if there is room to place the next object in our individual. We find that the minimum is 0 and we only have room for an object of width one. The next object we need to place is the second object, which has a width of 3. Thus, this object cannot fit, so we increment the height at the fifth entry of the strip vector: {4, 4, 1, 1, 1}. We do this to signify that that 1-by-1 area cannot be occupied by an object, i.e. it has already been packed.. In addition, this is done so that now when we search for the minimum height of the currently packed items, we will find either the same index or a different one. For example, when we now search for a minimum, we will find that it is 1 and that it first occurs at the third index of our strip vector. We see now that we can pack our next object, thus we update the strip vector: {4, 4, 3, 3, 3}. Note that we have packed our object to the edge of the strip, i.e. we cannot put the last object next to this one. Again, we find the minimum of the currently packed objects. We find that it is 3 and first occurs at the third index of our strip vector. The last object to pack is fourth object rotated by 90 degrees. It has width 3 and height 2, thus it can be packed into this location. Our strip vector now looks like this: {4, 4, 5, 5, 5}. 4

We have packed all of the object, thus we find the maximum of the strip vector, which is 5. This is our h value. We can now calculate the fitness of our individual: f ({1, 0, 3, 1, 2, 0, 4, 1}) = STRIP WIDTH (WORST HEIGHT h) Hence, the fitness value of our individual is 35. Selection = 5 (12 5) = 35. The selection was performed using a linear rank algorithm. This means the selection pressure can be provided as an input and from that a probability that each individual of the population is determined. The probability the i th individual is selected is given by α + β i where α and β are constants provided by the equations below. α = [ ] 2 N m (N+1) 2 N(N 1) 2(m 1) β = N(N 1) The individuals were ordered from least fit to most fit where the last individual is the most fit. Once ordered, a probability was assigned to each using the linear rank formula. Finally, individuals were selected using a strategy in which a random number R was selected from (0, 1) and if i 1 α + β j < R < j=1 i α + β j for i > 1 or 0 < R < α + β for i = 1 then the i th individual is selected. Cross-Over Since each individual is a sequence in which order matters the standard cross-over cannot be performed. When dealing with ordered sequences a sequential single point cross-over can be used. In this algorithm, a random location is chosen between 1 and N, where N is the number of objects. This location dictates the number of index-rotation pairs which are taken from the beginning of each parent and placed immediately in the corresponding child. The remainder of each child is filled using the elements from the other parent. This process is performed by starting at the beginning of the second parent and copying pairs on to the end of the child if and only if the pair does not already exist in the child. Example If a random location of 3 is chosen with N = 5 then the following will be the result for a cross-over between two parents, p 1 and p 2, generating two children, c 1 and c 2. j=1 p 1 = {1, 0, 3, 0, 5, 1, 2, 1, 4, 0} p 2 = {2, 1, 1, 1, 3, 0, 4, 1, 5, 0} c 1 = {1, 0, 3, 0, 5, 1, 2, 1, 4, 1} c 2 = {2, 1, 1, 1, 3, 0, 5, 1, 4, 0} 5

Mutation The mutation algorithm takes in as arguments the parent string and generates randomly an option of either interchanging two elements or flipping the orientation of one of the elements within the sequence. Example If an operation of swapping two object positions (Ops = 1) with N = 5, is randomly chosen, then the following will be the result of one parent, p 1, generating one mutation, m 1. p 1 = {1, 0, 3, 0, 5, 1, 2, 1, 4, 0} m 1 = {1, 0, 2, 0, 5, 1, 3, 1, 4, 0} It is clearly visible that the mutation has occurred, in the swapping of the second and fourth element in the parent p 1 to create m 1. The indexes ranging from 1 to N are references to a pair of dimensions corresponding to the length and width of the particular element, constrained to odd index values within the sequence. If an operation of flipping the orientation of one element (Ops = 2) within the sequence is chosen randomly with N = 5, then the following will be the one parent, p 1, and resulting mutation, m 1. p 1 = {1, 0, 3, 0, 5, 1, 2, 1, 4, 0} m 1 = {1, 0, 3, 1, 5, 1, 2, 1, 4, 0} The binary bit, representing the orientation is bounded to only take on even indexes within the range of 0 to N within the sequence, is randomly chosen. Suppose the orientation of the second element in the sequence is flipped, then the value of 0 is switched to 1, or vice-versa. The value of 0 corresponds to the original orientation of the object as it was initially entered into the program. The algorithm allows for only one orientation of exactly one element to be flipped per mutation. Terminating Condition Deciding when to terminate the genetic algorithm is based on two decision statements. The first being if an ideal solution is reached, and the second being if the maximum number of generations is reached. If the objects do not fit perfectly in the strip, meaning wasted space will never reach zero, the maximum number of generations decision is used to terminate. This introduces inefficiencies because there could be many generations performed in which the population changes little or not at all. Even with this defect it is one of the simpler terminating conditions in both theory and implementation. Alternately, it is possible to terminate upon receiving an ideal solution because in the cases where the objects will fit perfectly into the strip with a certain height the wasted space will be zero. This means that as the individuals approach zero the results are getting better and better. Testing Once the genetic algorithm was implemented, it was used to evaluate several sets of objects. The objects were stored in the files objects#.txt where # was 1 through 5. For each file, the algorithm 6

searched for the minimum height. During the testing several parameters were varied: population size (n), crossover probability (P c ), mutation probability (P m ) and maximum number of generations (g). Each of these parameters were varied separately from the others. This resulted in a decreased testing time. The fixed values for non-varying parameters were n = 20, P c =.5, P m =.5 and g = 200. During the testing for each parameter the following sets were used for testing. n {510204080240} P c {0.01.05.1.2.3.5.6.7.8.91} P m {0.01.05.1.2.3.5.6.7.8.91} g {1002004008001200} All results were stored in comma separated value files which were later combined into a single results file. A condensed version of this file is included at the end of the report. As a final test the best value for each parameter was selected and a trial for each object set was run using those parameter values. Set N P c P m g Height 1 20 0.05 0.01 200 11 2 240 0.2 0.2 200 22 3 240 0.1 0.1 800 17 4 240 0.01 0.01 1200 17 5 240 0.5 0.2 800 68 Instead of performing 20 trials of the genetic 2 trials were performed due to the extended execution time of the genetic algorithm with the specified parameters. Results When the parameters (population size, probability of cross-over and mutation, and the maximum number of generations) were individually manipulated, the genetic algorithm seems to have the solution centered over the maximum, although it does have a small spread. In order to clearly demonstrate the performance of the genetic algorithm, lets benchmark our implementation against a known solution with the first set. Knowing the optimum dimensions of the 20x11, the best packing height is 11. The mean and variance of the first set with varying parameters was calculated and shown in the table below: Table 1: Variable Manipulation for Set 1 Population Cross-Over Mutation Max. Generations Mean 11.3333 11.3333 11.5833 11.6 Variance 0.2667 0.2424 0.2652 0.3 Table 1 clearly shows that the parameter variations produce a solution within the neighborhood of the optimum height of 11, with a reasonably small variance. 7

Even when each parameter that resulted in the best solution was picked and the combination was tested together in one run, the algorithm didn t consistently find the optimum solution. The first set with all the parameters that found the optimum, did find the optimum height of 11. This was not the case for the other sets. For example, the second set found the optimum at 21 on the multiple trials varying parameters while the run in which all the parameters that individually resulted in the optimum combined, found the optimum at 22. Conclusion Due to the stochastic nature of the genetic algorithm, the search for the optimum result is strongly dependent on how many times the algorithm is ran and what answer is good enough. Computational time was significantly affected with certain parameters such as population size and maximum number of generations. In conclusion, the genetic algorithm has a trade-off of getting the best answer with a cost of resources, such as computational time or money. 8