با سلام و احترام
میخاستم بدونم کسی میدونه این کد که از الگوریتم خفاش استفاده کرده چه موضوعی
را حل میکنه و به چه شکلی میشه به یک بردار دو در دو مثل مسئله فروشنده دوره
گرد تبدیلش کرد
برای اجرا کافی هست داخل اکیلیپس اجرا بشه هیچگونه مشکلی نداره
با سپاس
package Test;
import java.util.Random;
public class BatAlgorithm {
/**
* @param args the command line arguments
*/
public int n, N_gen, Qmin, Qmax, N_iter, d;
public double A,r,min,max,fnew,fmin;
public double Lb[][],Ub[][],Q[],v[][],Sol[][],S[][],fitness[],temp[],best[];
public Random random;
public static void main(String[] args) {
BatAlgorithm x = new BatAlgorithm(2,10,0.5,0.5,10);
//pulse فرکانس پالس
}
public BatAlgorithm(
int bats,
int generations,
double loud,
double pulse,
int dimension
){
//initialization of variables
n=bats;
N_gen = generations;
A = loud;
r = pulse;
d = dimension;
Random rand = new Random();
//plan to change later and added as parameter
min = 0;
max = 100;
fmin = 0;
//decleration for the bounds
Lb = new double[1][d];
Ub = new double[1][d];
Q = new double[n]; // frequency
v = new double[n][d]; //velocity
//initialize solution array
Sol = new double[n][d];
S = new double[n][d];
fitness = new double[n]; // fitness container
best =new double[d];
temp = new double[d]; //temporary holder for a row in array Sol
for(int i=0;i<n;i++){
// for minimal coding : added initialize Q[]array with '0' as element
Q[i] = 0;
for(int x=0;x<d;x++){
// for minimal coding : added initialize v[][] array with '0' as
element
// v[i][x] = 0;
//find random double values from LB to UB
Sol[i][x]= (rand.nextDouble()*(max - min)) + min; //ارایه را
داره اینجا پر میکنه
temp[x] = Sol[i][x];
System.out.println("sol["+i+"]["+x+"] = "+Sol[i][x]); //test line
//System.out.println(rand.nextDouble()); //test line
}
fitness[i] = function(temp);
//initialize best and the fmin
if(i==0 || fmin > fitness[i]){
fmin = fitness[i];
for(int x=0;x<d;x++){
best[x] = Sol[i][x];
}
}
System.out.println("fitness["+i+"]"+fitness[i]); //test
}
System.out.println("fmin = "+fmin); //test
// special note to these variables (below)
// change if required for maximum effectivity
Qmin = 0;
Qmax = 2;
N_iter = 1; //number of function evaluation
// bat proper
for(int loop=0;loop<N_iter;loop++){
// loop over all bats/solutions
for(int i=0;i<n;i++){
Q[i] = Qmin+((Qmin-Qmax)*rand.nextDouble());
// loop for velocity
for(int vel=0;vel<d;vel++){
v[i][vel] = v[i][vel]+((Sol[i][vel]-best[vel])*Q[i]);
}
//new solutions
for(int x=0;x<d;x++){
S[i][x] = Sol[i][x] + v[i][x];
}
/**
* RESERVED SPOT for the QUESTIONABLE AREA ON THE
* MATLAB CODE (i think it is not needed for the java equivalent)
*/
// pulse rate
if(rand.nextDouble()>r){
for(int x=0;x<d;x++){
S[i][x] = best[x]+(0.001*rand.nextGaussian());
}
}
//putting current row of Sol to a temp array
for(int x=0;x<d;x++){
temp[x] = S[i][x];
}
fnew = function(temp);
// update if solution is improved, and not too loud
if((fnew<=fitness[i]) && (rand.nextDouble()<A)){
for(int x=0;x<d;x++){
Sol[i][x] = S[i][x];
fitness[i] = fnew;
}
}
//update current best solution
if(fnew<=fmin){
for(int x=0;x<d;x++){
best[x] = S[i][x];
fmin = fnew;
}
}
}
}
System.out.println(" ");
System.out.println("new fitness");
for(int i=0;i<n;i++){
System.out.println("fitness["+i+"]"+fitness[i]);
}
System.out.println("Fmin = "+fmin);
}
public double function(double value[]){
// sphere function where fmin is at 0
double result = 0;
for(int i=0;i<d;i++){
result += (value[i]*value[i]);
}
return result;
}
//possible that this function is not needed in java
public void set_bounds(int x, double L, double U){
//double temp_Lb[x];
//double temp_Ub[x];
for(int i=0; i<x; i++){
Lb[0][i] = L;
Ub[0][i] = U;
}
}
}
--
شما به این دلیل این پیغام را دریافت کرده اید که در گروه تخصصی رایانش ابری
وابسته به مرکز رایانش ابری دانشگاه صنعتی امیرکبیر و جامعه آزاد رایانش ابری
ایران عضو شده اید.
http://crc.aut.ac.ir
http://occc.ir
این گروه برای بحث پیرامون مسائل مختلف در حوزه رایانش ابری و اطلاع از آخرین
اخبار مربوط به این حوزه می باشد
برای ارتباط با افراد فعال در این حوزه میتوانید در جلسات حضوری جامعه آزاد رایانش
ابری ایران که بصورت عمومی برگزار میشود شرکت کنید
برای طرح پرسش و دریافت پاسخ میتوانید به سایت زیر نیز مراجعه نمایید
http://ask.occc.ir
برای استفاده از دانشنامه آزاد رایانش ابری میتوانید به سایت زیر مراجعه نمایید
http://wiki.occc.ir
برای اطلاع از آخرین اخبار و فعالیت های انجام شده در جامعه رایانش ابری میتوانید
به بورد عمومی مراجعه نمایید
https://trello.com/occc_board
همچنین میتوانید سری به رصد خانه رایانش ابری بزنید تا از رویدادهای اخیر در سطح
جهان مطلع شوید
http://news.occc.ir/index.php?hours=168
---
You received this message because you are subscribed to the Google Groups "Aut
Cloud Computing Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/aut-cloud-computing-group.
To view this discussion on the web visit
https://groups.google.com/d/msgid/aut-cloud-computing-group/c8b4a0ed-7029-45a7-a0e2-2745eee70360%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.