DiaDes  0.1
DIAgnosis of Discrete-Event System
Simulate.cc
Go to the documentation of this file.
1 
42 #include<iostream>
43 #include<fstream>
44 #include<vector>
45 #include<string>
46 #include<set>
47 #include<list>
48 #include<boost/date_time/posix_time/posix_time.hpp>
49 #include<diades/utils/Random.hh>
51 
53 //#include<diades/io/xml/automata/Simulation.hh>
55 #include"CmdInterface.hh"
56 #include"Simulator.hh"
57 
58 using namespace std;
59 using namespace boost::posix_time;
60 
61 typedef enum {
62  OBSMIN = 0, OBSMAX = 1, TIMEMIN = 2, TIMEMAX = 3, NOEVT = 4, SEED = 5, XML = 6, GENERATEFAULTS = 7, HELP = 8, INTERACTIVE = 9, PTALOG = 10, NBSIM = 11
63 } Option;
64 
65 typedef enum {
66  DESCOMP = 0, RULES = 1
68 unsigned numberOfOptions = 12;
70 
71 
73 vector<string> options(numberOfOptions);
74 vector<bool> isSet(numberOfOptions, false);
75 string description = "Usage: dd-simulate\n\t --help |\n\t model1.des_comp [model2.des_comp ... sync.rules]\n\t [--seed randomSeed]\n\t [--noevent e3 e4 ....]\n\t [--obsMin nbObsMin]\n\t [--obsMax nbObsMax]\n\t [--timeMin minSeconds]\n\t [--timeMax maxSeconds]\n\t [--generateFaults]\n\t [--xml simulation.xml]\n\t [--interactive]\n\t [--ptalog output.pta_log]\n\t [--nbSim number]\n\n\n Write an observable scenario on the standard output based on \n the model that contains at least one occurrence of the event e1, e2 \n and that does not contain the events e3 e4. The generated scenario \n contains [nbObsMin,nbObsMax] observations. If set, the delay between\n two event occurrences is in [minSeconds,maxSeconds]. Optionnaly, a xml\n file can be generated with option --xml. \n The option --generateFaults randomly selects unobservable events in\n the model that will be considered as fault in the generated scenario.\n --interactive is the interactive mode, invalidate any other simulation\n option. --ptalog write the observable simulation in a pta_log file.\n --nbSim defines the number of simulations (default is 1)";
76 
78  options[TIMEMIN] = "--timeMin";
79  options[TIMEMAX] = "--timeMax";
80  options[OBSMIN] = "--obsMin";
81  options[OBSMAX] = "--obsMax";
82  options[NOEVT] = "--noevent";
83  options[SEED] = "--seed";
84  options[GENERATEFAULTS] = "--generateFaults";
85  options[XML] = "--xml";
86  options[HELP] = "--help";
87  options[INTERACTIVE] = "--interactive";
88  options[PTALOG] = "--ptalog";
89  options[NBSIM] = "--nbSim";
90  fileExtensions[DESCOMP] = "des_comp";
91  fileExtensions[RULES] = "rules";
92 }
93 
94 
95 
96 using namespace Diades::Utils;
97 using namespace Diades::CmdInterface;
98 
104 void clean(vector<Diades::Automata::ObservableComponent *> & components) {
105  for (vector<Diades::Automata::ObservableComponent *>::size_type i = 0; i < components.size();
106  ++i) {
107  if (components[i] != nullptr) {
108  delete components[i];
109  components[i] = nullptr;
110  }
111  }
112  components.clear();
115 }
116 
132 bool readParameters(int argc, char ** argv,
133  vector<unsigned> & values,
134  vector< set<string> > & noevents,
135  set<string> & modelFiles,
136  string & ruleFile,
137  string & xmlFile,
138  string & ptaLogFile,
139  bool & faultGeneration,
140  bool & interactiveMode) {
141  if (argc == 1) {
142  printCommandLineError("dd-simulate requires parameters. Try dd-simulate --help for details");
143  return false;
144  }
145  int index = 1;
146  while (index < argc) {
147  Option currentOption;
148  if (getOption<Option>(argv[index], options, currentOption)) {
149  if (isSet[currentOption]) {
150  printCommandLineError("The option '" + options[currentOption] + "' occurs at least twice.");
151  return false;
152  } else {
153  isSet[currentOption] = true;
154  }
155 
156  switch (currentOption) {
157  case INTERACTIVE:
158  {
159  ++index;
160  interactiveMode = true;
161  break;
162  }
163  case HELP:
164  {
165  if ((index != 1) || (argc != 2)) {
166  printCommandLineError("Incorrect use of option --help.");
167  return false;
168  } else {
170  return 0;
171  }
172  }
173  case OBSMIN:
174  case OBSMAX:
175  case TIMEMIN:
176  case TIMEMAX:
177  case SEED:
178  case NBSIM:
179  {
180  ++index;
181  getParameter<unsigned>(argc, argv, index, values[currentOption]);
182  break;
183  }
184  case GENERATEFAULTS:
185  {
186  ++index;
187  faultGeneration = true;
188  break;
189  }
190  case NOEVT:
191  {
192  ++index;
193  getParameterList<string>(argc, argv, options, fileExtensions,
194  index, noevents[currentOption]);
195  if (noevents[currentOption].empty()) {
196  printCommandLineError("No parameter after the option " + options[currentOption]);
197  return false;
198  }
199  break;
200  }
201  case XML:
202  {
203  ++index;
204  set<string> files;
205  getParameterList<string>(argc, argv, options, fileExtensions,
206  index, files);
207  if (files.size() != 1) {
208  printCommandLineError("One and only one argument was expected after option --xml.");
209  return false;
210  }
211  xmlFile = *(files.begin());
212  break;
213  }
214  case PTALOG:
215  {
216  ++index;
217  set<string> files;
218  getParameterList<string>(argc, argv, options, fileExtensions,
219  index, files);
220  cout << files.size() << endl;
221  if (files.size() != 1) {
222  printCommandLineError("One and only one argument was expected after option --ptalog.");
223  return false;
224  }
225  ptaLogFile = *(files.begin());
226  break;
227  }
228  default:
229  {
230  printCommandLineError("Unrecognized option: " + string(argv[index]));
231  return false;
232  break;
233  }
234 
235  }
236  } else {
237  // then it should be the name of a file
238  vector<string>::const_iterator it =
239  getFileExtension(string(argv[index]), fileExtensions.begin(), fileExtensions.end());
240 
241  if (it == fileExtensions.end()) {
242  printCommandLineError("Unrecognized file extension in file name: " + string(argv[index]));
243 
244  return false;
245 
246  }
247 
248 
249  FileExtension extension = DESCOMP;
250  if (*it == fileExtensions[RULES]) {
251  extension = RULES;
252  }
253  switch (extension) {
254  case DESCOMP:
255  {
256  modelFiles.insert(string(argv[index]));
257  break;
258  }
259  case RULES:
260  {
261  if (!ruleFile.empty()) {
262  printCommandLineError("It seems that there are more than one synchronization rules file as a argument.");
263 
264  return false;
265 
266  }
267  ruleFile = string(argv[index]);
268  break;
269  }
270  }
271  ++index;
272  }
273  }
274  if (modelFiles.empty()) {
275  printCommandLineError("No model, so no simulation.");
276  return false;
277  }
278  if ((modelFiles.size() == 1) && (!ruleFile.empty())) {
279  printCommandLineError("There is one synchronization rule file but no more than one component.");
280  return false;
281  }
282  if ((modelFiles.size() > 1) && (ruleFile.empty())) {
283  printCommandLineError("There is no synchronization rule file but it is required as there is more than one component in the model.");
284  return false;
285  }
286  if ((modelFiles.size() == 1) && (!ruleFile.empty())) {
287  printCommandLineError("There is one synchronization rule file but no more than one component.");
288  }
289  if ((modelFiles.size() > 1) && (ruleFile.empty())) {
290  printCommandLineError("There is no synchronization rule file but it is required as there is more than one component in the model.");
291  }
292  if (isSet[TIMEMAX] && !isSet[TIMEMIN]) {
293  printCommandLineError("--timeMax is set so --timeMin must be set.");
294  return false;
295  }
296  if (isSet[TIMEMIN] && !isSet[TIMEMAX]) {
297  printCommandLineError("--timeMin is set so --timeMax must be set.");
298  return false;
299  }
300  if (values[TIMEMIN] > values[TIMEMAX]) {
301  printCommandLineError("--timeMin is greater than --timeMax.");
302  return false;
303  }
304  return true;
305 }
306 
315 bool readModels
316 (const set<string> & modelFiles,
317  const string & ruleFile,
318  vector<Diades::Automata::ObservableComponent *> & components,
321  try {
322  unsigned i = 0;
323  for (const string & name : modelFiles) {
324  components[i] = new Diades::Automata::ObservableComponent();
325  if (!components[i]->importDesCompModel(name)) {
326  throw (FunctionException("readModels", Diades::Utils::Msg("Cannot load the model file '%1%'") % name));
327  }
328  vectorComp.push_back(components[i]);
329  ++i;
330  }
331  if (!ruleFile.empty()) {
332  loadSynchronisationRules(vectorComp, ruleFile, rules);
333  }
334  } catch (exception & e) {
335  log<LgProcess>("The readModels function caught the following exception: \n\t%1%") % e.what();
336  saveLog(cerr);
337  clean(components);
338  printCommandLineError("Load of the files has failed. See log above.");
339  return false;
340  }
341  return true;
342 }
343 
351 void generateFaults(unsigned seed,
352  const vector<Diades::Automata::ObservableComponent *> components,
353  list<Diades::Automata::Event> & faults) {
355  for (unsigned i = 0; i < components.size(); ++i) {
356  for (auto & event : components[i]->events()) {
357  components[i]->setNormal(event);
358  }
359  }
360 
361 
362 
363  for (unsigned i = 0; i < components.size(); ++i) {
364  vector<Diades::Automata::Event> candidates;
365  for (Diades::Automata::ObservableComponent::EventIterator it = components[i]->eventBegin();
366  it != components[i]->eventEnd();
367  ++it) {
368  // any event except the identifiable ones are candidates
369  if (!components[i]->mask().isIdentifiable(*it)) {
370  candidates.push_back(*it);
371  }
372  }
373  long faultNb = Diades::Utils::generateRandomValue(0, candidates.size());
374  set<unsigned> indexes;
375  Diades::Utils::selectNValues(0, candidates.size() - 1, faultNb, indexes);
376  for (const unsigned & index : indexes) {
377  faults.push_back(candidates[index]);
378  components[i]->setFaulty(candidates[index]);
379  }
380  }
381 }
382 
383 void writeTimedSimulation(const list<Diades::Automata::Event> & simulation,
385  set<Diades::Automata::Event> & observables,
386  set<Diades::Automata::Event> & nonObservables,
387  unsigned timeMin,
388  unsigned timeMax,
389  unsigned & nbObs) {
390  nbObs = 0;
391  list< pair<time_duration, Diades::Automata::Event> > timedSimulation;
392  back_insert_iterator<list< pair<time_duration, Diades::Automata::Event> > > ii(timedSimulation);
393  timeStamp(simulation.begin(), simulation.end(), seconds(timeMin), seconds(timeMax), ii);
394  VerboseLevel level = VbOutput;
395  setVerboseLevel(level);
396  cout << "TIMED SIMULATION:" << endl;
397  cout << "{ ";
398  list< pair<time_duration, Diades::Automata::Event> > observableTimedSimulation;
399  for (const pair<time_duration, Diades::Automata::Event> & occurrence : timedSimulation) {
400  if (mask.isObservable(occurrence.second)) {
401  observableTimedSimulation.push_back(make_pair(occurrence.first, occurrence.second));
402  observables.insert(occurrence.second);
403  ++nbObs;
404  } else {
405  nonObservables.insert(occurrence.second);
406  }
407  cout << occurrence.second << " " << occurrence.first.total_seconds() << " ";
408  }
409  cout << "}" << endl << endl;
410  cout << "OBSERVABLE PART OF TIMED SIMULATION:" << endl;
411  cout << "{ ";
412  for (const pair<time_duration, Diades::Automata::Event> & occurrence : observableTimedSimulation) {
413  cout << occurrence.second << " " << occurrence.first.total_seconds() << " ";
414  }
415  cout << "}";
416  if (isSet[XML]) {
417  cout << "not implemented yet" << endl;
418  // try {
419  //
420  // cout << "not implemented yet" << endl;
421  // // Diades::Io::Xml::saveXmlSimulation(faults.begin(),faults.end(),timedSimulation.begin(),timedSimulation.end(),observableTimedSimulation.begin(),observableTimedSimulation.end(),xmlFile);
422  // // list< pair<time_duration,Diades::Automata::Event> > timedSimulation2;
423  // // list< pair<time_duration,Diades::Automata::Event> > observableTimedSimulation2;
424  // // list< Event > faults2;
425  // // loadXmlSimulation(xmlFile,back_insert_iterator< list< Diades::Automata::Event> > >(faults2), back_insert_iterator< list< pair<time_duration,Diades::Automata::Event> > >(timedSimulation2)
426  // // back_insert_iterator< list< pair<time_duration,Diades::Automata::Event> > >(observableTimedSimulation2));
427  // } catch (exception & e) {
428  // string msg = "An exception has been caught when saving the simulation to xml file.";
429  // msg += e.what();
430  // clean(components);
431  // printCommandLineError(msg);
432  // return 1;
433  // }
434  }
435 }
436 
437 void writeUntimedSimulation(const list<Diades::Automata::Event> & simulation,
439  set<Diades::Automata::Event> & observables,
440  set<Diades::Automata::Event> & nonObservables,
441  unsigned & nbObs) {
442 
443  nbObs = 0;
444  list< Diades::Automata::Event> observations;
445  VerboseLevel level = VbOutput;
446  setVerboseLevel(level);
447  cout << "SIMULATION:" << endl;
448  cout << toStream(simulation.begin(), simulation.end()) << endl << endl;
449  cout << "OBSERVABLE PART OF SIMULATION:" << endl;
450  for (const Diades::Automata::Event & e : simulation) {
451  if (mask.isObservable(e)) {
452  observations.push_back(e);
453  observables.insert(e);
454  ++nbObs;
455  } else {
456  nonObservables.insert(e);
457  }
458  }
459  cout << toStream(observations.begin(), observations.end());
460  if (isSet[XML]) {
461  // try {
462  cout << "not implemented yet" << endl;
463  //Diades::Io::Xml::saveXmlSimulation(faults.begin(),faults.end(),simulation.begin(),simulation.end(),observations.begin(),observations.end(),xmlFile);
464  // } catch (exception & e) {
465  // string msg = "An exception has been caught when saving the simulation to xml file.";
466  // msg += e.what();
467  // clean(components);
468  // printCommandLineError(msg);
469  // return 1;
470  // }
471  }
472 }
473 
475  const list<Diades::Automata::Event> & simulation,
476  bool faultGeneration,
477  const list<Diades::Automata::Event> & faults,
478  const set<Diades::Automata::Event> & identifiables,
479  const set<Diades::Automata::Event> & nonIdentifiables,
480  unsigned nbObs,
481  const set<Diades::Automata::Event> & events,
482  const Diades::Automata::ObservableMask & mask) {
483  cout << endl << endl << "Size of the scenario: " << simulation.size() << endl;
484  if (faultGeneration) {
485  cout << "Number of faults in the model: " << faults.size() << endl;
486  cout << "Faults: " << toStream(faults.begin(), faults.end()) << endl;
487  }
488  cout << "Size of the observable scenario: " << nbObs << endl;
489  cout << "Non-identifiable events in this scenario: " << toStream(nonIdentifiables.begin(), nonIdentifiables.end()) << endl;
490  cout << "Identifiable events in this scenario: " << toStream(identifiables.begin(), identifiables.end()) << endl;
491 
492 
493  cout << "Non-identifiable events that did not occur in this scenario: "
494  << toStream(events.begin(), events.end(),
495  unaryAnd(Diades::Utils::isNotIn(nonIdentifiables.begin(), nonIdentifiables.end()),
496  Diades::Automata::IsNonIdentifiable(mask))) << endl;
497  cout << "Identifiable events that did not occur in this scenario: "
498  << toStream(mask.observableBegin(), mask.observableEnd(),
499  Diades::Utils::isNotIn(identifiables.begin(), identifiables.end())) << endl;
500 }
501 
502 void writeSimulation(const list<Diades::Automata::Event> & simulation,
503  vector<unsigned> & values,
504  bool faultGeneration,
505  const list<Diades::Automata::Event> & faults,
506  const set<Diades::Automata::Event> & events,
507  const Diades::Automata::ObservableMask & mask) {
508  set<Diades::Automata::Event> observables;
509  set<Diades::Automata::Event> nonObservables;
510  unsigned nbObs = 0;
511  if (isSet[TIMEMIN]) {
512  writeTimedSimulation(simulation, mask, observables, nonObservables,
513  values[TIMEMIN], values[TIMEMAX], nbObs);
514  } else {
515  writeUntimedSimulation(simulation, mask, observables, nonObservables, nbObs);
516  }
517  writeFinalPartOfSimulation(simulation, faultGeneration, faults, observables,
518  nonObservables, nbObs, events, mask);
519 }
520 
522  const vector<Diades::Automata::ObservableComponent *> components,
525  set<Diades::Automata::Event> & events,
526  list<Diades::Automata::Event> & simulation) {
527  bool result = true;
528  if (components.size() == 1) {
529  mask = components[0]->mask();
530  events = components[0]->events();
531  if (!Diades::Automata::interactiveSimulation(*components[0],
532  simulation)) {
533  cout << "Failed SIMULATION:" << endl;
534  cout << toStream(simulation.begin(), simulation.end());
535  log<LgProcess>("The simulation has failed. See the log above.");
536  saveLog(cerr);
537  return false;
538  }
539  } else {
540  Diades::Automata::ComposableModel * model = nullptr;
541  vector<Diades::Automata::ComposableModel::ConstPointer> comps;
542  vector<const Diades::Automata::ObservableComponent *> comps2;
543  for (unsigned i = 0; i < components.size(); ++i) {
544  comps.push_back(new Diades::Automata::ComposableModel(*components[i], rules));
545  comps2.push_back(components[i]);
546  }
547 
548  model = new Diades::Automata::ComposableModel(comps, rules, true);
549  events = model->component().events();
550  Diades::Automata::ObservableMask synchronisedMask(rules, comps2);
551  mask = synchronisedMask;
553  mask,
554  simulation)) {
555  cout << "Failed SIMULATION:" << endl;
556  cout << toStream(simulation.begin(), simulation.end());
557  log<LgProcess>("The simulation has failed. See the log above.");
558  saveLog(cerr);
559  result = false;
560  }
561  if (model != nullptr) {
562  delete model;
563  }
564  for (unsigned i = 0; i < components.size(); ++i) {
565  delete comps[i];
566  }
567  comps.clear();
568  }
569  return result;
570 }
571 
573  const vector<Diades::Automata::ObservableComponent *> components,
575  const vector<unsigned> & values,
576  const vector< set<string> > & noevents,
578  set<Diades::Automata::Event> & events,
579  list<Diades::Automata::Event> & simulation,
580  unsigned simNb) {
581  bool result = true;
582  if (components.size() == 1) {
583  mask = components[0]->mask();
584  events = components[0]->events();
585  if (!Diades::Automata::simulate(*components[0],
586  noevents[NOEVT],
587  values[OBSMIN],
588  values[OBSMAX],
589  values[SEED] + simNb, simulation)) {
590  cout << "Failed SIMULATION:" << endl;
591  cout << toStream(simulation.begin(), simulation.end());
592  log<LgProcess>("The simulation has failed. See the log above.");
593  saveLog(cerr);
594  return false;
595  }
596  } else {
597  Diades::Automata::ComposableModel * model = nullptr;
598  vector<Diades::Automata::ComposableModel::ConstPointer> comps;
599  vector<const Diades::Automata::ObservableComponent *> comps2;
600  for (unsigned i = 0; i < components.size(); ++i) {
601  comps.push_back(new Diades::Automata::ComposableModel(*components[i], rules));
602  comps2.push_back(components[i]);
603  }
604 
605  model = new Diades::Automata::ComposableModel(comps, rules, true);
606  events = model->component().events();
607  Diades::Automata::ObservableMask synchronisedMask(rules, comps2);
608  mask = synchronisedMask;
609  if (!Diades::Automata::simulate(*model,
610  mask,
611  noevents[NOEVT],
612  values[OBSMIN],
613  values[OBSMAX],
614  values[SEED]+simNb,
615  simulation)) {
616  cout << "Failed SIMULATION:" << endl;
617  cout << toStream(simulation.begin(), simulation.end());
618  log<LgProcess>("The simulation has failed. See the log above.");
619  saveLog(cerr);
620  result = false;
621  }
622  if (model != nullptr) {
623  delete model;
624  }
625  for (unsigned i = 0; i < components.size(); ++i) {
626  delete comps[i];
627  }
628  comps.clear();
629  }
630  return result;
631 }
632 
633 void exportLogIntoPtaLogFile(const vector<Diades::Automata::ObservableComponent *> & components,
635  const list<Diades::Automata::Event> & simulation,
637  ostream & file) {
638 
639  // first pass, look for the faulty events
640  set<Diades::Automata::Event> faults;
641  for (auto & event : simulation) {
642  auto it = rules.beginOfSynchronisedEvents();
643  bool found = false;
644  while ((!found) && (it != rules.endOfSynchronisedEvents())) {
645  found = (event == it->synchronisedEvent());
646  if (!found) {
647  ++it;
648  }
649  }
650  bool isFaulty = false;
651  auto it2 = it->beginOfSupport();
652  while (!isFaulty && (it2 != it->endOfSupport())) {
653  isFaulty = it2->isFaulty(it->getAssociatedEvent(it2));
654  ++it2;
655  }
656  if (isFaulty) {
657  faults.insert(event);
658  }
659  }
660  if (faults.empty()) {
661  file << "N ";
662  } else {
663  for (auto & event : faults) {
664  file << event;
665  }
666  file << " ";
667  }
668  // second pass, look for the observable events
669  for (auto & event : simulation) {
670  if (!mask.isUnobservable(event)) {
671  Diades::Automata::Event obs = *mask.observableBegin(event);
672  if (obs == mask.noEvent()) {
673  obs = *(++mask.observableBegin(event));
674  }
675  file << obs << " ";
676  }
677  }
678  file << endl;
679 }
680 
692 int main(int argc, char ** argv) {
693  verbose<VbOutput>("DiaDes: Discrete Event System Simulator\n");
694  verbose<VbOutput>("LAAS-CNRS, 2006-2017, 7 avenue du Colonel Roche, Toulouse, France\n");
695  verbose<VbOutput>("Contact: yannick.pencole@laas.fr\n");
697  vector<unsigned> values(numberOfOptions);
698  values[SEED] = initialiseSeed();
699  values[NBSIM] = 1;
700  vector< set<string> > noevents(numberOfOptions);
701  set<string> modelFiles;
702  string ruleFile;
703  string xmlFile;
704  string ptaLogFile;
705  bool faultGeneration = false;
706  bool interactiveMode = false;
707 
708  // Parameter readings
709  if (!readParameters(argc, argv, values, noevents, modelFiles,
710  ruleFile, xmlFile, ptaLogFile, faultGeneration, interactiveMode)) {
711  return 1;
712  }
713 
714  // Model loading
715  vector<Diades::Automata::ObservableComponent *> components(modelFiles.size(), nullptr);
717  if (!readModels(modelFiles, ruleFile, components, rules)) {
718  return 1;
719  }
720 
721  ofstream file;
722  if (!ptaLogFile.empty()) {
723  file.open(ptaLogFile);
724  }
725 
726  // fault generation
727  list<Diades::Automata::Event> faults;
728  if (faultGeneration) {
729  generateFaults(values[SEED], components, faults);
730  }
731 
732 
733  for (unsigned i = 0; i < values[NBSIM]; ++i) {
734 
735 
736  list<Diades::Automata::Event> simulation;
737  set<Diades::Automata::Event> events;
738 
740  if (interactiveMode) {
741  if (!startInteractiveSimulation(components, rules, mask, events, simulation)) {
742  clean(components);
743  return 1;
744  }
745  } else {
746 
747  if (!startNonInteractiveSimulation(components, rules, values, noevents,
748  mask, events, simulation,i)) {
749  clean(components);
750  return 1;
751  }
752 
753  }
754 
755 
756 
757  // simulation writing on the standard output
758  writeSimulation(simulation, values, faultGeneration,
759  faults, events, mask);
760 
761  if (!ptaLogFile.empty()) {
762  exportLogIntoPtaLogFile(components, rules, simulation, mask, file);
763  }
764  }
765  if (!ptaLogFile.empty()) {
766  file.close();
767  }
768 
769  clean(components);
770  return 0;
771 }
772 
773 
774 
unsigned numberOfOptions
Definition: Simulate.cc:68
vector< const Component * > ComponentVector
bool readModels(const set< string > &modelFiles, const string &ruleFile, vector< Diades::Automata::ObservableComponent *> &components, Diades::Automata::ParametrizedSynchronisation &rules)
Definition: Simulate.cc:316
Definition: Simulate.cc:62
void writeUntimedSimulation(const list< Diades::Automata::Event > &simulation, const Diades::Automata::ObservableMask &mask, set< Diades::Automata::Event > &observables, set< Diades::Automata::Event > &nonObservables, unsigned &nbObs)
Definition: Simulate.cc:437
Some utilities to deal with the command line.
InputIterator getFileExtension(const std::basic_string< CharType, CharTraits > &fileName, InputIterator begin, InputIterator end)
Definition: StringTools.hh:57
unsigned initialiseSeed()
size_t printCommandLineError(const string &msg)
Definition: CmdInterface.cc:98
void setVerboseLevel(Diades::Utils::VerboseLevel level)
Definition: Verbose.hh:135
string description
Definition: Simulate.cc:75
STL namespace.
FileExtension
Definition: abstract.cc:33
bool loadSynchronisationRules(const ParametrizedSynchronisation::ComponentVector &models, const string &filename, ParametrizedSynchronisation &sync)
bool readParameters(int argc, char **argv, vector< unsigned > &values, vector< set< string > > &noevents, set< string > &modelFiles, string &ruleFile, string &xmlFile, string &ptaLogFile, bool &faultGeneration, bool &interactiveMode)
Definition: Simulate.cc:132
FileExtension
Definition: Simulate.cc:65
vector< string > fileExtensions(numberOfFileExtensions)
Option
Definition: Simulate.cc:61
void selectNValues(unsigned int min, unsigned int max, unsigned int n, set< unsigned > &result)
void initialiseRandomGenerator()
SynchronisationIterator beginOfSynchronisedEvents() const
IsNotIn< InputIterator > isNotIn(InputIterator first, InputIterator last)
Definition: Functors.hh:226
An observable Component defined as a automaton.
Definition: Simulate.cc:62
bool startNonInteractiveSimulation(const vector< Diades::Automata::ObservableComponent *> components, const Diades::Automata::ParametrizedSynchronisation &rules, const vector< unsigned > &values, const vector< set< string > > &noevents, Diades::Automata::ObservableMask &mask, set< Diades::Automata::Event > &events, list< Diades::Automata::Event > &simulation, unsigned simNb)
Definition: Simulate.cc:572
void writeSimulation(const list< Diades::Automata::Event > &simulation, vector< unsigned > &values, bool faultGeneration, const list< Diades::Automata::Event > &faults, const set< Diades::Automata::Event > &events, const Diades::Automata::ObservableMask &mask)
Definition: Simulate.cc:502
Random generation utilities.
Option
Definition: abstract.cc:32
void initialiseOptions()
Definition: Simulate.cc:77
vector< string > options(numberOfOptions)
void clean(vector< Diades::Automata::ObservableComponent *> &components)
Definition: Simulate.cc:104
ObservableEventIterator observableBegin() const
void saveLog(Logger logger, ostream &os)
Definition: Log.hh:163
vector< bool > isSet(numberOfOptions, false)
Diades::Utils::ToStream< InputIterator, Diades::Utils::AlwaysTrue< typename InputIterator::reference > > toStream(InputIterator first, InputIterator last)
Definition: Verbose.hh:143
void writeTimedSimulation(const list< Diades::Automata::Event > &simulation, const Diades::Automata::ObservableMask &mask, set< Diades::Automata::Event > &observables, set< Diades::Automata::Event > &nonObservables, unsigned timeMin, unsigned timeMax, unsigned &nbObs)
Definition: Simulate.cc:383
SynchronisationIterator endOfSynchronisedEvents() const
int main(int argc, char **argv)
Definition: Simulate.cc:692
Definition: Simulate.cc:62
ObservableEventIterator observableEnd() const
bool interactiveSimulation(const ObservableComponent &component, State &current, list< Event > &simulation)
Definition: Simulator.cc:568
void generateFaults(unsigned seed, const vector< Diades::Automata::ObservableComponent *> components, list< Diades::Automata::Event > &faults)
Definition: Simulate.cc:351
bool simulate(const ObservableComponent &component, const set< string > &absentEvents, unsigned obsMin, unsigned obsMax, unsigned seed, list< Event > &simulation)
Definition: Simulator.cc:192
bool isObservable(const Event &e) const
const Component & component() const
void timeStamp(InputIterator first, InputIterator last, time_duration min, time_duration max, OutputIterator result)
Definition: Simulator.hh:90
set< Event >::const_iterator EventIterator
Definition: Component.hh:73
unsigned numberOfFileExtensions
Definition: Simulate.cc:69
UnaryAnd< Predicate1, Predicate2 > unaryAnd(const Predicate1 &p1, const Predicate2 &p2)
Definition: Functors.hh:477
bool isUnobservable(const Event &e) const
void writeFinalPartOfSimulation(const list< Diades::Automata::Event > &simulation, bool faultGeneration, const list< Diades::Automata::Event > &faults, const set< Diades::Automata::Event > &identifiables, const set< Diades::Automata::Event > &nonIdentifiables, unsigned nbObs, const set< Diades::Automata::Event > &events, const Diades::Automata::ObservableMask &mask)
Definition: Simulate.cc:474
boost::format Msg
Definition: Verbose.hh:42
long generateRandomValue(long lower, long upper)
const set< Event > & events() const
Definition: Component.hh:318
bool startInteractiveSimulation(const vector< Diades::Automata::ObservableComponent *> components, const Diades::Automata::ParametrizedSynchronisation &rules, Diades::Automata::ObservableMask &mask, set< Diades::Automata::Event > &events, list< Diades::Automata::Event > &simulation)
Definition: Simulate.cc:521
void exportLogIntoPtaLogFile(const vector< Diades::Automata::ObservableComponent *> &components, const Diades::Automata::ParametrizedSynchronisation &rules, const list< Diades::Automata::Event > &simulation, const Diades::Automata::ObservableMask &mask, ostream &file)
Definition: Simulate.cc:633
void printUsage(const po::options_description &desc)