/* 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 <Poly.h>
#include <Array.h>
#include <max_cliques.h>
#include <argv_options.h>

#include <string>

namespace polymake {
namespace topaz {

void flag_complex(Poly& p_out, Poly& p_in, const char* graph_section,
		  const std::string& comment, const bool no_labels)
{
   const Graph<> G = p_in.give(graph_section);
   const Array<std::string> L = p_in.give("VERTEX_LABELS");
   
   const PowerSet<int> maxCliques = graph::max_cliques(G);
   
   p_out.take("DESCRIPTION") << comment;
   p_out.take("FACETS") << as_array(maxCliques);
   
   if (!no_labels)
      p_out.take("VERTEX_LABELS") << L;
}

} }
   
using namespace polymake;

/** @file flag_complex
 *
 *  Produce the flag_complex of a given graph.
 *
 *  The @c -nol flag tells the client not to write any labels.
 *
 *  @synopsis flag_complex <out_file> <in_file> <graph_section> [ -nol ]
 *
 *  @reading  <graph_section>, VERTEX_LABELS
 *  @writing  DESCRIPTION, FACETS, may write VERTEX_LABELS
 *
 *  @index clients Producing a simplicial complex from other objects
 */


int main(int argc, const char* argv[])
{
   argv_option options[]={ { "-nol" } };
   enum { no_labels };
   if ( !extract_options(argc,argv,3,options) || argc!=4 ) {
      cerr << "usage: " << argv[0] << " <out_file> <in_file> <graph_section> [ -nol ]" << endl;
      return 1;
   }
   try {
      Poly p_in(argv[2], ios::in);
      Poly p_out(argv[1], ios::out | ios::trunc, p_in.type());

      std::ostringstream comment;
      comment << "Flag complex of " << argv[3] << " of " << argv[2] << ".";
      
      topaz::flag_complex(p_out, p_in, argv[3], comment.str(), options[no_labels]);
   }
   catch (const std::exception& e) {
     cerr << e.what() << endl;
     return 1;
   }
   return 0;
}


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