VB.NET - 遗传算法 - 背包问题
我一直在使用遗传算法研究背包问题。但我遇到了一些困难......
首先,用户生成一个存储在文本文档中的数据集。从那里我将数据读入程序。
我很好地让程序计算适应度值,选择父母,产生孩子,然后变异孩子。但由于某种原因,它只在我的人口较少时才有效。当我的人口较少时,我的程序将持续发展,但当我的人口较多时,我的程序会非常不一致。
例如:当我的人口数量约为 10-200 时,遗传算法运行完美。但当我达到更高的人口数量(大约 300 多个)时,我将单击“运行”,但什么也没有发生。然后我重新启动程序并使用相同的数据集,程序成功执行。
我不确定我的代码的哪一部分导致了问题,所以如果您需要一段示例代码,请告诉我您想要哪一部分代码(父级选择、加载数据集等)。
多谢!
I have been working on the Knapsack problem using genetic algorithms. But I have run into a few difficulties...
First off the user generates a data set which is stored in a text document. From there I read the data in to the program.
I do fine getting the program to calculate fitness values, select parents, produce children, then mutate the children. But it for some reason only works when I have a low population. My program will consistently evolve when I have a low population, but is very inconsistent when I have a higher population.
For Example: When I have a population of around 10-200 the genetic algorithm runs flawlessly. But when I get to higher populations (around 300+), I will click run and nothing happens. Then I restart the program and use the same exact dataset and the program executes successfully.
I am not sure which part of my code is causing the problem, so If you need a piece of example code please tell me which part of code you would like (Parent Selection, Loading Data Set, etc).
Thanks Alot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想可能有以下三个原因。
1) 代码中的错误
这应该相对容易消除。尝试编写一些测试来检查程序的特定部分是否正确运行(例如父选择等)。尝试用一些小例子来测试它们,你可以自己在一张纸上弄清楚。
2) 内存不足问题 - btreat 提到的
3) 一些算法怪癖
这将更难解决。我只是猜测,所以我可能是错的,但我见过当问题规模超过某个阈值时,算法会极大地改变其行为。不太可能,但也不是不可能。在这里,您可以看到如果慢慢增加人口规模,您会看到运行时间的突然变化。
I guess there might be three reasons for that.
1) a bug in your code
This should be relatively straightforward to eliminate. Try writing some tests that check if particular parts of your program run correctly (e.g. Parent Selection, etc.). Try testing them against some small examples you can figure out on a piece of paper yourself.
2) out of memory problem - a mentioned by btreat
3) some algorithmic quirk
This will be more difficult to fight. I am just guessing, so I might be wrong, but I've seen algorithms that drastically change their behaviour when problem size exceeds some threshold. Not likely, but not impossible either. Here you could just see if slowly increasing the population size you can see a sudden shift in running times.
也许程序内存受到较高人群的限制?
Perhaps the program memory constrained with the higher populations?