I am implementing the Monarch butterfly optimization algorithm in Java. The levy flight function (which I converted from the matlab code of the original MBO project to java) used to update butterflies in subpopulation 2 generates data outside the range of subpopulation 2. Need help to correct the error. Is this the right equation?
Here is the code
public static double[] levyFlight(int stepSize, int dim) {
double[] deltaX = new double[dim];
Random rand = new Random().nextDouble();
for (int i = 0; i < dim; i++) {
double sum = 0.0;
for (int j = 0; j < stepSize; j++) {
double fx = (Math.tan(Math.PI * rand));
sum += fx;
}
deltaX[i] = sum;
}
return deltaX;
}
public static void imboupdate() {
int nbtask = taskNum;
double alpha = 0.0;
int stepSize
double[] deltaX = new double[nbtask];
stepSize = (int) Math.ceil(new Random().nextDouble() * 2 * maxIterations);
deltaX = levyFlight(stepSize, nbtask);
for(int j = 0; j<SP2; j++) {
alpha = maxStep /((currentIteration+1) * (currentIteration+1));
int[] Land2 = new int [taskNum];
Random rand = new Random().nextDouble();
for(int k = 0; k<nbtask; k++) {
if(rand> SelfAdaptiveStrategy && rand > adjustmentRate) {
int[] selectedButterfly = Subpopulation2.get(j);
int value = selectedButterfly[k];
**Land2[k] = (int) (value + alpha*(deltaX[k] - 0.5));**
}
}
newPopulation.add(Land2);
}
}