import java.io.*;

class f1 extends f_xj
{//adaptor class
fi_xi ff1;
public f1(fi_xi ffi) {ff1=ffi;}	

public double func(double x[]) 
{	
double ff=0.0;
double fa[]=ff1.func(x);
for(int i=0;i<fa.length;i++)  ff+=fa[i]*fa[i];
return 10-ff; //minimum değil maxsimum istendiğinden - ile çarptık
}
}


class fa extends fi_xi
{
public double[] func(double x[])
{	
//çözümü istenen fonksiyon	
double ff[]=new double[3];
ff[0]=3.0*x[0]-Math.cos(x[1]*x[2])-0.5;
ff[1]=x[0]*x[0]-81.0*(x[1]+0.1)*(x[1]+0.1)+Math.sin(x[2])+1.06;
ff[2]=Math.exp(-x[0]*x[1])+20.0*x[2]+(10.0*Math.PI-3.0)/3.0;
return ff;
} 
}

class NA118
{
    public static void main(String args[]) throws IOException
    {
    int N=18;
	int POPSIZE=500;
    int MAXGENS=500;
    int NVARS=3;
    double PXOVER=0.2;
    double PMUTATION=0.05;    
     fa ff=new fa();
     f1 f_x=new f1(ff);
    Genetic1 xx=new Genetic1(POPSIZE,MAXGENS,NVARS,N,PXOVER,PMUTATION);
    double low[]=new double[NVARS];
    double high[]=new double[NVARS];
    low[0]=-1.0;high[0]=1.0;
    low[1]=-1.0;high[1]=1.0;
    low[2]=-1.0;high[2]=1.0;
    xx.setPopulation(low,high,f_x);
    System.out.println("best=\n"+Matrix.toStringT(xx.calculate(f_x,false))); 
    }
}
