- Increased max. number of iteration
- Better tests.
3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
21 ///\brief DIMACS to LGF converter (demo).
23 /// This program converts various DIMACS formats to the LEMON Graph Format
26 /// \include dim_to_lgf.cc
32 #include <lemon/smart_graph.h>
33 #include <lemon/dimacs.h>
34 #include <lemon/graph_writer.h>
37 using namespace lemon;
39 const char* versionString =
40 "dim_to_lgf - part of lemon library\n";
42 const char* helpString =
43 "DIMACS to LGF converter\n"
44 "Usage: dim_to_lgf [OPTIONS]\n"
47 " dim_to_lgf --type shortestpath --input graph.dim --output graph.lgf\n"
50 " -i FILE, --input FILE use FILE as input instead of standard input\n"
51 " -o FILE, --output FILE use FILE as output instead of standard output\n"
52 " -t TYPE, --type TYPE set up the type of the graph\n"
55 " maxflow (default)\n"
59 " -v, --version shows the version of the converter\n"
60 " -h, --help shows the help of the converter\n";
63 int main(int argc, const char *argv[]) {
64 typedef SmartGraph Graph;
66 typedef Graph::Edge Edge;
67 typedef Graph::Node Node;
68 typedef Graph::EdgeIt EdgeIt;
69 typedef Graph::NodeIt NodeIt;
70 typedef Graph::EdgeMap<double> DoubleMap;
72 std::string inputName;
73 std::string outputName;
79 for (int arg = 1; arg < argc; ++arg) {
80 if (strcmp(argv[arg], "--type") == 0 ||
81 strcmp(argv[arg], "-t") == 0) {
82 if (!typeName.empty()) {
83 cerr << "Multiple type description" << endl;
86 if (arg + 1 == argc) {
87 cerr << "Parameter without value" << endl;
90 typeName = argv[++arg];
92 else if (strcmp(argv[arg], "--input") == 0 ||
93 strcmp(argv[arg], "-i") == 0) {
94 if (!inputName.empty()) {
95 cerr << "Multiple input description" << endl;
98 if (arg + 1 == argc) {
99 cerr << "Parameter without value" << endl;
102 inputName = argv[++arg];
104 else if (strcmp(argv[arg], "--output") == 0 ||
105 strcmp(argv[arg], "-o") == 0) {
106 if (!outputName.empty()) {
107 cerr << "Multiple input description" << endl;
110 if (arg + 1 == argc) {
111 cerr << "Parameter without value" << endl;
114 outputName = argv[++arg];
115 } else if (strcmp(argv[arg], "--help") == 0 ||
116 strcmp(argv[arg], "-h") == 0) {
118 } else if (strcmp(argv[arg], "--version") == 0 ||
119 strcmp(argv[arg], "-v") == 0) {
122 cerr << "Invalid option: " << argv[arg] << endl;
128 cout << versionString;
133 if (help || version) {
138 if (!inputName.empty()) {
139 input.open(inputName.c_str());
141 cerr << "File open error" << endl;
145 istream& is = (inputName.empty() ? cin : input);
148 if (!outputName.empty()) {
149 output.open(outputName.c_str());
151 cerr << "File open error" << endl;
155 ostream& os = (outputName.empty() ? cout : output);
157 if (typeName.empty()) {
158 typeName = "maxflow";
161 if (typeName == "mincostflow") {
164 DoubleMap cost(graph), capacity(graph);
165 readDimacs(is, graph, capacity, s, t, cost);
166 GraphWriter<Graph>(os, graph).
167 writeEdgeMap("capacity", capacity).
168 writeNode("source", s).
169 writeNode("target", t).
170 writeEdgeMap("cost", cost).
172 } else if (typeName == "maxflow") {
175 DoubleMap capacity(graph);
176 readDimacs(is, graph, capacity, s, t);
177 GraphWriter<Graph>(os, graph).
178 writeEdgeMap("capacity", capacity).
179 writeNode("source", s).
180 writeNode("target", t).
182 } else if (typeName == "shortestpath") {
185 DoubleMap capacity(graph);
186 readDimacs(is, graph, capacity, s);
187 GraphWriter<Graph>(os, graph).
188 writeEdgeMap("capacity", capacity).
189 writeNode("source", s).
191 } else if (typeName == "capacitated") {
193 DoubleMap capacity(graph);
194 readDimacs(is, graph, capacity);
195 GraphWriter<Graph>(os, graph).
196 writeEdgeMap("capacity", capacity).
198 } else if (typeName == "plain") {
200 readDimacs(is, graph);
201 GraphWriter<Graph>(os, graph).run();
203 cerr << "Invalid type error" << endl;