/* 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: t_hasse_diagram.cc,v 1.16 2004/10/26 18:57:00 gawrilow Exp $"

#include <Poly.h>
#include <complex_tools.h>
#include <argv_options.h>

#ifdef POLY_TIMING
#  include <stopwatch.h>
#endif

namespace polymake {
namespace topaz {
  
void t_hasse_diagram(Poly& p, const bool pure)
{
   const Array< Set<int> > C = p.give("FACETS");
   int dim; 
   p.give("DIM") >> dim;

#ifdef POLY_TIMING
   stopwatch timer;
   timer.start();
#endif
   
   const HasseDiagram<> HD= pure ? pure_hasse_diagram(C) : hasse_diagram(C,dim);
   
#ifdef POLY_TIMING
   timer.stop();
   cout << "facets:  " << C.size() << endl;
   cout << "faces:   " << HD.nodes() << endl;
   cout << "time:    " << timer << " seconds" << endl;
#endif
   
   p.take("HASSE_DIAGRAM") << HD;
}
   
} }

using namespace polymake;

/** @file t_hasse_diagram
 *
 *  Produce the Hasse Diagram of a simplicial complex.
 *
 *  @synopsis t_hasse_diagram <file> [ -pure ]
 *
 *  @reading  FACETS, DIM
 *  @writing  HASSE_DIAGRAM
 */

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


// Local Variables:
// mode:C++
// c-basic-offset:3
// End:
