
import java.io.*;

public class NYCTBlackBox
{
  public int popsize;
  public NYCTBlackBox()
  {
	  popsize=1000;
  }

  private void writeFile(boolean array[][])
  {
    try
    {
      PrintStream output = new PrintStream(new FileOutputStream("input.txt"));
      for(int j=0; j<popsize;j++)
         for (int i = 0;i < 84;i++)
			output.print((array[i][j])?(1):(0));
      output.println();
      output.flush();
      output.close();
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }

  private double readFile()
  {
    double answer = 0;

    try
    {
      BufferedReader input = new BufferedReader(new FileReader("output.txt"));
      String s = input.readLine();
      if (s != null) answer = (new Double(s)).doubleValue();
      input.close();
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }

    return answer;
  }

  public double objective(boolean chromosomes[][])
  {
    writeFile(chromosomes);
    try
    {
      System.out.println(Runtime.getRuntime().exec("command.com /c pipeBB.exe").waitFor());
    }
    catch (Exception e)
    {
      System.out.println("Error running NYCTBlackBox.exe");
    }
    return readFile();
  }

  public static void main(String args[])
  {
    NYCTBlackBox temp = new NYCTBlackBox();
    boolean array[][]= new boolean[84][temp.popsize];
    for(int j=0; j<temp.popsize;j++)
      for (int i = 0;i < 84;i++) array[i][j] = (Math.random() < 0.5);
    double d = temp.objective(array);
    System.out.print("array = ");
    for(int j=0;j<temp.popsize;j++)
        for (int i = 0;i < 84;i++) System.out.print("" + ((array[i][j])?("1"):("0")));
    System.out.println();
    System.out.println("rating = " + d);
    System.exit(0);
  }
}















