Professional Documents
Culture Documents
The Implementation of Simple Genetic Algorithm in A Simple Card Dividing Game
The Implementation of Simple Genetic Algorithm in A Simple Card Dividing Game
2. Fitness Function/Selection
The fitness function evaluate the fitness of every individuals. The probability of which a
certain individual is selected for reproduction is based on its fitness or evaluation
scores. A pair of individuals are chosen to be the parent to pass their genes to the next
generation. The individuals with high evaluation scores have more chance to be
selected to be the parents.
3. Crossover
Crossover is the most significant phase in a GA. In order to produce a better
individuals in the population, the least fit individual will be replaced by a better
individual which was bred from the population’s members themselves.
4. Mutation
In a certain offsprings, some of their genes can be subjected to a mutation with a low
probability. This implies that some of the bits in the bit string can be flipped.
5. Evolution
The evolution usually starts from a population of randomly generated individuals, and
happens in generations. In each generation, the fitness of every individual in the
population is evaluated, multiple individuals are stochastically selected from the
current population (based on their fitness), and modified (recombined and possibly
mutated) to form a new population. The new population is then used in the next
iteration of the algorithm.
As there are many types of GAs, the author will use a certain GA called Microbial GA.
The Microbial GA works for the population of genotypes, which are designed by a user to
attain his/her goal. Two genotypes are picked up at random, and then their fitness are
evaluated. The genotype that has a higher fitness is the winner, and the other is the loser
(Rank-based Selection). By copying the segment of the winner genotype to the loser
genotypes at the same locus, new offspring is generated, and the loser genotype is
deleted from the population. Unlike basic GAs, in the Microbial GA, only one offspring is
generated at a time, and then the loser genotype is replaced by the new one (Steady
State Method).
Derived from the definition of the Microbial GA, the basic operation of Microbial GA are
as follows:
1. Pick two individuals at random.
2. Compare evaluation scores of both individuals to produce a winner individual(with
higher fitness scores) and a loser individual(with lower fitness scores).
3. With some random probability, the loser will copy some genes from the winner.
4. With some random probability, the loser can mutate. Number 3 and 4 will produce a
new gene.
5. Replace the loser with the new gene.
The diagram processes of Microbial GA is as follows:
Problems
There are a pile of 10 cards
numbered 1 until 10. The task
is to divide the pile into two
piles containing 5 cards each.
The first pile is called the Sum
Pile and the second is the
Product Pile. The sum each
member of the Sum Pile must
equal to 36 and the product
of each member of the
Product Pile must equal to
360.
Solutions
The solution code for the sample problem can be found in
http://bit.ly/IF184981_TK_5116100107_ChristopherAndrew
0. Initialization
In this step, the function of initPopulation() gives a random value of 1 and 0 as the
gene to a population member.
2. The Fitness Function / Selection
There are three steps which are done in the fitness function(evaluationOf()):
- Loop through the population member’s gene.
- If the value of the gene is 0, add it to the sumPile
- If the value of the gene is 1, add it to the productPile
- Calculate the totalError of both piles.(the lower the error, the higher the fitness is)
While the selection process takes on the winner and loser selection.
3. Crossover
The crossover phase of Microbial GA only affect the loser. The probability is equal to
the recombinationChance
4. Mutation
There are only a little probability for the loser to mutate. The probability is equal to
the mutationChance
5. Evolution
The evaluation steps are including the Crossover and Mutation steps.
Result
After compiling the code using .NET 4.5, the following is the results:
Proofing:
1. sumPile: 2 + 7 + 8 + 9 + 10 = 36
2. productPile:1 × 3 × 4 × 5 × 6 = 360
Conclusions
GA is used mainly for the searching and optimization problems. The sample problem used
in the paper indicate that even though the problem itself can be solved by
hand(manually), it could take 100s or even 1000s trials of error before getting the final
results.
References
I. Harvey, the Microbial Genetic Algorithm, 1996
I. Harvey, Artificial Evolution: A Continuing SAGA, in Evolutionary Robotics. From Intelligent
Robotics to Artificial Life, Lecture Notes in Computer Science, pp. 94-109, 2001
https://www.codeproject.com/Articles/16286/AI-Simple-Genetic-Algorithm-GA-to-solve-
a-card-pro
https://www.brainz.org/15-real-world-applications-genetic-algorithms/
https://towardsdatascience.com/introduction-to-genetic-algorithms-including-example-
code-e396e98d8bf3
http://jkoba.net/jkoba-wiki/index.php?The%20Microbial%20Genetic%20Algorithm