/*
 *$Log$
 */
package general;

import java.net.*;
import java.io.*;
import java.util.*;

public class LP {
/**
 * call the CGI program which solves linear programming
 */
/*
public static String calculate(String sData) {
  String home = "www.cs.wustl.edu";
  String file = "/~hma/script/lp_solve.cgi";
  // the trailing (char)255 is needed so that the lp_solve can
  // know that it's the end of file
  int port = 80;
  Socket s = null;
  StringBuffer rbuf = new StringBuffer();
  String line;
  try {
    Thread.yield();
    s = new Socket("www.cs.wustl.edu", 80);
    DataOutputStream os = new DataOutputStream(s.getOutputStream());
    DataInputStream is = new DataInputStream(s.getInputStream());
    
    os.writeBytes("POST " + file
		  + " HTTP/1.0\r\n"
		  + "Content-type: text/plain\r\n"
		  + "Content-length: " 
		  + sData.length() + "\r\n\r\n");
    os.writeBytes(sData);

    while (is.available() == 0) {
      Thread.yield();
    }
    while ( (line = is.readLine()) != null )
      rbuf.append(line + "\n");
    is.close();
    os.close();
  }
  catch (Exception e) {
    System.out.println("Error " + e.getMessage());
    if (s != null) {
      try {
	s.close();
      }
      catch (IOException ex) {
	System.out.println("IOException in post:");
      }
    }
  } 
  return rbuf.toString();
}
*/
public static double parseObjectiveValue(String s) {
  StringTokenizer stk = new StringTokenizer(s, "\n");
  String line;
  while (stk.hasMoreTokens()) {
    if ((line = stk.nextToken()).startsWith("Value of objective function:")) {
      line.trim();
      return Double.valueOf(line.substring(line.lastIndexOf(' '))).
	doubleValue();
    }
  }
  return -1; // if reaches here, it's an error
}

} // end of class








