• No results found

The selection problem, in the previous chapter, was identified as being equivalent to the well-known one-dimensional knapsack problem, and a genetic algorithm (GA) was proposed to solve it. The proposed GA (see Algorithm 4.2) is a stan- dard GA implementation with standard chromosome representation and genetic operators i.e. selection, crossover, mutation. As GAs are well known and widely used across literature, we will not discuss in detail its general implementation and operation; we instead refer the reader to Goldberg [1989] and Hopgood [2001] where such detail is covered extensively.

In the selection GA, a candidate solution is represented as a chromosome which is encoded as an array of bits. The length of the array is equal to the total number of available jobs. Each bit in the array represents a unique job and can have its value set to 0 or 1, representing whether a job has been selected for inclusion into a container (i.e., the bit value is set to 1), or not (i.e., the bit value is set to 0). Each job represents a logical group of pallets that must all be completely packed together in the same container. The quality of a chromosome or candidate solution, known as its fitness, is the total sum of weights for all the jobs selected for inclusion in the container. The weight of each job is, in turn, the total sum of weights for every pallet that belongs to that particular job. If the total weight of all the selected jobs in a candidate solution exceeds the container’s maximum weight capacity, a penalty is applied and the fitness of the candidate solution is set to zero.

The selection GA begins its operation by generating an initial population of candidate solutions where each bit of the chromosome is randomly set to 0 or 1. The fitness of every chromosome in the population is then calculated, and the entire population is sorted according to fitness. This population is known as the first generation. To create a new population which will be known as the second generation, the GA concept of ‘elitism’ is first applied. This simply makes a copy

of the chromosome with highest fitness from the last generation and includes it as the first member of the new population. Two chromosomes are then selected from the previous population using ‘tournament selection’, which is one of several GA selection operators where a number of chromosomes are chosen at random from the population and placed in tournaments against each other. The winner of each ‘tournament’ (i.e. the chromosome with the best fitness) is selected for crossover. Based on a crossover probability, these two chromosomes, known as parent chromosomes, are either mated or cloned to produce two children chro- mosomes. The mating process is a standard one-point crossover operation which involves selecting a random point in both chromosomes and swapping their end parts. The cloning process simply creates an exact copy of a chromosome. Based on a mutation probability, the resulting children are mutated. In a mutation operation, a random position in the chromosome is selected, and its bit is flipped i.e. if the bit is 0, it is changed to 1, or vice versa. This process of selection, repro- duction and mutation is repeated until the number of chromosomes in the current generation matches the population size of the previous generation, at which point the creation of the new generation is complete. Subsequent generations are cre- ated using the same procedure until a specified number of generations have been produced.

The output of the selection algorithm is the population of chromosomes in the last generation. Each chromosome in this population is a candidate solution that represents a varied combination of jobs selected for inclusion into a container. The selection of jobs identified in each chromosome satisfies the practical constraints identified for the selection problem in the previous chapter, i.e., the total number of pallets resulting from the selected jobs have a total combined weight less than the maximum weight capacity of the container. The chromosomes in the last population are sorted in descending order by fitness to ensure that when the hybrid algorithm is iterating through the population, it will stack and pack job selections with a higher fitness first. As the fitness measure is the total sum of weights for every selected pallet, when a candidate solution is found that can be successfully stacked and packed, we can be sure that we have packed a solution that provides the maximum weight utility for the container, and that no other solution exists in the population with a higher container weight utility.

Algorithm 4.2 The Selection Algorithm Input:

PalletJobs . list of pallet groups Wmax . maximum container weight

Output:

JobSelections . selections of pallet groups InitialisePopulation(PalletJobs)

EvaluatePopulation(Wmax)

while max generation count not reached do create new population

apply elitism

while total population count not reached do

P arent1, P arent2 ← TournamentSelection(T ournamentSize)

Child1, Child2 ← Crossover(P arent1, P arent2)

Mutate(Child1)

Mutate(Child2)

add Child1 and Child2 to new population

end while

EvaluateNewPopulation(Wmax)

end while

JobSelections ← most recent population return JobSelections

end

function EvaluatePopulation(Wmax)

for all individual ∈ population do individual.fitness ← 0

for all bit ∈ individual do if bit == 1 then

Wjob ← weight of job at bit position

individual.fitness ← individual.fitness + Wjob

end if end for

if individual.fitness > Wmax then

individual.fitness ← 0 . penalty for greater weights end if

end for end function

function TournamentSelection(n) . n is the tournament size select n individuals from the population at random

bestIndividual ← select individual with best fitness return bestIndividual

end function

function Crossover(P arent1, P arent2) . a parent is a list of pallet groups

rand ← select random floating point number between 0 and 1 if rand < crossoverP robability then

crossoverP oint ← select a random pallet group’s position create Child1, Child2 as two empty list of pallet groups

for each pallet group in P arent do . P arent can be either parent position ← position of the pallet group

if position < crossoverP oint then

copy the value at position in P arent1 to Child1

copy the value at position in P arent2 to Child2

else

copy the value at position in P arent1 to Child2

copy the value at position in P arent2 to Child1

end if end for end if end function

function Mutate(Child)

rand ← select random floating point number between 0 and 1 if rand < mutationP robability then

pos ← select random position in Child

invert the value at position pos in Child . i.e. 0 → 1; 1 → 0 end if

end function