1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2008
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 Digraph Format
28 /// dimacs-to-lgf --help
30 /// for more info on usage.
37 #include <lemon/smart_graph.h>
38 #include <lemon/dimacs.h>
39 #include <lemon/lgf_writer.h>
41 #include <lemon/arg_parser.h>
44 using namespace lemon;
47 int main(int argc, const char *argv[]) {
48 typedef SmartDigraph Digraph;
50 typedef Digraph::Arc Arc;
51 typedef Digraph::Node Node;
52 typedef Digraph::ArcIt ArcIt;
53 typedef Digraph::NodeIt NodeIt;
54 typedef Digraph::ArcMap<double> DoubleArcMap;
55 typedef Digraph::NodeMap<double> DoubleNodeMap;
57 std::string inputName;
58 std::string outputName;
69 ArgParser ap(argc, argv);
70 ap.refOption("-input",
71 "use FILE as input instead of standard input",
72 inputName).synonym("i", "-input")
74 "use FILE as output instead of standard output",
75 outputName).synonym("o", "-output")
76 .refOption("-mincostflow",
77 "set the type of the digraph to \"mincostflow\" digraph",
79 .optionGroup("type", "-mincostflow").synonym("mcf", "-mincostflow")
80 .refOption("-maxflow",
81 "set the type of the digraph to \"maxflow\" digraph",
83 .optionGroup("type", "-maxflow").synonym("mf", "-maxflow")
84 .refOption("-shortestpath",
85 "set the type of the digraph to \"shortestpath\" digraph",
87 .optionGroup("type", "-shortestpath").synonym("sp", "-shortestpath")
88 .refOption("-capacitated",
89 "set the type of the digraph to \"capacitated\" digraph",
91 .optionGroup("type", "-capacitated").synonym("cap", "-capacitated")
93 "set the type of the digraph to \"plain\" digraph",
95 .optionGroup("type", "-plain").synonym("pl", "-plain")
97 .mandatoryGroup("type")
98 .refOption("-version", "show version information", version)
99 .synonym("v", "-version")
103 if (!inputName.empty()) {
104 input.open(inputName.c_str());
106 cerr << "File open error" << endl;
110 istream& is = (inputName.empty() ? cin : input);
113 if (!outputName.empty()) {
114 output.open(outputName.c_str());
116 cerr << "File open error" << endl;
120 ostream& os = (outputName.empty() ? cout : output);
124 DoubleArcMap lower(digraph), capacity(digraph), cost(digraph);
125 DoubleNodeMap supply(digraph);
126 readDimacs(is, digraph, lower, capacity, cost, supply);
127 DigraphWriter<Digraph>(digraph, os).
128 nodeMap("supply", supply).
129 arcMap("lower", lower).
130 arcMap("capacity", capacity).
131 arcMap("cost", cost).
133 } else if (maxflow) {
136 DoubleArcMap capacity(digraph);
137 readDimacs(is, digraph, capacity, s, t);
138 DigraphWriter<Digraph>(digraph, os).
139 arcMap("capacity", capacity).
143 } else if (shortestpath) {
146 DoubleArcMap capacity(digraph);
147 readDimacs(is, digraph, capacity, s);
148 DigraphWriter<Digraph>(digraph, os).
149 arcMap("capacity", capacity).
152 } else if (capacitated) {
154 DoubleArcMap capacity(digraph);
155 readDimacs(is, digraph, capacity);
156 DigraphWriter<Digraph>(digraph, os).
157 arcMap("capacity", capacity).
161 readDimacs(is, digraph);
162 DigraphWriter<Digraph>(digraph, os).run();
164 cerr << "Invalid type error" << endl;