DiaDes  0.1
DIAgnosis of Discrete-Event System
ScaleFree.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/plod_generator.hpp>
5 #include <boost/random/linear_congruential.hpp>
6 #include <boost/graph/graphviz.hpp>
7 #include <boost/date_time/posix_time/posix_time.hpp>
8 #include <boost/date_time/gregorian/gregorian.hpp>
9 typedef boost::adjacency_list<> Graph;
10 typedef boost::plod_iterator<boost::minstd_rand, Graph> SFGen;
11 
12 void printUsage()
13 {
14  std::cout << "Usage: scale_free nbNodes alpha beta random_generator_seed" << std::endl;
15  std::cout << "Produces a scale-free network (See Boost Graph Library) in 'topo' format on the standard output" << std::endl;
16  std::cout << "based the Power Law Out Degree algorithm. The number of connectivity 'credits' assigned to a node is defined by beta*random_number(0,nbNodes-1)^(-alpha)." << std::endl;
17  exit(1);
18 }
19 using namespace boost::posix_time;
20 int main(int argc, char ** argv)
21 {
22  boost::gregorian::date d(boost::gregorian::day_clock::local_day());
23  std::cout << d.month().as_long_string() << std::endl;
24  second_clock::local_time();
25  time_duration duration;
26  if(argc != 5)
27  {
28  printUsage();
29  }
30  std::stringstream stream;
31  stream << argv[1];
32  Graph::vertices_size_type nbNodes = 0;
33  stream >> nbNodes;
34  stream.clear();
35 
36  double alpha = 0;
37  stream << argv[2];
38  stream >> alpha;
39  stream.clear();
40 
41  double beta = 0.0;
42  stream << argv[3];
43  stream >> beta;
44  stream.clear();
45 
46 
47  int seed = 0;
48  stream << argv[4];
49  stream >> seed;
50  stream.clear();
51 
52  boost::minstd_rand gen;
53  gen.seed(seed);
54 
55  Graph g(SFGen(gen, nbNodes, alpha, beta,true), SFGen(), nbNodes);
56  typedef boost::property_map<Graph, boost::vertex_index_t>::type IndexMap;
57  IndexMap index = get(boost::vertex_index, g);
58  std::pair<Graph::edge_iterator,Graph::edge_iterator> pair = edges(g);
59  std::cout << "p top " << num_vertices(g) << " " << num_edges(g) << std::endl;
60  unsigned i = 0;
61  for(Graph::edge_iterator it = pair.first; it != pair.second; ++it)
62  {
63  std::cout << "c" << i << ": n" << index[source(*it,g)] << ", n" << index[target(*it,g)] << ";" << std::endl;
64  ++i;
65  }
66  return 0;
67 }
void printUsage()
Definition: ScaleFree.cc:12
int main(int argc, char **argv)
Definition: ScaleFree.cc:20
boost::plod_iterator< boost::minstd_rand, Graph > SFGen
Definition: ScaleFree.cc:10
boost::adjacency_list Graph
Definition: ScaleFree.cc:9