C# 中的遗传算法?

发布于 07-17 12:21 字数 134 浏览 7 评论 0原文

如何用 C# 编写遗传算法? 有可用的图书馆吗? 像 C++ 一样:http://lancet.mit.edu/ga/

How can I write genetic algorithms in C#? Are there libraries available? Like C++: http://lancet.mit.edu/ga/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

把昨日还给我2024-07-24 12:21:31

这可能听起来像是一个滑稽的答案,但您需要首先决定您希望遗传算法解决什么问题。 如前所述,旅行推销员问题是一个常见问题,也是了解其工作方式的一种相当好的方法。

我之所以这么说,是因为 GA 最重要的部分之一是适应度函数,没有任何框架会为你编写它。

这篇 2003 年的 codeproject 文章涵盖了:

  • 健身功能
  • 偏向轮盘赌轮
  • 突变

很容易使用:

GA ga = new GA(crossover rate, 
               mutation rate, 
               population size, 
               number of generations,
               number of parameters for the fitness function);

ga.FitnessFunction = new GAFunction(theActualFunction);

这可以升级到.NET 3:

ga.FitnessFunction = delegate(double[] values)
{
    return 1.2d;
};

正如您所看到的,其适应度函数期望您的基因表示为双值(而不是例如位字符串)。

然而(这并不是要驳回这篇文章,这很好),只要您知道基本的 GA 是如何工作的,您就可以很容易地自己编写这篇文章。

This may sound like a facetious answer, but you will want to firstly decide what you want the genetic algorithm to solve. As mentioned the Travelling Sales Person problem is a common one and a fairly good way of learning how they work.

I say this as one the most important parts of a GA is the fitness function, which no framework is going to write for you.

This codeproject article from 2003 does cover:

  • Fitness functions
  • Biased roulette wheels
  • Mutation

It's easy to use:

GA ga = new GA(crossover rate, 
               mutation rate, 
               population size, 
               number of generations,
               number of parameters for the fitness function);

ga.FitnessFunction = new GAFunction(theActualFunction);

This could be upgraded to .NET 3:

ga.FitnessFunction = delegate(double[] values)
{
    return 1.2d;
};

As you can see the fitness function for this expects your genes to be represented as double values (rather than for example bit strings).

However (and this is not dismissing the article, which is good), you could write this quite easily yourself providing you know how basic GAs work.

伴我老2024-07-24 12:21:31

有一个很好的框架“AForge.NET Genetics”,它将为您提供的不仅仅是您可以在 codeproject 上找到的“hello world”示例。
请参阅重复的帖子 C# 中的遗传编程

There is a nice framework "AForge.NET Genetics" which will give you more than just "hello world" example you can find on codeproject.
See duplicate post Genetic Programming in C#

十雾2024-07-24 12:21:31

您可以在 CodeProject 上找到一些 C# 遗传算法信息。

You can find some genetic algorithm information for C# on CodeProject.

羞稚2024-07-24 12:21:31

我用 C# 开发了一个简单的 GA 展示项目。 这是遗传算法的世界,我在一组接口上构建了该示例,这些接口足够通用,可以用作开发遗传算法的模式。

您可以在github 页面上找到代码和文档(包括包含设计图的 Enterprise Architect 文档)。 您还可以下载可执行文件以查看其运行情况。

希望能帮助到你。

I developed a simple GA showcase project in C#. It's the hello world of genetic algorithms, and I built the example on a set of interfaces that are general enough to be used as a pattern for developing genetic algorithms.

You can find code and documentation (including an Enterprise Architect doc including design diagrams) on the github page. You can also download the executable to see it in action.

Hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文