RNAblueprint-1.3.2
graphcommon.h
Go to the documentation of this file.
1 
11 #ifndef GRAPHCOMMON_H
12 #define GRAPHCOMMON_H
13 
14 // include common header with graph definition and global variables
15 #include "common.h"
16 #include "probability_matrix.h"
17 
18 // include standard library parts
19 #include <limits>
20 #include <sstream>
21 
22 namespace design {
23  namespace detail {
24 
25  // get property with Graph[Vertex].bipartite_color = int;
26 
27  struct vertex_property {
28  int color = 0;
29  int base = N;
30  int constraint = N;
31  bool articulation = false;
32  };
33 
34  struct edge_property {
35  int ear = 0;
36  int color = 0;
37  };
38 
39  struct graph_property {
40  // concurrent number from 0 to # of components-1
41  int id;
42  /*
43  0 -> root
44  1 -> cc
45  2 -> bc
46  3 -> ear
47  4 -> path
48  */
49  int type;
50  SolutionSizeType nos;
51  bool is_path = false;
52  std::map<int, char> cutpoints;
53  };
54 
55  // graph_properties
56  // boost graph template
57  typedef boost::uninduced_subgraph<
58  boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS,
59  boost::property< boost::vertex_color_t, int, vertex_property >,
60  boost::property< boost::edge_index_t, int, edge_property >,
61  boost::property< boost::graph_name_t, graph_property> > > Graph;
62  typedef Graph::edge_descriptor Edge;
63  typedef Graph::vertex_descriptor Vertex;
64 
65  // get max degree of a graph
66  inline std::pair <int, int> get_min_max_degree(Graph& g) {
67  int max_degree = 0;
68  int min_degree = std::numeric_limits<int>::max();
69 
70  BGL_FORALL_VERTICES_T(v, g, Graph) {
71  int current_degree = boost::out_degree(v, g);
72  if (current_degree > max_degree) {
73  max_degree = current_degree;
74  }
75  if (current_degree < min_degree) {
76  min_degree = current_degree;
77  }
78  }
79 
80  return std::make_pair(min_degree, max_degree);
81  }
82 
83  // get the vertex descriptor from a vertex_color_t tag
84  inline Vertex int_to_vertex(unsigned int i, Graph& g) {
85  Vertex v = boost::vertex(i, g.root());
86  if (i >= boost::num_vertices(g.root()) || v == Graph::null_vertex()) {
87  std::stringstream ss;
88  ss << "Error getting vertex descriptor from integer: " << i;
89  throw std::out_of_range(ss.str());
90  }
91  return g.global_to_local(v);
92  }
93 
94  // get the vertex_color_t tag from a vertex descriptor
95  inline int vertex_to_int(Vertex v, Graph& g) {
96  return boost::get(boost::vertex_color_t(), g.root(), g.local_to_global(v));
97  }
98 
99  // get the set of vertices for a certain (sub)graph
100  inline std::vector<int> getVertexList(Graph& g) {
101  std::vector<int> result;
102 
103  BGL_FORALL_VERTICES(v, g, Graph) {
104  result.push_back(vertex_to_int(v, g));
105  }
106  return result;
107  }
108  }
109 }
110 #endif
111 
112 
113 /*
114  * \endcond INTERNAL
115  */
This file holds all global includes, definitions and variables.
All classes and functions for the RNA design library are under the design namespace.
Definition: RNAblueprint.h:101
This file holds the class definitions for the Probability Matrix.