DiaDes  0.1
DIAgnosis of Discrete-Event System
GenerateTopology.cc
Go to the documentation of this file.
1 
35 #include<cstdlib>
36 #include<iostream>
37 #include<diades/utils/Random.hh>
40 
41 
42 using namespace std;
43 using namespace Diades::Utils;
44 using namespace Diades::Automata;
45 
46 void printUsage();
47 template<typename T>
48 void getParameter(int argc, char ** argv, int index, T & param, bool & alreadyRegistered);
49 
50 int main(int argc, char ** argv)
51 {
52  cout << "Topology generator" << endl;
53  cout << "LAAS-CNRS, 2006-2011, 7 avenue du Colonel Roche, Toulouse, France" << endl;
54  cout << "Contact: yannick.pencole@laas.fr" << endl;
55  bool nbNodeRegistered = false;
56  unsigned nbNode = 3;
57  bool connectivityRegistered = false;
58  unsigned connectivity = 2;
59  bool cliqueSizeMaxRegistered = false;
60  unsigned cliqueSizeMax = 2;
61  bool commonConnectionMaxRegistered = false;
62  unsigned commonConnectionMax = 2;
63  bool seedRegistered = false;
64  unsigned seed = initialiseSeed();
65  string output;
66  bool outputRegistered = false;
68 
69  if(argc==1)
70  {
71  printUsage();
72  }
73  if(argc ==2)
74  {
75  string currentParameter = argv[1];
76  if(currentParameter == "--help")
77  {
78  printUsage();
79  }
80  }
81 
82  if(argc > 1)
83  {
84  int index = 1;
85  while(index < argc)
86  {
87  string currentParameter = argv[index];
88  int param = -1;
89  if(currentParameter == "--nodes") { param = 0; }
90  if((param == -1) && (currentParameter == "--connectivity")) { param = 1; }
91  if((param == -1) && (currentParameter == "--commonConnectionMax")) { param = 2; }
92  if((param == -1) && (currentParameter == "--cliqueSizeMax")) { param = 3; }
93  if((param == -1) && (currentParameter == "--seed")) { param = 4; }
94  if((param == -1) && (currentParameter == "--output")) { param = 5; }
95  switch(param)
96  {
97  case 0:
98  {
99  getParameter<unsigned>(argc,argv,index, nbNode, nbNodeRegistered);
100  if(nbNode == 0)
101  {
102  cout << "The number of nodes must be greater than 0" << endl;
103  printUsage();
104  }
105  }
106  break;
107  case 1:
108  {
109  getParameter<unsigned>(argc,argv,index, connectivity, connectivityRegistered);
110  if(connectivity < 2)
111  {
112  cout << "The maximal connectivity of a node must be at least 2" << endl;
113  printUsage();
114  }
115  }
116  break;
117  case 2:
118  {
119  getParameter<unsigned>(argc,argv,index, commonConnectionMax, commonConnectionMaxRegistered);
120  if(commonConnectionMax < 1)
121  {
122  cout << "The maximal connectivity between two nodes must be at least 1" << endl;
123  printUsage();
124  }
125  }
126  break;
127  case 3:
128  {
129  getParameter<unsigned>(argc,argv,index, cliqueSizeMax,cliqueSizeMaxRegistered);
130  if(cliqueSizeMax < 2)
131  {
132  cout << "The maximal clique size must be at least 2" << endl;
133  printUsage();
134  }
135  }
136  break;
137  case 4:
138  {
139  getParameter<unsigned>(argc,argv,index, seed, seedRegistered);
140  }
141  break;
142  case 5:
143  {
144  getParameter<string>(argc,argv,index, output, outputRegistered);
145  }
146  break;
147  default:
148  {
149  cout << "The parameter " << currentParameter << " is not recognized." << endl << endl;
150  printUsage();
151  }
152  break;
153  }
154  index = index + 2;
155  }
156  }
157 
158 
159  generateTopology(nbNode,connectivity,cliqueSizeMax,
160  commonConnectionMax,seed,topology);
161  if(outputRegistered)
162  {
163  topology.save(output);
164  cout << "Topology saved in " << output << "." << endl;
165  }
166  else
167  {
168  stringstream stream;
169  stream << "generatedTopology_";
170  stream << nbNode << "_";
171  stream << connectivity << "_";
172  stream << cliqueSizeMax << "_";
173  stream << commonConnectionMax << "_";
174  stream << seed;
175  stream << ".topo";
176  topology.save(stream.str());
177  cout << "Topology saved in " << stream.str() << "." << endl;
178  }
179 
180 
181 }
183 {
184  cout << "Usage: GenerateTopology " << endl;
185  cout << "\t [--nodes nbNode] " << endl;
186  cout << "\t [--connectivity nbConn] " << endl;
187  cout << "\t [--commonConnectionMax nbConn]" << endl;
188  cout << "\t [--cliqueSizeMax cliqueSize]" << endl;
189  cout << "\t [--seed randomSeed]" << endl;
190  cout << "\t [--output fileName]" << endl;
191  cout << " " << endl;
192  cout << "Generate a topology of 'nbNode' nodes (default = 3). A connection " << endl;
193  cout << "between a set of nodes corresponds to a set of synchronised events " << endl;
194  cout << "between the nodes. Any node is directly or indirectly connected " << endl;
195  cout << "to the other nodes. The connectivity of a node is the set of connections " << endl;
196  cout << "in which the node is involved (default = 2). The parameter " << endl;
197  cout << "'connectivity' sets the maximal number of connections that a node can " << endl;
198  cout << "have. A connection involves a set of nodes (that is then called a clique). " << endl;
199  cout << "'cliqueSizeMax' sets the maximal size of a clique (default = 2). Two nodes " << endl;
200  cout << "may have several connections in common, 'commonConnectionMax' sets the " << endl;
201  cout << "maximal number of connections involving two components (default = 2). " << endl;
202  cout << "The generation is random and require a seed " << endl;
203  cout << "(default = depends on the time). Two runs with the same seed and parameters " << endl;
204  cout << "generate the same topology. The topology is then saved in the 'fileName' " << endl;
205  cout << "(default = \"generatedTopology+Params.topo\") " << endl;
206  exit(0);
207 }
208 
209 
210 template<typename T>
211 void getParameter(int argc, char ** argv, int index, T & param, bool & alreadyRegistered)
212 {
213  if(!alreadyRegistered)
214  {
215  if(argc == index + 1)
216  {
217  cout << "The parameter " << argv[index] << " is not correct" << endl << endl;
218  printUsage();
219  }
220  else
221  {
222  stringstream stream;
223  stream << argv[index + 1];
224  if(stream >> param)
225  {
226  alreadyRegistered = true;
227  }
228  else
229  {
230  cout << "The parameter " << argv[index + 1] << " has an incorrect format" << endl << endl;
231  printUsage();
232  }
233  }
234  }
235 }
236 
237 
238 
239 
240 
241 
242 
243 
244 
245 
246 
unsigned initialiseSeed()
int main(int argc, char **argv)
STL namespace.
void generateTopology(unsigned nbComp, unsigned connectivity, unsigned nbSharedMax, Graph &topology, NodeMap< unsigned > &compIds)
void printUsage()
Random generation utilities.
void getParameter(int argc, char **argv, int index, T &param, bool &alreadyRegistered)
void save(const string &fileName)