/* 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: bipartite.cc,v 1.5 2005/04/07 15:33:23 witte Exp $"

#include <Poly.h>
#include <bipartite.h>
#include <Graph.h>

namespace polymake { namespace graph {

void bipartite(Poly& p, const char *graph_section, const char *bipartite_section)
{
   const Graph<> G=p.give(graph_section);
   p.take(bipartite_section) << is_bipartite(G);
}

void bipartite_sign(Poly& p, const char *graph_section, const char *bipartite_section, const char *signature_section)
{
   const Graph<> G=p.give(graph_section);
   const int sign = is_bipartite_sign(G);

   p.take(bipartite_section) << (sign>=0);
   p.take(signature_section) << sign;
}

} }

using namespace polymake;

/** @file bipartite
 *
 *  Determine whether an undirected graph is bipartite.
 *
 *  @synopsis bipartite <file> <graph_section> <bipartite_section> [ <signature_section> ]
 *
 *  @reading  <graph_section>
 *  @writing  <bipartite_section>
 *
 *  @author Niko Witte <witte@math.tu-berlin.de>
 */

int main(int argc, const char *argv[]) {
   if (argc<4 || argc>5) {
      cerr << "usage: " << argv[0] << " <file> <graph_section> <bipartite_section> [ <signature_section> ]\n";
      return 1;
   }
   try {
      Poly p(argv[1], ios::in | ios::out);
      if (argc==4)
	graph::bipartite(p, argv[2], argv[3]);
      else
	graph::bipartite_sign(p, argv[2], argv[3], argv[4]);
   }
   catch (const std::exception& e) {
     cerr << e.what() << endl;
     return 1;
   }
   return 0;
}
