CMR  1.3.0
r10.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <boost/graph/isomorphism.hpp>
4 
5 namespace tu
6 {
7 
13  {
14  public:
15  typedef boost::adjacency_list <boost::vecS, boost::vecS, boost::undirectedS> graph_t;
16 
17  private:
18 
24  {
25  typedef std::pair <int, int> E;
26 
27  E g1_edges[] =
28  { E(0, 5), E(0, 8), E(0, 9), E(1, 5), E(1, 6), E(1, 9), E(2, 6), E(2, 7), E(2, 9), E(3, 7), E(3, 8), E(3, 9), E(4, 5), E(4, 6), E(4, 7),
29  E(4, 8), E(4, 9) };
30  g1 = graph_t(&g1_edges[0], &g1_edges[0] + sizeof(g1_edges) / sizeof(E), 10);
31 
32  E g2_edges[] =
33  { E(0, 5), E(0, 8), E(0, 9), E(1, 5), E(1, 6), E(1, 8), E(2, 6), E(2, 7), E(2, 9), E(3, 7), E(3, 8), E(3, 9), E(4, 5), E(4, 6), E(4, 7) };
34  g2 = graph_t(&g2_edges[0], &g2_edges[0] + sizeof(g2_edges) / sizeof(E), 10);
35  }
36 
43  static bipartite_r10_graphs& instance()
44  {
45  static bipartite_r10_graphs* instance = NULL;
46  if (instance == NULL)
47  instance = new bipartite_r10_graphs();
48  return *instance;
49  }
50 
51  public:
52 
60  template <typename Graph>
61  static bool is_r10_graph(const Graph& graph)
62  {
63  return boost::isomorphism(graph, instance().g1) || boost::isomorphism(graph, instance().g2);
64  }
65 
66  private:
67  graph_t g1, g2;
68  };
69 
78  template <typename MatrixType>
79  inline bool is_r10(MatrixType matrix)
80  {
81  if (matrix.size1() != 5 || matrix.size2() != 5)
82  return false;
83 
85 
86  for (size_t row = 0; row < 5; ++row)
87  {
88  for (size_t column = 0; column < 5; ++column)
89  {
90  if (matrix(row, column))
91  {
92  boost::add_edge(boost::vertex(row, graph), boost::vertex(5 + column, graph), graph);
93  }
94  }
95  }
96 
98  }
99 } /* namespace tu */
Definition: r10.hpp:13
static bool is_r10_graph(const Graph &graph)
Definition: r10.hpp:61
boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS > graph_t
Definition: r10.hpp:15
Definition: algorithm.hpp:14
bool is_r10(MatrixType matrix)
Definition: r10.hpp:79