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

#include <Poly.h>
#include <Array.h>

#include <ext/hash_set>
#include <string>

namespace polymake {
namespace topaz {
  
void labels_consistency(std::ostream& os, Poly& p)
{
   const int n = p.give("N_VERTICES");
   const Array<std::string> L = p.give("VERTEX_LABELS");
   bool is_consistent = true;
   
   if (L.size()!=n) {
      os << "Wrong amount of labels." << endl;
      is_consistent = false;
   }
   
   std_ext::hash_set<std::string> labels(L.size());
   for (Entire< Array<std::string> >::const_iterator l=entire(L);
	!l.at_end(); ++l)
      if (labels.find(*l) != labels.end()) {  // label not unique
	 os << "Label " << *l << " is not unique." << endl;
	 is_consistent = false;
      } else
	 labels.insert(*l);
   
   if (is_consistent)
      os << "VERTEX_LABELS is consistent." << endl;
   else
      os << "\nVERTEX_LABELS is NOT consistent." << endl;
}
   
} }

using namespace polymake;

/** @file labels_consistency
 *
 *  Verifies whether the @see VERTEX_LABELS are unique and that their size
 *  matches @see N_VERTICES
 *
 *  @synopsis labels_consistency <file>
 *
 *  @reading  VERTEX_LABELS, N_VERTICES
 *
 *  @index clients Consistency checks
 */

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


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