3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2007
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.
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>
36 #include <lemon/arg_parser.h>
39 using namespace lemon;
42 int main(int argc, const char *argv[]) {
43 typedef SmartGraph Graph;
45 typedef Graph::Edge Edge;
46 typedef Graph::Node Node;
47 typedef Graph::EdgeIt EdgeIt;
48 typedef Graph::NodeIt NodeIt;
49 typedef Graph::EdgeMap<double> DoubleMap;
51 std::string inputName;
52 std::string outputName;
63 ArgParser ap(argc, argv);
64 ap.refOption("-input",
65 "use FILE as input instead of standard input",
66 inputName).synonym("i", "-input")
68 "use FILE as output instead of standard output",
69 outputName).synonym("o", "-output")
70 .refOption("-mincostflow",
71 "set the type of the graph to \"mincostflow\" graph",
73 .optionGroup("type", "-mincostflow").synonym("mcf", "-mincostflow")
74 .refOption("-maxflow",
75 "set the type of the graph to \"maxflow\" graph",
77 .optionGroup("type", "-maxflow").synonym("mf", "-maxflow")
78 .refOption("-shortestpath",
79 "set the type of the graph to \"shortestpath\" graph",
81 .optionGroup("type", "-shortestpath").synonym("sp", "-shortestpath")
82 .refOption("-capacitated",
83 "set the type of the graph to \"capacitated\" graph",
85 .optionGroup("type", "-capacitated").synonym("cap", "-capacitated")
87 "set the type of the graph to \"plain\" graph",
89 .optionGroup("type", "-plain").synonym("pl", "-plain")
91 .mandatoryGroup("type")
92 .refOption("-version", "show version information", version)
93 .synonym("v", "-version")
97 if (!inputName.empty()) {
98 input.open(inputName.c_str());
100 cerr << "File open error" << endl;
104 istream& is = (inputName.empty() ? cin : input);
107 if (!outputName.empty()) {
108 output.open(outputName.c_str());
110 cerr << "File open error" << endl;
114 ostream& os = (outputName.empty() ? cout : output);
119 DoubleMap cost(graph), capacity(graph);
120 readDimacs(is, graph, capacity, s, t, cost);
121 GraphWriter<Graph>(os, graph).
122 writeEdgeMap("capacity", capacity).
123 writeNode("source", s).
124 writeNode("target", t).
125 writeEdgeMap("cost", cost).
127 } else if (maxflow) {
130 DoubleMap capacity(graph);
131 readDimacs(is, graph, capacity, s, t);
132 GraphWriter<Graph>(os, graph).
133 writeEdgeMap("capacity", capacity).
134 writeNode("source", s).
135 writeNode("target", t).
137 } else if (shortestpath) {
140 DoubleMap capacity(graph);
141 readDimacs(is, graph, capacity, s);
142 GraphWriter<Graph>(os, graph).
143 writeEdgeMap("capacity", capacity).
144 writeNode("source", s).
146 } else if (capacitated) {
148 DoubleMap capacity(graph);
149 readDimacs(is, graph, capacity);
150 GraphWriter<Graph>(os, graph).
151 writeEdgeMap("capacity", capacity).
155 readDimacs(is, graph);
156 GraphWriter<Graph>(os, graph).run();
158 cerr << "Invalid type error" << endl;