/* -*- mode: C++; indent-tabs-mode: nil; -*-
* This file is a part of LEMON, a generic C++ optimization library.
* Copyright (C) 2003-2008
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
* (Egervary Research Group on Combinatorial Optimization, EGRES).
* Permission to use, modify and distribute this software is granted
* provided that this copyright notice appears in all copies. For
* precise terms see the accompanying LICENSE file.
* This software is provided "AS IS" with no warranty of any kind,
* express or implied, and with no claim as to its suitability for any
///\brief DIMACS to LGF converter.
/// This program converts various DIMACS formats to the LEMON Digraph Format
/// for more info on usage.
#include <lemon/smart_graph.h>
#include <lemon/dimacs.h>
#include <lemon/lgf_writer.h>
#include <lemon/arg_parser.h>
int main(int argc, const char *argv[]) {
typedef SmartDigraph Digraph;
typedef Digraph::Arc Arc;
typedef Digraph::Node Node;
typedef Digraph::ArcIt ArcIt;
typedef Digraph::NodeIt NodeIt;
typedef Digraph::ArcMap<double> DoubleArcMap;
typedef Digraph::NodeMap<double> DoubleNodeMap;
ArgParser ap(argc, argv);
"use FILE as input instead of standard input",
inputName).synonym("i", "-input")
"use FILE as output instead of standard output",
outputName).synonym("o", "-output")
.refOption("-mincostflow",
"set the type of the digraph to \"mincostflow\" digraph",
.optionGroup("type", "-mincostflow").synonym("mcf", "-mincostflow")
"set the type of the digraph to \"maxflow\" digraph",
.optionGroup("type", "-maxflow").synonym("mf", "-maxflow")
.refOption("-shortestpath",
"set the type of the digraph to \"shortestpath\" digraph",
.optionGroup("type", "-shortestpath").synonym("sp", "-shortestpath")
.refOption("-capacitated",
"set the type of the digraph to \"capacitated\" digraph",
.optionGroup("type", "-capacitated").synonym("cap", "-capacitated")
"set the type of the digraph to \"plain\" digraph",
.optionGroup("type", "-plain").synonym("pl", "-plain")
.refOption("-version", "show version information", version)
.synonym("v", "-version")
if (!inputName.empty()) {
input.open(inputName.c_str());
cerr << "File open error" << endl;
istream& is = (inputName.empty() ? cin : input);
if (!outputName.empty()) {
output.open(outputName.c_str());
cerr << "File open error" << endl;
ostream& os = (outputName.empty() ? cout : output);
DoubleArcMap lower(digraph), capacity(digraph), cost(digraph);
DoubleNodeMap supply(digraph);
readDimacsMin(is, digraph, lower, capacity, cost, supply);
DigraphWriter<Digraph>(digraph, os).
nodeMap("supply", supply).
arcMap("capacity", capacity).
DoubleArcMap capacity(digraph);
readDimacsMax(is, digraph, capacity, s, t);
DigraphWriter<Digraph>(digraph, os).
arcMap("capacity", capacity).
} else if (shortestpath) {
DoubleArcMap capacity(digraph);
readDimacsSp(is, digraph, capacity, s);
DigraphWriter<Digraph>(digraph, os).
arcMap("capacity", capacity).
} else if (capacitated) {
DoubleArcMap capacity(digraph);
readDimacsMax(is, digraph, capacity);
DigraphWriter<Digraph>(digraph, os).
arcMap("capacity", capacity).
readDimacsMat(is, digraph);
DigraphWriter<Digraph>(digraph, os).run();
cerr << "Invalid type error" << endl;