import java.util.*;
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
import javax.swing.*;

class f2 extends f_xj
{//adaptation function
fi_xi ff1;
public f2(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 ff; 
}
}

class fa extends fi_xi
{ // Nonlinear system of equation
public double[] func(double x[])
{		
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;
} 


public class particleswarmtest3
{
public static void main(String arg[])
{
String s="leave a space between initial root guess values: xmin0 xmin1.. ";
         double [] xmin=NA43D.inputdata(s);
         s="leave a space between initial root guess values: xmax0 xmax1.. ";
         double [] xmax=NA43D.inputdata(s);
         fa ff=new fa();
         f2 f=new f2(ff);

particle_swarm1 ps=new particle_swarm1(f,2000,xmin,xmax,2.0,0.7,2000);
double r1[]= ps.nelder(ff,ps.gmin());
String s="Particle swarm optimisation  : \n"+ps.toString()+"\n Nelder-Mead: \n"+ps.toString(r1);     
     String s2="Particle swarm-Nelder-Mead simplex optimization method ";
     JOptionPane.showMessageDialog(null,s,s2,JOptionPane.PLAIN_MESSAGE);
 
}
}