DiaDes  0.1
DIAgnosis of Discrete-Event System
SmallWorld.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <sstream>
3 #include <boost/graph/adjacency_list.hpp>
4 #include <boost/graph/small_world_generator.hpp>
5 #include <boost/random/linear_congruential.hpp>
6 #include <boost/graph/graphviz.hpp>
7 
8 
9 typedef boost::adjacency_list<> Graph;
10 typedef boost::small_world_iterator<boost::minstd_rand, Graph> SWGen;
11 
12 void printUsage()
13 {
14  std::cout << "Usage: small_world nb_nodes connectivity rewiring_probability random_generator_seed" << std::endl;
15  std::cout << "Produces a small word network (See Boost Graph Library) in 'topo' format on the standard output" << std::endl;
16  exit(1);
17 }
18 
19 int main(int argc, char ** argv)
20 {
21  if(argc != 5)
22  {
23  printUsage();
24  }
25  std::stringstream stream;
26  stream << argv[1];
27  Graph::vertices_size_type nbNodes = 0;
28  stream >> nbNodes;
29  stream.clear();
30 
31  Graph::vertices_size_type k = 0;
32  stream << argv[2];
33  stream >> k;
34  stream.clear();
35 
36  double probability = 0.0;
37  stream << argv[3];
38  stream >> probability;
39  stream.clear();
40 
41 
42  int seed = 0;
43  stream << argv[4];
44  stream >> seed;
45  stream.clear();
46 
47  boost::minstd_rand gen;
48  gen.seed(seed);
49 
50  Graph g(SWGen(gen, nbNodes, k, probability), SWGen(), nbNodes);
51  typedef boost::property_map<Graph, boost::vertex_index_t>::type IndexMap;
52  IndexMap index = get(boost::vertex_index, g);
53  std::pair<Graph::edge_iterator,Graph::edge_iterator> pair = edges(g);
54  std::cout << "p top " << num_vertices(g) << " " << num_edges(g) << std::endl;
55  unsigned i = 0;
56  for(Graph::edge_iterator it = pair.first; it != pair.second; ++it)
57  {
58  std::cout << "c" << i << ": n" << index[source(*it,g)] << ", n" << index[target(*it,g)] << ";" << std::endl;
59  ++i;
60  }
61  return 0;
62 }
int main(int argc, char **argv)
Definition: SmallWorld.cc:19
boost::adjacency_list Graph
Definition: SmallWorld.cc:9
void printUsage()
Definition: SmallWorld.cc:12
boost::adjacency_list Graph
Definition: ScaleFree.cc:9
boost::small_world_iterator< boost::minstd_rand, Graph > SWGen
Definition: SmallWorld.cc:10