/* Copyright (c) 1997-2004
   Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
   http://www.math.tu-berlin.de/polymake,  mailto:polymake@math.tu-berlin.de

   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, or (at your option) any
   later version: http://www.gnu.org/licenses/gpl.txt.

   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.
*/

#include <lp_client.h>
#define GMPRATIONAL
#include <cdd_interface.h>
#include <argv_options.h>

using namespace polymake;

/** @file cdd_lp_client
 *
 *  Solve a linear programm with @see external.cddlib.
 *
 *  @synopsis cdd_lp_client <file> { -maximize | -minimize }
 *
 *  @reading  FACETS | INEQUALITIES, AFFINE HULL | EQUATIONS, LINEAR_OBJECTIVE
 *  @writing  MAXIMAL_VALUE | MINIMAL_VALUE, MAXIMAL_VERTEX | MINIMAL_VERTEX, FEASIBLE
 *
 *  @author Marc Pfetsch <pfetsch@math.tu-berlin.de>
 */

int main(int argc, const char *argv[])
{
   argv_option options[]={ { "-maximize" }, { "-minimize" } };
   enum { maximize, minimize };
   if (argc!=3 || !extract_options(argc,argv,1,options) || argc!=2) {
      cerr << "usage: " << argv[0] << " <file> { -maximize | -minimize }" << endl;
      return 1;
   }
   try {
      Poly p(argv[1], ios::in | ios::out);
      polytope::cdd_interface::solver<Rational> solver;
      polytope::solve_lp(p, solver, options[maximize]);
   }
   catch (const std::exception& e) {
      cerr << e.what() << endl;
      return 1;
   }
   return 0;
}
