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

#ident "$Project: polymake $$Id: lrs_lp_client.cc,v 1.8 2004/11/23 20:58:05 gawrilow Exp $"

#include <lp_client.h>
#include <lrs_interface.h>
#include <argv_options.h>

using namespace polymake;

/** @file lrs_lp_client
 *
 *  Simplex algorithm using @see external.lrslib
 *
 *  @synopsis lrs_lp_client <file> { -maximize | -minimize | -valid }
 *
 *  @reading  FACETS | INEQUALITIES, AFFINE_HULL | EQUATIONS, LINEAR_OBJECTIVE
 *  @writing  MAXIMAL_VALUE | MINIMAL_VALUE, MAXIMAL_VERTEX | MINIMAL_VERTEX, FEASIBLE
 */

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