EdgeMapEditor is on its way, but it is far not yet ready.
5 #include <lemon/smart_graph.h>
6 #include <lemon/dimacs.h>
7 #include <lemon/graph_writer.h>
10 using namespace lemon;
12 const char* versionString =
13 "dim_to_lgf - part of lemon library\n";
15 const char* helpString =
16 "Dimacs to LGF converter\n"
17 "Usage: dim_to_lgf [OPTIONS]\n"
20 " dim_to_lgf --type shortestpath --input graph.dim --output graph.lgf\n"
23 " -i FILE, --input FILE use FILE as input instead of standard input\n"
24 " -o FILE, --output FILE use FILE as output instead of standard output\n"
25 " -t TYPE, --type TYPE set up the type of the graph\n"
28 " maxflow (default)\n"
32 " -v, --version shows the version of the converter\n"
33 " -h, --help shows the help of the converter\n";
36 int main(int argc, const char *argv[]) {
37 typedef SmartGraph Graph;
39 typedef Graph::Edge Edge;
40 typedef Graph::Node Node;
41 typedef Graph::EdgeIt EdgeIt;
42 typedef Graph::NodeIt NodeIt;
43 typedef Graph::EdgeMap<string> StringMap;
45 std::string inputName;
46 std::string outputName;
52 for (int arg = 1; arg < argc; ++arg) {
53 if (strcmp(argv[arg], "--type") == 0 ||
54 strcmp(argv[arg], "-t") == 0) {
55 if (!typeName.empty()) {
56 cerr << "Multiple type description" << endl;
59 if (arg + 1 == argc) {
60 cerr << "Parameter without value" << endl;
63 typeName = argv[++arg];
65 else if (strcmp(argv[arg], "--input") == 0 ||
66 strcmp(argv[arg], "-i") == 0) {
67 if (!inputName.empty()) {
68 cerr << "Multiple input description" << endl;
71 if (arg + 1 == argc) {
72 cerr << "Parameter without value" << endl;
75 inputName = argv[++arg];
77 else if (strcmp(argv[arg], "--output") == 0 ||
78 strcmp(argv[arg], "-o") == 0) {
79 if (!outputName.empty()) {
80 cerr << "Multiple input description" << endl;
83 if (arg + 1 == argc) {
84 cerr << "Parameter without value" << endl;
87 outputName = argv[++arg];
88 } else if (strcmp(argv[arg], "--help") == 0 ||
89 strcmp(argv[arg], "-h") == 0) {
91 } else if (strcmp(argv[arg], "--version") == 0 ||
92 strcmp(argv[arg], "-v") == 0) {
95 cerr << "Invalid option: " << argv[arg] << endl;
101 cout << versionString;
106 if (help || version) {
111 if (!inputName.empty()) {
112 input.open(inputName.c_str());
114 cerr << "File open error" << endl;
118 istream& is = (inputName.empty() ? cin : input);
121 if (!outputName.empty()) {
122 output.open(outputName.c_str());
124 cerr << "File open error" << endl;
128 ostream& os = (outputName.empty() ? cout : output);
130 if (typeName.empty()) {
131 typeName = "maxflow";
134 if (typeName == "mincostflow") {
137 StringMap cost(graph), capacity(graph);
138 readDimacs(is, graph, capacity, s, t, cost);
139 writeGraph(os, graph, capacity, s, t, cost);
140 } else if (typeName == "maxflow") {
143 StringMap capacity(graph);
144 readDimacs(is, graph, capacity, s, t);
145 writeGraph(os, graph, capacity, s, t);
146 } else if (typeName == "shortestpath") {
149 StringMap capacity(graph);
150 readDimacs(is, graph, capacity, s);
151 writeGraph(os, graph, capacity, s);
152 } else if (typeName == "capacitated") {
154 StringMap capacity(graph);
155 readDimacs(is, graph, capacity);
156 writeGraph(os, graph, capacity);
157 } else if (typeName == "plain") {
159 readDimacs(is, graph);
160 writeGraph(os, graph);
162 cerr << "Invalid type error" << endl;