布谷鸟优化算法C++

#include <iostream>
#include <vector>
#include <cmath>
#include <random>
#include <time.h>
#include <fstream>
#define pi acos(-1)
//5只布谷鸟
constexpr int NestNum = 40;    
//pi值
//规定X,Y 的取值范围
constexpr double X_max = 5;
constexpr double X_min = 0;
constexpr double Y_max = 5;
constexpr double Y_min = 0;
//最大迭代次数
constexpr int MaxIterationTimes = 300;
//被宿主发现的概率
constexpr double Pa = 0.25;

//自变量结构体
struct Nest {
    double x;
    double y;
    double fitness;
};
void fitFunc(Nest& nest);
int findBetterNest(std::vector<Nest>&);
std::vector<Nest> levy(std::vector<Nest> OldNestPop, std::size_t bestNum);
std::vector<Nest> RandomAbandonPaNestPop(std::vector<Nest> OldNestPop);
//随机数引擎
static std::default_random_engine e(time(0));
static std::uniform_real_distribution<double> u(0, 1);
int main(void)
{
    bool flag_output = false;
    double Xold;
    double Xnew;
    double Yold;
    double Ynew;
    std::ofstream outfileX("D:\\cuckoo\\cuckooX.txt");
    std::ofstream outfileY("D:\\cuckoo\\cuckooY.txt");
    std::ofstream outfileZ("D:\\cuckoo\\cuckooZ.txt");
    //现在的鸟巢群
    std::vector<Nest> current_nestPop;
    //迭代次数
    int num = 0;
    //最优鸟巢
    int BestNestCurrent;    
    //初始化
    for (int i = 0; i < NestNum; ++i)
    {
        Nest nestinitial;
        nestinitial.x = (X_max - X_min) * u(e) + X_min;
        nestinitial.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

优化大师傅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值