Polish the doc.
2 * demo/dim_to_lgf.cc - Part of LEMON, a generic C++ optimization library
4 * Copyright (C) 2006 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Research Group on Combinatorial Optimization, EGRES).
7 * Permission to use, modify and distribute this software is granted
8 * provided that this copyright notice appears in all copies. For
9 * precise terms see the accompanying LICENSE file.
11 * This software is provided "AS IS" with no warranty of any kind,
12 * express or implied, and with no claim as to its suitability for any
19 ///\brief DIMACS to LGF converter (demo).
21 /// This program converts various DIMACS formats to the LEMON Graph Format
24 /// \include dim_to_lgf.cc
30 #include <lemon/smart_graph.h>
31 #include <lemon/dimacs.h>
32 #include <lemon/graph_writer.h>
35 using namespace lemon;
37 const char* versionString =
38 "dim_to_lgf - part of lemon library\n";
40 const char* helpString =
41 "DIMACS to LGF converter\n"
42 "Usage: dim_to_lgf [OPTIONS]\n"
45 " dim_to_lgf --type shortestpath --input graph.dim --output graph.lgf\n"
48 " -i FILE, --input FILE use FILE as input instead of standard input\n"
49 " -o FILE, --output FILE use FILE as output instead of standard output\n"
50 " -t TYPE, --type TYPE set up the type of the graph\n"
53 " maxflow (default)\n"
57 " -v, --version shows the version of the converter\n"
58 " -h, --help shows the help of the converter\n";
61 int main(int argc, const char *argv[]) {
62 typedef SmartGraph Graph;
64 typedef Graph::Edge Edge;
65 typedef Graph::Node Node;
66 typedef Graph::EdgeIt EdgeIt;
67 typedef Graph::NodeIt NodeIt;
68 typedef Graph::EdgeMap<double> DoubleMap;
70 std::string inputName;
71 std::string outputName;
77 for (int arg = 1; arg < argc; ++arg) {
78 if (strcmp(argv[arg], "--type") == 0 ||
79 strcmp(argv[arg], "-t") == 0) {
80 if (!typeName.empty()) {
81 cerr << "Multiple type description" << endl;
84 if (arg + 1 == argc) {
85 cerr << "Parameter without value" << endl;
88 typeName = argv[++arg];
90 else if (strcmp(argv[arg], "--input") == 0 ||
91 strcmp(argv[arg], "-i") == 0) {
92 if (!inputName.empty()) {
93 cerr << "Multiple input description" << endl;
96 if (arg + 1 == argc) {
97 cerr << "Parameter without value" << endl;
100 inputName = argv[++arg];
102 else if (strcmp(argv[arg], "--output") == 0 ||
103 strcmp(argv[arg], "-o") == 0) {
104 if (!outputName.empty()) {
105 cerr << "Multiple input description" << endl;
108 if (arg + 1 == argc) {
109 cerr << "Parameter without value" << endl;
112 outputName = argv[++arg];
113 } else if (strcmp(argv[arg], "--help") == 0 ||
114 strcmp(argv[arg], "-h") == 0) {
116 } else if (strcmp(argv[arg], "--version") == 0 ||
117 strcmp(argv[arg], "-v") == 0) {
120 cerr << "Invalid option: " << argv[arg] << endl;
126 cout << versionString;
131 if (help || version) {
136 if (!inputName.empty()) {
137 input.open(inputName.c_str());
139 cerr << "File open error" << endl;
143 istream& is = (inputName.empty() ? cin : input);
146 if (!outputName.empty()) {
147 output.open(outputName.c_str());
149 cerr << "File open error" << endl;
153 ostream& os = (outputName.empty() ? cout : output);
155 if (typeName.empty()) {
156 typeName = "maxflow";
159 if (typeName == "mincostflow") {
162 DoubleMap cost(graph), capacity(graph);
163 readDimacs(is, graph, capacity, s, t, cost);
164 GraphWriter<Graph>(os, graph).
165 writeEdgeMap("capacity", capacity).
166 writeNode("source", s).
167 writeNode("target", t).
168 writeEdgeMap("cost", cost).
170 } else if (typeName == "maxflow") {
173 DoubleMap capacity(graph);
174 readDimacs(is, graph, capacity, s, t);
175 GraphWriter<Graph>(os, graph).
176 writeEdgeMap("capacity", capacity).
177 writeNode("source", s).
178 writeNode("target", t).
180 } else if (typeName == "shortestpath") {
183 DoubleMap capacity(graph);
184 readDimacs(is, graph, capacity, s);
185 GraphWriter<Graph>(os, graph).
186 writeEdgeMap("capacity", capacity).
187 writeNode("source", s).
189 } else if (typeName == "capacitated") {
191 DoubleMap capacity(graph);
192 readDimacs(is, graph, capacity);
193 GraphWriter<Graph>(os, graph).
194 writeEdgeMap("capacity", capacity).
196 } else if (typeName == "plain") {
198 readDimacs(is, graph);
199 GraphWriter<Graph>(os, graph).run();
201 cerr << "Invalid type error" << endl;