/************************************************************************\ |* gtf is a framework for analyzing two-player zero-sum games *| |* Copyright (C) 2005 Troels Bjerre Sorensen *| |* *| |* This program is free software; you can redistribute it and/or modify *| |* it under the terms of the GNU General Public License as published by *| |* the Free Software Foundation; either version 2 of the License, or *| |* (at your option) any later version. *| |* *| |* This program is distributed in the hope that it will be useful, but *| |* WITHOUT ANY WARRANTY; without even the implied warranty of *| |* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *| |* General Public License for more details. *| |* *| |* You should have received a copy of the GNU General Public License *| |* along with this program; if not, write to the *| |* Free Software Foundation, Inc., 59 Temple Place - Suite 330, *| |* Boston, MA 02111-1307, USA. *| \************************************************************************/ package gtf.util; import gtf.*; import java.io.*; import java.util.*; public class PCx extends LPSolver { private void skip(int num, BufferedReader br) throws IOException { for (int i = 0 ; i < num ; i++) { // System.out.println("Skipping line: " + br.readLine(); } } private void skip(int num, StringTokenizer st) throws IOException { for (int i = 0 ; i < num ; i++) { // System.out.println("Skipping token: " + st.nextToken(); } } protected Map solve(MPS problem) { Map vals = new HashMap(); try { String name = problem.getName(); File mpsfile = new File(name + ".mps"); problem.printMPS(new PrintStream(new FileOutputStream(mpsfile))); Runtime.getRuntime().exec("gtf/ext/PCx " + name + ".mps").waitFor(); File logfile = new File(name + ".log"); File outfile = new File(name + ".out"); String line; BufferedReader varfile = new BufferedReader(new FileReader(outfile)); skip(3, varfile); // header for(line = varfile.readLine() ; ! line.equals("") ; line = varfile.readLine()) { StringTokenizer st = new StringTokenizer(line, " ", false); skip(1, st); //skip line number String var = st.nextToken(); vals.put(var, new DoubleReal(Double.parseDouble(st.nextToken()))); } skip(2, varfile); //ship header for(line = varfile.readLine() ; line != null ; line = varfile.readLine()) { StringTokenizer st = new StringTokenizer(line, " ", false); st.nextToken(); //skip line number String var = st.nextToken(); skip(3, st); //skip cols vals.put(var, new DoubleReal(Double.parseDouble(st.nextToken()))); } mpsfile.delete(); logfile.delete(); outfile.delete(); } catch (Exception e) { throw new RuntimeException( "PCx.java: trold was too lazy to write a real error message" + ", so now you're screwed.\nAre you running this on a Linux " + "machine?\n"+e+"\n"+e.getStackTrace()[0]+"\n"); } return vals; } }