/* 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 <ch_client.h>
#define GMPRATIONAL
#include <cdd_interface.h>
#include <argv_options.h>

using namespace polymake;

/** @file cdd_ch_client
 *
 *  For an inequality description of a polyhedron, compute the vertices with @see external.cddlib
 *
 *  @synopsis cdd_ch_client <file> { -primal | -dual}
 *
 *  @reading  primal mode: VERTICES | POINTS 
 *              dual mode: FACETS | INEQUALITIES and AFFINE_HULL | EQUATIONS
 *  @writing  primal mode: FACETS, AFFINE_HULL
 *              dual mode: VERTICES, POINTED, FEASIBLE
 *
 *  @author Marc Pfetsch <pfetsch@math.tu-berlin.de>
 */

int main(int argc, const char *argv[])
{
   argv_option options[]={ { "-primal" }, { "-dual" } };
   enum { primal, dual };
   if (argc!=3 || !extract_options(argc,argv,1,options) || argc!=2) {
      cerr << "usage: " << argv[0] << " <file> { -primal | -dual }" << endl;
      return 1;
   }
   try {
      Poly p(argv[1], ios::in | ios::out);
      stopwatch timer;
      polytope::cdd_interface::solver<Rational> solver;

      if (options[primal])
	 polytope::ch_primal(p, solver, timer);
      else
	 polytope::ch_dual(p, solver, timer);

#ifdef POLY_TIMING
      cout << "time: " << timer << " seconds" << endl;
#endif
  }
  catch (const std::exception& e) {
     cerr << e.what() << endl;
     return 1;
  }
  return 0;
}
