#include<iostream>
#include<cstdio>
#include<stack>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<cmath>
#include<algorithm>
#define Gene_Num 10000
#define Descedant 3000
#define NUM 15
#define Cross_Chance 0.3
#define Varia_Chance 0.1
#define Pi 3.1415926
using namespace std;
class Gene
{
public:
Gene() {}
Gene(const Gene& p)
{
for(int i = 0; i < 21; i++)
gene1[i] = p.gene1[i];
for(int i = 0; i < 18; i++)
gene2[i] = p.gene2[i];
Pro = p.Pro;
x1_num = p.x1_num;
x2_num = p.x2_num;
}
public:
int gene2[50];
int gene1[50];
double x1_num;
double x2_num;
double Pro;
};
Gene g[NUM];
Gene g2[NUM];
Gene p[NUM];
Gene temp_cross[NUM];
Gene temp_select[NUM];
double X1_Min = -2.9;
double X2_Min = 4.2;
double X1_Max = 12.0;
double X2_Max = 5.7;
double X1_LEN,X2_LEN;
double X1,X2;
double X1_ROOT,X2_ROOT;
double MAX;
double SUM;
void Bin_Ini(int index)
{
X1_ROOT = pow(2,21) - 1;
X2_ROOT = pow(2,18) - 1;
X1_LEN = X1_Max - X1_Min;
X2_LEN = X2_Max - X2_Min;
for(int i = 0; i < 21; i++){
int val1 = rand() % 2;
int val2 = rand() % 2;
int val = max(val1,val2);
g[index].gene1[i] = val;
}
for(int i = 0; i < 18; i++){
int val1 = rand() % 2;
int val2 = rand() % 2;
int val = max(val1,val2);
g[index].gene2[i] = val;
}
}
void Initial(
遗传算法实现单目标优化问题【智能信息处理作业】C++
最新推荐文章于 2024-04-27 15:28:25 发布