作业帮 > 综合 > 作业

人工蜂群算法里太多比喻了,能不能就算法本身的步骤来讲讲?

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/11/09 10:11:29
人工蜂群算法里太多比喻了,能不能就算法本身的步骤来讲讲?
哪位熟悉人工蜂群算法的么?硕士论文中要用,只是介绍的论文和文章中都是原始意义,就是太多比喻,雇佣蜂侦查蜂回巢跳舞什么的.能不能就计算机算法本身,如怎样编码,初始种群生成,从这个角度来讲讲这个算法的步骤?
直接给你JAVA代码吧,看的简单易懂
import java.lang.Math;
public class beeColony {
\x05/* Control Parameters of ABC algorithm*/
\x05int NP=20; /* The number of colony size (employed bees+onlooker bees)*/
\x05int FoodNumber = NP/2; /*The number of food sources equals the half of the colony size*/
\x05int limit = 100; /*A food source which could not be improved through "limit" trials is abandoned by its employed bee*/
\x05int maxCycle = 2500; /*The number of cycles for foraging {a stopping criteria}*/
\x05/* Problem specific variables*/
\x05int D = 100; /*The number of parameters of the problem to be optimized*/
\x05double lb = -5.12; /*lower bound of the parameters.*/
\x05double ub = 5.12; /*upper bound of the parameters.lb and ub can be defined as arrays for the problems of which parameters have different bounds*/
\x05int runtime = 30; /*Algorithm can be run many times in order to see its robustness*/
\x05int dizi1[]=new int[10];
\x05double Foods[][]=new double[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*/
\x05double f[]=new double[FoodNumber]; /*f is a vector holding objective function values associated with food sources */
\x05double fitness[]=new double[FoodNumber]; /*fitness is a vector holding fitness (quality) values associated with food sources*/
\x05double trial[]=new double[FoodNumber]; /*trial is a vector holding trial numbers through which solutions can not be improved*/
\x05double prob[]=new double[FoodNumber]; /*prob is a vector holding probabilities of food sources (solutions) to be chosen*/
\x05double solution[]=new double[D]; /*New solution (neighbour) produced by v_{ij}=x_{ij}+\phi_{ij}*(x_{kj}-x_{ij}) j is a randomly chosen parameter and k is a randomlu chosen solution different from i*/
\x05
\x05double ObjValSol; /*Objective function value of new solution*/
\x05double FitnessSol; /*Fitness value of new solution*/
\x05int neighbour,param2change; /*param2change corrresponds to j,neighbour corresponds to k in equation v_{ij}=x_{ij}+\phi_{ij}*(x_{kj}-x_{ij})*/
\x05double GlobalMin; /*Optimum solution obtained by ABC algorithm*/
\x05double GlobalParams[]=new double[D]; /*Parameters of the optimum solution*/
\x05double GlobalMins[]=new double[runtime];
\x05 /*GlobalMins holds the GlobalMin of each run in multiple runs*/
\x05double r; /*a random number in the range [0,1)*/
\x05/*a function pointer returning double and taking a D-dimensional array as argument */
\x05/*If your function takes additional arguments then change function pointer definition and lines calling "...=function(solution);" in the code*/
//\x05typedef double (*FunctionCallback)(double sol[D]);
\x05/*benchmark functions */
//\x05double sphere(double sol[D]);
//\x05double Rosenbrock(double sol[D]);
//\x05double Griewank(double sol[D]);
//\x05double Rastrigin(double sol[D]);
\x05/*Write your own objective function name instead of sphere*/
//\x05FunctionCallback function = &sphere;
\x05/*Fitness function*/
\x05double CalculateFitness(double fun)
\x05 {
\x05\x05 double result=0;
\x05\x05 if(fun>=0)
\x05\x05 {
\x05\x05\x05 result=1/(fun+1);
\x05\x05 }
\x05\x05 else
\x05\x05 {
\x05\x05\x05
\x05\x05\x05 result=1+Math.abs(fun);
\x05\x05 }
\x05\x05 return result;
\x05 }
\x05/*The best food source is memorized*/
\x05void MemorizeBestSource()
\x05{
\x05 int i,j;
\x05
\x05\x05for(i=0;i