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

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

?? 米凱利維奇遺傳算法源程序.txt

?? 米凱利維奇遺傳算法
?? 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,
                                   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);
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲美女一区二区三区| 成人免费av网站| 成人深夜在线观看| 欧美挠脚心视频网站| 中文在线免费一区三区高中清不卡| 亚洲黄色录像片| 懂色中文一区二区在线播放| 91麻豆精品国产91久久久久久| 国产精品白丝在线| 国产在线视频精品一区| 欧美日韩午夜在线视频| 国产精品久久久久久久久动漫| 久久99国产精品成人| 欧美日韩高清一区二区不卡| 亚洲品质自拍视频网站| jvid福利写真一区二区三区| 26uuu国产日韩综合| 奇米色一区二区| 欧美日韩一区二区三区四区五区| 国产精品久久久久久久蜜臀| 国产精品一区免费在线观看| 精品国产免费人成在线观看| 三级成人在线视频| 欧美区在线观看| 亚洲一区国产视频| 日本道精品一区二区三区| 国产欧美日产一区| 国产一区二区三区四| 久久久久99精品国产片| 国产一区二区看久久| www国产成人免费观看视频 深夜成人网| 丝袜亚洲另类欧美综合| 欧美一区二区精品| 久久99日本精品| 精品乱人伦小说| 极品少妇xxxx精品少妇| 精品剧情在线观看| 国产精品正在播放| 国产精品久久久久国产精品日日 | 最新高清无码专区| 国产91色综合久久免费分享| 国产网红主播福利一区二区| 成人激情小说网站| 国产精品福利电影一区二区三区四区| 国产精品996| 亚洲欧美在线aaa| 91久久一区二区| 轻轻草成人在线| 精品久久久久久久久久久久包黑料| 国产原创一区二区三区| 国产视频一区二区在线| 91亚洲精品久久久蜜桃网站| 亚洲图片欧美激情| 欧美日韩极品在线观看一区| 日韩成人伦理电影在线观看| 精品国产自在久精品国产| 国产91精品一区二区麻豆网站| 国产精品色眯眯| 欧洲一区二区三区免费视频| 美国一区二区三区在线播放| 欧美国产1区2区| 欧美日韩激情一区二区三区| 久久 天天综合| 国产精品久久久久久久久免费桃花 | 成人久久18免费网站麻豆| 亚洲人妖av一区二区| 日韩一级片在线播放| 国产精品888| 亚洲一区影音先锋| 国产校园另类小说区| 色婷婷综合久色| 久久av老司机精品网站导航| 自拍偷拍欧美激情| 日韩午夜电影av| 一本久久a久久精品亚洲| 免费在线观看精品| 1024亚洲合集| 久久亚洲精华国产精华液| 91网站最新网址| 久久国产视频网| 亚洲一区二区三区美女| 久久蜜桃av一区精品变态类天堂 | 91精品久久久久久蜜臀| 成人一区二区在线观看| 天天影视网天天综合色在线播放| 国产调教视频一区| 51久久夜色精品国产麻豆| 99麻豆久久久国产精品免费优播| 日韩电影在线免费看| 亚洲日本电影在线| 欧美激情中文字幕一区二区| 日韩精品一区二区三区视频播放| 91啦中文在线观看| 成人一区在线看| 国产一区二区美女诱惑| 男女性色大片免费观看一区二区| 亚洲精品视频在线看| 中文字幕免费不卡在线| 久久婷婷成人综合色| 欧美一区二区三级| 精品视频色一区| 在线观看日韩电影| av日韩在线网站| 成人晚上爱看视频| 国产91富婆露脸刺激对白| 麻豆国产精品视频| 青青国产91久久久久久| 亚洲图片欧美视频| 亚洲一区二区三区在线看| 亚洲免费观看高清完整版在线| 国产精品久线在线观看| 国产精品视频yy9299一区| 欧美高清在线精品一区| 中文幕一区二区三区久久蜜桃| 国产色产综合色产在线视频| 久久综合中文字幕| 久久先锋影音av鲁色资源网| 精品久久久久久久久久久久久久久久久| 91精品黄色片免费大全| 91精品国产麻豆国产自产在线 | 精品国产乱码久久久久久免费 | 久久人人超碰精品| 2020国产精品自拍| 久久精品欧美一区二区三区麻豆| 精品国产露脸精彩对白| 国产色91在线| 国产精品区一区二区三区| 亚洲色图清纯唯美| 亚洲午夜久久久久久久久电影院 | 国产精品久久久久久户外露出| 亚洲国产精品99久久久久久久久 | 99久久免费视频.com| 91免费观看在线| 欧美天堂亚洲电影院在线播放| 欧美剧在线免费观看网站 | 在线观看日韩毛片| 欧美肥大bbwbbw高潮| 精品久久免费看| 亚洲欧美怡红院| 日韩国产在线一| 国产在线看一区| 91国内精品野花午夜精品| 欧美老女人第四色| 国产丝袜欧美中文另类| 亚洲自拍偷拍麻豆| 久久精品久久精品| 99热99精品| 欧美夫妻性生活| 国产精品久久久久影院色老大 | 亚洲欧美综合色| 免费成人结看片| 波多野结衣中文字幕一区二区三区| 欧美怡红院视频| 久久久影院官网| 亚洲动漫第一页| 国产成人精品www牛牛影视| 欧美性高清videossexo| 久久久.com| 视频在线在亚洲| 白白色亚洲国产精品| 欧美一级日韩免费不卡| 国产精品初高中害羞小美女文| 日韩中文欧美在线| 91麻豆高清视频| 国产色爱av资源综合区| 免费观看久久久4p| 欧美丝袜丝交足nylons图片| 欧美精品一区二区三区四区| 亚洲国产日韩一区二区| 成人少妇影院yyyy| 精品日产卡一卡二卡麻豆| 亚洲午夜一区二区| 99精品欧美一区二区三区小说| 日韩精品一区二区三区中文不卡 | 欧美大片国产精品| 亚洲最大的成人av| 成人视屏免费看| 久久久久久麻豆| 蜜乳av一区二区| 欧美日韩国产天堂| 亚洲日韩欧美一区二区在线| 国产成人精品综合在线观看| 欧美日产在线观看| 亚洲香蕉伊在人在线观| 色综合天天性综合| 国产精品乱码一区二区三区软件| 久久精品国产免费看久久精品| 精品污污网站免费看| 亚洲美女视频一区| 99riav一区二区三区| 国产精品嫩草影院com| 国产伦精一区二区三区| 精品福利二区三区| 免费观看一级特黄欧美大片| 在线播放91灌醉迷j高跟美女 | 日本欧美一区二区三区乱码| 欧美婷婷六月丁香综合色| 亚洲福利一区二区三区| 欧美日韩亚州综合| 视频在线观看国产精品|