Candidate_v1.7.0
        stable
      
      
        
          | Last change
 on this file since 5aa337 was             1be100, checked in by Frederik Heber <frederik.heber@…>, 5 years ago | 
        
          | 
FIX: Several small errors in Graph6Reader.
 off-by-one error with encoding starts at 63 (0), not 64.
cur_byte needs to exist outside of scope of next_edge().
need a mapping from edges_by_vertices in the subgraph (with indices
from the subgraph vertices) to the edge index used in th degrees array
to properly calculate the bond degrees.
TESTS: Added a chemical space evaluator test case with 3 nodes.
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            1.6 KB | 
      
      
| Line |  | 
|---|
| 1 | /* | 
|---|
| 2 | * Graph6Reader.hpp | 
|---|
| 3 | * | 
|---|
| 4 | *  Created on: Sep 26, 2017 | 
|---|
| 5 | *      Author: heber | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 |  | 
|---|
| 9 | #ifndef GRAPH_GRAPH6READER_HPP_ | 
|---|
| 10 | #define GRAPH_GRAPH6READER_HPP_ | 
|---|
| 11 |  | 
|---|
| 12 | // include config.h | 
|---|
| 13 | #ifdef HAVE_CONFIG_H | 
|---|
| 14 | #include <config.h> | 
|---|
| 15 | #endif | 
|---|
| 16 |  | 
|---|
| 17 | #include <istream> | 
|---|
| 18 | #include <iterator> | 
|---|
| 19 | #include <string> | 
|---|
| 20 | #include <vector> | 
|---|
| 21 |  | 
|---|
| 22 | class Graph6ReaderUnitTest; | 
|---|
| 23 |  | 
|---|
| 24 | /** This functor parses graph6 formatted strings and returns number of nodes | 
|---|
| 25 | * and a edge list. | 
|---|
| 26 | * | 
|---|
| 27 | * This is inspired by https://github.com/adrianN/graph6/, only I found the code | 
|---|
| 28 | * there quite ugly and unnecessarily complicated: inheriting from std::iterator, | 
|---|
| 29 | * overriding all the operators (++, *, ...) for no apparent reason instead of | 
|---|
| 30 | * adding normal functions, ... | 
|---|
| 31 | * | 
|---|
| 32 | */ | 
|---|
| 33 | struct Graph6Reader | 
|---|
| 34 | { | 
|---|
| 35 | //!> grant unit test access to private parts | 
|---|
| 36 | friend class Graph6ReaderUnitTest; | 
|---|
| 37 |  | 
|---|
| 38 | typedef std::pair<int, int> edge_t; | 
|---|
| 39 | typedef std::vector< edge_t > edges_t; | 
|---|
| 40 |  | 
|---|
| 41 | Graph6Reader() : | 
|---|
| 42 | column(1), | 
|---|
| 43 | row(-1), | 
|---|
| 44 | eos(false), | 
|---|
| 45 | bit_pos(-1), | 
|---|
| 46 | cur_byte(0), | 
|---|
| 47 | num_nodes(0) | 
|---|
| 48 | {} | 
|---|
| 49 |  | 
|---|
| 50 | void operator()(std::istream &_graph_string); | 
|---|
| 51 |  | 
|---|
| 52 | int get_num_nodes() const | 
|---|
| 53 | { return num_nodes; } | 
|---|
| 54 |  | 
|---|
| 55 | const edges_t& get_edges() const | 
|---|
| 56 | { return edges; } | 
|---|
| 57 |  | 
|---|
| 58 | private: | 
|---|
| 59 |  | 
|---|
| 60 | void scan_num_nodes(std::istream_iterator<unsigned char> &_it); | 
|---|
| 61 | void scan_edges(std::istream_iterator<unsigned char> &_it); | 
|---|
| 62 | void next_edge(std::istream_iterator<unsigned char> &_it); | 
|---|
| 63 |  | 
|---|
| 64 | private: | 
|---|
| 65 | int column; | 
|---|
| 66 | int row; | 
|---|
| 67 | bool eos; | 
|---|
| 68 | int bit_pos; | 
|---|
| 69 | int cur_byte; | 
|---|
| 70 | static const int packet_size; | 
|---|
| 71 |  | 
|---|
| 72 | //!> contains number of edges | 
|---|
| 73 | int num_nodes; | 
|---|
| 74 | //!> contains edge list | 
|---|
| 75 | std::vector< edge_t > edges; | 
|---|
| 76 | }; | 
|---|
| 77 |  | 
|---|
| 78 |  | 
|---|
| 79 | #endif /* GRAPH_GRAPH6READER_HPP_ */ | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.