- 浏览: 8316 次
- 性别:
- 来自: 南京
最近访客 更多访客>>
最新评论
-
JamesBound:
I've know that't something but ...
AI - Simple Genetic Algorithm (GA) to solve a card problem -
天才白痴:
嘿嘿,是啊,完全意料之外的
我今天人品大爆发啊,赚了299美元 -
ouspec:
运气很好啊
我今天人品大爆发啊,赚了299美元
|
|||||||||||||||
<!---->
<script src="/script/togglePre.js" type="text/javascript"></script>
IntroductionThis article describes how to solve a logic problem using a Genetic Algorithm. It assumes no prior knowledge of GAs. In fact, half of this article is dedicated to explaining the internal structure of a Genetic Algorithm. So what is the problem domain we are trying to solve?Well, GAs can be used to solve many problems. In fact, GAs have been used to grow new mathematical syntax trees, train multi-layer neural networks, to name but a few instances. However, for this example, I have used a simple card splitting excercise, which is as detailed here:
Now, I am not saying that this could not be done by hand, using old fashioned brain juice, it's just better suited to a GA, as it could take 100s or even 1000s of different combinations to get the correct result. Well, probably not that many for this simple problem, but it certainly could take a lot of combinations for a more difficult problem. Suffice to say, it is just good fun to do it with a GA. So, let's carry on. So what is a Genetic Algorithm?Well, Wikipedia says this: A genetic algorithm is a search technique used in computing, to find true or approximate solutions to optimization and search problems, and is often abbreviated as GA. Genetic algorithms are categorized as global search heuristics. Genetic algorithms are a particular class of evolutionary algorithms that use techniques inspired by evolutionary biology such as inheritance, mutation, selection, and crossover (also called recombination). Genetic algorithms are implemented as a computer simulation in which a population of abstract representations (called chromosomes or the genotype or the genome) of candidate solutions (called individuals, creatures, or phenotypes) to an optimization problem evolves towards better solutions. Traditionally, solutions are represented in binary as strings of 0s and 1s, but other encodings are also possible. 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. Follow that?? If not, let's try a diagram. (Note that this is a Microbial GA, there are lots of GA types, but I just happen to like this one, and it's the one this article uses.) I prefer to think of a GA as a way of really quickly (well, may be quite slow, depending on the problem) trying out some evolutionary programming techniques, that mother nature has always had. So how does this translate into an algorithm (this article uses a Microbial GA, but there are many other varieties)?The basic operation of the Microbial GA training is as follows:
That is:
That's it. That is the complete algorithm. But there are some essential issues to be aware of, when playing with GAs:
These two items must be developed again, whenever a new problem is specified. For example, if we wanted to find a person's favourite pizza toppings, the genotype and fitness would be different from that which is used for this article's problem domain. These two essential elements of a GA (for this article's problem domain) are specified below. 1. The Geneotype
Well, for this article, the problem domain states that we have 10 cards. So, I created a two dimensional genes array, which is a 30*10 array. The 30 represents a population size of 30. I picked this. It could be any size, but should be big enough to allow some dominant genes to form. 2. The Fitness FunctionRemembering that the problem domain description stated the following:
Well, all that is being done is the following :
Using the codeThe demo project attached actually contains a Visual Studio 2005 solution, with the following two classes. Program classIs the main entry point into the Simple_GeneticAlgorithm application. All this class does is create a new
Simple_GeneticAlgorithm classRuns the GA to solve the problem domain.
The resultsTaking the last good population member results found, let's test it out. 2 + 7 + 8 + 9 + 10 = 36 in Pile 0, this is all good 1 * 3 * 4 * 5 * 6 = 360 in Pile 1, this is all good Points of InterestI hope this article has demonstrated how to write a simple GA to solve a problem that we as humans would probably find hard to do manually. Remember this is a simple problem. what would happen if we upped the problem domain? A GA really is the way to go. I will very shortly publish an article on a GA training a multi layer neural network to solve some logic problems. So if your'e into this sort of stuff, watch this space. History
About Sacha Barber
|
相关推荐
Priority-Based Genetic Algorithm for Shortest Path Routing Problem in OSPF 主要介绍了遗传算法求解最短路径问题中的基于优先级的编码。这种编码方式可以很有效地解决图的最短路径等问题。
遗传算法,背包问题_GA-Genetic-Algorithm-for-knapsack-problem
简单的遗传算法实例_Simple-Genetic-Algorithm-Example
在这个项目中,我们使用遗传算法(Genetic Algorithm, GA)来寻找解决方案。 遗传算法是一种模拟自然选择和遗传学原理的全局优化方法。它通过创建一组初始解(称为个体或种群),然后通过选择、交叉和变异等操作...
遗传算法(Genetic Algorithm, GA)是模拟自然选择和遗传机制的一种优化算法,它源于进化计算领域,由John Henry Holland在20世纪60年代提出。这种算法通过模拟生物进化过程中的适者生存、基因重组和突变等原则,...
本文将深入探讨一个具体的优化问题——二进制打包问题(Bin-Packing Problem),并介绍如何运用遗传算法(Genetic Algorithm)来解决这一问题。在这个特定的项目“Bin-Packing-Problem-Genetic-Algorithm-master_...
This paper presents a multi-objective genetic algorithm (MOGA) based on immune and entropy principle to solve the multi-objective FJSP. In this improved MOGA, the fitness scheme based on Pareto-...
一个《简单》的遗传算法实验。_Simple-Genetic-Algorithm
实数编码遗传算法(Real-coded Genetic Algorithm)是一种启发式搜索算法,用于解决优化问题。与二进制遗传算法不同,实数编码遗传算法适用于解决决策变量为实数的优化问题。以下是实数编码遗传算法的基本描述: ...
NSGA-II(非支配排序遗传算法II)是由Kalyanmoy Deb等人于2002年提出的一种多目标遗传算法(Multiobjective Genetic Algorithm, MOGA)。在多目标优化问题中,存在多个目标函数需要同时优化,这导致了一系列的Pareto...
机械设计遗传算法设计_Mechanical-design-genetic-algorithm-design
遗传算法(Genetic Algorithm)是一种基于生物进化原理的全局优化方法,由John Holland于1960年代提出。它模拟了自然界中的生物进化过程,通过选择、交叉和突变等操作来搜索解决方案空间,寻找最优解。遗传算法在...
python-genetic_algorithm.rar
GA轮盘赌选遗传算法模板_GeneticAlgorithm-Simple
* This Java code was derived from the C code in the Appendix of "Genetic * Algorithms + Data Structures = Evolution Programs," by Zbigniew * Michalewicz, Second Extended Edition, New York: Springer...
在本文中,作者提出了一种改进的混合遗传算法(Hybrid Genetic Algorithm, HGA)来解决多约束0-1背包问题(Multiconstrained 0-1 Knapsack Problem, MKP)。MKP是一个著名的NP完全组合优化问题,其定义如下: 目标...
遗传算法(Genetic Algorithm,简称GA)是一种模拟生物进化过程的优化算法,广泛应用于解决复杂问题的全局优化。这一算法源于1960年代John Holland提出的适应度函数和遗传机制的概念,通过模拟自然选择、基因重组和...
Applying genetic algorithms to solve real-world deep learning and artificial intelligence problems》这本书是Eyal Wirsansky的作品,旨在通过Python语言实践遗传算法来解决实际中的深度学习和人工智能问题。...