Example: Reading an MPS file.

This example reads the data for a linear programming problem from an MPS file.
import com.imsl.io.MPSReader;
import java.io.*;
import java.util.Iterator;

public class MPSReaderEx1 {    
    static public void main(String arg[]) throws IOException, MPSReader.InvalidMPSFileException {
        InputStream stream = MPSReaderEx1.class.getResourceAsStream("testprob.mps");
        Reader reader = new InputStreamReader(stream);
        MPSReader mps = new MPSReader();
        mps.read(reader);
        
        System.out.println("Name   " + mps.getName());
        System.out.println("RHS    " + mps.getNameRHS());
        System.out.println("BOUNDS " + mps.getNameBounds());
        System.out.println("RANGES " + mps.getNameRanges());
        
        int nRows = mps.getNumberOfRows();
        System.out.println("NumberOfConstraints " + nRows);
        for (int i = 0;  i < nRows;  i++) {
            System.out.println("   " +
                    mps.getLowerRange(i) +
                    " <= row[" + i + "] = " +
                    mps.getNameRow(i) +
                    " <= " + mps.getUpperRange(i));
        }
        
        int nColumns = mps.getNumberOfColumns();
        System.out.println("NumberOfColumns " + nColumns);
        for (int i = 0;  i < nColumns;  i++) {
            System.out.println("   " +
                    mps.getLowerBound(i) +
                    " <= var[" + i + "] = " +
                    mps.getNameColumn(i) +
                    " <= " + mps.getUpperBound(i));
        }
        
        System.out.println("NumberOfNonZeros " + mps.getNumberOfNonZeros());
        for (int iRow = 0;  iRow < nRows;  iRow++) {
            System.out.println("       row "+mps.getNameRow(iRow));
            Iterator iter = mps.getRow(iRow).iterator();
            while (iter.hasNext()) {
                MPSReader.Element elem = (MPSReader.Element)iter.next();
                int iColumn = elem.getColumn();
                String nameColumn = mps.getNameColumn(iColumn);
                System.out.println("          "+nameColumn+": "+elem.getValue());
            }
        }
    }
}

Output

Name   TESTPROB
RHS    RHS1
BOUNDS BND1
RANGES null
NumberOfConstraints 3
   -Infinity <= row[0] = LIM1 <= 5.0
   10.0 <= row[1] = LIM2 <= Infinity
   7.0 <= row[2] = MYEQN <= 7.0
NumberOfColumns 3
   0.0 <= var[0] = XONE <= 4.0
   -1.0 <= var[1] = YTWO <= 1.0
   0.0 <= var[2] = ZTHREE <= Infinity
NumberOfNonZeros 6
       row LIM1
          XONE: 1.0
          YTWO: 1.0
       row LIM2
          XONE: 1.0
          ZTHREE: 1.0
       row MYEQN
          YTWO: -1.0
          ZTHREE: 1.0
Link to Java source.