001package algs9; // section 6.5
002import stdlib.*;
003import java.io.IOException;
004import qs.Problem;
005import qs.QS;
006import qs.QSException;
007import qs.Reporter;
008/* ***********************************************************************
009 *  Compilation:  javac -cp .:qsopt.jar XQSoptSolver.java
010 *  Execution:    java  -cp .:qsopt.jar XQSoptSolver input.lp
011 *  Dependencies: http://algs4.cs.princeton.edu/65reductions/qpopt.jar
012 *  Reference:    http://www2.isye.gatech.edu/~wcook/qsopt/software/java.htm
013 *
014 *  % java  -cp .:qsopt.jar XQSoptSolver beer.lp
015 *  Optimal profit = 800.0
016 *  Optimal primal solution (nonzeros only):
017 *    A = 12.000000
018 *    B = 28.000000
019 *  Optimal dual solution (nonzeros only):
020 *    corn = -1.000000
021 *    hops = -2.000000
022 *
023 *************************************************************************/
024
025public class XQSoptSolver {
026
027        public static void main(String[] args) throws QSException, IOException {
028                Problem problem = Problem.read(args[0], false);
029                problem.opt_primal();
030                if (problem.get_status() == QS.LP_OPTIMAL) {
031                        StdOut.println("Optimal " + problem.get_objname() + " = " + problem.get_objval());
032                        StdOut.println("Optimal primal solution (nonzeros only): ");
033                        problem.print_x(new Reporter(System.out), true, 6);
034                        StdOut.println("Optimal dual solution (nonzeros only): ");
035                        problem.print_pi(new Reporter(System.out), true, 6);
036                }
037                else {
038                        System.out.println("Problem maybe unbounded or infeasible.\n");
039                }
040        }
041}