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> DoubleEdgeMap;
50 typedef Graph::NodeMap<double> DoubleNodeMap;
52 std::string inputName;
53 std::string outputName;
64 ArgParser ap(argc, argv);
65 ap.refOption("-input",
66 "use FILE as input instead of standard input",
67 inputName).synonym("i", "-input")
69 "use FILE as output instead of standard output",
70 outputName).synonym("o", "-output")
71 .refOption("-mincostflow",
72 "set the type of the graph to \"mincostflow\" graph",
74 .optionGroup("type", "-mincostflow").synonym("mcf", "-mincostflow")
75 .refOption("-maxflow",
76 "set the type of the graph to \"maxflow\" graph",
78 .optionGroup("type", "-maxflow").synonym("mf", "-maxflow")
79 .refOption("-shortestpath",
80 "set the type of the graph to \"shortestpath\" graph",
82 .optionGroup("type", "-shortestpath").synonym("sp", "-shortestpath")
83 .refOption("-capacitated",
84 "set the type of the graph to \"capacitated\" graph",
86 .optionGroup("type", "-capacitated").synonym("cap", "-capacitated")
88 "set the type of the graph to \"plain\" graph",
90 .optionGroup("type", "-plain").synonym("pl", "-plain")
92 .mandatoryGroup("type")
93 .refOption("-version", "show version information", version)
94 .synonym("v", "-version")
98 if (!inputName.empty()) {
99 input.open(inputName.c_str());
101 cerr << "File open error" << endl;
105 istream& is = (inputName.empty() ? cin : input);
108 if (!outputName.empty()) {
109 output.open(outputName.c_str());
111 cerr << "File open error" << endl;
115 ostream& os = (outputName.empty() ? cout : output);
119 DoubleEdgeMap lower(graph), capacity(graph), cost(graph);
120 DoubleNodeMap supply(graph);
121 readDimacs(is, graph, lower, capacity, cost, supply);
122 GraphWriter<Graph>(os, graph).
123 writeNodeMap("supply", supply).
124 writeEdgeMap("lower", lower).
125 writeEdgeMap("capacity", capacity).
126 writeEdgeMap("cost", cost).
128 } else if (maxflow) {
131 DoubleEdgeMap capacity(graph);
132 readDimacs(is, graph, capacity, s, t);
133 GraphWriter<Graph>(os, graph).
134 writeEdgeMap("capacity", capacity).
135 writeNode("source", s).
136 writeNode("target", t).
138 } else if (shortestpath) {
141 DoubleEdgeMap capacity(graph);
142 readDimacs(is, graph, capacity, s);
143 GraphWriter<Graph>(os, graph).
144 writeEdgeMap("capacity", capacity).
145 writeNode("source", s).
147 } else if (capacitated) {
149 DoubleEdgeMap capacity(graph);
150 readDimacs(is, graph, capacity);
151 GraphWriter<Graph>(os, graph).
152 writeEdgeMap("capacity", capacity).
156 readDimacs(is, graph);
157 GraphWriter<Graph>(os, graph).run();
159 cerr << "Invalid type error" << endl;