文档下载 文档下载导航
设为首页 | 加入收藏
搜索 请输入内容:  
 导航当前位置: 文档下载 > 所有分类 > IT/计算机 > 人工智能遗传算法c++实现
侵权投诉

人工智能遗传算法c++实现

人工智能遗传算法c++实现

#include <iostream.h>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <cmath>
#define PI 3.1415926

using namespace std;

class Software{ //软件类及其属性,即价格和运行时间
public :
float price; //价格
float time ; //时间
float adapt; //适应度范围0~1
};

double AverageRandom(double min,double max) { //产生在min与max间的随机数
int minInteger = (int)(min*10000);
int maxInteger = (int)(max*10000);
int randInteger = rand()*rand();
int diffInteger = maxInteger - minInteger;
int resultInteger = randInteger % diffInteger + minInteger;
return resultInteger/10000.0;
}

double Normal(double x,double miu,double sigma) { //概率密度函数
return 1.0/(sqrt(2*PI)*sigma) * exp(-1*(x-miu)*(x-miu)/(2*sigma*sigma));
}

double NormalRandom(double miu, double sigma,double min,double max){ //产生正态分布随机数
double x;
double dScope;
double y;
do {
x = AverageRandom(min,max);
y = Normal(x, miu, sigma);
dScope = AverageRandom(0, Normal(miu,miu,sigma));
}while( dScope > y);
return x;
}

void Init(int type, int n , vector<vector<Software> > &soft){//初始化,产生software样本组
Software temp_s;
vector<Software> temp_v;
for(int i = 0;i<n;i++){
cout<<"class "<<i+1<<endl;
for(int j=0;j<type;j++){
temp_s.price=(int)NormalRandom(0, 0.2,1,10000);
temp_s.time= (int)NormalRandom(0, 0.2,1,10);
temp_s.adapt=2/((temp_s.price/1000)+temp_s.time);
temp_v.push_back(temp_s);
cout<<j+1<<"("<<temp_s.price<<","<<temp_s.time<<","<<temp_s.adapt<<")"<<" ";
}
cout<<endl;
soft.push_back(temp_v);
temp_v.clear();
}
}

float Select(vector<vector<Software> > &soft){//选择
vector<vector<Software> > temp_soft(soft);
float share=0;
float one_share=0;
soft.clear();
for(int num=0;num<temp_soft.size();num++){
for(int type=0;type<temp_soft[num].size();type++){
share+=temp_soft[num][type].adapt;
}
}
for(num=0;num<temp_soft.size();num++){
for(int type=0;type<temp_soft[num].size();type++){
one_share+=temp_soft[num][type].adapt;
}
if(one_share>share/(2*temp_soft.size()))//如果小于两倍适应度平均值就淘汰
soft.push_back(temp_soft[num]);
one_share=0;
}
return share;
}

void Cross(int type,vector<vector<Software> > &soft){ //交叉
int dot=0;
float odds=0;
vector<Software>::iterator iter1,iter2;
for(int num=0;num<soft.size()-1;num++){
odds=rand()%100/100.0;
if(odds>0.6&&odds<0.95){//杂交率设置为0.6~0.95
dot=NormalRandom(0, 0.2,1,type);
iter1=soft[num].begin() + dot-1;
iter2=soft[num+1].begin()+dot-1;
while(iter1!=soft[num].end()){
swap(*iter1,*iter2);
iter1++;
iter2++;
}
}
}
}

void Mutation(int type,vector<vector<Software> > &soft){//变异
float odds=0;
int dot=0;
vector<Softwa

第1页

你可能喜欢

  • 遗传算法应用实例
  • 遗传算法解决TSP问题
  • 智能优化算法
  • 模拟退火算法
  • 图像匹配算法研究
  • 人工智能实验报告
  • 遗传算法matlab代码
  • 算法入门

热门文档

相关文档

  • 第7章 遗传算法人工智能

    用C++实现遗传算法 5页 1财富值 遗传算法(初学者) 5页 免费 第七讲 遗传算法 69页 免费 人工智能第七章 遗传算法 99页 免费 中国、世界历史大事年表 11页...

  • 用C++实现遗传算法

    用C++实现遗传算法_IT/计算机_专业资料。用C++语言实现了一个简单的遗传算法算例/* 本程序试用遗传算法来解决 Rosenbrock 函数的全局最大值计算问题: max s.t....

  • 基本遗传算法的C++语言实现

    基本遗传算法的C++语言实现_IT/计算机_专业资料。基本遗传算法的C++语言实现/***/ /* 基于基本遗传算法的函数最优化 SGA.C */ /* A Function Optimizer using...

  • 人工智能---遗传算法

    人工智能---遗传算法_工学_高等教育_教育专区。人工智能、遗传算法... 人工智能遗传算法c++实现... 2页 1下载券 人工智能_第三章_遗传算... 174...

  • 人工智能(遗传算法)

    人工智能 遗传算法实验报告实验目的 1. 熟悉和掌握遗传算法的原理、实质 2. 学会使用遗传算法解决问题 3. 学会编写遗传算法程序寻找函数最值 实验原理遗传算法是...

  • 人工智能-遗传算法

    人工智能遗传算法c++实现... 2页 1下载券 人工智能-8遗传算法(1) 60页 1...5.1 遗传算法 遗传算法概述 v 遗传算法是模仿生物遗传学和自 然选择机理,通过...

  • 人工智能A星算法(C++)

    人工智能A星算法(C++)_工学_高等教育_教育专区。#include<iostream> #include... A星算法 21页 免费 A 寻路算法模拟实现 C++... 6页 免费 astar(a星)...

  • 人工智能--关于遗传算法求最优路径的设计与实现

    人工智能遗传算法c++实现... 2页 1下载券 遗传算法求最优路径的设... 4...新技术专题文献综述 之一) (之一) 专班学姓 题: 关于遗传算法求最优路径的...

  • 遗传算法及轮盘赌选择的C++实现

    遗传算法及轮盘赌选择的C++实现_互联网_IT/计算机...的重要机理运用到计算机系统 、工程系 统等人工 ...参考文献 【l 】易继楷, 侯嫒彬 . 智能控 制...

  • 人工智能之遗传算法论文含源代码

    人工智能之遗传算法论文含源代码_计算机软件及应用_IT/计算机_专业资料 暂无评价0人阅读0次下载举报文档 人工智能之遗传算法论文含源代码_计算机软件及应用_IT/...

站点地图 | 文档上传 | 侵权投诉 | 手机版
本站所有资源均来自互联网,本站只负责收集和整理,均不承担任何法律责任,如有侵权等其它行为请联系我们.
文档下载 Copyright 2013 doc.guandang.net All Rights Reserved.  -  email