⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 genetic.h

📁 毕业设计论文~~要的来看啊~~~ 很完整的
💻 H
字号:
// Genetic.h: interface for the CGenetic class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_GENETIC_H__2604FE9C_3233_460F_9077_1F63A0CAE5D4__INCLUDED_)
#define AFX_GENETIC_H__2604FE9C_3233_460F_9077_1F63A0CAE5D4__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


#include "windows.h"
#include <float.h>
#include <math.h>
#include <stdlib.h>
#include "tasks.h"
#include "agents.h"

#include "mydefine.h"

struct individual //单个染色体
{
	char chrom[MAXSTRING]; //基因编码串
	float fitness;	//适应度
	int parent1, parent2; //双亲
	int xsite;	//交叉点 
};

class CAgents;

class CGenetic
{
public:
	int *cs_flag; //最优解的任务标志
	int m_subtask; //子任务个数
	
public:
	
	CGenetic(); //构造函数
	CGenetic(int number, int length, int gen, float c_p,
		float m_p, CAgents *re_agents, CTasks *re_tasks, int task_number,
		int cond); //重载构造函数
	
	virtual ~CGenetic(); //虚析构函数

	void init(int number, //种群数量
		int len, //agent长度
		int gen, //遗传代数
		float c_p, //交叉率
		float m_p, //变异率
		CAgents *re_agents, //当前agents
		CTasks* re_tasks, //当前tasks
		int task_number,
		int cond); //条件
	
	void sort(individual *pop); //对种群排序
	float fitness_v(char *p); //计算染色体适应度
	
	int r_flag; //标志?
	int condition; //条件
	struct individual elitist; //最优个体
	
	void generation(); //产生下一代
	int flip(float prob); //伯努利试验
	
	float p_mutation; //变异率
	float p_cross; //交叉率
	double sumfitness; //整体适应度
	
	void statistics(struct individual *pop); //计算种群适应度
	
	int length; //基因长度,代表agent个数
	int popsize; //种群大小
	int gen_number; //遗传代数
	
	struct individual *oldpop; //上一代种群
	struct individual *newpop; //新一代种群
	struct individual *temppop; //临时辅助
	
	int get_random(int min, int max); //获取随机值min~max
	int initpop(); //初始化种群
	int mutation(char ch); //变异
	int crossover(char * parent1, char *parenet2, int j); //交叉
	int select(); //选择
	
	CAgents *a_t; //agents table
	CTasks * r_tasks; //tasks table
	
};

#endif // !defined(AFX_GENETIC_H__2604FE9C_3233_460F_9077_1F63A0CAE5D4__INCLUDED_)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -