43 #include<unordered_map> 46 #include<boost/program_options.hpp> 51 #include"../AutomataInterface.hh" 52 #include"../CmdInterface.hh" 59 namespace Poptions = boost::program_options;
68 const string briefcomment(
": dd-sim simulates a model. Given a ddaut file, dd-sim computes some runs of the model");
70 dd-sim simulates a model. Given a ddaut file, dd-sim computes some runs of the model 75 dd-sim file.ddaut --seed=30 --size=100 --through='.*o\.p=ko.*' 76 --format='@s -> @t [@e]' --format='@o' --timer=10 77 --observable=observable.txt 78 --controllable=controllable.txt -o result.run 81 In Example 1. dd-sim computes a random run (seed of the random generator is 30), the size 82 of the run is 100, and the run must go through a state with a label containing 'o.p=ko'. 83 The run must be found within 10 seconds, if not the simulator stops. 84 The resulting run will be written in the file result1.run following the format: 88 That is 'sourcestate -> targetstate [event]': 89 - @s stands for source state, 90 - @t stands for target state, 91 - @e stands for event. 93 Other possible tags are: 94 - @o stands for observable event, 95 - @c stands for controllable event. 97 @o and @c are respectively defined in observable.txt and controllable.txt. For a given 98 event @e, the observable parts are the substring of @e that are in observable.txt, 99 the controllable parts are the substring of @e that are in controllable.txt. 101 A second file result2.run contains the sequence of observable events of the same run 122 Poptions::options_description & desc,
123 Poptions::variables_map & vm)
126 (
"help,h",
"produce help message")
127 (
"file,f", Poptions::value< string >(),
"file that contains the model to simulate (.ddaut format)")
128 (
"output,o", Poptions::value< string >(),
129 R
"(template name for the generated output files: 130 Suppose the template name is 'output.run' then, depending on the number of requested simulations, 131 the generated files will named as follows: output_1.run, output_2.run, ...)") 132 ("seed",Poptions::value< unsigned int >(),
133 R
"(seed used by the random generator: if no seed is given, take as seed the starting time of the process.)") 134 ("size", Poptions::value< unsigned int >(),
135 R
"(size is the size (number of transitions) of the run to simulate. If the simulator cannot find 136 such a requested run, it will simplify give up. (default value is 100))") 137 ("through", Poptions::value< string >(),
138 R
"(This parameter requests a regular expression as defined at the following address: 140 http://www.cplusplus.com/reference/regex/ECMAScript/ 142 This parameter states that the simulator must look for a run that must go at least once through one state 143 whose label matches the given regular expression.)") 144 ("format", Poptions::value< std::vector<string> >(),
145 R
"(format of the result. The expression given in the format will be used as a template to write the simulation 146 in the output file. @s stands for source state, @t for target state, @e for transition event, @o observable part of 147 the event, @c controllable part of the event. Many formats are allowed, one format generates one output file.)") 148 ("timer", Poptions::value< unsigned int >(),
149 R
"(simulation timer. Does not allow the simulator to look for one run after the time set (in seconds) 150 by the timer is reached. If no timer is set, the program may not end if no run is found.)") 151 ("observable", Poptions::value< string >(),
152 R
"(set the file that defines the observable events of the model. An event of the model is considered as observable 153 if at least one of its substring matches an event contained in the given file. If the option observable is not set, 154 no event of the model is considered as observable (@o will keep return the empty string).)") 155 ("controllable", Poptions::value< string >(),
156 R
"(set the file that defines the controllable events of the model. An event of the model is considered as controllable 157 if at least one of its substring matches an event contained in the given file. If the option controlable is not set, 158 no event of the model is considered as controlable (@o will keep return the empty string).)") 160 Poptions::positional_options_description p; 163 Poptions::store(Poptions::command_line_parser(argc, argv).
options(desc).positional(p).run(), vm);
164 Poptions::notify(vm);
178 unsigned int size = 100;
194 Poptions::options_description desc(
"Options");
195 Poptions::variables_map vm;
203 options.
fileName = vm[
"file"].as<std::string> ();
205 if(vm.count(
"observable"))
207 options.
observable = vm[
"observable"].as<std::string> ();
209 if(vm.count(
"controllable"))
211 options.
controllable = vm[
"controllable"].as<std::string> ();
213 if(vm.count(
"output"))
215 options.
output = vm[
"output"].as<std::string>();
219 options.
seed = vm[
"seed"].as<
unsigned int>();
223 options.
size = vm[
"size"].as<
unsigned int>();
225 if(vm.count(
"timer"))
227 options.
timer = vm[
"timer"].as<
unsigned int>();
229 if(vm.count(
"through"))
231 options.
through = vm[
"through"].as<std::string>();
233 if(vm.count(
"format"))
235 options.
formats = vm[
"format"].as<std::vector<std::string>>();
238 catch(Poptions::required_option & e)
242 catch(Poptions::error & e)
265 const std::regex & regularExpression,
268 if(throughStates[state] == 1) {
return true; }
269 if(throughStates[state] == 2) {
return false; }
273 throughStates[state] = 1;
278 throughStates[state] = 2;
307 auto now = std::chrono::system_clock::now();
309 options.
seed = std::chrono::system_clock::to_time_t(now);
312 if(result!=
SUCCESS) {
return result; }
316 if(result!=
SUCCESS) {
return result; }
321 if(result!=
SUCCESS) {
return result; }
Diades::Graph::ConstNodeMap< Type > CstStMap
StatePropertyManager< DdAutStateLabel, DdAutStateId > DdAutStateManager
size_t printCommandLineError(const string &msg)
size_t isOpenableFile(const std::string &filename)
check that the file can be opened
const string program("dd-sim")
data structure that gathers an Fsm, a StateManager and a EventManager
FileSuffixes suffixes({"ddaut"})
size_t prepareSimulation(const DdSimOptions &options)
size_t checkDdAutFile(const std::string &filename)
check that filename is a proper file with the ddaut suffix check that the file 'filename' can be ope...
FiniteAutomaton< DdAutStateId, DdAutEventId > DdAutFA
vector< string > options(numberOfOptions)
std::vector< std::string > formats
unsigned numberOfStates() const
int main(int argc, char **argv)
Graph::Graph & behaviour()
bool isThroughState(const ConstManagedDdAutFsm &mfsm, State state, const std::regex ®ularExpression, CstStMap< char > &throughStates)
check whether the state is matching the 'through-state' expression given by –through ...
EventManager< DdAutEventLabel, DdAutEventId > DdAutEventManager
const string briefcomment(": dd-sim simulates a model. Given a ddaut file, dd-sim computes some runs of the model")
Diades::Graph::NodeMap< Type > StMap
StateMachine< DdAutStateId, DdAutEventId > DdAutFsm
const DdAutStateManager & sMgr
size_t setOptions(int argc, char **argv, DdSimOptions &options)
const string detailedcomment
const StatePropertyId & getStatePropertyId(State state) const
const StateProperty & getStateProperty(StatePropertyId id) const
size_t loadFiniteStateMachine(const std::string &input, const Diades::Automata::Experimental::ManagedDdAutFsm &mfsm)
Load the fsm from a file called 'input'.
void printUsage(const po::options_description &desc)