C++练习项目:演化模拟之Weasel程序的实现

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

介绍

该程序实现了道金斯(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<
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值