package ss;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Random;
import jxl.Workbook;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
/* Reference and Contact
/* Reference: [1]Liu, F., Huang, H., Yang, Z., Hao, Z., Wang, J., 2019. Search-based algorithm with scatter search strategy for automated test case generation of NLP toolkit. IEEE Trans. Emerg. Top. Comput. Intell. 1–13.
[2]Hu, Z., Xu, X., Su, Q., Zhu, H., Guo, J., 2020. Grey prediction evolution algorithm for global optimization. Appl. Math. Model. 79, 145–160.
/*
* the name of benchmark program(numbering,dimension,number of paths,number of nodes)highest path coverage
* transmit(1,3,2,1) 100%; send(2,2,9,5)66%; processEvent(3,7,9,6)100%; executeTuple(4,7,5,3)100%;
* checkCloudletCompletion(5,5,6,3)100%; getResultantTuple(6,8,7,4)100%
* initFactory(7,7,48,4)
* CleanXmlAnnotator(8,6,3,2)
* WordsToSentencesAnnotator(9,11,12,7)
* annotate(10,4,3,2)
* NERClassifierCombiner(11,8,4,2)
* setTrueCaseText(12,6,10,5)
*/
public class GPE_IS {
private static final int RUN = 30; //Run times
private static final int pop_num = 50; //Population size
/*Parameters of the fitness function*/
private static final int K = 1;
private static final double alpha = 0.001;
/*Parameters of DE*/
// private static final double Pc = 0.2;
// private static final double F = 0.5;
static int num=11; //numbering of program
static int[][] G={{1,3,2,1},{2,2,9,5},{3,7,9,6},{4,7,5,3},{5,5,6,3},{6,8,7,4},{7,7,48,4},{8,6,3,2},{9,11,12,7},{10,4,3,2},{11,8,4,2},{12,6,10,5}};
private static final int fun_num = G[num][0];//numbering of program
private static final int R = G[num][1];//dimension
private static final int PATHNUM = G[num][2];//number of paths
private static final int NODENUM = G[num][3];//number of nodes
private static boolean[][] visit = new boolean[NODENUM][8];
private static int[] record = new int[pop_num]; /* Record the coverage information of the population*/
private static String[] PATH = new String[PATHNUM]; /*Record the direction of branch nodes in different paths*/
/*Start time, finish time, run time, path coverage, number of test cases */
static double start;
static double finish;
static double[] runtime = new double[RUN];
static double[] coverage = new double[RUN];
static int[] case_num = new int[RUN];
private static final int MCN = 300000; //maximum generations
private static final int col = fun_num;
public static void main(String[] args){
/*low/up bound of variable*/
int[] Lb = new int[R];
int[] Ub = new int[R];
// transmit(1,3,2,1) 100%;
if(fun_num==1){
for(int i=0;i<R;i++)
{
Lb[i] = 0; //Initialize low bound of variable
Ub[i] = 255; //Initialize up bound of variable
}
}//send(2,2,9,5)66%;
if(fun_num==2){
for(int i=0;i<R;i++)
{
Lb[i] = -1000000;
Ub[i] = 1000000;
}
}//processEvent(3,7,9,6)100%;
if(fun_num==3){
Lb[0]=0;Ub[0]=100;
Lb[1]=0;Ub[1]=3;
Lb[2]=-1;Ub[2]=10000;
Lb[3]=0;Ub[3]=1;
Lb[4]=0;Ub[4]=10000;
Lb[5]=0;Ub[5]=9999;
Lb[6]=-1;Ub[6]=100000;
}//executeTuple(4,7,5,3)100%;
if(fun_num==4){
Lb[0]=1;Ub[0]=3;
for(int i=1;i<R;i++)
{
Lb[i] = 0;
Ub[i] = 255;
}
}//checkCloudletCompletion(5,5,6,3)100%;
if(fun_num==5){
Lb[0]=0;Ub[0]=1;
for(int i=1;i<R-1;i++)
{
Lb[i] = 0;
Ub[i] = 255;
}
Lb[R-1]=0;Ub[R-1]=1;
}// getResultantTuple(6,8,7,4)100%*/
if(fun_num==6){
for(int i=0;i<6;i++)
{
Lb[i] = 0;
Ub[i] = 255;
}
Lb[6]=0;Ub[6]=1;
Lb[7]=1;Ub[7]=3;
}//initFactory
if(fun_num==7){
for(int i=0;i<6;i++)
{
Lb[i] = 0;
Ub[i] = 255;
}
Lb[6] = 0;
Ub[6] = Integer.MAX_VALUE;
// Ub[6] = 100;
}//CleanXmlAnnotator(9,6,3,2)
if(fun_num == 8){
for(int i=0;i<R;i++)
{
Lb[i] = 0;
Ub[i] = 255;
}
}//WordsToSentencesAnnotator(9,11,12,7)
if(fun_num == 9){
Lb[0] = 0; Ub[0] = 1;
Lb[1] = 0; Ub[1] = 1;
for(int i=2;i<R;i++)
{
Lb[i] = 0;
Ub[i] = 255;
}
}//annotate(10,4,3,2)
if(fun_num==10){
for(int i=0;i<R-1;i++){
Lb[i] = 0;
Ub[i] = 255;
}
Lb[R-1] = 1;Ub[R-1] = Integer.MAX_VALUE;
}//NERClassifierCombiner(11,8,4,2)
if(fun_num == 11){
for(int i=0;i<R-1;i++){
Lb[i] = 0;
Ub[i] = 255;
}
Lb[R-1]=0;Ub[R-1]=1;
}//setTrueCaseText(12,6,8,2)
if(fun_num == 12){
for(int i=0;i<R-1;i++){
Lb[i] = 0;
Ub[i] = 255;
}
Lb[R-1]=0;Ub[R-1]=1;
}
switch(fun_num){
case 1:
PATH[0] = "0";
PATH[1] = "1";
break;
case 2:
PATH[0] = "0 ";
PATH[1] = "100 ";
PATH[2] = "1010 ";
PATH[3] = "10110";
PATH[4] = "10111";
PATH[5] = "110 ";
PATH[6] = "1110 ";
PATH[7] = "11110";
PATH[8] = "11111";
break;
case 3:
PATH[0] = "0 ";
PATH[1] = "10 ";
PATH[2] = "110 ";
PATH[3] = "111 00";
PATH[4] = "111 01";
PATH[5] = "111 1 ";
PATH[6] = "12 0 ";
PATH[7] = "12 1 ";
PATH[8] = "13 ";
break;
case 4:
PATH[0] = "000";
PATH[1] = "001";
PATH[2] = "010";
PATH[3] = "011";
PATH[4] = "1 ";
break;
case 5:
PATH[0] = "000";
PATH[1] = "001";
PATH[2] = "010";
PATH[3] = "011";
PATH[4] = "1 0";
PATH[5] = "1 1";
break;
case 6:
PATH[0] = "0000";
PATH[1] = "0001";
PATH[2] = "001 ";
PATH[3] = "0100";
PATH[4] = "0101";
PATH[5] = "011 ";
PATH[6] = "1 ";
break;
case 7:
PATH[0] = "0000";
PATH[1] = "0001";
PATH[2] = "0002";
PATH[3] = "0003";
PATH[4] = "0004";
PATH[5] = "0005";
PATH[6] = "0006";
PATH[7] = "0007";
PATH[8] = "0010";
PATH[9] = "0011";
PATH[10] = "0012";
PATH[11] = "0013";
PATH[12] = "0014";
PATH[13] = "0015";
PATH[14] = "0016";
PATH[15] = "0017";
PATH[16] = "01 0";
PATH[17] = "01 1";
PATH[18] = "01 2";
PATH[19] = "01 3";
PATH[20] = "01 4";
PATH[21] = "01 5";
PATH[22] = "01 6";
PATH[23] = "01 7";
PATH[24] = "1000";
PATH[25] = "1001";
PATH[26] = "1002";
PATH[27] = "1003";
PATH[28] = "1004";
PATH[29] = "1005";
PATH[30] = "1006";
PATH[31] = "1007";
PATH[32] = "1010";
PATH[33] = "1011";
PATH[34] = "1012";
PATH[35] = "1013";
PATH[36] = "1014";
PATH[37] = "1015";
PATH[38] = "1016";
PATH[39] = "1017";
PATH[40] = "11 0";
PATH[41] = "11 1";
PATH[42] = "11 2";
PATH[43] = "11 3";
PATH[44] = "11 4";
PATH[45] = "11 5";
PATH[46] = "11 6";
PATH[47] = "11 7";
break;
case 8:
PATH[0] = "00";
PATH[1] = "01";
PATH[2] = "1 ";
break;
case 9:
PATH[0] = "000 ";
PATH[1] = "001 ";
PATH[2] = "01 ";
PATH[3] = "1 0 ";
PATH[4] = "1 1000";
PATH[5] = "1 1001";
PATH[6] = "1 1010";
PATH[7] = "1 1011";
PATH[8] = "1 1100";
PATH[9] = "1 1101";
PATH[10] = "1 1110";
PATH[11] = "1 1111";
break;
case 10:
PATH[0] = "00";
PATH[1] = "01";
PATH[2] = "1 ";
break;
case 11:
PATH[0] = "00";
PATH[1] = "01";
PATH[2] = "10";
PATH[3] = "11";
break;
case 12:
PATH[0] = "0 0";
PATH[1] = "0 1";
PATH[2] = "10 0";
PATH[3] = "10 1";
PATH[4] = "110 0";
PATH[5] = "110 1";
PATH[6] = "11100";
PATH[7] = "11101";
PATH[8] = "11110";
PATH[9] = "11111";
break;
}
int[] lb = new int[R];
int[] ub = new int[R];
for(int j=0;