91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

研一時候上智能優(yōu)化算法課程,因為論文需要,通過遺傳算法的代碼自己改寫的。通過插樁的方式,自動生成分支覆蓋的測試用例,用來判斷三角形的類型。

資源截圖

代碼片段和文件信息

#include?
#include?
#include?
#include?

/*?Change?any?of?these?parameters?to?match?your?needs?*/
#define?POPSIZE?500?/*?種群大小?*/
#define?MAXGENS?15
/*?最多生成的代數(shù)?*/
#define?NVARS?3?/*?變量的個數(shù)?*/
#define?PXOVER?0.8?/*?交叉的概率?*/
#define?PMUTATION?0.15?/*?突變的概率?*/
#define?TRUE?1
#define?FALSE?0
#define?branch_no??5/*?分支個數(shù)?*/

int?generation;?/*?當前的代數(shù)?*/
int?cur_best;?/*?最佳的個體?*/
int?all_branchfit[branch_no];???/*整個種群的分支覆蓋情況*/

int?randint?=?0;

FILE?*galog;?/*?an?output?file?*/

/*?genotype?(GT)?a?member?of?the?population?*/
struct?genotype?
{
double?gene[NVARS];?/*?a?string?of?variables?*/
int?branchfit[branch_no];?/*?分支覆蓋情況?*/
double?fitness;?/*?GT‘s?fitness?*/

double?rfitness;?/*?relative?fitness?*/
double?cfitness;?/*?cumulative?fitness?*/
};
struct?genotype?population[POPSIZE+1];?/*?population?*/
struct?genotype?newpopulation[POPSIZE+1];?/*?new?population;?*/

/************被測程序***********/
void?testedPro(double?adouble?bdouble?cint*?fi)
{
if(a<=0?||?b<=0?||?c<=0)
{
//printf(“邊值無效!\n“);
fi[0]?=?1;
}
else?if(a+b<=c||a+c<=b||b+c<=a)?
{
//printf(“不能構成三角形!\n“);
fi[1]?=?1;
}
else
{
if(a==c||a==b||b==c)?
{
if(a==c&&a==b)?
{
//printf(“等邊三角形!\n“);
fi[2]?=?1;
}
else?
{
//printf(“等腰三角形!\n“);
fi[3]?=?1;
}
}???
else?
{
//printf(“斜三角形!\n“);
fi[4]?=?1;
}
}
}


/***********************************************************/
/*?Random?value?generator:?Generates?a?value?within?bounds?*/
/***********************************************************/
double?randval(void)
{
double?val;
randint++;

val?=?(double)(rand()%100-10);
return(val);
}


//種群初始化
void?initialize(void)
{

int?i?j?z;
/*?initialize?variables?within?the?bounds?*/
srand((unsigned)time(NULL));
for?(i?=?0;?i? {
for?(j?=?0;?j? {
population[j].fitness?=?0;
population[j].rfitness?=?0;
population[j].cfitness?=?0;
population[j].gene[i]?=?randval();
for(z?=?0;?z? population[j].branchfit[z]?=?0;
}
}
}

/*************************************************************/
/*?Evaluation?function:?This?takes?a?user?defined?function.?*/
/*?Each?time?this?is?changed?the?code?has?to?be?recompiled.?*/
/*?The?current?function?is:??*/
/*************************************************************/
void?evaluate(void)
{
int?membno;
for?(mem?=?0;?mem? {
testedPro(population[mem].gene[0]population[mem].gene[1]population[mem].gene[2]population[mem].branchfit);
}

for(bno?=?0;bno? {
for?(mem?=?0;?mem? {
all_branchfit[bno]?+=population[mem].branchfit[bno];
}
}
for?(mem?=?0;?mem? {
for(bno?=?0;bno? {
if(all_branchfit[bno]?!=?0)
population[mem].fitness?+=?population[mem].branchfit[bno]/doubl

評論

共有 條評論