DiaDes  0.1
DIAgnosis of Discrete-Event System
Enumerations | Functions | Variables
Simulate.cc File Reference
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <set>
#include <list>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <diades/utils/Random.hh>
#include <diades/utils/Verbose.hh>
#include <diades/automata/ComposableModel.hh>
#include <diades/automata/SyncRulesLoad.hh>
#include "CmdInterface.hh"
#include "Simulator.hh"

Go to the source code of this file.

Enumerations

enum  Option {
  OUTPUT =0, VERBOSE =1, EVENTS =2, NOTEVENTS =3,
  HELP =4, STATEABSTRACTIONS = 5, EVENT = 0, HELP = 1,
  OUTPUT =0, HELP = 0, EVENTS = 1, EVENTNB = 2,
  STATES = 3, STATENB = 4, TRANSITIONS = 5, TRANSITIONNB = 6,
  OBSERVABLES = 7, OBSERVABLENB = 8, UNOBSERVABLES = 9, UNOBSERVABLENB =10,
  INITIALSTATES = 11, INITIALSTATENB = 12, NAME = 13, STATISTICS = 14,
  STATEMIN = 0, STATEMAX = 1, OBSMIN = 2, OBSMAX = 3,
  EVTMIN = 4, EVTMAX = 5, SEED = 6, DIRNAME = 7,
  LATEXFILENAME = 8, TOPOLOGYFILENAME = 9, OBSINTERACTIONMIN = 10, OBSINTERACTIONMAX = 11,
  NODEBEHAVIOUR = 12, HELP = 13, OUTPUTDEGREEMAX = 14, PETRINET = 15,
  STATISTICS =0, HELP =1, FAULTS = 2, NOFAILURES =0,
  FAILURES =1, OBSERVABLES =2, HDFILE =3, DOTFILE =4,
  CPPFILE =5, WITHSILENTCLOSURE =6, HELP =7, FAULTMAX =0,
  SEED =1, HELP =2, HELP =0, FAULTS = 0,
  ALGORITHMS = 1, HELP = 0, EVENTS = 1, TIMEDEVENTS = 2,
  OBSERVATIONS = 3, TIMEDOBSERVATIONS = 4, FAULTS = 5, OBSMIN = 0,
  OBSMAX = 1, TIMEMIN = 2, TIMEMAX = 3, NOEVT = 4,
  SEED = 5, XML = 6, GENERATEFAULTS = 7, HELP = 8,
  INTERACTIVE = 9, PTALOG = 10, NBSIM = 11, HELP =0,
  COMPONENTS =0, EVENTS =1, NUMBER =2, CONNECTIONWITHEVENT =3,
  HELP =4
}
 
enum  FileExtension {
  DESCOMP =0, DESCOMP =0, RULES =1, DESCOMP =0,
  DESCOMP =0, RULES =1, XML =2, ABSTRACTION = 3,
  DIAGNOSER = 4, DESCOMP =0, ARCHV = 0, DESCOMP =0,
  RULES =1, XML =2, DESCOMP = 0, RULES = 1,
  XML =0, RULES =0
}
 

Functions

vector< string > fileExtensions (numberOfFileExtensions)
 
vector< string > options (numberOfOptions)
 
vector< bool > isSet (numberOfOptions, false)
 
void initialiseOptions ()
 
void clean (vector< Diades::Automata::ObservableComponent *> &components)
 
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)
 
bool readModels (const set< string > &modelFiles, const string &ruleFile, vector< Diades::Automata::ObservableComponent *> &components, Diades::Automata::ParametrizedSynchronisation &rules)
 
void generateFaults (unsigned seed, const vector< Diades::Automata::ObservableComponent *> components, list< Diades::Automata::Event > &faults)
 
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)
 
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)
 
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)
 
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)
 
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)
 
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)
 
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)
 
int main (int argc, char **argv)
 

Variables

unsigned numberOfOptions = 12
 
unsigned numberOfFileExtensions = 2
 
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)"
 

Enumeration Type Documentation

◆ FileExtension

Enumerator
DESCOMP 
DESCOMP 
RULES 
DESCOMP 
DESCOMP 
RULES 
XML 
ABSTRACTION 
DIAGNOSER 
DESCOMP 
ARCHV 
DESCOMP 
RULES 
XML 
DESCOMP 
RULES 
XML 
RULES 

Definition at line 65 of file Simulate.cc.

◆ Option

enum Option
Enumerator
OUTPUT 
VERBOSE 
EVENTS 
NOTEVENTS 
HELP 
STATEABSTRACTIONS 
EVENT 
HELP 
OUTPUT 
HELP 
EVENTS 
EVENTNB 
STATES 
STATENB 
TRANSITIONS 
TRANSITIONNB 
OBSERVABLES 
OBSERVABLENB 
UNOBSERVABLES 
UNOBSERVABLENB 
INITIALSTATES 
INITIALSTATENB 
NAME 
STATISTICS 
STATEMIN 
STATEMAX 
OBSMIN 
OBSMAX 
EVTMIN 
EVTMAX 
SEED 
DIRNAME 
LATEXFILENAME 
TOPOLOGYFILENAME 
OBSINTERACTIONMIN 
OBSINTERACTIONMAX 
NODEBEHAVIOUR 
HELP 
OUTPUTDEGREEMAX 
PETRINET 
STATISTICS 
HELP 
FAULTS 
NOFAILURES 
FAILURES 
OBSERVABLES 
HDFILE 
DOTFILE 
CPPFILE 
WITHSILENTCLOSURE 
HELP 
FAULTMAX 
SEED 
HELP 
HELP 
FAULTS 
ALGORITHMS 
HELP 
EVENTS 
TIMEDEVENTS 
OBSERVATIONS 
TIMEDOBSERVATIONS 
FAULTS 
OBSMIN 
OBSMAX 
TIMEMIN 
TIMEMAX 
NOEVT 
SEED 
XML 
GENERATEFAULTS 
HELP 
INTERACTIVE 
PTALOG 
NBSIM 
HELP 
COMPONENTS 
EVENTS 
NUMBER 
CONNECTIONWITHEVENT 
HELP 

Definition at line 61 of file Simulate.cc.

Function Documentation

◆ clean()

void clean ( vector< Diades::Automata::ObservableComponent *> &  components)

Clean the allocated structure for components

Parameters
componentsthe set of loaded components

Definition at line 104 of file Simulate.cc.

References Diades::Utils::LoggerFactory::destroy(), and Diades::Automata::EventFactory::destroy().

Referenced by main(), and readModels().

◆ exportLogIntoPtaLogFile()

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 
)

◆ fileExtensions()

vector<string> fileExtensions ( numberOfFileExtensions  )

◆ generateFaults()

void generateFaults ( unsigned  seed,
const vector< Diades::Automata::ObservableComponent *>  components,
list< Diades::Automata::Event > &  faults 
)

Generate faulty events from the component's models

Parameters
seedthe random seed to initialise the generator
componentsthe models of the component
faultsthe events that are select as faults. Note that the components are updated so that the selected events are set to faulty.

Definition at line 351 of file Simulate.cc.

References Diades::Utils::generateRandomValue(), initialiseRandomGenerator(), and Diades::Utils::selectNValues().

Referenced by main().

◆ initialiseOptions()

void initialiseOptions ( )

Definition at line 77 of file Simulate.cc.

References DESCOMP, fileExtensions(), GENERATEFAULTS, HELP, INTERACTIVE, NBSIM, NOEVT, OBSMAX, OBSMIN, options(), PTALOG, RULES, SEED, TIMEMAX, TIMEMIN, and XML.

Referenced by main(), and setOptions().

◆ isSet()

vector<bool> isSet ( numberOfOptions  ,
false   
)

◆ main()

int main ( int  argc,
char **  argv 
)

Main function of the program simulate

Basically, this function analyses the parameters to initiate the simulation.

Parameters
argcthe number of parameters
argvthe list of parameters
Returns
0 if success

Definition at line 692 of file Simulate.cc.

References clean(), exportLogIntoPtaLogFile(), generateFaults(), initialiseOptions(), Diades::Utils::initialiseSeed(), NBSIM, numberOfOptions, Diades::Automata::ParametrizedSynchronisation::open(), readModels(), readParameters(), SEED, startInteractiveSimulation(), startNonInteractiveSimulation(), and writeSimulation().

◆ options()

vector<string> options ( numberOfOptions  )

◆ readModels()

bool readModels ( const set< string > &  modelFiles,
const string &  ruleFile,
vector< Diades::Automata::ObservableComponent *> &  components,
Diades::Automata::ParametrizedSynchronisation rules 
)

Real the models from the input files

Parameters
modelFilesthe list of des_comp files
ruleFilethe file of the synchronisation rules
componentsthe set of components to be loaded
rulesthe synchronisation rules that are loaded
Returns
true if the files are interpretable

Definition at line 316 of file Simulate.cc.

References clean(), Diades::Automata::loadSynchronisationRules(), Diades::CmdInterface::printCommandLineError(), and Diades::Utils::saveLog().

Referenced by main(), and readParameters().

◆ readParameters()

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 
)

Read the parameters of the dd-simulate command

Parameters
argcthe number of arguments
argvthe list of arguments
valuesset the values for timeMin timeMax obsMin obsMax seed
noeventsset the 'noevent' list
modelFilesset the name of the model files
ruleFileset the name of the rule file
xmlFileset the name of the xml output
ptaLogFileset the name of the pta_log output
faultGenerationset whether faults must be generated at simulation time
interactiveModeset the interactive mode
Returns
true if the read parameters are interpretable, false otherwise. Perform some consistency-checking by comparing some of the read paramaters.

Definition at line 132 of file Simulate.cc.

References DESCOMP, description, fileExtensions(), GENERATEFAULTS, Diades::Utils::getFileExtension(), HELP, INTERACTIVE, isSet(), NBSIM, NOEVT, OBSMAX, OBSMIN, options(), Diades::CmdInterface::printCommandLineError(), printUsage(), PTALOG, readModels(), RULES, SEED, TIMEMAX, TIMEMIN, and XML.

Referenced by main().

◆ startInteractiveSimulation()

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 
)

◆ startNonInteractiveSimulation()

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 
)

◆ writeFinalPartOfSimulation()

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 
)

◆ writeSimulation()

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 
)

◆ writeTimedSimulation()

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 
)

◆ writeUntimedSimulation()

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 
)

Variable Documentation

◆ description

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)"

Definition at line 75 of file Simulate.cc.

Referenced by readParameters().

◆ numberOfFileExtensions

unsigned numberOfFileExtensions = 2

Definition at line 69 of file Simulate.cc.

◆ numberOfOptions

unsigned numberOfOptions = 12

Definition at line 68 of file Simulate.cc.

Referenced by main().