# HG changeset patch # User alpar # Date 1173707873 0 # Node ID ec474604075e68ae968c68f8fdebcfb16c3799e5 # Parent b8f65d8528e1babe0b05b71479b6ba0bb8524866 dim_to_lgf has been moved to tools/ (from demo/) diff -r b8f65d8528e1 -r ec474604075e demo/Makefile.am --- a/demo/Makefile.am Mon Mar 12 13:45:50 2007 +0000 +++ b/demo/Makefile.am Mon Mar 12 13:57:53 2007 +0000 @@ -24,7 +24,6 @@ demo/dim_to_dot \ demo/dijkstra_demo \ demo/reader_writer_demo \ - demo/dim_to_lgf \ demo/eps_demo \ demo/graph_to_eps_demo \ demo/graph_orientation \ @@ -67,8 +66,6 @@ demo_reader_writer_demo_SOURCES = demo/reader_writer_demo.cc -demo_dim_to_lgf_SOURCES = demo/dim_to_lgf.cc - demo_coloring_SOURCES = demo/coloring.cc demo_maps_summary_SOURCES = demo/maps_summary.cc diff -r b8f65d8528e1 -r ec474604075e demo/dim_to_lgf.cc --- a/demo/dim_to_lgf.cc Mon Mar 12 13:45:50 2007 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,207 +0,0 @@ -/* -*- C++ -*- - * - * This file is a part of LEMON, a generic C++ optimization library - * - * Copyright (C) 2003-2007 - * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport - * (Egervary Research Group on Combinatorial Optimization, EGRES). - * - * Permission to use, modify and distribute this software is granted - * provided that this copyright notice appears in all copies. For - * precise terms see the accompanying LICENSE file. - * - * This software is provided "AS IS" with no warranty of any kind, - * express or implied, and with no claim as to its suitability for any - * purpose. - * - */ - -///\ingroup demos -///\file -///\brief DIMACS to LGF converter (demo). -/// -/// This program converts various DIMACS formats to the LEMON Graph Format -/// (LGF). -/// -/// \include dim_to_lgf.cc - -#include -#include -#include - -#include -#include -#include - -using namespace std; -using namespace lemon; - -const char* versionString = -"dim_to_lgf - part of lemon library\n"; - -const char* helpString = -"DIMACS to LGF converter\n" -"Usage: dim_to_lgf [OPTIONS]\n" -"\n" -"Examples:\n" -" dim_to_lgf --type shortestpath --input graph.dim --output graph.lgf\n" -"\n" -"Options:\n" -" -i FILE, --input FILE use FILE as input instead of standard input\n" -" -o FILE, --output FILE use FILE as output instead of standard output\n" -" -t TYPE, --type TYPE set up the type of the graph\n" -" Possible types:\n" -" mincostflow\n" -" maxflow (default)\n" -" shortestpath\n" -" capacitated\n" -" plain\n" -" -v, --version shows the version of the converter\n" -" -h, --help shows the help of the converter\n"; - - -int main(int argc, const char *argv[]) { - typedef SmartGraph Graph; - - typedef Graph::Edge Edge; - typedef Graph::Node Node; - typedef Graph::EdgeIt EdgeIt; - typedef Graph::NodeIt NodeIt; - typedef Graph::EdgeMap DoubleMap; - - std::string inputName; - std::string outputName; - std::string typeName; - - bool help = false; - bool version = false; - - for (int arg = 1; arg < argc; ++arg) { - if (strcmp(argv[arg], "--type") == 0 || - strcmp(argv[arg], "-t") == 0) { - if (!typeName.empty()) { - cerr << "Multiple type description" << endl; - return -1; - } - if (arg + 1 == argc) { - cerr << "Parameter without value" << endl; - return -1; - } - typeName = argv[++arg]; - } - else if (strcmp(argv[arg], "--input") == 0 || - strcmp(argv[arg], "-i") == 0) { - if (!inputName.empty()) { - cerr << "Multiple input description" << endl; - return -1; - } - if (arg + 1 == argc) { - cerr << "Parameter without value" << endl; - return -1; - } - inputName = argv[++arg]; - } - else if (strcmp(argv[arg], "--output") == 0 || - strcmp(argv[arg], "-o") == 0) { - if (!outputName.empty()) { - cerr << "Multiple input description" << endl; - return -1; - } - if (arg + 1 == argc) { - cerr << "Parameter without value" << endl; - return -1; - } - outputName = argv[++arg]; - } else if (strcmp(argv[arg], "--help") == 0 || - strcmp(argv[arg], "-h") == 0) { - help = true; - } else if (strcmp(argv[arg], "--version") == 0 || - strcmp(argv[arg], "-v") == 0) { - version = true; - } else { - cerr << "Invalid option: " << argv[arg] << endl; - return -1; - } - } - - if (version) { - cout << versionString; - } - if (help) { - cout << helpString; - } - if (help || version) { - return 0; - } - - ifstream input; - if (!inputName.empty()) { - input.open(inputName.c_str()); - if (!input) { - cerr << "File open error" << endl; - return -1; - } - } - istream& is = (inputName.empty() ? cin : input); - - ofstream output; - if (!outputName.empty()) { - output.open(outputName.c_str()); - if (!output) { - cerr << "File open error" << endl; - return -1; - } - } - ostream& os = (outputName.empty() ? cout : output); - - if (typeName.empty()) { - typeName = "maxflow"; - } - - if (typeName == "mincostflow") { - Graph graph; - Node s, t; - DoubleMap cost(graph), capacity(graph); - readDimacs(is, graph, capacity, s, t, cost); - GraphWriter(os, graph). - writeEdgeMap("capacity", capacity). - writeNode("source", s). - writeNode("target", t). - writeEdgeMap("cost", cost). - run(); - } else if (typeName == "maxflow") { - Graph graph; - Node s, t; - DoubleMap capacity(graph); - readDimacs(is, graph, capacity, s, t); - GraphWriter(os, graph). - writeEdgeMap("capacity", capacity). - writeNode("source", s). - writeNode("target", t). - run(); - } else if (typeName == "shortestpath") { - Graph graph; - Node s; - DoubleMap capacity(graph); - readDimacs(is, graph, capacity, s); - GraphWriter(os, graph). - writeEdgeMap("capacity", capacity). - writeNode("source", s). - run(); - } else if (typeName == "capacitated") { - Graph graph; - DoubleMap capacity(graph); - readDimacs(is, graph, capacity); - GraphWriter(os, graph). - writeEdgeMap("capacity", capacity). - run(); - } else if (typeName == "plain") { - Graph graph; - readDimacs(is, graph); - GraphWriter(os, graph).run(); - } else { - cerr << "Invalid type error" << endl; - return -1; - } - return 0; -} diff -r b8f65d8528e1 -r ec474604075e tools/Makefile.am --- a/tools/Makefile.am Mon Mar 12 13:45:50 2007 +0000 +++ b/tools/Makefile.am Mon Mar 12 13:57:53 2007 +0000 @@ -5,8 +5,11 @@ if WANT_TOOLS bin_PROGRAMS += \ + tools/dim_to_lgf \ tools/lgf-gen endif WANT_TOOLS tools_lgf_gen_SOURCES = tools/lgf-gen.cc + +tools_dim_to_lgf_SOURCES = tools/dim_to_lgf.cc diff -r b8f65d8528e1 -r ec474604075e tools/dim_to_lgf.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/dim_to_lgf.cc Mon Mar 12 13:57:53 2007 +0000 @@ -0,0 +1,207 @@ +/* -*- C++ -*- + * + * This file is a part of LEMON, a generic C++ optimization library + * + * Copyright (C) 2003-2007 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport + * (Egervary Research Group on Combinatorial Optimization, EGRES). + * + * Permission to use, modify and distribute this software is granted + * provided that this copyright notice appears in all copies. For + * precise terms see the accompanying LICENSE file. + * + * This software is provided "AS IS" with no warranty of any kind, + * express or implied, and with no claim as to its suitability for any + * purpose. + * + */ + +///\ingroup demos +///\file +///\brief DIMACS to LGF converter (demo). +/// +/// This program converts various DIMACS formats to the LEMON Graph Format +/// (LGF). +/// +/// \include dim_to_lgf.cc + +#include +#include +#include + +#include +#include +#include + +using namespace std; +using namespace lemon; + +const char* versionString = +"dim_to_lgf - part of lemon library\n"; + +const char* helpString = +"DIMACS to LGF converter\n" +"Usage: dim_to_lgf [OPTIONS]\n" +"\n" +"Examples:\n" +" dim_to_lgf --type shortestpath --input graph.dim --output graph.lgf\n" +"\n" +"Options:\n" +" -i FILE, --input FILE use FILE as input instead of standard input\n" +" -o FILE, --output FILE use FILE as output instead of standard output\n" +" -t TYPE, --type TYPE set up the type of the graph\n" +" Possible types:\n" +" mincostflow\n" +" maxflow (default)\n" +" shortestpath\n" +" capacitated\n" +" plain\n" +" -v, --version shows the version of the converter\n" +" -h, --help shows the help of the converter\n"; + + +int main(int argc, const char *argv[]) { + typedef SmartGraph Graph; + + typedef Graph::Edge Edge; + typedef Graph::Node Node; + typedef Graph::EdgeIt EdgeIt; + typedef Graph::NodeIt NodeIt; + typedef Graph::EdgeMap DoubleMap; + + std::string inputName; + std::string outputName; + std::string typeName; + + bool help = false; + bool version = false; + + for (int arg = 1; arg < argc; ++arg) { + if (strcmp(argv[arg], "--type") == 0 || + strcmp(argv[arg], "-t") == 0) { + if (!typeName.empty()) { + cerr << "Multiple type description" << endl; + return -1; + } + if (arg + 1 == argc) { + cerr << "Parameter without value" << endl; + return -1; + } + typeName = argv[++arg]; + } + else if (strcmp(argv[arg], "--input") == 0 || + strcmp(argv[arg], "-i") == 0) { + if (!inputName.empty()) { + cerr << "Multiple input description" << endl; + return -1; + } + if (arg + 1 == argc) { + cerr << "Parameter without value" << endl; + return -1; + } + inputName = argv[++arg]; + } + else if (strcmp(argv[arg], "--output") == 0 || + strcmp(argv[arg], "-o") == 0) { + if (!outputName.empty()) { + cerr << "Multiple input description" << endl; + return -1; + } + if (arg + 1 == argc) { + cerr << "Parameter without value" << endl; + return -1; + } + outputName = argv[++arg]; + } else if (strcmp(argv[arg], "--help") == 0 || + strcmp(argv[arg], "-h") == 0) { + help = true; + } else if (strcmp(argv[arg], "--version") == 0 || + strcmp(argv[arg], "-v") == 0) { + version = true; + } else { + cerr << "Invalid option: " << argv[arg] << endl; + return -1; + } + } + + if (version) { + cout << versionString; + } + if (help) { + cout << helpString; + } + if (help || version) { + return 0; + } + + ifstream input; + if (!inputName.empty()) { + input.open(inputName.c_str()); + if (!input) { + cerr << "File open error" << endl; + return -1; + } + } + istream& is = (inputName.empty() ? cin : input); + + ofstream output; + if (!outputName.empty()) { + output.open(outputName.c_str()); + if (!output) { + cerr << "File open error" << endl; + return -1; + } + } + ostream& os = (outputName.empty() ? cout : output); + + if (typeName.empty()) { + typeName = "maxflow"; + } + + if (typeName == "mincostflow") { + Graph graph; + Node s, t; + DoubleMap cost(graph), capacity(graph); + readDimacs(is, graph, capacity, s, t, cost); + GraphWriter(os, graph). + writeEdgeMap("capacity", capacity). + writeNode("source", s). + writeNode("target", t). + writeEdgeMap("cost", cost). + run(); + } else if (typeName == "maxflow") { + Graph graph; + Node s, t; + DoubleMap capacity(graph); + readDimacs(is, graph, capacity, s, t); + GraphWriter(os, graph). + writeEdgeMap("capacity", capacity). + writeNode("source", s). + writeNode("target", t). + run(); + } else if (typeName == "shortestpath") { + Graph graph; + Node s; + DoubleMap capacity(graph); + readDimacs(is, graph, capacity, s); + GraphWriter(os, graph). + writeEdgeMap("capacity", capacity). + writeNode("source", s). + run(); + } else if (typeName == "capacitated") { + Graph graph; + DoubleMap capacity(graph); + readDimacs(is, graph, capacity); + GraphWriter(os, graph). + writeEdgeMap("capacity", capacity). + run(); + } else if (typeName == "plain") { + Graph graph; + readDimacs(is, graph); + GraphWriter(os, graph).run(); + } else { + cerr << "Invalid type error" << endl; + return -1; + } + return 0; +}