/* -*- 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);
ap.other("[INFILE [OUTFILE]]",
"If either the INFILE or OUTFILE file is missing the standard\n"
" input/output will be used instead.")
switch(ap.files().size())
output.open(ap.files()[1].c_str());
throw IoError("Cannot open the file for writing", ap.files()[1]);
input.open(ap.files()[0].c_str());
throw IoError("File cannot be found", ap.files()[0]);
cerr << ap.commandName() << ": too many arguments\n";
istream& is = (ap.files().size()<1 ? cin : input);
ostream& os = (ap.files().size()<2 ? cout : output);
DimacsDescriptor desc = dimacsType(is);
case DimacsDescriptor:
:MIN:
DoubleArcMap lower(digraph), capacity(digraph), cost(digraph);
DoubleNodeMap supply(digraph);
readDimacsMin(is, digraph, lower, capacity, cost, supply, desc);
DigraphWriter<Digraph>(digraph, os).
nodeMap("supply", supply).
arcMap("capacity", capacity).
attribute("problem","min").
case DimacsDescriptor:
:MAX:
DoubleArcMap capacity(digraph);
readDimacsMax(is, digraph, capacity, s, t, desc);
DigraphWriter<Digraph>(digraph, os).
arcMap("capacity", capacity).
attribute("problem","max").
case DimacsDescriptor:
:SP:
DoubleArcMap capacity(digraph);
readDimacsSp(is, digraph, capacity, s, desc);
DigraphWriter<Digraph>(digraph, os).
arcMap("capacity", capacity).
attribute("problem","sp").
case DimacsDescriptor:
:MAT:
readDimacsMat(is, digraph,desc);
DigraphWriter<Digraph>(digraph, os).
attribute("problem","mat").