/* 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: node_edge_incidences.h 9751 2010-08-06 16:21:30Z joswig $
*/

#ifndef _POLYMAKE_NODE_EDGE_INCIDENCES_H
#define _POLYMAKE_NODE_EDGE_INCIDENCES_H

#include <Matrix.h>
#include <Graph.h>

namespace pm { namespace graph {

// the node-edge incidence matrix of a directed graph is totally unimodular
Matrix<int> node_edge_incidences(const Graph<Directed>& G) {
   Matrix<int> ne(G.nodes(),G.edges());
   int k=0;
   for (Entire< Edges< Graph<Directed> > >::const_iterator e=entire(edges(G)); !e.at_end(); ++e, ++k) {
      ne(e.to_node(),k)=1; ne(e.from_node(),k)=-1;
   }
   return ne;
}

// this is the undirected case
// the node-edge incidence matrix of a /bipartite/ graph is also totally unimodular
Matrix<int> node_edge_incidences(const Graph<Undirected>& G) {
   Matrix<int> ne(G.nodes(),G.edges());
   int k=0;
   for (Entire< Edges< Graph<Undirected> > >::const_iterator e=entire(edges(G)); !e.at_end(); ++e, ++k) {
      ne(e.to_node(),k)=1; ne(e.from_node(),k)=1;
   }
   return ne;
}

} // end namespace graph
} // end namespace pm

namespace polymake {
   using pm::graph::node_edge_incidences;
}

#endif // _POLYMAKE_NODE_EDGE_INCIDENCES_H

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