/* 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: poly2leda_graph.cc 4714 2004-06-22 16:23:15Z gawrilow $" #include #include #include namespace polymake { namespace graph { namespace { template void print_LEDA_graph(std::basic_ostream& os, const _Graph& G) { const int nodes=G.nodes(); os << "LEDA.GRAPH\n\n\n" << nodes << endl; for (int i=0; i >::const_iterator e=entire(edges(G)); !e.at_end(); ++e) os << e.from_node() << " " << e.to_node() << " 0 |{}|\n"; } } template void poly2leda_graph(Poly& p, const char* section, bool dir, std::basic_ostream& os) { if (dir) { const Graph G=p.give(section); print_LEDA_graph(os,G); } else { const Graph G=p.give(section); print_LEDA_graph(os,G); } } } } using namespace polymake; /** @file poly2leda_graph * * Convert a polymake graph into a leda graph, write the latter to standard output. * * @synopsis poly2leda_graph { -directed, -undirected } * * @index utilities */ int main(int argc, const char *argv[]) { argv_option options[]={ { "-directed" }, { "-undirected" } }; enum { dir, undir }; if (argc != 4 || !extract_options(argc,argv,2,options) || argc != 3) { cerr << "usage: " << argv[0] << " { -directed, -undirected } \n"; return 1; } try { Poly p(argv[1],ios::in); graph::poly2leda_graph(p, argv[2], options[dir], std::cout); } catch (const std::exception& e) { cerr << e.what() << endl; return 1; } return 0; }