介绍
该程序实现了道金斯(Dawkins)在《The Blind Watchmaker》一书中提到的演化过程,这个过程展示了自然选择的过程。程序中使用了莎士比亚(Shakespere)的短语“ METHINKS IT IS LIKE A WEASEL”。
实现
#include <string>
#include <random>
#include <array>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <sstream>
class Weasel
{
std::string target;
std::uniform_int_distribution<> chardist;
std::uniform_int_distribution<> ratedist;
std::mt19937 mt;
std::string const allowed_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
public:
Weasel(std::string_view t) : target(t), chardist(0, 26), ratedist(0, 100)
{
std::random_device rd;
auto seed_data = std::array<

这篇博客介绍了如何用C++实现道金斯在《The Blind Watchmaker》中提出的演化模拟项目。通过模拟自然选择过程,从随机字符串开始,逐步进化,最终达到目标字符串——莎士比亚的短语'METHINKS IT IS LIKE A WEASEL'。程序通过复制并随机出错的策略,经过不断淘汰和优化,展示了演化的力量。
最低0.47元/天 解锁文章
373

被折叠的 条评论
为什么被折叠?



