SubGraphAdaptors with edge checking functionality.
Improved grid_graph_demo
2 * demo/dim_to_lgf.cc - Part of LEMON, a generic C++ optimization library
4 * Copyright (C) 2005 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<string> StringMap;
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 StringMap cost(graph), capacity(graph);
163 readDimacs(is, graph, capacity, s, t, cost);
164 writeGraph(os, graph, capacity, s, t, cost);
165 } else if (typeName == "maxflow") {
168 StringMap capacity(graph);
169 readDimacs(is, graph, capacity, s, t);
170 writeGraph(os, graph, capacity, s, t);
171 } else if (typeName == "shortestpath") {
174 StringMap capacity(graph);
175 readDimacs(is, graph, capacity, s);
176 writeGraph(os, graph, capacity, s);
177 } else if (typeName == "capacitated") {
179 StringMap capacity(graph);
180 readDimacs(is, graph, capacity);
181 writeGraph(os, graph, capacity);
182 } else if (typeName == "plain") {
184 readDimacs(is, graph);
185 writeGraph(os, graph);
187 cerr << "Invalid type error" << endl;