2024年5月10日发(作者:)
import ;
public class beeColony {
bees)*/
/* Problem specific variables*/
int D = 100; /*The number of parameters of the problem to be
double lb = -5.12; /*lower bound of the parameters. */
double ub = 5.12; /*upper bound of the parameters. lb and ub can be
int FoodNumber = NP/2; /*The number of food sources equals the half
int limit = 100; /*A food source which could not be improved through
int maxCycle = 2500; /*The number of cycles for foraging {a stopping
of the colony size*/
"limit" trials is abandoned by its employed bee*/
criteria}*/
/* Control Parameters of ABC algorithm*/
int NP=20; /* The number of colony size (employed bees+onlooker
optimized*/
defined as arrays for the problems of which parameters have different
bounds*/
int dizi1[]=new int[10];
double Foods[][]=new double[FoodNumber][D]; /*Foods is
int runtime = 30; /*Algorithm can be run many times in order to see
its robustness*/
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[]=new double[FoodNumber]; /*f is a vector holding
objective function values associated with food sources */
double fitness[]=new double[FoodNumber]; /*fitness is a vector
double trial[]=new double[FoodNumber]; /*trial is a vector
double prob[]=new double[FoodNumber]; /*prob is a vector
double solution[]=new double[D]; /*New solution
holding fitness (quality) values associated with food sources*/
holding trial numbers through which solutions can not be improved*/
holding probabilities of food sources (solutions) to be chosen*/
(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*/
double ObjValSol; /*Objective function value of new
double FitnessSol; /*Fitness value of new solution*/
int neighbour, param2change; /*param2change
solution*/
corrresponds to j, neighbour corresponds to k in equation
v_{ij}=x_{ij}+phi_{ij}*(x_{kj}-x_{ij})*/
runs*/
//
/*benchmark functions */
typedef double (*FunctionCallback)(double sol[D]);
/*a function pointer returning double and taking a D-dimensional array
/*If your function takes additional arguments then change function
as argument */
pointer definition and lines calling "...=function(solution);" in the code*/
double r; /*a random number in the range [0,1)*/
double GlobalMin; /*Optimum solution
double GlobalParams[]=new double[D];
double GlobalMins[]=new double[runtime];
/*GlobalMins holds the GlobalMin of each run in multiple
obtained by ABC algorithm*/
/*Parameters of the optimum solution*/
发布评论