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

? 歡迎來(lái)到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? ga.c

?? 遺傳算法是近來(lái)較為熱門的結(jié)構(gòu)優(yōu)化方法,C源代碼
?? C
字號(hào):
/* 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); 
} 
  
/**************************************************************/ 
/* 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"); 
} 
/***************************************************************/ 

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
99视频热这里只有精品免费| 亚洲精品福利视频网站| 国产精品乱码人人做人人爱 | 伊人开心综合网| 亚洲高清视频中文字幕| 麻豆国产欧美一区二区三区| 国产精品白丝av| 91成人在线免费观看| 日韩一级在线观看| 欧美激情一区三区| 亚洲一二三级电影| 国产一区二区三区香蕉| 99re热这里只有精品视频| 欧美日韩久久一区二区| 国产色一区二区| 亚洲无人区一区| 国产精品亚洲第一| 欧美日韩在线综合| 国产精品无遮挡| 日韩福利电影在线| 99re8在线精品视频免费播放| 五月婷婷综合在线| 国产精品亚洲综合一区在线观看| 欧美在线观看视频一区二区三区| 欧美大片一区二区三区| 亚洲另类在线制服丝袜| 精品一区二区三区香蕉蜜桃 | 欧美国产禁国产网站cc| 午夜一区二区三区在线观看| 狠狠色丁香九九婷婷综合五月| 91小视频在线免费看| 日韩欧美卡一卡二| 亚洲精品久久7777| 国产乱子轮精品视频| 欧美揉bbbbb揉bbbbb| 中文欧美字幕免费| 久久99精品久久久久| 在线免费观看日本欧美| 中文一区在线播放| 理论电影国产精品| 欧美日韩午夜精品| 亚洲色图另类专区| 国产91富婆露脸刺激对白| 欧美一区二区网站| 亚洲一二三四区| 成人app下载| 久久久一区二区| 久久超碰97中文字幕| 欧美三区在线观看| 亚洲精品日韩一| 成人黄色电影在线 | 国产精品综合在线视频| 欧美日本在线视频| 亚洲一区二区视频在线观看| youjizz久久| 国产亚洲人成网站| 韩国女主播一区二区三区| 在线成人免费视频| 亚洲午夜激情网站| 欧美视频日韩视频在线观看| 亚洲视频电影在线| 99国产欧美久久久精品| 国产精品免费aⅴ片在线观看| 国产在线视频一区二区三区| 日韩精品一区二区三区三区免费| 亚洲成av人片在线观看| 亚洲日本中文字幕区| 国产成人亚洲精品青草天美| 日韩欧美视频在线| 天堂精品中文字幕在线| 欧美日韩精品系列| 丝袜诱惑制服诱惑色一区在线观看| 色狠狠一区二区三区香蕉| 亚洲欧洲一区二区在线播放| gogo大胆日本视频一区| 日韩一区日韩二区| 99久久国产综合精品女不卡| 国产精品国产三级国产有无不卡| 春色校园综合激情亚洲| 日本一区二区三区视频视频| 风间由美中文字幕在线看视频国产欧美 | 欧美激情一区在线| 成人激情免费视频| 国产精品护士白丝一区av| 成人小视频在线| 亚洲视频小说图片| 欧美在线免费观看亚洲| 午夜精品免费在线| 日韩一区二区三区免费观看| 久久99热99| 久久久久国产精品麻豆| 粉嫩av亚洲一区二区图片| 1024精品合集| 欧美性猛片xxxx免费看久爱| 亚洲成人动漫在线观看| 91精品国产综合久久精品| 久久国产生活片100| 国产欧美一区二区精品久导航| 成人黄色网址在线观看| 一区二区三区蜜桃网| 欧美丰满美乳xxx高潮www| 日本欧美一区二区| 国产视频一区二区在线| 色视频成人在线观看免| 免费成人在线观看| 久久噜噜亚洲综合| 91小宝寻花一区二区三区| 亚洲最新视频在线播放| 欧美一级黄色大片| 成人免费视频一区二区| 一区二区在线观看免费| 欧美一级高清片| 成人av在线电影| 亚洲成人免费在线| 精品国产露脸精彩对白| av动漫一区二区| 日日夜夜精品视频免费| 久久精品无码一区二区三区| 91小宝寻花一区二区三区| 日本免费新一区视频| 中文字幕国产一区二区| 欧美午夜电影一区| 精品一区二区三区视频在线观看 | 成人午夜视频在线观看| 一区二区三区中文在线观看| 日韩无一区二区| 97精品国产97久久久久久久久久久久| 亚洲午夜免费电影| 国产精品综合二区| 亚洲一区二区五区| 国产色婷婷亚洲99精品小说| 欧美日韩一级二级三级| 国产suv精品一区二区6| 午夜精品123| 国产精品国产馆在线真实露脸| 欧美群妇大交群中文字幕| 国产精品一二三区| 日韩黄色免费电影| 亚洲精选在线视频| 久久亚洲一区二区三区四区| 欧美在线视频日韩| 成人综合在线网站| 伦理电影国产精品| 亚洲国产va精品久久久不卡综合| 国产亚洲综合在线| 欧美高清视频一二三区 | 国产精品视频免费看| 日韩三区在线观看| 欧美综合色免费| 成人国产一区二区三区精品| 久久99精品视频| 亚洲综合精品久久| 国产精品美女www爽爽爽| 精品国产一区二区三区久久久蜜月| 91久久人澡人人添人人爽欧美| 国产一区二区三区四区五区美女| 午夜精品久久久| 亚洲人成小说网站色在线| 国产欧美一区二区三区在线看蜜臀 | 久久久91精品国产一区二区精品| 欧美高清精品3d| 色偷偷成人一区二区三区91 | 久久久综合视频| 日韩丝袜美女视频| 欧美精品欧美精品系列| 91免费视频大全| 成人高清在线视频| 国产精品一区二区三区网站| 美女视频一区二区三区| 午夜电影网一区| 亚洲国产欧美日韩另类综合| 亚洲精品成人悠悠色影视| 国产精品久久久久婷婷| 中文字幕欧美日韩一区| 国产亚洲综合在线| 久久久久久久久久看片| 精品国产91洋老外米糕| 日韩欧美国产综合在线一区二区三区| 欧美视频一二三区| 欧洲一区二区av| 欧美中文字幕亚洲一区二区va在线| 99久久久无码国产精品| 成人av资源下载| 99视频精品全部免费在线| 9色porny自拍视频一区二区| 成人av电影在线观看| a美女胸又www黄视频久久| 成人精品国产免费网站| 成人免费看片app下载| eeuss影院一区二区三区| 波多野结衣一区二区三区| 中国色在线观看另类| 国产精品美女久久久久久久久久久| 欧美国产日韩精品免费观看| 中文字幕第一区二区| 国产精品久久久一本精品| 亚洲欧美另类在线| 夜夜嗨av一区二区三区| 爽好久久久欧美精品| 久久精品国产免费看久久精品|