Bonjour,
bonjour;
et je vous souhaite une agréable journée
j'ai un petit souci de l'utilisation d'un tableau multi dimension en plusieurs méthodes de la même classe
la premiere méthode l'initialise la deuxieme utilise les valeurs qu'on a fait entrer dans la premiere
les deux tableaux sont
matrice_flux[][]
matrice_distance[][]
package Meta_heuristique; //import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.StreamTokenizer; public class Agent extends Essaim { int best; //best of the best position double E; double f_min; //objective to search int LINKS[][]=new int[S_max][S_max]; static int nb_eval; String txt=""; // just to set text String txt1=""; int s; //number of particle current int function; int init_links; //flag to (re)init or not the information links double error_perv;//error after previous iteration int m; int g; //rank of the best informant double error; int K; double min; double eps_mean; int n_failure; double eps; int eval_max; double eval_mean; double variance; double c, w; public static boolean QAP; static int D_QAP; int matrice_flux[][]=new int[2*D_QAP][2*D_QAP]; int matrice_distance[][]=new int[2*D_QAP][D_QAP*2]; int problem; int xmin_QAP; int xmax_QAP; int j; Position X[]=new Position[S_max]; Vilocity V[]=new Vilocity[S_max]; Position P[]=new Position[S_max]; pos X1[] =new pos[S_max]; static int k=0; static int l=0; velocity V1[]=new velocity[S_max]; boolean test; pos P1[]=new pos[S_max]; static int nb_perm; double mean_best[]=new double[R_max]; int A; int Q; public Agent( ){ super(); QAP=true; D_QAP=26; problem=0; xmin_QAP=1; xmax_QAP=26; function=0; n_exec=0; eval_mean=0; eps_mean=0; n_failure=0; E=Math.exp(1); eval_max=30000; xmin=-100; xmax=100; K=3; w=1/(2*Math.log(2)); c=0.5+Math.log(2); eps=0.9; f_min=0; } //=============================================================================================================================================== public double rand(double a,double b){ double r=0.0; r=Math.random(); return(a+r*(b-a)); } //================================================================================================================================================ public int rand(int a,int b){ int ir; double r=0.0; r=Math.random(); ir=(int)(a+r*(b+1-a)); if(ir>b){ ir=b; } return ir; } //==============================================================================================================================================Init public void Execution(){ D=20; S=10+(int)(2*Math.sqrt(D)); n_exec_max=100; if(S>S_max){ S=S_max; } if(n_exec_max>R_max){ n_exec_max=R_max; } } public void init() throws IOException { boolean test_array[] =new boolean [D_QAP]; n_exec=n_exec+1; for( l=0;l<D_QAP;l++){ test_array[l]=false; } if(QAP==false){ for( s=0;s<S;s++){ //Position and velocity X[s]=new Position(); //Position X[]=new Position[S_max]; X[s].size=D; V[s]=new Vilocity(); V[s].size=D; for(d=0;d<D;d++){ X[s].x[d]=rand(xmin,xmax); V[s].v[d]=(rand(xmin,xmax)-X[s].x[d])/2; } } // first evaluation nb_eval=0; for(s=0;s<S;s++){ X[s].f=Math.abs(perf(s,function)-f_min); P[s]=new Position(); P[s].copie(X[s]); //best position current one } //find the best best=0; for(s=1;s<S;s++) if(P[s].f<P[best].f) best=s; error=P[best].f; //current minimum error if(n_exec==1) min=error; error_perv=error;//Previous minimum error init_links=1; //so that information links will be initialized }else { for(s=0;s<S;s++){ X1[s]=new pos(); X1[s].size=D_QAP; V1[s]=new velocity(); V1[s].size=D_QAP; for(d=0;d<D_QAP;d++){ test=false; Affectation(s,d); test_array[X1[s].x[d]-1]=true; do{ for(j=0;j<d;j++){ if(X1[s].x[d]==X1[s].x[j]){ test=true; } if(test==true) { Affectation(s,d); test_array[X1[s].x[d]-1]=true; } } }while(test==false); } /*for(d=D_QAP;d<D_QAP;d++){ j=0; while(j<D_QAP && test_array[j]==false){ j=j+1; } X1[s].x[d]=j+1; }*/ for(d=0;d<D_QAP;d++){ V1[s].v+= Math.abs(rand(xmin_QAP,xmax_QAP)-X1[s].x[d])/2; V1[s].v=(int)(V1[s].v/D_QAP); } } //first evaluation // fichier_QAP(problem); nb_eval=0; for(s=0;s<S;s++){ X1[s].f=(int) Math.abs(perf(s,6)-f_min); P1[s]=new pos(); P1[s].copie(X1[s]); //best position current one } //find the best best=0; for(s=1;s<S;s++) if(P1[s].f<P1[best].f) best=s; error=P1[best].f; //current minimum error if(n_exec==1) min=error; error_perv=error;//Previous minimum error init_links=1; //so that information links will be initialized } } public void Affectation( int s,int d){ //int n; X1[s].x[d]=rand(xmin_QAP,xmax_QAP); //X1[s].x[d]=d; } //===========================================================================================================================================Iteration public String loop() { do{ if(init_links==1){ //who informs who;at random for(s=0;s<S;s++){ for(m=0;m<S;m++) LINKS[m][s]=0; //init to no link LINKS[s][s]=1; } for(m=0;m<S;m++) { //other links for(int i=0;i<K;i++){ s=rand(0,S-1); LINKS[m][s]=1; } } } //the swarm moves for(s=0;s<S;s++){ //for each particle //find the best informant g=s; for(m=0;m<S;m++){ if(LINKS[m][s]==1 && P[m].f<P[g].f) g=m; } //compute the new velocity and move for(d=0;d<D;d++){ V[s].v[d]=w*V[s].v[d]+rand(0,c)*(P[s].x[d]-X[s].x[d]); V[s].v[d]=V[s].v[d]+rand(0,c)*(P[g].x[d]-X[s].x[d]); X[s].x[d]=X[s].x[d]+V[s].v[d]; } //interval confinement(keep in the box) for(d=0;d<D;d++){ if(X[s].x[d]<xmin){ X[s].x[d]=xmin; V[s].v[d]=0; } if(X[s].x[d]>xmax){ X[s].x[d]=xmax; V[s].v[d]=0; } } //evaluate the new position X[s].f=Math.abs(perf(s,function)-f_min); if(X[s].f<P[s].f) P[s].copie(X[s]); //update the best of the best if(P[s].f<P[best].f) best=s; } //=============================================================================================================================================== // Check if finished // If no improvement, information links will be reinitialized error=P[best].f; if(error>=error_perv) init_links=1; else init_links=0; error_perv=error; }while(error>eps && nb_eval<eval_max); if(error>eps) n_failure=n_failure+1; txt = "\n\n"+"\t " +n_exec+ "\t " +nb_eval+ "\t " +error + "\t "; for(d=0;d<D;d++){ txt += "\t" + P[best].x[d];} //compute some,statistical information if(error<min){ min=error;} eval_mean=eval_mean+nb_eval; eps_mean=eps_mean+error; mean_best[n_exec-1]=error; return txt ; } public String loop1() throws IOException{ do{ //if(init_links==1){ for(s=0;s<S;s++){ for(m=0;m<S;m++) LINKS[m][s]=0; LINKS[s][s]=1; //} for(m=0;m<S;m++){ for(int i=0;i<K;i++){ s=rand(1,S-1); LINKS[m][s]=1; } } } for(s=0;s<S;s++){ g=s; for(m=0;m<S;m++){ if(LINKS[m][s]==1 && P1[m].f<P1[g].f) g=m; } for (d=0;d<D_QAP;d++){ Q=P1[s].x[d]-X1[s].x[d]; A=P1[g].x[d]-X1[s].x[d]; } V1[s].v=(int)(w*V1[s].v+rand(0,c)*(Q/D_QAP)); V1[s].v=(int)(V1[s].v+rand(0,c)*(A/D_QAP)); X1[s].copie(Permut(s)); //evaluate the new position X1[s].f=(int) Math.abs(perf(s,6)-f_min); //update the best previous position if(X1[s].f<P1[s].f){ P1[s].copie(X1[s]); //update the best of the best if(P1[s].f<P1[best].f) best=s; } } //====================================================================================================================================================== // Check if finished // If no improvement, information links will be reinitialized error=P1[best].f; /*if(error>=error_perv) init_links=1; else init_links=0; error_perv=error;*/ }while(error>eps && nb_eval<eval_max); if(error>eps) n_failure=n_failure+1; txt = "\n\n"+"\t " +n_exec+ "\t " +nb_eval+ "\t " +error + "\t "; for(d=0;d<D_QAP;d++){ txt += "\t" + P1[best].x[d]; } //compute some,statistical information if(error<min) min=error; eval_mean=eval_mean+nb_eval; eps_mean=eps_mean+error; mean_best[n_exec-1]=error; return txt; } public pos Permutation(int l,int n, int t){ int C; C=X1[l].x[d]; X1[l].x[d]=X1[n].x[d]; X1[n].x[d]=C; return X1[s]; } public pos Permut(int t){ int l;int n; int i; for(i=0;i<V1[t].v;i++){ n=rand(1,D_QAP); do{ l=rand(1,D_QAP); }while(l==n); X1[t].copie(Permutation(l,n, t)); } return X1[t]; } //END Display some statistical information public String affiche(){ eval_mean=eval_mean/(double)n_exec; eps_mean=eps_mean/(double)n_exec; txt1 +="\n\n\tEval.(mean)="+eval_mean; txt1 += "\n\tError(mean)="+eps_mean; //variance variance=0; for(d=0;d<n_exec_max;d++){ variance=variance+(mean_best[d]-eps_mean)*(mean_best[d]-eps_mean); variance=Math.sqrt(variance/n_exec_max);} txt1 += "\n\tStd.dev "+variance; txt1 += "\n\tSuccess rate="+(100*(1-n_failure/(double)n_exec)+"%"); txt1 += "\n\t best min value="+min; return txt1 ; } //for the Quadratic problem //=========================================================================================================================================================== public int emplacement(int i,int s){ int M=0; for(d=0;d<D_QAP;d++){ if(X1[s].x[d]==i){ M=d; } } return M; } public void fichier_QAP(int problem) throws IOException { boolean passer; int i = 0; int j=1 ; // X[s]=new Position(); //Position X[]=new Position[S_max]; int matrice_flux[][]=new int[2*D_QAP][2*D_QAP]; int matrice_distance[][]=new int[2*D_QAP][2*D_QAP]; //matrice=new matrice_flux[D_QAP][D_QAP]; //matrice_distance=new int[D_QAP][D_QAP]; passer=false; switch(problem){ case 0: //Bur26a //File file =new File("Bur26a"); FileReader fichier = new FileReader("Bur26a"); StreamTokenizer entree = new StreamTokenizer(fichier); while(entree.nextToken() ==StreamTokenizer.TT_NUMBER && entree.lineno()<=2*D_QAP+3 ) { if(entree.lineno()>2 && entree.lineno()<D_QAP+3){ i=entree.lineno()-2; matrice_flux[i-1][j-1]=(int)entree.nval; System.out.print("f["+i+"]["+j+"]="+ matrice_flux[i-1][j-1]+"\t"); if(j==D_QAP){ System.out.print("\n"); j=0; } j=j+1; } else{ if (!passer) { passer=true; j=1; } if(entree.lineno()<=2*D_QAP+3 && entree.lineno()>D_QAP+3){ i=entree.lineno()-(D_QAP+3); matrice_distance[i-1][j-1]=(int)entree.nval; System.out.print("d["+i+"]["+j+"]= "+matrice_distance[i-1][j-1]+"\t"); if(j==D_QAP){ System.out.print("\n"); // i=i+1; j=0; } j=j+1; // l=l+1; } } } fichier.close(); break; case 1: //Bur26b FileReader fichier1 = new FileReader("Bur26b"); StreamTokenizer entree1 = new StreamTokenizer(fichier1); i=entree1.lineno(); while(entree1.nextToken() ==StreamTokenizer.TT_NUMBER && entree1.lineno()<=2*D_QAP+3 ) { if(entree1.lineno()>2 && entree1.lineno()<D_QAP+3){ matrice_flux[i][j]=(int)entree1.nval; System.out.print("f["+i+"]["+j+"]="+ matrice_flux[i][j]+"\t"); j=j+1; if(j==D_QAP+1){ System.out.print("\n"); i=i+1; j=1; } k=k+1; } else{ if(entree1.lineno()<=2*D_QAP+3 && entree1.lineno()>D_QAP+3){ i=entree1.lineno()-(D_QAP+3); matrice_distance[i][j]=(int)entree1.nval; System.out.print("d["+i+"]["+j+"]= "+matrice_distance[i][j]+"\t"); if(j==D_QAP){ System.out.print("\n"); i=i+1; j=0; } j=j+1; l=l+1; } } } fichier1.close(); break; case 2: //Bur26c FileReader fichier2 = new FileReader("Bur26c"); StreamTokenizer entree2 = new StreamTokenizer(fichier2); i=entree2.lineno(); while(entree2.nextToken() ==StreamTokenizer.TT_NUMBER && entree2.lineno()<=2*D_QAP+3 ) { if(entree2.lineno()>2 && entree2.lineno()<D_QAP+3){ matrice_flux[i][j]=(int)entree2.nval; System.out.print("f["+i+"]["+j+"]="+ matrice_flux[i][j]+"\t"); j=j+1; if(j==D_QAP+1){ System.out.print("\n"); i=i+1; j=1; } k=k+1; } else{ if(entree2.lineno()<=2*D_QAP+3 && entree2.lineno()>D_QAP+3){ i=entree2.lineno()-(D_QAP+3); matrice_distance[i][j]=(int)entree2.nval; System.out.print("d["+i+"]["+j+"]= "+matrice_distance[i][j]+"\t"); if(j==D_QAP){ System.out.print("\n"); i=i+1; j=0; } j=j+1; l=l+1; } } } fichier2.close(); break; case 3://bur26d FileReader fichier3 = new FileReader("Bur26d"); StreamTokenizer entree3 = new StreamTokenizer(fichier3); i=entree3.lineno(); while(entree3.nextToken() ==StreamTokenizer.TT_NUMBER && entree3.lineno()<=2*D_QAP+3 ) { if(entree3.lineno()>2 && entree3.lineno()<D_QAP+3){ matrice_flux[i][j]=(int)entree3.nval; System.out.print("f["+i+"]["+j+"]="+ matrice_flux[i][j]+"\t"); j=j+1; if(j==D_QAP+1){ System.out.print("\n"); i=i+1; j=1; } k=k+1; } else{ if(entree3.lineno()<=2*D_QAP+3 && entree3.lineno()>D_QAP+3){ i=entree3.lineno()-(D_QAP+3); matrice_distance[i][j]=(int)entree3.nval; System.out.print("d["+i+"]["+j+"]= "+matrice_distance[i][j]+"\t"); if(j==D_QAP){ System.out.print("\n"); i=i+1; j=0; } j=j+1; l=l+1; } } } fichier3.close(); break; case 4: //Bur26e FileReader fichier4 = new FileReader("Bur26e"); StreamTokenizer entree4 = new StreamTokenizer(fichier4); i=entree4.lineno(); while(entree4.nextToken() ==StreamTokenizer.TT_NUMBER && entree4.lineno()<=2*D_QAP+3 ) { if(entree4.lineno()>2 && entree4.lineno()<D_QAP+3){ matrice_flux[i][j]=(int)entree4.nval; System.out.print("f["+i+"]["+j+"]="+ matrice_flux[i][j]+"\t"); j=j+1; if(j==D_QAP+1){ System.out.print("\n"); i=i+1; j=1; } k=k+1; } else{ if(entree4.lineno()<=2*D_QAP+3 && entree4.lineno()>D_QAP+3){ i=entree4.lineno()-(D_QAP+3); matrice_distance[i][j]=(int)entree4.nval; System.out.print("d["+i+"]["+j+"]= "+matrice_distance[i][j]+"\t"); if(j==D_QAP){ System.out.print("\n"); i=i+1; j=0; } j=j+1; l=l+1; } } } fichier4.close(); break; case 5://Bur26f FileReader fichier5 = new FileReader("Bur26f"); StreamTokenizer entree5 = new StreamTokenizer(fichier5); i=entree5.lineno(); while(entree5.nextToken() ==StreamTokenizer.TT_NUMBER && entree5.lineno()<=2*D_QAP+3 ) { if(entree5.lineno()>2 && entree5.lineno()<D_QAP+3){ matrice_flux[i][j]=(int)entree5.nval; System.out.print("f["+i+"]["+j+"]="+ matrice_flux[i][j]+"\t"); j=j+1; if(j==D_QAP+1){ System.out.print("\n"); i=i+1; j=1; } k=k+1; } else{ if(entree5.lineno()<=2*D_QAP+3 && entree5.lineno()>D_QAP+3){ i=entree5.lineno()-(D_QAP+3); matrice_distance[i][j]=(int)entree5.nval; System.out.print("d["+i+"]["+j+"]= "+matrice_distance[i][j]+"\t"); if(j==D_QAP){ System.out.print("\n"); i=i+1; j=0; } j=j+1; l=l+1; } } } fichier5.close(); break; case 6://chr12a FileReader fichier6 = new FileReader("chr12a"); StreamTokenizer entree6 = new StreamTokenizer(fichier6); i=entree6.lineno(); while(entree6.nextToken() ==StreamTokenizer.TT_NUMBER && entree6.lineno()<=2*D_QAP+3 ) { if(entree6.lineno()>2 && entree6.lineno()<D_QAP+3){ matrice_flux[i][j]=(int)entree6.nval; System.out.print("f["+i+"]["+j+"]="+ matrice_flux[i][j]+"\t"); j=j+1; if(j==D_QAP+1){ System.out.print("\n"); i=i+1; j=1; } k=k+1; } else{ if(entree6.lineno()<=2*D_QAP+3 && entree6.lineno()>D_QAP+3){ i=entree6.lineno()-(D_QAP+3); matrice_distance[i][j]=(int)entree6.nval; System.out.print("d["+i+"]["+j+"]= "+matrice_distance[i][j]+"\t"); if(j==D_QAP){ System.out.print("\n"); i=i+1; j=0; } j=j+1; l=l+1; } } } fichier6.close(); break; case 7://chr12b FileReader fichier7 = new FileReader("chr12b"); StreamTokenizer entree7 = new StreamTokenizer(fichier7); i=entree7.lineno(); while(entree7.nextToken() ==StreamTokenizer.TT_NUMBER && entree7.lineno()<=2*D_QAP+3 ) { if(entree7.lineno()>2 && entree7.lineno()<D_QAP+3){ matrice_flux[i][j]=(int)entree7.nval; System.out.print("f["+i+"]["+j+"]="+ matrice_flux[i][j]+"\t"); j=j+1; if(j==D_QAP+1){ System.out.print("\n"); i=i+1; j=1; } k=k+1; } else{ if(entree7.lineno()<=2*D_QAP+3 && entree7.lineno()>D_QAP+3){ i=entree7.lineno()-(D_QAP+3); matrice_distance[i][j]=(int)entree7.nval; System.out.print("d["+i+"]["+j+"]= "+matrice_distance[i][j]+"\t"); if(j==D_QAP){ System.out.print("\n"); i=i+1; j=0; } j=j+1; l=l+1; } } } fichier7.close(); break; case 8://chr12c FileReader fichier8 = new FileReader("chr12c"); StreamTokenizer entree8 = new StreamTokenizer(fichier8); i=entree8.lineno(); while(entree8.nextToken() ==StreamTokenizer.TT_NUMBER && entree8.lineno()<=2*D_QAP+3 ) { if(entree8.lineno()>2 && entree8.lineno()<D_QAP+3){ matrice_flux[i][j]=(int)entree8.nval; System.out.print("f["+i+"]["+j+"]="+ matrice_flux[i][j]+"\t"); j=j+1; if(j==D_QAP+1){ System.out.print("\n"); i=i+1; j=1; } k=k+1; } else{ if(entree8.lineno()<=2*D_QAP+3 && entree8.lineno()>D_QAP+3){ i=entree8.lineno()-(D_QAP+3); matrice_distance[i][j]=(int)entree8.nval; System.out.print("d["+i+"]["+j+"]= "+matrice_distance[i][j]+"\t"); if(j==D_QAP){ System.out.print("\n"); i=i+1; j=0; } j=j+1; l=l+1; } } } fichier8.close(); break; case 9://esc16a FileReader fichier9 = new FileReader("esc16a"); StreamTokenizer entree9 = new StreamTokenizer(fichier9); i=entree9.lineno(); while(entree9.nextToken() ==StreamTokenizer.TT_NUMBER && entree9.lineno()<=2*D_QAP+3 ) { if(entree9.lineno()>2 && entree9.lineno()<D_QAP+3){ matrice_flux[i][j]=(int)entree9.nval; System.out.print("f["+i+"]["+j+"]="+ matrice_flux[i][j]+"\t"); j=j+1; if(j==D_QAP+1){ System.out.print("\n"); i=i+1; j=1; } k=k+1; } else{ if(entree9.lineno()<=2*D_QAP+3 && entree9.lineno()>D_QAP+3){ i=entree9.lineno()-(D_QAP+3); matrice_distance[i][j]=(int)entree9.nval; System.out.print("d["+i+"]["+j+"]= "+matrice_distance[i][j]+"\t"); if(j==D_QAP){ System.out.print("\n"); i=i+1; j=0; } j=j+1; l=l+1; } } } fichier9.close(); break; case 10://esc16b FileReader fichier10 = new FileReader("esc16b"); StreamTokenizer entree10 = new StreamTokenizer(fichier10); i=entree10.lineno(); while(entree10.nextToken() ==StreamTokenizer.TT_NUMBER && entree10.lineno()<=2*D_QAP+3 ) { if(entree10.lineno()>2 && entree10.lineno()<D_QAP+3){ matrice_flux[i][j]=(int)entree10.nval; System.out.print("f["+i+"]["+j+"]="+ matrice_flux[i][j]+"\t"); j=j+1; if(j==D_QAP+1){ System.out.print("\n"); i=i+1; j=1; } k=k+1; } else{ if(entree10.lineno()<=2*D_QAP+3 && entree10.lineno()>D_QAP+3){ i=entree10.lineno()-(D_QAP+3); matrice_distance[i][j]=(int)entree10.nval; System.out.print("d["+i+"]["+j+"]= "+matrice_distance[i][j]+"\t"); if(j==D_QAP){ System.out.print("\n"); i=i+1; j=0; } j=j+1; l=l+1; } } } fichier10.close(); break; case 11://esc16c FileReader fichier11 = new FileReader("esc16c"); StreamTokenizer entree11 = new StreamTokenizer(fichier11); i=entree11.lineno(); while(entree11.nextToken() ==StreamTokenizer.TT_NUMBER && entree11.lineno()<=2*D_QAP+3 ) { if(entree11.lineno()>2 && entree11.lineno()<D_QAP+3){ matrice_flux[i][j]=(int)entree11.nval; System.out.print("f["+i+"]["+j+"]="+ matrice_flux[i][j]+"\t"); j=j+1; if(j==D_QAP+1){ System.out.print("\n"); i=i+1; j=1; } k=k+1; } else{ if(entree11.lineno()<=2*D_QAP+3 && entree11.lineno()>D_QAP+3){ i=entree11.lineno()-(D_QAP+3); matrice_distance[i][j]=(int)entree11.nval; System.out.print("d["+i+"]["+j+"]= "+matrice_distance[i][j]+"\t"); if(j==D_QAP){ System.out.print("\n"); i=i+1; j=0; } j=j+1; l=l+1; } } } fichier11.close(); break; case 12://esc16d FileReader fichier12 = new FileReader("esc16d"); StreamTokenizer entree12 = new StreamTokenizer(fichier12); i=entree12.lineno(); while(entree12.nextToken() ==StreamTokenizer.TT_NUMBER && entree12.lineno()<=2*D_QAP+3 ) { if(entree12.lineno()>2 && entree12.lineno()<D_QAP+3){ matrice_flux[i][j]=(int)entree12.nval; System.out.print("f["+i+"]["+j+"]="+ matrice_flux[i][j]+"\t"); j=j+1; if(j==D_QAP+1){ System.out.print("\n"); i=i+1; j=1; } k=k+1; } else{ if(entree12.lineno()<=2*D_QAP+3 && entree12.lineno()>D_QAP+3){ i=entree12.lineno()-(D_QAP+3); matrice_distance[i][j]=(int)entree12.nval; System.out.print("d["+i+"]["+j+"]= "+matrice_distance[i][j]+"\t"); if(j==D_QAP){ System.out.print("\n"); i=i+1; j=0; } j=j+1; l=l+1; } } } fichier12.close(); break; case 13: //esc16e FileReader fichier13 = new FileReader("esc16e"); StreamTokenizer entree13 = new StreamTokenizer(fichier13); i=entree13.lineno(); while(entree13.nextToken() ==StreamTokenizer.TT_NUMBER && entree13.lineno()<=2*D_QAP+3 ) { if(entree13.lineno()>2 && entree13.lineno()<D_QAP+3){ matrice_flux[i][j]=(int)entree13.nval; System.out.print("f["+i+"]["+j+"]="+ matrice_flux[i][j]+"\t"); j=j+1; if(j==D_QAP+1){ System.out.print("\n"); i=i+1; j=1; } k=k+1; } else{ if(entree13.lineno()<=2*D_QAP+3 && entree13.lineno()>D_QAP+3){ i=entree13.lineno()-(D_QAP+3); matrice_distance[i][j]=(int)entree13.nval; System.out.print("d["+i+"]["+j+"]= "+matrice_distance[i][j]+"\t"); if(j==D_QAP){ System.out.print("\n"); i=i+1; j=0; } j=j+1; l=l+1; } } } fichier13.close(); break; case 14://esc16f FileReader fichier14 = new FileReader("esc16f"); StreamTokenizer entree14 = new StreamTokenizer(fichier14); i=entree14.lineno(); while(entree14.nextToken() ==StreamTokenizer.TT_NUMBER && entree14.lineno()<=2*D_QAP+3 ) { if(entree14.lineno()>2 && entree14.lineno()<D_QAP+3){ matrice_flux[i][j]=(int)entree14.nval; System.out.print("f["+i+"]["+j+"]="+ matrice_flux[i][j]+"\t"); j=j+1; if(j==D_QAP+1){ System.out.print("\n"); i=i+1; j=1; } k=k+1; } else{ if(entree14.lineno()<=2*D_QAP+3 && entree14.lineno()>D_QAP+3){ i=entree14.lineno()-(D_QAP+3); matrice_distance[i][j]=(int)entree14.nval; System.out.print("d["+i+"]["+j+"]= "+matrice_distance[i][j]+"\t"); if(j==D_QAP){ System.out.print("\n"); i=i+1; j=0; } j=j+1; l=l+1; } } } fichier14.close(); break; case 15://tai10a FileReader fichier15 = new FileReader("tai10a"); StreamTokenizer entree15 = new StreamTokenizer(fichier15); i=entree15.lineno(); while(entree15.nextToken() ==StreamTokenizer.TT_NUMBER && entree15.lineno()<=2*D_QAP+3 ) { if(entree15.lineno()>2 && entree15.lineno()<D_QAP+3){ matrice_flux[i][j]=(int)entree15.nval; System.out.print("f["+i+"]["+j+"]="+ matrice_flux[i][j]+"\t"); j=j+1; if(j==D_QAP+1){ System.out.print("\n"); i=i+1; j=1; } k=k+1; } else{ if(entree15.lineno()<=2*D_QAP+3 && entree15.lineno()>D_QAP+3){ i=entree15.lineno()-(D_QAP+3); matrice_distance[i][j]=(int)entree15.nval; System.out.print("d["+i+"]["+j+"]= "+matrice_distance[i][j]+"\t"); if(j==D_QAP){ System.out.print("\n"); i=i+1; j=0; } j=j+1; l=l+1; } } } fichier15.close(); break; case 16://tai12a FileReader fichier16 = new FileReader("tai12a"); StreamTokenizer entree16 = new StreamTokenizer(fichier16); i=entree16.lineno(); while(entree16.nextToken() ==StreamTokenizer.TT_NUMBER && entree16.lineno()<=2*D_QAP+3 ) { if(entree16.lineno()>2 && entree16.lineno()<D_QAP+3){ matrice_flux[i][j]=(int)entree16.nval; System.out.print("f["+i+"]["+j+"]="+ matrice_flux[i][j]+"\t"); j=j+1; if(j==D_QAP+1){ System.out.print("\n"); i=i+1; j=1; } k=k+1; } else{ if(entree16.lineno()<=2*D_QAP+3 && entree16.lineno()>D_QAP+3){ i=entree16.lineno()-(D_QAP+3); matrice_distance[i][j]=(int)entree16.nval; System.out.print("d["+i+"]["+j+"]= "+matrice_distance[i][j]+"\t"); if(j==D_QAP){ System.out.print("\n"); i=i+1; j=0; } j=j+1; l=l+1; } } } fichier16.close(); break; } } public double perf(int s ,int function) { double f=0 ; // int matrice_flux[][]=new int[2*D_QAP][2*D_QAP]; // int matrice_distance[][]=new int[2*D_QAP][2*D_QAP]; Position xs; xs=X[s]; double p; double xd; double x1; double x2; double pi=Math.acos(-1); double sum1; double sum2; double t0; double t1; double tt; int k; double y=-1; nb_eval=nb_eval+1; switch(function){ case 0: //parabola(Sphere) p=0; for( d=0;d<D;d++){ xd=xs.x[d]-p; f=f+xd*xd; } break; case 1: //Griewank p=1; for( d=0;d<D;d++){ xd=xs.x[d]; f=f+xd*xd; p*=Math.cos(xd/Math.sqrt(d+1)); } f=f/ 4000-p+1; break; case 2://Rosenbrock t0=xs.x[0]; for( d=1;d<D;d++){ t1=xs.x[d]; tt=1-t0; f+=tt*tt; tt=t1-t0*t0; f+=100*tt*tt; t0=t1; } break; case 3://Rastrigin k=10; for( d=0;d<D;d++){ xd=xs.x[d]; f+=xd*xd-k*Math.cos(2*pi*xd); } f+=D*k; break; case 4://Ackley sum1=0; sum2=0; for( d=0;d<D;d++){ xd=xs.x[d]; sum1+=xd*xd; sum2+=Math.cos(2*pi*xd); } y=D; f=Math.E+20-20*Math.exp(-0.2*Math.sqrt(sum1/y)-Math.exp(sum2/y)); break; case 5://tripod function x1=xs.x[0]; x2=xs.x[1]; if(x2<0){ f=Math.abs(x1)+Math.abs(x2+50); } else{if(x1<0)f=1+Math.abs(x1+50)+Math.abs(x2-50); else f=2+Math.abs(x1-50)+Math.abs(x2-50); } break; case 6:// QAP function for(k=0;k<D_QAP;k++){ for(l=0;l<D_QAP;l++){ f+=matrice_flux[k][l]*matrice_distance[emplacement(k,s)][emplacement(l,s)]; } } System.out.println("f ="+f); break; } return f; } }
Afficher la suite