如何为多项选择题编写遗传算法代码? [英] How do I write a Genetic algorithm code for multiple choice questions?

查看:129
本文介绍了如何为多项选择题编写遗传算法代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好..

有谁可以帮帮我?

我必须写一个GA代码才能找到解决方案案例

有10个问题有4个选择

这意味着有4 ^ 10 = 1,048,576个案例,其中一个就是解决案例。

我已经明白,染色体的长度必须是10个阵列,而b / b $ b,人口的大小也是10个。 br />
我对编码一无所知,看了一些代码示例,注意到我必须计算交叉,变异和健身......





#include< stdio.h>

#include< conio.h>

#include< stdlib.h>



typedef struct Chrom //创建chrom结构

{

short int bit [10];

int fit;

} chrom;



void * evpop(chrom popcurrent [4]);

int x(chrom popcurrent);

int y(int x);

void * pickchroms(chrom popcurrent [4]);

void * crossover(chrom popnext [4]);

void * mutation(chrom popnext [4]);



这就是我现在想出来的。我在google上找到了这个示例源代码,我不明白为什么有popcurrent,popnext ..

非常感谢..

推荐答案

理解GA的机制已经很难了,更不用说试图解释实现它的其他人的代码了。如果你以前从未编码,那就更难了。

回到GA,您可以创建这样的模型:

1.用40基因染色体代表每个潜在的解决方案,其中每个基因代表一个多项选择回答。

2.第一个问题由前4个基因代表,第二个问题代表接下来的4个基因,依此类推......

3.基因的排列将是为人口生成不同的解决方案。

4.通过GA进化,即选择,交叉,变异和适应性评估。您应该已经将其作为学习的一部分学习。如果没有,请阅读我关于遗传算法揭秘的文章[ ^ ]和遗传算法实现 [ ^ ]

最后但并非最不重要的是,您应该学会自己编写代码并实现它。只有这样你才能真正了解GA的工作。
Understanding the mechanism of GA is already hard, not to mention trying to interpret other people's code that implements it. That is even harder if you never code before.
Come back to the GA, you can create a model like this:
1. Represent each potential solution by a 40 gene-chromosome, where each gene represents a multiple choice answer.
2. The first question is represented by the first 4 genes, the second question the next 4 genes, and so on...
3. Permutation of the genes will generate different solutions for the population.
4. Put the population through the GA evolution, i.e. selection, crossover, mutation, and fitness evaluation. You should have already learnt it as part of your study. If not, read my articles on Genetic Algorithms Demystified[^] and Genetic Algorithms Implementation[^]
Last but not least, you should learn to code and implement it yourself. Only then will you really understand the working of GA.


在互联网上查找源代码不是一个好方法:特别是如果你不知道你找到的代码是什么或者它是如何做到的。



说真的,你需要学习这个主题并亲自尝试 - 你不会通过查找代码学到很多东西(如果有的话) 并试图让我们为你做功课。如果你不学习这些东西,你怎么期望理解下一个作业,或者在课程结束时通过考试?



所以坐下来,阅读您的课程笔记,并尝试一下。如果你遇到某个问题,那就问一下,但是我们不会为你做这一切!
Finding source code on the internet is not a good way to do this: particularly if you have no idea what the code you have found does or how it does it.

Seriously, you need to learn the subject and try it for yourself - you won't learn much (if anything) by "finding code" and trying to get us to do your homework for you. If you don't learn this stuff, how do you expect to understand the next assignment, or pass the exam at the end of the course?

So sit down, read your course notes, and give it a try. If you get stuck on a particular point then ask about that, but we aren't going to do it all for you!


这篇关于如何为多项选择题编写遗传算法代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆