#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.