1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2009
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
26 /// \ingroup nauty_group
28 /// \brief Nauty file reader.
32 /// \ingroup nauty_group
34 /// \brief Nauty file reader
36 /// The \e geng program is in the \e gtools suite of the nauty
37 /// package. This tool can generate all non-isomorphic undirected
38 /// graphs of several classes with given node number (e.g.
39 /// general, connected, biconnected, triangle-free, 4-cycle-free,
40 /// bipartite and graphs with given edge number and degree
41 /// constraints). This function reads a \e nauty \e graph6 \e format
42 /// line from the given stream and builds it in the given graph.
44 /// The site of nauty package: http://cs.anu.edu.au/~bdm/nauty/
46 /// For example, the number of all non-isomorphic planar graphs
47 /// can be computed with the following code.
51 /// while (readNautyGraph(graph, std::cin)) {
52 /// PlanarityChecking<SmartGraph> pc(graph);
53 /// if (pc.run()) ++num;
55 /// std::cout << "Number of planar graphs: " << num << std::endl;
58 /// The nauty files are quite huge, therefore instead of the direct
59 /// file generation pipelining is recommended. For example,
61 /// ./geng -c 10 | ./num_of_planar_graphs
63 template <typename Graph>
64 std::istream& readNautyGraph(Graph& graph, std::istream& is = std::cin) {
68 if (getline(is, line)) {
73 if (line[index] == '>') {
77 char c = line[index++]; c -= 63;
81 c = line[index++]; c -= 63;
83 c = line[index++]; c -= 63;
85 c = line[index++]; c -= 63;
89 std::vector<typename Graph::Node> nodes;
90 for (int i = 0; i < n; ++i) {
91 nodes.push_back(graph.addNode());
95 for (int j = 0; j < n; ++j) {
96 for (int i = 0; i < j; ++i) {
98 c = line[index++]; c -= 63;
101 bool b = (c & (1 << (bit--))) != 0;
104 graph.addEdge(nodes[i], nodes[j]);