/* 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: hasse_diagram.cc,v 1.17 2005/12/09 16:39:22 thilosch Exp $"

#include <Poly.h>
#include <face_lattice_tools.h>
#include <HasseDiagram.h>
#include <stopwatch.h>

namespace polymake { namespace polytope {

   void hasse_diagram(Poly& p, stopwatch& timer, const char* incidence_section)
{
   const IncidenceMatrix<> VIF=p.give(incidence_section);
   timer.start();
   HasseDiagram<> HD;
   if (VIF.cols() <= VIF.rows()) {
      face_lattice::compute(VIF, filler(HD,true));
   } else {
      face_lattice::compute(T(VIF), filler(HD,false));
   }
   timer.stop();
   p.take("HASSE_DIAGRAM") << HD;
}

} }

using namespace polymake;

/** @file hasse_diagram
 *
 *  Compute the @see HASSE_DIAGRAM of the polytope.
 *
 *  @synopsis hasse_diagram <file> <incidence_section>
 *
 *  @reading  VERTICES_IN_FACETS
 *  @writes   HASSE_DIAGRAM
 */

int main(int argc, const char *argv[]) {
   if (argc!=3) {
      cerr << "usage: " << argv[0]  << " <file> <incidence_section>" << endl;
      return 1;
   }
   try {
      Poly p(argv[1], ios::in | ios::out);
      stopwatch timer;
      polytope::hasse_diagram(p,timer,argv[2]);
#ifdef POLY_TIMING
      cout << "time: " << timer << " seconds" << endl;
#endif
   }
   catch (const std::exception& e) {
      cerr << e.what() << endl;
      return 1;
   }
   return 0;
}
