import java.io.*;
import java.util.Scanner;

public class gibbsbestfinder
{

	public void readandshowbest_eq1()//CO+O2=CO2   1 mol CO  1 mol O2 ----> xCO2   at T=3000 K and P=1 atm
	{
	double a[][]=Text.readDouble("hybridsearch2_gibbs.txt"); 
    int nn=a.length;
    double[] gibbsvals=new double[nn];
    for(int i=0;i<nn;i++)
    {gibbsvals[i]=a[i][0];}
	double dd[]=getminval_index(gibbsvals);
	double gibbsminval=dd[0];
	int k=(int)dd[1];
	
	System.out.println("CO = "+a[k][1]+" mol");
	System.out.println("O2 = "+a[k][2]+" mol");
	System.out.println("CO2 = "+a[k][3]+" mol");
	//expected values  
	//CO 0.3398329938870405
	//O2 0.6699164969435255
	//CO2 0.6601670061129572
	
	}

	public void readandshowbest_eq2()//   1 mol CO + 1 mol H2O ------> xCO2  +  yH2 at T=1000 K  and P=1 atm
	{
	double a[][]=Text.readDouble("hybridsearch2_gibbs2.txt"); 
    int nn=a.length;
    double[] gibbsvals=new double[nn];
    for(int i=0;i<nn;i++)
    {gibbsvals[i]=a[i][0];}
	double dd[]=getminval_index(gibbsvals);
	double gibbsminval=dd[0];
	int k=(int)dd[1];
	
	System.out.println("CO = "+a[k][1]+" mol");
	System.out.println("H2O = "+a[k][2]+" mol");
	System.out.println("CO2 = "+a[k][3]+" mol");
	System.out.println("H2 = "+a[k][4]+" mol");
	// expected values        gibbstest
	// CO 0.4549              0.0047077
	// H2O 0.4549             0.0047077 
	// CO2 0.5451             0.9952  
	// H2 0.5451              0.9952
	}
	
	
	
	public void readandshowbest_eq4()//   1.0 C2H6 + 4.0 H2O  ---->      at 1000K and 1 atm
	{
	double a[][]=Text.readDouble("hybridsearch2_gibbs4.txt"); 
    int nn=a.length;
    double[] gibbsvals=new double[nn];
    for(int i=0;i<nn;i++)
    {gibbsvals[i]=a[i][0];}
	double dd[]=getminval_index(gibbsvals);
	double gibbsminval=dd[0];
	int k=(int)dd[1];
	
	System.out.println("CH4 = "+a[k][1]+" mol");
	System.out.println("C2H4 = "+a[k][2]+" mol");
	System.out.println("C2H2 = "+a[k][3]+" mol");
	System.out.println("CO2 = "+a[k][4]+" mol");
	System.out.println("CO = "+a[k][5]+" mol");
	System.out.println("O2 = "+a[k][6]+" mol");
	System.out.println("H2 = "+a[k][7]+" mol");
	System.out.println("H2O = "+a[k][8]+" mol");
	System.out.println("C2H6 = "+a[k][9]+" mol");
	
	
	//      CH4    0.0664        0.023338       
    //      C2H4 8.88e-008       0.00305
    //      C2H2 2.76e-021       3.19e-13
    //       CO2     0.545       1.965 
    //        CO      1.39       0.0047
    //        O2 4.56e-021       1.975e-234 
    //        H2      5.35       6.88  
    //       H2O      1.52       0.063
    //      C2H6  1.6e-007       2.6088e-6
	}
	
	public void readandshowbest_eq5()//   1 mol CO + 0.5 mol O2 + 0.5 mol N2 ------> xCO2  +  yCO + zO2  + tN2 + mNO    at T=3000 K  and P=1 atm
	{
	double a[][]=Text.readDouble("hybridsearch2_gibbs5.txt"); 
    int nn=a.length;
    double[] gibbsvals=new double[nn];
    for(int i=0;i<nn;i++)
    {gibbsvals[i]=a[i][0];}
	double dd[]=getminval_index(gibbsvals);
	double gibbsminval=dd[0];
	int k=(int)dd[1];
	
	
	System.out.println("CO2 = "+a[k][1]+" mol");
	System.out.println("CO = "+a[k][2]+" mol");
	System.out.println("O2 = "+a[k][3]+" mol");
	System.out.println("N2 = "+a[k][4]+" mol");
	System.out.println("NO = "+a[k][5]+" mol");
	
    //       CO2     0.625         0.997631    
    //        CO     0.3745        0.00236
    //        O2     0.635         0.001134
    //        N2     0.4663        0.49999
    //        NO     0.0675        9.98025e-5
    
	}
	
	public void readandshowbest_eq6()//   2 mol CO + 3 mol O2  ------> xCO2  +  yCO + zO2      at T=2600 K  and P=3 atm
	{
	double a[][]=Text.readDouble("hybridsearch2_gibbs6.txt"); 
    int nn=a.length;
    double[] gibbsvals=new double[nn];
    for(int i=0;i<nn;i++)
    {gibbsvals[i]=a[i][0];}
	double dd[]=getminval_index(gibbsvals);
	double gibbsminval=dd[0];
	int k=(int)dd[1];
	
	
	System.out.println("CO = "+a[k][1]+" mol");
	System.out.println("O2 = "+a[k][2]+" mol");
	System.out.println("CO2 = "+a[k][3]+" mol");
	
	//             kitap              gibbs
    //       CO     0.094           2.12791E-5
    //       O2     2.074           2.00000
    //       CO2     1.906          1.9999
    
    
	}
	
	public void readandshowbest_eq7()//   1 mol H2O + 2 mol O2  ------> xH2O  +  yH2 + zO2 + wOH      at T=4000 K  and P=1 atm
	{
	double a[][]=Text.readDouble("hybridsearch2_gibbs7.txt"); 
    int nn=a.length;
    double[] gibbsvals=new double[nn];
    for(int i=0;i<nn;i++)
    {gibbsvals[i]=a[i][0];}
	double dd[]=getminval_index(gibbsvals);
	double gibbsminval=dd[0];
	int k=(int)dd[1];
	
	
	System.out.println("H2O = "+a[k][1]+" mol");
	System.out.println("O2 = "+a[k][2]+" mol");
	System.out.println("H2 = "+a[k][3]+" mol");
	System.out.println("OH = "+a[k][4]+" mol");
	//              kitap           gibbstest
    //       H2O     0.094           0.04985
    //       O2     2.074            2.47086
    //       H2     1.906            0.9459
    //       OH     1.032            0.00841 
    
	}
	
	
	
	 double[] getminval_index(double[] a)
	 {
	 double m=0.0;	 
	 double b[]=new double[a.length];
	 for(int i=0;i<a.length;i++)
	 {b[i]=a[i];}  
	 double minval=a[0];
	 for(int i=0;i<a.length;i++)
	 {if(a[i]<minval){minval=a[i];}}
	 for(int i=0;i<a.length;i++)
	 {if(b[i]==minval){m=i;break;}};
	 double[] dep=new double[2];
	 dep[0]=minval;
	 dep[1]=m;
	 return dep;	 
	 }
	
	 
	 /////////////////////////////////////////////////////////////////////////////////////////
	 ///////////////BIG BANG///////////////////////////////////////////////////////
	 /////////////////////////////////////////////////////////////////////////////////////////
	 
	 
	public void bigbangreadandshowbest_eq1()//CO+O2=CO2   1 mol CO  1 mol O2 ----> xCO2   at T=3000 K and P=1 atm
	{
	double a[][]=Text.readDouble("bigbang_gibbs1.txt"); 
    int nn=a.length;
    double[] gibbsvals=new double[nn];
    for(int i=0;i<nn;i++)
    {gibbsvals[i]=a[i][0];}
	double dd[]=getminval_index(gibbsvals);
	double gibbsminval=dd[0];
	int k=(int)dd[1];
	
	System.out.println("CO = "+a[k][1]+" mol");
	System.out.println("O2 = "+a[k][2]+" mol");
	System.out.println("CO2 = "+a[k][3]+" mol");
	//expected values  
	//CO 0.3398329938870405
	//O2 0.6699164969435255
	//CO2 0.6601670061129572
	
	}
	 
	public void bigbangreadandshowbest_eq2()//   1 mol CO + 1 mol H2O ------> xCO2  +  yH2 at T=1000 K  and P=1 atm
	{
	double a[][]=Text.readDouble("bigbang_gibbs2.txt"); 
    int nn=a.length;
    double[] gibbsvals=new double[nn];
    for(int i=0;i<nn;i++)
    {gibbsvals[i]=a[i][0];}
	double dd[]=getminval_index(gibbsvals);
	double gibbsminval=dd[0];
	int k=(int)dd[1];
	
	System.out.println("CO = "+a[k][1]+" mol");
	System.out.println("H2O = "+a[k][2]+" mol");
	System.out.println("CO2 = "+a[k][3]+" mol");
	System.out.println("H2 = "+a[k][4]+" mol");
	// expected values        gibbstest
	// CO 0.4549              0.0047077
	// H2O 0.4549             0.0047077 
	// CO2 0.5451             0.9952  
	// H2 0.5451              0.9952
	}
	
	public void bigbangreadandshowbest_eq4()//   1.0 C2H6 + 4.0 H2O  ---->      at 1000K and 1 atm
	{
	double a[][]=Text.readDouble("bigbang_gibbs3.txt"); 
    int nn=a.length;
    double[] gibbsvals=new double[nn];
    for(int i=0;i<nn;i++)
    {gibbsvals[i]=a[i][0];}
	double dd[]=getminval_index(gibbsvals);
	double gibbsminval=dd[0];
	int k=(int)dd[1];
	
	System.out.println("CH4 = "+a[k][1]+" mol");
	System.out.println("C2H4 = "+a[k][2]+" mol");
	System.out.println("C2H2 = "+a[k][3]+" mol");
	System.out.println("CO2 = "+a[k][4]+" mol");
	System.out.println("CO = "+a[k][5]+" mol");
	System.out.println("O2 = "+a[k][6]+" mol");
	System.out.println("H2 = "+a[k][7]+" mol");
	System.out.println("H2O = "+a[k][8]+" mol");
	System.out.println("C2H6 = "+a[k][9]+" mol");
	
	
	//      CH4    0.0664        0.023338       
    //      C2H4 8.88e-008       0.00305
    //      C2H2 2.76e-021       3.19e-13
    //       CO2     0.545       1.965 
    //        CO      1.39       0.0047
    //        O2 4.56e-021       1.975e-234 
    //        H2      5.35       6.88  
    //       H2O      1.52       0.063
    //      C2H6  1.6e-007       2.6088e-6
	}
	
	public void bigbangreadandshowbest_eq5()//   1 mol CO + 0.5 mol O2 + 0.5 mol N2 ------> xCO2  +  yCO + zO2  + tN2 + mNO    at T=3000 K  and P=1 atm
	{
	double a[][]=Text.readDouble("bigbang_gibbs4.txt"); 
    int nn=a.length;
    double[] gibbsvals=new double[nn];
    for(int i=0;i<nn;i++)
    {gibbsvals[i]=a[i][0];}
	double dd[]=getminval_index(gibbsvals);
	double gibbsminval=dd[0];
	int k=(int)dd[1];
	
	
	System.out.println("CO2 = "+a[k][1]+" mol");
	System.out.println("CO = "+a[k][2]+" mol");
	System.out.println("O2 = "+a[k][3]+" mol");
	System.out.println("N2 = "+a[k][4]+" mol");
	System.out.println("NO = "+a[k][5]+" mol");
	
    //       CO2     0.625         0.997631    
    //        CO     0.3745        0.00236
    //        O2     0.635         0.001134
    //        N2     0.4663        0.49999
    //        NO     0.0675        9.98025e-5
    
	}
	
	public void bigbangreadandshowbest_eq6()//   2 mol CO + 3 mol O2  ------> xCO2  +  yCO + zO2      at T=2600 K  and P=3 atm
	{
	double a[][]=Text.readDouble("bigbang_gibbs5.txt"); 
    int nn=a.length;
    double[] gibbsvals=new double[nn];
    for(int i=0;i<nn;i++)
    {gibbsvals[i]=a[i][0];}
	double dd[]=getminval_index(gibbsvals);
	double gibbsminval=dd[0];
	int k=(int)dd[1];
	
	
	System.out.println("CO = "+a[k][1]+" mol");
	System.out.println("O2 = "+a[k][2]+" mol");
	System.out.println("CO2 = "+a[k][3]+" mol");
	
	//             kitap              gibbs
    //       CO     0.094           2.12791E-5
    //       O2     2.074           2.00000
    //       CO2     1.906          1.9999
    
    
	}
	
	public void bigbangreadandshowbest_eq7()//   1 mol H2O + 2 mol O2  ------> xH2O  +  yH2 + zO2 + wOH      at T=4000 K  and P=1 atm
	{
	double a[][]=Text.readDouble("bigbang_gibbs6.txt"); 
    int nn=a.length;
    double[] gibbsvals=new double[nn];
    for(int i=0;i<nn;i++)
    {gibbsvals[i]=a[i][0];}
	double dd[]=getminval_index(gibbsvals);
	double gibbsminval=dd[0];
	int k=(int)dd[1];
	
	
	System.out.println("H2O = "+a[k][1]+" mol");
	System.out.println("O2 = "+a[k][2]+" mol");
	System.out.println("H2 = "+a[k][3]+" mol");
	System.out.println("OH = "+a[k][4]+" mol");
	//              kitap           gibbstest
    //       H2O     0.094           0.04985
    //       O2     2.074            2.47086
    //       H2     1.906            0.9459
    //       OH     1.032            0.00841 
    
	}
	
	
	
	
	
	
	
	
	
	
	
	
	 /////////////////////////////////////////////////////////////////////////////////////////
	 ///////////////MELODY SEARCH///////////////////////////////////////////////////////
	 ///////////////////////////////////////////////////////////////////////////////////////// 
	 
	 public void melodyreadandshowbest_eq1()//CO+O2=CO2   1 mol CO  1 mol O2 ----> xCO2   at T=3000 K and P=1 atm
	{
	double a[][]=Text.readDouble("melody_gibbs1.txt"); 
    int nn=a.length;
    double[] gibbsvals=new double[nn];
    for(int i=0;i<nn;i++)
    {gibbsvals[i]=a[i][0];}
	double dd[]=getminval_index(gibbsvals);
	double gibbsminval=dd[0];
	int k=(int)dd[1];
	
	System.out.println("CO = "+a[k][1]+" mol");
	System.out.println("O2 = "+a[k][2]+" mol");
	System.out.println("CO2 = "+a[k][3]+" mol");
	//expected values  
	//CO 0.3398329938870405
	//O2 0.6699164969435255
	//CO2 0.6601670061129572
	
	}
	 
	public void melodyreadandshowbest_eq2()//   1 mol CO + 1 mol H2O ------> xCO2  +  yH2 at T=1000 K  and P=1 atm
	{
	double a[][]=Text.readDouble("melody_gibbs2.txt"); 
    int nn=a.length;
    double[] gibbsvals=new double[nn];
    for(int i=0;i<nn;i++)
    {gibbsvals[i]=a[i][0];}
	double dd[]=getminval_index(gibbsvals);
	double gibbsminval=dd[0];
	int k=(int)dd[1];
	
	System.out.println("CO = "+a[k][1]+" mol");
	System.out.println("H2O = "+a[k][2]+" mol");
	System.out.println("CO2 = "+a[k][3]+" mol");
	System.out.println("H2 = "+a[k][4]+" mol");
	// expected values        gibbstest
	// CO 0.4549              0.0047077
	// H2O 0.4549             0.0047077 
	// CO2 0.5451             0.9952  
	// H2 0.5451              0.9952
	}
	 
	public void melodyreadandshowbest_eq4()//   1.0 C2H6 + 4.0 H2O  ---->      at 1000K and 1 atm
	{
	double a[][]=Text.readDouble("melody_gibbs3.txt"); 
    int nn=a.length;
    double[] gibbsvals=new double[nn];
    for(int i=0;i<nn;i++)
    {gibbsvals[i]=a[i][0];}
	double dd[]=getminval_index(gibbsvals);
	double gibbsminval=dd[0];
	int k=(int)dd[1];
	
	System.out.println("CH4 = "+a[k][1]+" mol");
	System.out.println("C2H4 = "+a[k][2]+" mol");
	System.out.println("C2H2 = "+a[k][3]+" mol");
	System.out.println("CO2 = "+a[k][4]+" mol");
	System.out.println("CO = "+a[k][5]+" mol");
	System.out.println("O2 = "+a[k][6]+" mol");
	System.out.println("H2 = "+a[k][7]+" mol");
	System.out.println("H2O = "+a[k][8]+" mol");
	System.out.println("C2H6 = "+a[k][9]+" mol");
	
	
	//      CH4    0.0664        0.023338       
    //      C2H4 8.88e-008       0.00305
    //      C2H2 2.76e-021       3.19e-13
    //       CO2     0.545       1.965 
    //        CO      1.39       0.0047
    //        O2 4.56e-021       1.975e-234 
    //        H2      5.35       6.88  
    //       H2O      1.52       0.063
    //      C2H6  1.6e-007       2.6088e-6
	}
	
	public void melodyreadandshowbest_eq5()//   1 mol CO + 0.5 mol O2 + 0.5 mol N2 ------> xCO2  +  yCO + zO2  + tN2 + mNO    at T=3000 K  and P=1 atm
	{
	double a[][]=Text.readDouble("melody_gibbs4.txt"); 
    int nn=a.length;
    double[] gibbsvals=new double[nn];
    for(int i=0;i<nn;i++)
    {gibbsvals[i]=a[i][0];}
	double dd[]=getminval_index(gibbsvals);
	double gibbsminval=dd[0];
	int k=(int)dd[1];
	
	
	System.out.println("CO2 = "+a[k][1]+" mol");
	System.out.println("CO = "+a[k][2]+" mol");
	System.out.println("O2 = "+a[k][3]+" mol");
	System.out.println("N2 = "+a[k][4]+" mol");
	System.out.println("NO = "+a[k][5]+" mol");
	
    //       CO2     0.625         0.997631    
    //        CO     0.3745        0.00236
    //        O2     0.635         0.001134
    //        N2     0.4663        0.49999
    //        NO     0.0675        9.98025e-5
    
	}
	
	
	public void melodyreadandshowbest_eq6()//   2 mol CO + 3 mol O2  ------> xCO2  +  yCO + zO2      at T=2600 K  and P=3 atm
	{
	double a[][]=Text.readDouble("melody_gibbs5.txt"); 
    int nn=a.length;
    double[] gibbsvals=new double[nn];
    for(int i=0;i<nn;i++)
    {gibbsvals[i]=a[i][0];}
	double dd[]=getminval_index(gibbsvals);
	double gibbsminval=dd[0];
	int k=(int)dd[1];
	
	
	System.out.println("CO = "+a[k][1]+" mol");
	System.out.println("O2 = "+a[k][2]+" mol");
	System.out.println("CO2 = "+a[k][3]+" mol");
	
	//             kitap              gibbs
    //       CO     0.094           2.12791E-5
    //       O2     2.074           2.00000
    //       CO2     1.906          1.9999
    
    
	}
	
	public void melodyreadandshowbest_eq7()//   1 mol H2O + 2 mol O2  ------> xH2O  +  yH2 + zO2 + wOH      at T=4000 K  and P=1 atm
	{
	double a[][]=Text.readDouble("melody_gibbs6.txt"); 
    int nn=a.length;
    double[] gibbsvals=new double[nn];
    for(int i=0;i<nn;i++)
    {gibbsvals[i]=a[i][0];}
	double dd[]=getminval_index(gibbsvals);
	double gibbsminval=dd[0];
	int k=(int)dd[1];
	
	
	System.out.println("H2O = "+a[k][1]+" mol");
	System.out.println("O2 = "+a[k][2]+" mol");
	System.out.println("H2 = "+a[k][3]+" mol");
	System.out.println("OH = "+a[k][4]+" mol");
	//              kitap           gibbstest
    //       H2O     0.094           0.04985
    //       O2     2.074            2.47086
    //       H2     1.906            0.9459
    //       OH     1.032            0.00841 
    
	}
	
	public void melodyreadandshowbest_f70()
	{
	double a[][]=Text.readDouble("melody_f70.txt"); 
    int nn=a.length;
    double[] gibbsvals=new double[nn];
    for(int i=0;i<nn;i++)
    {gibbsvals[i]=a[i][0];}
	double dd[]=getminval_index(gibbsvals);
	double gibbsminval=dd[0];
	int k=(int)dd[1];
	
	System.out.println("fmin = "+gibbsminval);
	for(int i=1;i<a[0].length;i++)
	{System.out.println("x["+i+"]= "+a[k][i]);}
    
	}
	
	public void melodyreadandshowbest_f71()
	{
	double a[][]=Text.readDouble("melody_f71.txt"); 
    int nn=a.length;
    double[] gibbsvals=new double[nn];
    for(int i=0;i<nn;i++)
    {gibbsvals[i]=a[i][0];}
	double dd[]=getminval_index(gibbsvals);
	double gibbsminval=dd[0];
	int k=(int)dd[1];
	
	System.out.println("fmin = "+gibbsminval);
	for(int i=1;i<a[0].length;i++)
	{System.out.println("x["+i+"]= "+a[k][i]);}
    
	}
	
	public void melodyreadandshowbest_f72()
	{
	double a[][]=Text.readDouble("melody_f72.txt"); 
    int nn=a.length;
    double[] gibbsvals=new double[nn];
    for(int i=0;i<nn;i++)
    {gibbsvals[i]=a[i][0];}
	double dd[]=getminval_index(gibbsvals);
	double gibbsminval=dd[0];
	int k=(int)dd[1];
	
	System.out.println("fmin = "+gibbsminval);
	for(int i=1;i<a[0].length;i++)
	{System.out.println("x["+i+"]= "+a[k][i]);}
    
	}
	
	public void melodyreadandshowbest_f68()
	{
	double a[][]=Text.readDouble("melody_f68.txt"); 
    int nn=a.length;
    double[] gibbsvals=new double[nn];
    for(int i=0;i<nn;i++)
    {gibbsvals[i]=a[i][0];}
	double dd[]=getminval_index(gibbsvals);
	double gibbsminval=dd[0];
	int k=(int)dd[1];
	
	System.out.println("fmin = "+gibbsminval);
	for(int i=1;i<a[0].length;i++)
	{System.out.println("x["+i+"]= "+a[k][i]);}
    
	}
	
	
	
	 
	 
	 
	 
	 
	 public static void main(String args[])
     {
	  gibbsbestfinder gbs=new gibbsbestfinder();   
	  gbs.readandshowbest_eq2();   
	     
	 }


	 



}