bat algorithm java code
#1

RESPECTED SIR,
        Please help to me the BAT Algorithm code in any language.  
If it is in java most Welcome.
      Thanking You
Reply
#2
import java.util.Random;

public class Bat
{
private int n;
private float A, r;
private float Qmin, Qmax;
private int d;
private int NofGen;
private float fmin;
private int fminIndex;
private float Fnew;
private int loopCounter;

private float Q[], V[][], Sol[][], UL_bound[][], fitness[], S[][], Best[];

private Random myRand;

public Bat(
int NBats,
float loudness,
float pulseRate,
float minFreq,
float maxFreq,
int NofGeneration,
int dimension
)
{
n = NBats;
A = loudness;
r = pulseRate;
Qmin = minFreq;
Qmax = maxFreq;
NofGen = NofGeneration;
d = dimension;

S = new float[n][d];
Best = new float[d];
UL_bound = new float[2][d];

//default bounds
for(int i = 0 ; i < d ; i++)
{
UL_bound[0][i] = -10000;
UL_bound[1][i] = 10000;
}

loopCounter = 0;
myRand = new Random();

Q = new float[n];
for(int i = 0 ; i < n ; i++)
Q[i] = 0;

V = new float[n][d];
for(int i = 0 ; i < n ; i++)
for(int j = 0 ; j < d ; j++)
V[i][j] = 0;

}



public void intial()
{

Sol = new float[n][d];
for(int i = 0 ; i < n ; i++)
for(int j = 0 ; j < d ; j++)
{
float t = myRand.nextFloat();
//(upper -lower)*rand + lower
Sol[i][j] = t * (UL_bound[1][j] - UL_bound[0][j]) + UL_bound[0][j];
}


fitness = new float[n];
for(int i = 0 ; i < n ; i++)
fitness[i] = function(Sol[i]);

//finding fmin
fmin = fitness[0];
fminIndex = 0;
for(int i = 0 ; i < n ; i++)
{
if (fitness[i] < fmin)
{
fmin = fitness[i];
fminIndex = i;
}
}

//setting best
for(int j = 0 ; j < d ; j++)
Best[j] = Sol[fminIndex][j];

}

public void start()
{

while(loopCounter < NofGen)
{

for(int i = 0 ; i < n ; i++)
{

Q[i] = Qmin + (Qmin - Qmax)* myRand.nextFloat();

for(int j = 0 ; j < d ; j++)
V[i][j] = V[i][j] + (Sol[i][j]-Best[j])*Q[i];

for(int j = 0 ; j < d ; j++)
S[i][j] = Sol[i][j] + V[i][j];

Sol[i] = simpleBounds(Sol[i]);

if(myRand.nextFloat() > r)
for(int j = 0 ; j < d ; j++)
S[i][j] = (float) (Best[j] + (.001 * myRand.nextFloat()) );

Fnew = function(S[i]);

if(Fnew <= fitness[i] && myRand.nextFloat() < A)
{
for(int j = 0 ; j < d ; j++)
Sol[i][j] = S[i][j];

fitness[i] = Fnew;
}

if(Fnew <= fmin)
{
fmin = Fnew;
for(int j = 0 ; j < d ; j++)
Best[j] = S[i][j];
}

}
loopCounter++;

}

}

public float[] simpleBounds(float p[])
{
for(int i = 0 ; i < d ; i++)
{
if(p[i] < UL_bound[0][i])
p[i] = UL_bound[0][i];

if(p[i] > UL_bound[1][i])
p[i] = UL_bound[1][i];
}
return p;
}
float function(float p[])
{
// Sphere function with fmin=0 at (0,0,...,0)
float sum = 0;
for(int i = 0 ; i < p.length ; i++)
sum = sum + p[i]*p[i];
return sum;

}
public float printResult()
{
System.out.println("After " + loopCounter + "Repeats :");

for(int i = 0 ; i < d ; i++)
System.out.print(Best[i] + ", ");

System.out.println ( "F(x) = " + fmin);
return fmin;
}

public void set_UL_Bound(int n, float L, float U)
{
if( n < d && n >= 0)
{
UL_bound[0][n] = L;
UL_bound[1][n] = U;
}
}




}
Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Popular Searches: float, spectral bat, history of mobile charging by heart bat, bat ball information in marathi, bat algorithm ppt, blind as a bat, spectral bat pictures,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Possibly Related Threads...
Thread Author Replies Views Last Post
  program for ticket reservation using multithreading in java 0 1,067 08-10-2018, 10:00 AM
Last Post: Guest
  algorithm of railway reservation system 0 669 02-10-2018, 10:50 PM
Last Post: Guest
  icse java projects class 10 free download 0 848 25-09-2018, 10:32 PM
Last Post: Guest
  java source code for voice based email for blinds 0 736 25-09-2018, 09:40 AM
Last Post: Guest
  techmax core java book pdf download 0 656 20-09-2018, 12:54 PM
Last Post: Guest
  rnsit java notes download 0 763 08-08-2018, 10:23 PM
Last Post: Guest
  image steganography source code in java pdf 0 759 04-08-2018, 09:38 PM
Last Post: Guest
  download prisoner face identification system in java source code 0 528 02-08-2018, 01:28 PM
Last Post: Guest
  data flow diagram for chess game in core java 0 694 02-08-2018, 10:39 AM
Last Post: Guest
  java project on automated robot for military system 0 621 23-07-2018, 11:27 AM
Last Post: Guest

Forum Jump: