Rel.07 NEWS - 3. round
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
19 #ifndef LEMON_NAUTY_READER_H
20 #define LEMON_NAUTY_READER_H
29 /// @defgroup nauty_group NAUTY format
31 /// \brief Read \e Nauty format
33 /// Tool to read graphs from \e Nauty format data
35 /// \ingroup nauty_group
37 /// \brief Nauty file reader.
40 /// \ingroup nauty_group
42 /// \brief Nauty file reader
44 /// The \e geng program is in the \e gtools suite of the nauty
45 /// package. This tool can generate all non-isomorphic undirected
46 /// graphs with given node number from several classes (for example,
47 /// general, connected, biconnected, triangle-free, 4-cycle-free,
48 /// bipartite and graphs with given edge number and degree
49 /// constraints). This function reads a \e nauty \e graph6 \e format
50 /// line from the given stream and builds it in the given graph.
52 /// The site of nauty package: http://cs.anu.edu.au/~bdm/nauty/
54 /// For example, the number of all non-isomorphic connected graphs
55 /// can be computed with next code:
58 /// SmartUGraph ugraph;
59 /// while(readNauty(std::cin, ugraph)) {
60 /// PlanarityChecking<SmartUGraph> pc(ugraph);
61 /// if (pc.run()) ++num;
63 /// std::cout << "Number of planar graphs: " << num << std::endl;
66 /// The nauty files are quite huge, therefore instead of the direct
67 /// file generation the pipelining is recommended. The execution of
70 /// ./geng -c 10 | ./num_of_pg
72 template <typename UGraph>
73 std::istream& readNauty(std::istream& is, UGraph& ugraph) {
77 if (getline(is, line)) {
82 if (line[index] == '>') {
86 char c = line[index++]; c -= 63;
90 c = line[index++]; c -= 63;
92 c = line[index++]; c -= 63;
94 c = line[index++]; c -= 63;
98 std::vector<typename UGraph::Node> nodes;
99 for (int i = 0; i < n; ++i) {
100 nodes.push_back(ugraph.addNode());
104 for (int j = 0; j < n; ++j) {
105 for (int i = 0; i < j; ++i) {
107 c = line[index++]; c -= 63;
110 bool b = (c & (1 << (bit--))) != 0;
112 ugraph.addEdge(nodes[i], nodes[j]);