/* Copyright (c) 1997-2010
   Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Darmstadt, Germany)
   http://www.polymake.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.
--------------------------------------------------------------------------------
   $Project: polymake $$Id: matching_polytope.cc 9751 2010-08-06 16:21:30Z joswig $
*/

#include <polymake.h>
#include <Matrix.h>
#include <Vector.h>
#include <Graph.h>
#include <node_edge_incidences.h>

namespace {
   typedef pm::graph::Graph<pm::graph::Undirected> graph_type;
}

namespace polymake { namespace polytope {

   perl::Object matching_polytope(const graph_type& G) {
      const Matrix<int> A(node_edge_incidences(G));
      const int n_nodes=A.rows();
      const int n_edges=A.cols();
      const Matrix<int> M((zero_vector<int>(n_edges) | diag(ones_vector<int>(n_edges))) /
			  (ones_vector<int>(n_nodes) | -A));
      
      perl::Object p("Polytope<Rational>");
      p.take("INEQUALITIES") << M;
      p.take("BOUNDED") << true;
      return p;
   }
      
   UserFunction4perl("#@category Producing from other"
		     "# Matching polytope of an undirected graph."
		     "# @param Graph G"
		     "# @return Polytope",
		     &matching_polytope,"matching_polytope(props::Graph)");
      
} }

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