logo资料库

一种人工蜂群算法(简称ABC算法),最新算法,本人编写.doc

第1页 / 共10页
第2页 / 共10页
第3页 / 共10页
第4页 / 共10页
第5页 / 共10页
第6页 / 共10页
第7页 / 共10页
第8页 / 共10页
资料共10页,剩余部分请下载后查看
/* ABC algorithm coded using C programming language */ /* Artificial Bee Colony (ABC) is one of the most recently defined algorithms by Dervis Karaboga in 2005, motivated by the intelligent behavior of honey bees. */ /* Referance Papers*/ /*D. Karaboga, AN IDEA BASED ON HONEY BEE SWARM FOR NUMERICAL OPTIMIZATION,TECHNICAL REPORT-TR06, Erciyes University, Engineering Faculty, Computer Engineering Department 2005.*/ /*D. Karaboga, B. Basturk, A powerful and Efficient Algorithm for Numerical Function Optimization: Artificial Bee Colony (ABC) Algorithm, Journal of Global Optimization, Volume:39, Issue:3,pp:459-171, November 2007,ISSN:0925-5001 , doi: 10.1007/s10898-007-9149-x */ /*D. Karaboga, B. Basturk, On The Performance Of Artificial Bee Colony (ABC) Algorithm, Applied Soft Computing,Volume 8, Issue 1, January 2008, Pages 687-697. */ /*D. Karaboga, B. Akay, A Comparative Study of Artificial Bee Colony Algorithm, Applied Mathematics and Computation, 214, 108-132, 2009. */ /*Copyright ? 2009 Erciyes University, Intelligent Systems Research Group, The Dept. of Computer Engineering*/ /*Contact: Dervis Karaboga (karaboga@erciyes.edu.tr ) Bahriye Basturk Akay (bahriye@erciyes.edu.tr) */ #include #include #include #include #include /* Control Parameters of ABC algorithm*/ //定义常量 #define NP 20 /* The number of colony size (employed bees+onlooker bees)*/ #define FoodNumber NP/2 /*The number of food sources equals the half of the colony size*/ #define limit 100 /*A food source which could not be improved through "limit"
trials is abandoned by its employed bee*/ #define maxCycle 2500 /*The number of cycles for foraging {a stopping criteria}*/ /* Problem specific variables*/ #define D 100 /*The number of parameters of the problem to be optimized*/ #define lb -100 /*lower bound of the parameters. */ #define ub 100 /*upper bound of the parameters. lb and ub can be defined as arrays for the problems of which parameters have different bounds*/ #define runtime 30 robustness*/ /*Algorithm can be run many times in order to see its /*f is a vector holding objective function values associated double Foods[FoodNumber][D]; /*Foods is the population of food sources. Each row of Foods matrix is a vector holding D parameters to be optimized. The number of rows of Foods matrix equals to the FoodNumber*/ double f[FoodNumber]; with food sources */ double fitness[FoodNumber]; /*fitness is a vector holding fitness (quality) values associated with food sources*/ double trial[FoodNumber]; /*trial is a vector holding trial numbers through which solutions can not be improved*/ double prob[FoodNumber]; /*prob is a vector holding probabilities of food sources (solutions) to be chosen*/ double by [D]; v_{ij}=x_{ij}+\phi_{ij}*(x_{kj}-x_{ij}) j is a rand()omly chosen parameter and k is a rand()omlu chosen solution different from i*/ double ObjValSol; /*Objective function value of new solution*/ double FitnessSol; /*Fitness value of new solution*/ int neighbour, param2change; corresponds to k in equation v_{ij}=x_{ij}+\phi_{ij}*(x_{kj}-x_{ij})*/ double GlobalMin; /*Optimum solution obtained by ABC algorithm*/ double GlobalParams[D]; /*Parameters of the optimum solution*/ double GlobalMins[runtime]; /*GlobalMins holds the GlobalMin of each run in multiple runs*/ double r; /*a rand()om number in the range [0,1)*/ (neighbour) /*param2change corrresponds to j, neighbour produced solution /*New solution /*a function pointer returning double and taking a D-dimensional array as argument */ /*If your function takes additional arguments then change function pointer definition and lines calling "...=function(solution);" in the code*/ typedef double (*FunctionCallback)(double sol[D]); /*benchmark functions */ double sphere(double sol[D]); double Rosenbrock(double sol[D]);
double Griewank(double sol[D]); double Rastrigin(double sol[D]); /*Write your own objective function name instead of sphere*/ FunctionCallback function = &sphere; /*Fitness function*/ double CalculateFitness(double fun) { double result=0; if(fun>=0) { result=1/(fun+1); } else { result=1+fabs(fun); } return result; } /*The best food source is memorized*/ //记忆最佳值组合 void MemorizeBestSource() { int i,j; for(i=0;i
for (j=0;j
neighbour=(int)(r*FoodNumber); } for(j=0;jub) solution[param2change]=ub; ObjValSol=function(solution); FitnessSol=CalculateFitness(ObjValSol); /*a greedy selection is applied between the current solution i and its mutant*/ if (FitnessSol>fitness[i]) { /*If the mutant solution is better than the current solution i, replace the solution with the mutant and reset the trial counter of solution i*/ trial[i]=0; for(j=0;j
/*Different schemes can be used to calculate the probability values*/ /*For example prob(i)=fitness(i)/sum(fitness)*/ /*or in a way used in the metot below prob(i)=a*fitness(i)/max(fitness)+b*/ /*probability values are calculated by using fitness values and normalized by dividing maximum fitness value*/ void CalculateProbabilities() { int i; double maxfit; maxfit=fitness[0]; for (i=1;imaxfit) maxfit=fitness[i]; for (i=0;i
solution i*/ (double)rand() / ((double)(RAND_MAX)+(double)(1)) ); r = ( neighbour=(int)(r*FoodNumber); (double)rand() / ((double)(RAND_MAX)+(double)(1)) ); /*Randomly selected solution must be different from the solution i*/ while(neighbour==i) { r = ( neighbour=(int)(r*FoodNumber); } for(j=0;jub) solution[param2change]=ub; ObjValSol=function(solution); FitnessSol=CalculateFitness(ObjValSol); /*a greedy selection is applied between the current solution i and its mutant*/ if (FitnessSol>fitness[i]) { /*If the mutant solution is better than the current solution i, replace the solution with the mutant and reset the trial counter of solution i*/ trial[i]=0; for(j=0;j
} /*if */ i++; if (i==FoodNumber-1) i=0; }/*while*/ /*end of onlooker bee phase */ } /*determine the food sources whose trial counter exceeds the "limit" value. In Basic ABC, only one scout is allowed to occur in each cycle*/ void SendScoutBees() { int maxtrialindex,i; maxtrialindex=0; for (i=1;itrial[maxtrialindex]) maxtrialindex=i; if(trial[maxtrialindex]>=limit) { init(maxtrialindex); } } /*Main program of the ABC algorithm*/ int main() { int iter,run,j; double mean; mean=0; srand(time(NULL)); for(run=0;run
分享到:
收藏