/* 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_redund_client.cc,v 1.6 2004/11/23 20:58:05 gawrilow Exp $"

#include <Poly.h>
#include <Rational.h>
#include <lrs_interface.h>

namespace polymake { namespace polytope {

void lrs_redundant_points(Poly& p)
{
   lrs_interface::solver solver;
   const Matrix<Rational> P=p.give("POINTS");
   const lrs_interface::solver::non_redundant V=solver.find_vertices_among_points(P);
   p.take("VERTICES") << P.minor(V.first,All);
   p.take("AFFINE_HULL") << V.second;
}

} }

using namespace polymake;

/** @file lrs_redund_client
 *
 *  Redundant point elimination using @see external.lrslib
 *
 *  @synopsis lrs_redund_client <file>
 *
 *  @reading  POINTS
 *  @writing  VERTICES, AFFINE_HULL
 */

int main(int argc, const char *argv[]) {
   if (argc!=2) {
      cerr << "usage: " << argv[0] << " <file>" << endl;
      return 1;
   }
   try {
      Poly p(argv[1], ios::in | ios::out);
      polytope::lrs_redundant_points(p);
   }
   catch (const std::exception& e) {
      cerr << e.what() << endl;
      return 1;
   }
   return 0;
}
