用混合遗传算法解决单机调度问题c语言程序
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
用混合遗传算法解决单机调度问题c语言程序
#include
#include
#include
#include
#include
#include "ceshi.h"
void main()
{
s_individual *temp=NULL;
long run_start,run_finish,run_sum=0;
float run_avg=0;
int sum_k=0;
srand((unsigned)time(NULL));/*将当前时间设置成随机函数的种子,所以每次产生的数都不一样*/
//printf("%d\n",time(NULL));
//srand((unsigned)1398759277);
if((outfp = fopen("newfile1","w")) == NULL)
{
fprintf(stderr,"Cannot open output file %s\n","file1");
exit(-1);
}
init_parameter();//初始化工件参数
print_parameter();//打印工件参数
for(run=1; run<=maxruns; run++)
{
run_start=clock();
initialize();//初始化包括初始参数设置
initmalloc();//分配全局空间
gererate_pop();//产生初始种群
statistics(oldpop);//统计种群数据,得到最优个体
init_temperature=(min-max)/log(preceive); temperature_k=init_temperature;
while(k
{
generation();//交叉
select_better(oldpop,newpop);//保留最佳个体newpop popsize_copy(oldpop,newpop);
gen_mu(newpop);//变异保留最佳个体
select_better(oldpop,newpop);
popsize_copy(oldpop,newpop);
CSA(newpop);//模拟退火操作定步长抽样
select_better(oldpop,newpop);
statistics(newpop);
run_finish=clock();
if (last_fitness==bestfit.fitness)
{
last_maxgen++;
}
else{
last_maxgen=0;
last_runtime=run_finish;
}
last_fitness=bestfit.fitness;
k++;//退温
temperature_k=temperature_k*ptemper;
temp=oldpop;
oldpop=newpop;
newpop=temp;
}
sum_k=sum_k+k;
run_time=last_runtime-run_start;
run_sum=run_sum+run_time;
print_popsize();
ceshi_popstatic();
freeall();
}
run_avg=(float)run_sum/float(maxruns);
fprintf(outfp,"\nmax=%d min=%d avg=%d run_sum=%f avg_k=%d\n",pop_max,pop_min,pop_sum/maxruns,run_avg,su m_k);
fclose(outfp);
}。