Merge #382 to branch 1.1 1.1
authorAlpar Juttner <alpar@cs.elte.hu>
Thu, 04 Aug 2011 21:19:55 +0200
branch1.1
changeset 1069b1b534ddb539
parent 1064 40bbb450143e
parent 1067 54464584b157
child 1074 c5d7f7538832
Merge #382 to branch 1.1
doc/lgf.dox
lemon/lgf_reader.h
test/CMakeLists.txt
test/Makefile.am
     1.1 --- a/doc/lgf.dox	Wed Jul 13 14:40:05 2011 +0200
     1.2 +++ b/doc/lgf.dox	Thu Aug 04 21:19:55 2011 +0200
     1.3 @@ -63,11 +63,11 @@
     1.4   3      (40,10)      10      "Third node"
     1.5  \endcode
     1.6  
     1.7 -The \c \@arcs section is very similar to the \c \@nodes section,
     1.8 -it again starts with a header line describing the names of the maps,
     1.9 -but the \c "label" map is not obligatory here. The following lines
    1.10 -describe the arcs. The first two tokens of each line are
    1.11 -the source and the target node of the arc, respectively, then come the map
    1.12 +The \c \@arcs section is very similar to the \c \@nodes section, it
    1.13 +again starts with a header line describing the names of the maps, but
    1.14 +the \c "label" map is not obligatory here. The following lines
    1.15 +describe the arcs. The first two tokens of each line are the source
    1.16 +and the target node of the arc, respectively, then come the map
    1.17  values. The source and target tokens must be node labels.
    1.18  
    1.19  \code
    1.20 @@ -78,10 +78,21 @@
    1.21   2   3   18
    1.22  \endcode
    1.23  
    1.24 +If there is no map in the \c \@arcs section at all, then it must be
    1.25 +indicated by a sole '-' sign in the first line.
    1.26 +
    1.27 +\code
    1.28 + @arcs
    1.29 +         -
    1.30 + 1   2
    1.31 + 1   3
    1.32 + 2   3
    1.33 +\endcode
    1.34 +
    1.35  The \c \@edges is just a synonym of \c \@arcs. The \@arcs section can
    1.36  also store the edge set of an undirected graph. In such case there is
    1.37  a conventional method for store arc maps in the file, if two columns
    1.38 -has the same caption with \c '+' and \c '-' prefix, then these columns
    1.39 +have the same caption with \c '+' and \c '-' prefix, then these columns
    1.40  can be regarded as the values of an arc map.
    1.41  
    1.42  The \c \@attributes section contains key-value pairs, each line
     2.1 --- a/lemon/lgf_reader.h	Wed Jul 13 14:40:05 2011 +0200
     2.2 +++ b/lemon/lgf_reader.h	Thu Aug 04 21:19:55 2011 +0200
     2.3 @@ -2,7 +2,7 @@
     2.4   *
     2.5   * This file is a part of LEMON, a generic C++ optimization library.
     2.6   *
     2.7 - * Copyright (C) 2003-2009
     2.8 + * Copyright (C) 2003-2011
     2.9   * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    2.10   * (Egervary Research Group on Combinatorial Optimization, EGRES).
    2.11   *
    2.12 @@ -964,6 +964,13 @@
    2.13          std::string map;
    2.14          int index = 0;
    2.15          while (_reader_bits::readToken(line, map)) {
    2.16 +          if(map == "-") {
    2.17 +              if(index!=0)
    2.18 +                throw FormatError("'-' is not allowed as a map name");
    2.19 +              else if (line >> std::ws >> c)
    2.20 +                throw FormatError("Extra character at the end of line");
    2.21 +              else break;
    2.22 +            }
    2.23            if (maps.find(map) != maps.end()) {
    2.24              std::ostringstream msg;
    2.25              msg << "Multiple occurence of arc map: " << map;
    2.26 @@ -1834,6 +1841,13 @@
    2.27          std::string map;
    2.28          int index = 0;
    2.29          while (_reader_bits::readToken(line, map)) {
    2.30 +          if(map == "-") {
    2.31 +              if(index!=0)
    2.32 +                throw FormatError("'-' is not allowed as a map name");
    2.33 +              else if (line >> std::ws >> c)
    2.34 +                throw FormatError("Extra character at the end of line");
    2.35 +              else break;
    2.36 +            }
    2.37            if (maps.find(map) != maps.end()) {
    2.38              std::ostringstream msg;
    2.39              msg << "Multiple occurence of edge map: " << map;
     3.1 --- a/test/CMakeLists.txt	Wed Jul 13 14:40:05 2011 +0200
     3.2 +++ b/test/CMakeLists.txt	Thu Aug 04 21:19:55 2011 +0200
     3.3 @@ -31,6 +31,7 @@
     3.4    hao_orlin_test
     3.5    heap_test
     3.6    kruskal_test
     3.7 +  lgf_test
     3.8    maps_test
     3.9    matching_test
    3.10    min_cost_arborescence_test
     4.1 --- a/test/Makefile.am	Wed Jul 13 14:40:05 2011 +0200
     4.2 +++ b/test/Makefile.am	Thu Aug 04 21:19:55 2011 +0200
     4.3 @@ -25,6 +25,7 @@
     4.4  	test/hao_orlin_test \
     4.5  	test/heap_test \
     4.6  	test/kruskal_test \
     4.7 +	test/lgf_test \
     4.8  	test/maps_test \
     4.9  	test/matching_test \
    4.10  	test/min_cost_arborescence_test \
    4.11 @@ -67,9 +68,10 @@
    4.12  test_graph_copy_test_SOURCES = test/graph_copy_test.cc
    4.13  test_graph_test_SOURCES = test/graph_test.cc
    4.14  test_graph_utils_test_SOURCES = test/graph_utils_test.cc
    4.15 +test_hao_orlin_test_SOURCES = test/hao_orlin_test.cc
    4.16  test_heap_test_SOURCES = test/heap_test.cc
    4.17  test_kruskal_test_SOURCES = test/kruskal_test.cc
    4.18 -test_hao_orlin_test_SOURCES = test/hao_orlin_test.cc
    4.19 +test_lgf_test_SOURCES = test/lgf_test.cc
    4.20  test_lp_test_SOURCES = test/lp_test.cc
    4.21  test_maps_test_SOURCES = test/maps_test.cc
    4.22  test_mip_test_SOURCES = test/mip_test.cc
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/lgf_test.cc	Thu Aug 04 21:19:55 2011 +0200
     5.3 @@ -0,0 +1,169 @@
     5.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
     5.5 + *
     5.6 + * This file is a part of LEMON, a generic C++ optimization library.
     5.7 + *
     5.8 + * Copyright (C) 2003-2011
     5.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    5.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
    5.11 + *
    5.12 + * Permission to use, modify and distribute this software is granted
    5.13 + * provided that this copyright notice appears in all copies. For
    5.14 + * precise terms see the accompanying LICENSE file.
    5.15 + *
    5.16 + * This software is provided "AS IS" with no warranty of any kind,
    5.17 + * express or implied, and with no claim as to its suitability for any
    5.18 + * purpose.
    5.19 + *
    5.20 + */
    5.21 +
    5.22 +#include <lemon/list_graph.h>
    5.23 +#include <lemon/lgf_reader.h>
    5.24 +#include "test_tools.h"
    5.25 +
    5.26 +using namespace lemon;
    5.27 +
    5.28 +char test_lgf[] =
    5.29 +  "@nodes\n"
    5.30 +  "label\n"
    5.31 +  "0\n"
    5.32 +  "1\n"
    5.33 +  "@arcs\n"
    5.34 +  "     label\n"
    5.35 +  "0 1  0\n"
    5.36 +  "1 0  1\n"
    5.37 +  "@attributes\n"
    5.38 +  "source 0\n"
    5.39 +  "target 1\n";
    5.40 +
    5.41 +char test_lgf_nomap[] =
    5.42 +  "@nodes\n"
    5.43 +  "label\n"
    5.44 +  "0\n"
    5.45 +  "1\n"
    5.46 +  "@arcs\n"
    5.47 +  "     -\n"
    5.48 +  "0 1\n";
    5.49 +
    5.50 +char test_lgf_bad1[] =
    5.51 +  "@nodes\n"
    5.52 +  "label\n"
    5.53 +  "0\n"
    5.54 +  "1\n"
    5.55 +  "@arcs\n"
    5.56 +  "     - another\n"
    5.57 +  "0 1\n";
    5.58 +
    5.59 +char test_lgf_bad2[] =
    5.60 +  "@nodes\n"
    5.61 +  "label\n"
    5.62 +  "0\n"
    5.63 +  "1\n"
    5.64 +  "@arcs\n"
    5.65 +  "     label -\n"
    5.66 +  "0 1\n";
    5.67 +
    5.68 +
    5.69 +int main() 
    5.70 +{
    5.71 +  {
    5.72 +    ListDigraph d; 
    5.73 +    ListDigraph::Node s,t;
    5.74 +    ListDigraph::ArcMap<int> label(d);
    5.75 +    std::istringstream input(test_lgf);
    5.76 +    digraphReader(d, input).
    5.77 +      node("source", s).
    5.78 +      node("target", t).
    5.79 +      arcMap("label", label).
    5.80 +      run();
    5.81 +    check(countNodes(d) == 2,"There should be 2 nodes");
    5.82 +    check(countArcs(d) == 2,"There should be 2 arcs");
    5.83 +  }
    5.84 +  {
    5.85 +    ListGraph g;
    5.86 +    ListGraph::Node s,t;
    5.87 +    ListGraph::EdgeMap<int> label(g);
    5.88 +    std::istringstream input(test_lgf);
    5.89 +    graphReader(g, input).
    5.90 +      node("source", s).
    5.91 +      node("target", t).
    5.92 +      edgeMap("label", label).
    5.93 +      run();
    5.94 +    check(countNodes(g) == 2,"There should be 2 nodes");
    5.95 +    check(countEdges(g) == 2,"There should be 2 arcs");
    5.96 +  }
    5.97 +
    5.98 +  {
    5.99 +    ListDigraph d; 
   5.100 +    std::istringstream input(test_lgf_nomap);
   5.101 +    digraphReader(d, input).
   5.102 +      run();
   5.103 +    check(countNodes(d) == 2,"There should be 2 nodes");
   5.104 +    check(countArcs(d) == 1,"There should be 1 arc");
   5.105 +  }
   5.106 +  {
   5.107 +    ListGraph g;
   5.108 +    std::istringstream input(test_lgf_nomap);
   5.109 +    graphReader(g, input).
   5.110 +      run();
   5.111 +    check(countNodes(g) == 2,"There should be 2 nodes");
   5.112 +    check(countEdges(g) == 1,"There should be 1 edge");
   5.113 +  }
   5.114 +
   5.115 +  {
   5.116 +    ListDigraph d; 
   5.117 +    std::istringstream input(test_lgf_bad1);
   5.118 +    bool ok=false;
   5.119 +    try {
   5.120 +      digraphReader(d, input).
   5.121 +        run();
   5.122 +    }
   5.123 +    catch (FormatError& error) 
   5.124 +      {
   5.125 +        ok = true;
   5.126 +      }
   5.127 +    check(ok,"FormatError exception should have occured");
   5.128 +  }
   5.129 +  {
   5.130 +    ListGraph g;
   5.131 +    std::istringstream input(test_lgf_bad1);
   5.132 +    bool ok=false;
   5.133 +    try {
   5.134 +      graphReader(g, input).
   5.135 +        run();
   5.136 +    }
   5.137 +    catch (FormatError& error)
   5.138 +      {
   5.139 +        ok = true;
   5.140 +      }
   5.141 +    check(ok,"FormatError exception should have occured");
   5.142 +  }
   5.143 +
   5.144 +  {
   5.145 +    ListDigraph d; 
   5.146 +    std::istringstream input(test_lgf_bad2);
   5.147 +    bool ok=false;
   5.148 +    try {
   5.149 +      digraphReader(d, input).
   5.150 +        run();
   5.151 +    }
   5.152 +    catch (FormatError& error)
   5.153 +      {
   5.154 +        ok = true;
   5.155 +      }
   5.156 +    check(ok,"FormatError exception should have occured");
   5.157 +  }
   5.158 +  {
   5.159 +    ListGraph g;
   5.160 +    std::istringstream input(test_lgf_bad2);
   5.161 +    bool ok=false;
   5.162 +    try {
   5.163 +      graphReader(g, input).
   5.164 +        run();
   5.165 +    }
   5.166 +    catch (FormatError& error)
   5.167 +      {
   5.168 +        ok = true;
   5.169 +      }
   5.170 +    check(ok,"FormatError exception should have occured");
   5.171 +  }
   5.172 +}