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

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

namespace polymake {
namespace topaz {
  
void facets_from_hasse_diagram(Poly& p)
{
   const HasseDiagram<> HD = p.give("HASSE_DIAGRAM");
   
   std::list< Set<int> > Facets;
   for (Entire<HasseDiagram<>::in_edge_list>::const_iterator e=entire(HD.in_edges(HD.top_node()));
	!e.at_end(); ++e)
      Facets.push_back( HD.node(e.from_node()) );
   
   p.take("FACETS") << as_array(Facets);
}

} }

using namespace polymake;

/** @file facets_from_hasse_diagram
 *
 *  Extracts the facets of a hasse diagram
 *
 *  @synopsis facets_from_hasse_diagram <file>
 *
 *  @reading  HASSE_DIAGRAM
 *  @writing  FACETS
 */

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);
      topaz::facets_from_hasse_diagram(p);
   }
   catch (const std::exception& e) {
     cerr << e.what() << endl;
     return 1;
   }
   return 0;
}


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