test_bigraph.cxx
Go to the documentation of this file.
1 // https://stackoverflow.com/a/45850742
2 
3 #include <boost/graph/adjacency_list.hpp>
4 #include <boost/graph/filtered_graph.hpp>
5 #include <boost/intrusive/set_hook.hpp>
6 #include <boost/intrusive/set.hpp>
7 #include <boost/any.hpp>
8 #include <iostream>
9 
10 namespace bi = boost::intrusive;
11 
12 /// vertex properties
13 struct VertexData : bi::set_base_hook<bi::link_mode<bi::auto_unlink>, bi::constant_time_size<false> > {
15  int num;
16 
17  VertexData(std::string label, int num) : label(label), num(num) {}
18 
19  struct by_label {
20  using type = std::string;
21  const type& operator()(VertexData const& vd) const { return vd.label; }
22  };
23 };
24 
25 using by_label_idx_t = bi::set<VertexData, bi::constant_time_size<false>, bi::key_of_value<VertexData::by_label> >;
26 
27 /// edges properties
28 struct EdgeData {
31 };
32 
33 /// define the boost-graph
34 typedef boost::adjacency_list<boost::vecS, boost::vecS,
35  boost::bidirectionalS,
36  VertexData,
37  boost::property<boost::edge_weight_t, double, EdgeData> > Graph;
38 
39 int main() {
40  using vertex_t = Graph::vertex_descriptor;
41 
42  Graph g;
43  for (auto label : { "alerts", "amazed", "buster", "deaths", "ekes", "Enoch", "gale", "hug", "input", "knifed", "lire", "man", "pithy", "Purims", "Rodger", "suckle", "Terr", "theme", "tiling", "vases", }) {
44  boost::add_vertex(VertexData{label, 1+rand()%5}, g);
45  }
46 
47  /// define vertexMap
48  by_label_idx_t label_idx;
49  auto reindex = [&] {
50  label_idx.clear();
51  for (auto vd : boost::make_iterator_range(boost::vertices(g)))
52  label_idx.insert(g[vd]);
53  };
54 
55  reindex();
56  std::cout << "Index: " << label_idx.size() << " elements\n";
57 
58  g.clear();
59  std::cout << "Index: " << label_idx.size() << " elements\n";
60 
61  for (auto& vertex : label_idx) {
62  std::cout << vertex.label << " " << vertex.num << "\n";
63  }
64 }
std::string string
Definition: nybbler.cc:12
static const double g
Definition: Units.h:145
double edge_confidence
const type & operator()(VertexData const &vd) const
edges properties
std::string label
VertexData(std::string label, int num)
int main()
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, VertexData, boost::property< boost::edge_weight_t, double, EdgeData > > Graph
define the boost-graph
bi::set< VertexData, bi::constant_time_size< false >, bi::key_of_value< VertexData::by_label > > by_label_idx_t
vertex properties
std::string edge_name
vertex reconstruction