1.1 --- a/demo/Makefile.am Mon Mar 12 13:45:50 2007 +0000
1.2 +++ b/demo/Makefile.am Mon Mar 12 13:57:53 2007 +0000
1.3 @@ -24,7 +24,6 @@
1.4 demo/dim_to_dot \
1.5 demo/dijkstra_demo \
1.6 demo/reader_writer_demo \
1.7 - demo/dim_to_lgf \
1.8 demo/eps_demo \
1.9 demo/graph_to_eps_demo \
1.10 demo/graph_orientation \
1.11 @@ -67,8 +66,6 @@
1.12
1.13 demo_reader_writer_demo_SOURCES = demo/reader_writer_demo.cc
1.14
1.15 -demo_dim_to_lgf_SOURCES = demo/dim_to_lgf.cc
1.16 -
1.17 demo_coloring_SOURCES = demo/coloring.cc
1.18
1.19 demo_maps_summary_SOURCES = demo/maps_summary.cc
2.1 --- a/demo/dim_to_lgf.cc Mon Mar 12 13:45:50 2007 +0000
2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
2.3 @@ -1,207 +0,0 @@
2.4 -/* -*- C++ -*-
2.5 - *
2.6 - * This file is a part of LEMON, a generic C++ optimization library
2.7 - *
2.8 - * Copyright (C) 2003-2007
2.9 - * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
2.10 - * (Egervary Research Group on Combinatorial Optimization, EGRES).
2.11 - *
2.12 - * Permission to use, modify and distribute this software is granted
2.13 - * provided that this copyright notice appears in all copies. For
2.14 - * precise terms see the accompanying LICENSE file.
2.15 - *
2.16 - * This software is provided "AS IS" with no warranty of any kind,
2.17 - * express or implied, and with no claim as to its suitability for any
2.18 - * purpose.
2.19 - *
2.20 - */
2.21 -
2.22 -///\ingroup demos
2.23 -///\file
2.24 -///\brief DIMACS to LGF converter (demo).
2.25 -///
2.26 -/// This program converts various DIMACS formats to the LEMON Graph Format
2.27 -/// (LGF).
2.28 -///
2.29 -/// \include dim_to_lgf.cc
2.30 -
2.31 -#include <iostream>
2.32 -#include <fstream>
2.33 -#include <cstring>
2.34 -
2.35 -#include <lemon/smart_graph.h>
2.36 -#include <lemon/dimacs.h>
2.37 -#include <lemon/graph_writer.h>
2.38 -
2.39 -using namespace std;
2.40 -using namespace lemon;
2.41 -
2.42 -const char* versionString =
2.43 -"dim_to_lgf - part of lemon library\n";
2.44 -
2.45 -const char* helpString =
2.46 -"DIMACS to LGF converter\n"
2.47 -"Usage: dim_to_lgf [OPTIONS]\n"
2.48 -"\n"
2.49 -"Examples:\n"
2.50 -" dim_to_lgf --type shortestpath --input graph.dim --output graph.lgf\n"
2.51 -"\n"
2.52 -"Options:\n"
2.53 -" -i FILE, --input FILE use FILE as input instead of standard input\n"
2.54 -" -o FILE, --output FILE use FILE as output instead of standard output\n"
2.55 -" -t TYPE, --type TYPE set up the type of the graph\n"
2.56 -" Possible types:\n"
2.57 -" mincostflow\n"
2.58 -" maxflow (default)\n"
2.59 -" shortestpath\n"
2.60 -" capacitated\n"
2.61 -" plain\n"
2.62 -" -v, --version shows the version of the converter\n"
2.63 -" -h, --help shows the help of the converter\n";
2.64 -
2.65 -
2.66 -int main(int argc, const char *argv[]) {
2.67 - typedef SmartGraph Graph;
2.68 -
2.69 - typedef Graph::Edge Edge;
2.70 - typedef Graph::Node Node;
2.71 - typedef Graph::EdgeIt EdgeIt;
2.72 - typedef Graph::NodeIt NodeIt;
2.73 - typedef Graph::EdgeMap<double> DoubleMap;
2.74 -
2.75 - std::string inputName;
2.76 - std::string outputName;
2.77 - std::string typeName;
2.78 -
2.79 - bool help = false;
2.80 - bool version = false;
2.81 -
2.82 - for (int arg = 1; arg < argc; ++arg) {
2.83 - if (strcmp(argv[arg], "--type") == 0 ||
2.84 - strcmp(argv[arg], "-t") == 0) {
2.85 - if (!typeName.empty()) {
2.86 - cerr << "Multiple type description" << endl;
2.87 - return -1;
2.88 - }
2.89 - if (arg + 1 == argc) {
2.90 - cerr << "Parameter without value" << endl;
2.91 - return -1;
2.92 - }
2.93 - typeName = argv[++arg];
2.94 - }
2.95 - else if (strcmp(argv[arg], "--input") == 0 ||
2.96 - strcmp(argv[arg], "-i") == 0) {
2.97 - if (!inputName.empty()) {
2.98 - cerr << "Multiple input description" << endl;
2.99 - return -1;
2.100 - }
2.101 - if (arg + 1 == argc) {
2.102 - cerr << "Parameter without value" << endl;
2.103 - return -1;
2.104 - }
2.105 - inputName = argv[++arg];
2.106 - }
2.107 - else if (strcmp(argv[arg], "--output") == 0 ||
2.108 - strcmp(argv[arg], "-o") == 0) {
2.109 - if (!outputName.empty()) {
2.110 - cerr << "Multiple input description" << endl;
2.111 - return -1;
2.112 - }
2.113 - if (arg + 1 == argc) {
2.114 - cerr << "Parameter without value" << endl;
2.115 - return -1;
2.116 - }
2.117 - outputName = argv[++arg];
2.118 - } else if (strcmp(argv[arg], "--help") == 0 ||
2.119 - strcmp(argv[arg], "-h") == 0) {
2.120 - help = true;
2.121 - } else if (strcmp(argv[arg], "--version") == 0 ||
2.122 - strcmp(argv[arg], "-v") == 0) {
2.123 - version = true;
2.124 - } else {
2.125 - cerr << "Invalid option: " << argv[arg] << endl;
2.126 - return -1;
2.127 - }
2.128 - }
2.129 -
2.130 - if (version) {
2.131 - cout << versionString;
2.132 - }
2.133 - if (help) {
2.134 - cout << helpString;
2.135 - }
2.136 - if (help || version) {
2.137 - return 0;
2.138 - }
2.139 -
2.140 - ifstream input;
2.141 - if (!inputName.empty()) {
2.142 - input.open(inputName.c_str());
2.143 - if (!input) {
2.144 - cerr << "File open error" << endl;
2.145 - return -1;
2.146 - }
2.147 - }
2.148 - istream& is = (inputName.empty() ? cin : input);
2.149 -
2.150 - ofstream output;
2.151 - if (!outputName.empty()) {
2.152 - output.open(outputName.c_str());
2.153 - if (!output) {
2.154 - cerr << "File open error" << endl;
2.155 - return -1;
2.156 - }
2.157 - }
2.158 - ostream& os = (outputName.empty() ? cout : output);
2.159 -
2.160 - if (typeName.empty()) {
2.161 - typeName = "maxflow";
2.162 - }
2.163 -
2.164 - if (typeName == "mincostflow") {
2.165 - Graph graph;
2.166 - Node s, t;
2.167 - DoubleMap cost(graph), capacity(graph);
2.168 - readDimacs(is, graph, capacity, s, t, cost);
2.169 - GraphWriter<Graph>(os, graph).
2.170 - writeEdgeMap("capacity", capacity).
2.171 - writeNode("source", s).
2.172 - writeNode("target", t).
2.173 - writeEdgeMap("cost", cost).
2.174 - run();
2.175 - } else if (typeName == "maxflow") {
2.176 - Graph graph;
2.177 - Node s, t;
2.178 - DoubleMap capacity(graph);
2.179 - readDimacs(is, graph, capacity, s, t);
2.180 - GraphWriter<Graph>(os, graph).
2.181 - writeEdgeMap("capacity", capacity).
2.182 - writeNode("source", s).
2.183 - writeNode("target", t).
2.184 - run();
2.185 - } else if (typeName == "shortestpath") {
2.186 - Graph graph;
2.187 - Node s;
2.188 - DoubleMap capacity(graph);
2.189 - readDimacs(is, graph, capacity, s);
2.190 - GraphWriter<Graph>(os, graph).
2.191 - writeEdgeMap("capacity", capacity).
2.192 - writeNode("source", s).
2.193 - run();
2.194 - } else if (typeName == "capacitated") {
2.195 - Graph graph;
2.196 - DoubleMap capacity(graph);
2.197 - readDimacs(is, graph, capacity);
2.198 - GraphWriter<Graph>(os, graph).
2.199 - writeEdgeMap("capacity", capacity).
2.200 - run();
2.201 - } else if (typeName == "plain") {
2.202 - Graph graph;
2.203 - readDimacs(is, graph);
2.204 - GraphWriter<Graph>(os, graph).run();
2.205 - } else {
2.206 - cerr << "Invalid type error" << endl;
2.207 - return -1;
2.208 - }
2.209 - return 0;
2.210 -}
3.1 --- a/tools/Makefile.am Mon Mar 12 13:45:50 2007 +0000
3.2 +++ b/tools/Makefile.am Mon Mar 12 13:57:53 2007 +0000
3.3 @@ -5,8 +5,11 @@
3.4 if WANT_TOOLS
3.5
3.6 bin_PROGRAMS += \
3.7 + tools/dim_to_lgf \
3.8 tools/lgf-gen
3.9
3.10 endif WANT_TOOLS
3.11
3.12 tools_lgf_gen_SOURCES = tools/lgf-gen.cc
3.13 +
3.14 +tools_dim_to_lgf_SOURCES = tools/dim_to_lgf.cc
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/tools/dim_to_lgf.cc Mon Mar 12 13:57:53 2007 +0000
4.3 @@ -0,0 +1,207 @@
4.4 +/* -*- C++ -*-
4.5 + *
4.6 + * This file is a part of LEMON, a generic C++ optimization library
4.7 + *
4.8 + * Copyright (C) 2003-2007
4.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
4.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
4.11 + *
4.12 + * Permission to use, modify and distribute this software is granted
4.13 + * provided that this copyright notice appears in all copies. For
4.14 + * precise terms see the accompanying LICENSE file.
4.15 + *
4.16 + * This software is provided "AS IS" with no warranty of any kind,
4.17 + * express or implied, and with no claim as to its suitability for any
4.18 + * purpose.
4.19 + *
4.20 + */
4.21 +
4.22 +///\ingroup demos
4.23 +///\file
4.24 +///\brief DIMACS to LGF converter (demo).
4.25 +///
4.26 +/// This program converts various DIMACS formats to the LEMON Graph Format
4.27 +/// (LGF).
4.28 +///
4.29 +/// \include dim_to_lgf.cc
4.30 +
4.31 +#include <iostream>
4.32 +#include <fstream>
4.33 +#include <cstring>
4.34 +
4.35 +#include <lemon/smart_graph.h>
4.36 +#include <lemon/dimacs.h>
4.37 +#include <lemon/graph_writer.h>
4.38 +
4.39 +using namespace std;
4.40 +using namespace lemon;
4.41 +
4.42 +const char* versionString =
4.43 +"dim_to_lgf - part of lemon library\n";
4.44 +
4.45 +const char* helpString =
4.46 +"DIMACS to LGF converter\n"
4.47 +"Usage: dim_to_lgf [OPTIONS]\n"
4.48 +"\n"
4.49 +"Examples:\n"
4.50 +" dim_to_lgf --type shortestpath --input graph.dim --output graph.lgf\n"
4.51 +"\n"
4.52 +"Options:\n"
4.53 +" -i FILE, --input FILE use FILE as input instead of standard input\n"
4.54 +" -o FILE, --output FILE use FILE as output instead of standard output\n"
4.55 +" -t TYPE, --type TYPE set up the type of the graph\n"
4.56 +" Possible types:\n"
4.57 +" mincostflow\n"
4.58 +" maxflow (default)\n"
4.59 +" shortestpath\n"
4.60 +" capacitated\n"
4.61 +" plain\n"
4.62 +" -v, --version shows the version of the converter\n"
4.63 +" -h, --help shows the help of the converter\n";
4.64 +
4.65 +
4.66 +int main(int argc, const char *argv[]) {
4.67 + typedef SmartGraph Graph;
4.68 +
4.69 + typedef Graph::Edge Edge;
4.70 + typedef Graph::Node Node;
4.71 + typedef Graph::EdgeIt EdgeIt;
4.72 + typedef Graph::NodeIt NodeIt;
4.73 + typedef Graph::EdgeMap<double> DoubleMap;
4.74 +
4.75 + std::string inputName;
4.76 + std::string outputName;
4.77 + std::string typeName;
4.78 +
4.79 + bool help = false;
4.80 + bool version = false;
4.81 +
4.82 + for (int arg = 1; arg < argc; ++arg) {
4.83 + if (strcmp(argv[arg], "--type") == 0 ||
4.84 + strcmp(argv[arg], "-t") == 0) {
4.85 + if (!typeName.empty()) {
4.86 + cerr << "Multiple type description" << endl;
4.87 + return -1;
4.88 + }
4.89 + if (arg + 1 == argc) {
4.90 + cerr << "Parameter without value" << endl;
4.91 + return -1;
4.92 + }
4.93 + typeName = argv[++arg];
4.94 + }
4.95 + else if (strcmp(argv[arg], "--input") == 0 ||
4.96 + strcmp(argv[arg], "-i") == 0) {
4.97 + if (!inputName.empty()) {
4.98 + cerr << "Multiple input description" << endl;
4.99 + return -1;
4.100 + }
4.101 + if (arg + 1 == argc) {
4.102 + cerr << "Parameter without value" << endl;
4.103 + return -1;
4.104 + }
4.105 + inputName = argv[++arg];
4.106 + }
4.107 + else if (strcmp(argv[arg], "--output") == 0 ||
4.108 + strcmp(argv[arg], "-o") == 0) {
4.109 + if (!outputName.empty()) {
4.110 + cerr << "Multiple input description" << endl;
4.111 + return -1;
4.112 + }
4.113 + if (arg + 1 == argc) {
4.114 + cerr << "Parameter without value" << endl;
4.115 + return -1;
4.116 + }
4.117 + outputName = argv[++arg];
4.118 + } else if (strcmp(argv[arg], "--help") == 0 ||
4.119 + strcmp(argv[arg], "-h") == 0) {
4.120 + help = true;
4.121 + } else if (strcmp(argv[arg], "--version") == 0 ||
4.122 + strcmp(argv[arg], "-v") == 0) {
4.123 + version = true;
4.124 + } else {
4.125 + cerr << "Invalid option: " << argv[arg] << endl;
4.126 + return -1;
4.127 + }
4.128 + }
4.129 +
4.130 + if (version) {
4.131 + cout << versionString;
4.132 + }
4.133 + if (help) {
4.134 + cout << helpString;
4.135 + }
4.136 + if (help || version) {
4.137 + return 0;
4.138 + }
4.139 +
4.140 + ifstream input;
4.141 + if (!inputName.empty()) {
4.142 + input.open(inputName.c_str());
4.143 + if (!input) {
4.144 + cerr << "File open error" << endl;
4.145 + return -1;
4.146 + }
4.147 + }
4.148 + istream& is = (inputName.empty() ? cin : input);
4.149 +
4.150 + ofstream output;
4.151 + if (!outputName.empty()) {
4.152 + output.open(outputName.c_str());
4.153 + if (!output) {
4.154 + cerr << "File open error" << endl;
4.155 + return -1;
4.156 + }
4.157 + }
4.158 + ostream& os = (outputName.empty() ? cout : output);
4.159 +
4.160 + if (typeName.empty()) {
4.161 + typeName = "maxflow";
4.162 + }
4.163 +
4.164 + if (typeName == "mincostflow") {
4.165 + Graph graph;
4.166 + Node s, t;
4.167 + DoubleMap cost(graph), capacity(graph);
4.168 + readDimacs(is, graph, capacity, s, t, cost);
4.169 + GraphWriter<Graph>(os, graph).
4.170 + writeEdgeMap("capacity", capacity).
4.171 + writeNode("source", s).
4.172 + writeNode("target", t).
4.173 + writeEdgeMap("cost", cost).
4.174 + run();
4.175 + } else if (typeName == "maxflow") {
4.176 + Graph graph;
4.177 + Node s, t;
4.178 + DoubleMap capacity(graph);
4.179 + readDimacs(is, graph, capacity, s, t);
4.180 + GraphWriter<Graph>(os, graph).
4.181 + writeEdgeMap("capacity", capacity).
4.182 + writeNode("source", s).
4.183 + writeNode("target", t).
4.184 + run();
4.185 + } else if (typeName == "shortestpath") {
4.186 + Graph graph;
4.187 + Node s;
4.188 + DoubleMap capacity(graph);
4.189 + readDimacs(is, graph, capacity, s);
4.190 + GraphWriter<Graph>(os, graph).
4.191 + writeEdgeMap("capacity", capacity).
4.192 + writeNode("source", s).
4.193 + run();
4.194 + } else if (typeName == "capacitated") {
4.195 + Graph graph;
4.196 + DoubleMap capacity(graph);
4.197 + readDimacs(is, graph, capacity);
4.198 + GraphWriter<Graph>(os, graph).
4.199 + writeEdgeMap("capacity", capacity).
4.200 + run();
4.201 + } else if (typeName == "plain") {
4.202 + Graph graph;
4.203 + readDimacs(is, graph);
4.204 + GraphWriter<Graph>(os, graph).run();
4.205 + } else {
4.206 + cerr << "Invalid type error" << endl;
4.207 + return -1;
4.208 + }
4.209 + return 0;
4.210 +}