亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? simple genetic algorithm implementation.txt

?? /* This a simple genetic algorithm implementation where the */ /* evaluation function takes positiv
?? TXT
字號:
/***************************************************************/
/* This is a simple genetic algorithm implementation where the */
/* evaluation function takes positive values only and the      */
/* fitness of an individual is the same as the value of the    */
/* objective function                                          */
/***************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

/* Change any of these parameters to match your needs */

#define POPSIZE 50               /* population size */
#define MAXGENS 1000             /* max. number of generations */
#define NVARS 3                  /* no. of problem variables */
#define PXOVER 0.8               /* probability of crossover */
#define PMUTATION 0.15           /* probability of mutation */
#define TRUE 1
#define FALSE 0

int generation;                  /* current generation no. */
int cur_best;                    /* best individual */
FILE *galog;                     /* an output file */

struct genotype /* genotype (GT), a member of the population */
{
 double gene[NVARS];        /* a string of variables */
 double fitness;            /* GT's fitness */
 double upper[NVARS];       /* GT's variables upper bound */
 double lower[NVARS];       /* GT's variables lower bound */
 double rfitness;           /* relative fitness */
 double cfitness;           /* cumulative fitness */
};

struct genotype population[POPSIZE+1];    /* population */
struct genotype newpopulation[POPSIZE+1]; /* new population; */
                                         /* replaces the */
                                         /* old generation */

/* Declaration of procedures used by this genetic algorithm */

void initialize(void);
double randval(double, double);
void evaluate(void);
void keep_the_best(void);
void elitist(void);
void select(void);
void crossover(void);
void Xover(int,int);
void swap(double *,double *);
void mutate(void);
void report(void);

/***************************************************************/
/* Initialization function: Initializes the values of genes    */
/* within the variables bounds. It also initializes (to zero)  */
/* all fitness values for each member of the population. It    */
/* reads upper and lower bounds of each variable from the      */
/* input file `gadata.txt'. It randomly generates values       */
/* between these bounds for each gene of each genotype in the  */
/* population. The format of the input file `gadata.txt' is    */
/* var1_lower_bound var1_upper bound                           */
/* var2_lower_bound var2_upper bound ...                       */
/***************************************************************/

void initialize(void)
{
FILE *infile;
int i, j;
double lbound, ubound;

if ((infile = fopen("gadata.txt","r"))==NULL)
     {
     fprintf(galog,"\nCannot open input file!\n");
     exit(1);
     }

/* initialize variables within the bounds */

for (i = 0; i < NVARS; i++)
     {
     fscanf(infile, "%lf",&lbound);
     fscanf(infile, "%lf",&ubound);

     for (j = 0; j < POPSIZE; j++)
          {
          population[j].fitness = 0;
          population[j].rfitness = 0;
          population[j].cfitness = 0;
          population[j].lower = lbound;
          population[j].upper= ubound;
          population[j].gene = randval(population[j].lower,
        &n bsp;                         population[j].upper);
          }
     }

fclose(infile);
}

/***********************************************************/
/* Random value generator: Generates a value within bounds */
/***********************************************************/

double randval(double low, double high)
{
double val;
val = ((double)(rand()%1000)/1000.0)*(high - low) + low;
return(val);
}

/*************************************************************/
/* Evaluation function: This takes a user defined function.  */
/* Each time this is changed, the code has to be recompiled. */
/* The current function is:  x[1]^2-x[1]*x[2]+x[3]           */
/*************************************************************/

void evaluate(void)
{
int mem;
int i;
double x[NVARS+1];

for (mem = 0; mem < POPSIZE; mem++)
     {
     for (i = 0; i < NVARS; i++)
           x[i+1] = population[mem].gene;
     
     population[mem].fitness = (x[1]*x[1]) - (x[1]*x[2]) + x[3];
     }
}

/***************************************************************/
/* Keep_the_best function: This function keeps track of the    */
/* best member of the population. Note that the last entry in  */
/* the array Population holds a copy of the best individual    */
/***************************************************************/

void keep_the_best()
{
int mem;
int i;
cur_best = 0; /* stores the index of the best individual */

for (mem = 0; mem < POPSIZE; mem++)
     {
     if (population[mem].fitness > population[POPSIZE].fitness)
           {
           cur_best = mem;
           population[POPSIZE].fitness = population[mem].fitness;
           }
     }
/* once the best member in the population is found, copy the genes */
for (i = 0; i < NVARS; i++)
     population[POPSIZE].gene = population[cur_best].gene;
}

/****************************************************************/
/* Elitist function: The best member of the previous generation */
/* is stored as the last in the array. If the best member of    */
/* the current generation is worse then the best member of the  */
/* previous generation, the latter one would replace the worst  */
/* member of the current population                             */
/****************************************************************/

void elitist()
{
int i;
double best, worst;             /* best and worst fitness values */
int best_mem, worst_mem; /* indexes of the best and worst member */

best = population[0].fitness;
worst = population[0].fitness;
for (i = 0; i < POPSIZE - 1; ++i)
     {
     if(population.fitness > population[i+1].fitness)
           {      
           if (population.fitness >= best)
                 {
                 best = population.fitness;
                 best_mem = i;
                 }
           if (population[i+1].fitness <= worst)
                 {
                 worst = population[i+1].fitness;
                 worst_mem = i + 1;
                 }
           }
     else
           {
           if (population.fitness <= worst)
                 {
                 worst = population.fitness;
                 worst_mem = i;
                 }
           if (population[i+1].fitness >= best)
                 {
                 best = population[i+1].fitness;
                 best_mem = i + 1;
                 }
           }
     }
/* if best individual from the new population is better than */
/* the best individual from the previous population, then    */
/* copy the best from the new population; else replace the   */
/* worst individual from the current population with the     */
/* best one from the previous generation                     */

if (best >= population[POPSIZE].fitness)
   {
   for (i = 0; i < NVARS; i++)
      population[POPSIZE].gene = population[best_mem].gene;
   population[POPSIZE].fitness = population[best_mem].fitness;
   }
else
   {
   for (i = 0; i < NVARS; i++)
      population[worst_mem].gene = population[POPSIZE].gene;
   population[worst_mem].fitness = population[POPSIZE].fitness;
   }
}
/**************************************************************/
/* Selection function: Standard proportional selection for    */
/* maximization problems incorporating elitist model - makes  */
/* sure that the best member survives                         */
/**************************************************************/

void select(void)
{
int mem, i, j, k;
double sum = 0;
double p;

/* find total fitness of the population */
for (mem = 0; mem < POPSIZE; mem++)
     {
     sum += population[mem].fitness;
     }

/* calculate relative fitness */
for (mem = 0; mem < POPSIZE; mem++)
     {
     population[mem].rfitness =  population[mem].fitness/sum;
     }
population[0].cfitness = population[0].rfitness;

/* calculate cumulative fitness */
for (mem = 1; mem < POPSIZE; mem++)
     {
     population[mem].cfitness =  population[mem-1].cfitness +      
                         population[mem].rfitness;
     }

/* finally select survivors using cumulative fitness. */

for (i = 0; i < POPSIZE; i++)
     {
     p = rand()%1000/1000.0;
     if (p < population[0].cfitness)
           newpopulation = population[0];      
     else
           {
           for (j = 0; j < POPSIZE;j++)      
                 if (p >= population[j].cfitness &&
                             p<population[j+1].cfitness)
                       newpopulation = population[j+1];
           }
     }
/* once a new population is created, copy it back */

for (i = 0; i < POPSIZE; i++)
     population = newpopulation;      
}

/***************************************************************/
/* Crossover selection: selects two parents that take part in  */
/* the crossover. Implements a single point crossover          */
/***************************************************************/

void crossover(void)
{
int i, mem, one;
int first  =  0; /* count of the number of members chosen */
double x;

for (mem = 0; mem < POPSIZE; ++mem)
     {
     x = rand()%1000/1000.0;
     if (x < PXOVER)
           {
           ++first;
           if (first % 2 == 0)
                 Xover(one, mem);
           else
                 one = mem;
           }
     }
}
/**************************************************************/
/* Crossover: performs crossover of the two selected parents. */
/**************************************************************/

void Xover(int one, int two)
{
int i;
int point; /* crossover point */

/* select crossover point */
if(NVARS > 1)
  {
  if(NVARS == 2)
        point = 1;
  else
        point = (rand() % (NVARS - 1)) + 1;

  for (i = 0; i < point; i++)
       swap(&population[one].gene, &population[two].gene);

  }
}

/*************************************************************/
/* Swap: A swap procedure that helps in swapping 2 variables */
/*************************************************************/

void swap(double *x, double *y)
{
double temp;

temp = *x;
*x = *y;
*y = temp;

}

/**************************************************************/
/* Mutation: Random uniform mutation. A variable selected for */
/* mutation is replaced by a random value between lower and   */
/* upper bounds of this variable                              */
/**************************************************************/

void mutate(void)
{
int i, j;
double lbound, hbound;
double x;

for (i = 0; i < POPSIZE; i++)
     for (j = 0; j < NVARS; j++)
           {
           x = rand()%1000/1000.0;
           if (x < PMUTATION)
                 {
                 /* find the bounds on the variable to be mutated */
                 lbound = population.lower[j];
                 hbound = population.upper[j];  
                 population.gene[j] = randval(lbound, hbound);
                 }
           }
}

/***************************************************************/
/* Report function: Reports progress of the simulation. Data   */
/* dumped into the  output file are separated by commas        */
/***************************************************************/

void report(void)
{
int i;
double best_val;            /* best population fitness */
double avg;                 /* avg population fitness */
double stddev;              /* std. deviation of population fitness */
double sum_square;          /* sum of square for std. calc */
double square_sum;          /* square of sum for std. calc */
double sum;                 /* total population fitness */

sum = 0.0;
sum_square = 0.0;

for (i = 0; i < POPSIZE; i++)
     {
     sum += population.fitness;
     sum_square += population.fitness * population.fitness;
     }

avg = sum/(double)POPSIZE;
square_sum = avg * avg * POPSIZE;
stddev = sqrt((sum_square - square_sum)/(POPSIZE - 1));
best_val = population[POPSIZE].fitness;

fprintf(galog, "\n%5d,      %6.3f, %6.3f, %6.3f \n\n", generation,
                                     best_val, avg, stddev);
}

/**************************************************************/
/* Main function: Each generation involves selecting the best */
/* members, performing crossover & mutation and then          */
/* evaluating the resulting population, until the terminating */
/* condition is satisfied                                     */
/**************************************************************/

void main(void)
{
int i;

if ((galog = fopen("galog.txt","w"))==NULL)
     {
     exit(1);
     }
generation = 0;

fprintf(galog, "\n generation  best  average  standard \n");
fprintf(galog, " number      value fitness  deviation \n");

initialize();
evaluate();
keep_the_best();
while(generation<MAXGENS)
     {
     generation++;
     select();
     crossover();
     mutate();
     report();
     evaluate();
     elitist();
     }
fprintf(galog,"\n\n Simulation completed\n");
fprintf(galog,"\n Best member: \n");

for (i = 0; i < NVARS; i++)
  {
  fprintf (galog,"\n var(%d) = %3.3f",i,population[POPSIZE].gene);
  }
fprintf(galog,"\n\n Best fitness = %3.3f",population[POPSIZE].fitness);
fclose(galog);
printf("Success\n");
}
/***************************************************************/

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲欧美在线视频| 欧美高清hd18日本| 欧美在线免费观看视频| 日韩亚洲欧美在线观看| 亚洲欧美另类图片小说| 国产在线播精品第三| 欧美日韩大陆一区二区| 国产精品每日更新| 免费在线观看视频一区| 在线观看日产精品| 国产精品久久久久影院亚瑟| 精品一区二区国语对白| 欧美狂野另类xxxxoooo| 亚洲资源在线观看| 99国产精品久久久久久久久久 | 久久精品国产一区二区| 91成人国产精品| 最近中文字幕一区二区三区| 国产麻豆视频精品| 久久亚洲二区三区| 蜜臀va亚洲va欧美va天堂 | 91小视频在线| 中国av一区二区三区| 国产精品资源在线看| 欧美一区二区三区啪啪| 日韩黄色一级片| 欧美日韩国产首页| 亚洲国产欧美在线人成| 欧美无砖砖区免费| 亚洲bt欧美bt精品777| 欧美性猛交xxxxxxxx| 亚洲一区中文在线| 欧美影片第一页| 亚洲国产日韩av| 欧美放荡的少妇| 秋霞午夜鲁丝一区二区老狼| 日韩精品最新网址| 国产在线视视频有精品| 国产无一区二区| 成人黄页毛片网站| 亚洲男帅同性gay1069| 91国产视频在线观看| 亚洲午夜成aⅴ人片| 91精品欧美一区二区三区综合在| 日本大胆欧美人术艺术动态| 欧美精品一区二区高清在线观看| 色8久久精品久久久久久蜜| 亚洲免费观看视频| 欧美日韩国产精品自在自线| 日日夜夜免费精品| 久久久亚洲高清| 99麻豆久久久国产精品免费| 亚洲国产aⅴ成人精品无吗| 在线播放视频一区| 国产一区美女在线| 国产精品久久久一本精品| 在线亚洲一区观看| 卡一卡二国产精品 | 26uuu亚洲| 97精品视频在线观看自产线路二| 亚洲一区自拍偷拍| 欧美成人激情免费网| yourporn久久国产精品| 午夜精品福利一区二区三区蜜桃| 日韩一区二区三区电影| 成人avav影音| 日本亚洲视频在线| 日韩毛片一二三区| 欧美电视剧在线观看完整版| 成人福利在线看| 日本视频在线一区| 亚洲免费观看高清完整版在线观看| 欧美日韩国产高清一区二区三区| 国产乱人伦偷精品视频不卡| 一区二区久久久久久| 26uuuu精品一区二区| 欧美体内she精视频| 国产一区二区三区美女| 亚洲国产美女搞黄色| 国产精品水嫩水嫩| 亚洲欧美日本在线| 精品999在线播放| 欧美视频在线观看一区| 成人在线视频一区二区| 日韩电影免费在线| 亚洲精品高清在线| 国产女同互慰高潮91漫画| 这里只有精品电影| 色综合天天综合给合国产| 国产一级精品在线| 美国av一区二区| 午夜伊人狠狠久久| 一区二区三区国产精华| 国产精品久久久久久久久动漫| 日韩视频在线观看一区二区| 欧美伊人精品成人久久综合97| 大桥未久av一区二区三区中文| 久久99久国产精品黄毛片色诱| 亚洲成人av一区二区三区| 亚洲欧美自拍偷拍| 国产精品国产三级国产aⅴ原创| 欧美电视剧在线观看完整版| 欧美一卡2卡三卡4卡5免费| 欧美性色黄大片| 在线免费观看不卡av| 91蝌蚪国产九色| 91免费视频观看| 99精品久久99久久久久| www.99精品| 91麻豆123| 日本高清成人免费播放| 色av一区二区| 一本一本大道香蕉久在线精品| www.欧美色图| 91在线播放网址| 91国产福利在线| 欧美日产在线观看| 欧美日韩国产另类不卡| 日韩视频不卡中文| 欧美精品一区二区三区四区| 国产欧美日韩激情| 国产精品入口麻豆九色| 亚洲天堂av一区| 亚洲精品乱码久久久久久久久 | 精品一区二区久久| 韩国成人福利片在线播放| 精品无码三级在线观看视频| 国产揄拍国内精品对白| 丰满放荡岳乱妇91ww| 色综合中文综合网| 久久理论电影网| 久久久久国产精品麻豆| 欧美国产日韩亚洲一区| 亚洲欧洲日韩av| 亚洲国产精品久久久久秋霞影院| 日本在线不卡一区| 国产精品一区一区| 久久精品欧美日韩精品| 国产精品国产三级国产普通话99 | 日韩欧美国产一区二区在线播放| 日韩午夜三级在线| 国产精品五月天| 亚洲一卡二卡三卡四卡五卡| 免费在线观看视频一区| 成人av在线看| 欧美日本一区二区在线观看| 久久综合九色综合欧美98| 中文字幕一区二区三区四区不卡| 亚洲小少妇裸体bbw| 国产一区二区精品久久99| 99精品热视频| 欧美r级在线观看| 亚洲日本青草视频在线怡红院| 日本伊人色综合网| 91在线免费视频观看| 欧美mv日韩mv| 一区二区三区成人| 国产精品一区久久久久| 欧美体内she精高潮| 亚洲国产精品成人久久综合一区 | 亚洲精品一卡二卡| 美女视频黄免费的久久| 色综合天天综合网天天看片| 亚洲精品在线免费观看视频| 亚洲永久精品国产| 国产不卡视频在线观看| 欧美一区二区视频网站| 亚洲品质自拍视频网站| 韩国一区二区在线观看| 欧美日韩久久一区| 亚洲欧美日韩中文字幕一区二区三区 | k8久久久一区二区三区| 欧美电视剧免费全集观看| 一区二区三区欧美在线观看| 国产福利不卡视频| 日韩亚洲欧美在线| 日韩av在线免费观看不卡| 色婷婷一区二区| 国产精品污网站| 国产精品资源在线| 精品少妇一区二区三区在线播放 | 精品一区二区三区欧美| 欧美精品高清视频| 亚洲第一成年网| 一本大道综合伊人精品热热| 国产三级精品三级在线专区| 久久精品国产第一区二区三区| 欧美老女人第四色| 亚洲一二三四久久| 在线视频一区二区三| 国产精品护士白丝一区av| 粉嫩一区二区三区在线看 | 欧美一区二区三区在线| 亚洲国产精品一区二区www在线| 99久久综合国产精品| 国产精品乱人伦一区二区| 国产精品456露脸| 中文字幕欧美区| 99视频在线精品| 亚洲精品国产一区二区三区四区在线|