44 const set<Event> & noEvents,
46 unsigned obsMax,
unsigned depth,
47 list<Event> & simulation) {
63 "simulated twice the number of transitions of the component and still no observable transitions: the simulation is very likely in an unobservable deadend. Give up for the beauty of randomness."));
71 msg <<
"Reaching the state " << component.
getLabel(source);
72 if (source.outDeg() == 0) {
73 msg <<
" but it has no output events. Simulation stopped" << std::endl;
75 msg <<
" but it has only fordidden events as output events, cannot go futher. Simulation stopped" 76 << endl <<
"Output events of the last state:" << endl;
81 msg << component.
getEvent(*it) << std::endl;
84 std::cerr <<
"WARNING: " << msg.str() << std::endl;
87 simulation.push_back(component.
getEvent(transition));
95 randomSimulateState(component, transition.target(), noEvents, obsMin, obsMax, depth, simulation);
112 const set<Event> & noEvents,
115 list<Event> & simulation) {
139 const set<Event> & noEvents,
142 list<Event> & simulation) {
159 const set<string> & labels,
160 set<Event> & events) {
161 set<string> labelsLeft = labels;
163 while ((!labelsLeft.empty()) && (eventIt != component.
eventEnd())) {
164 set<string>::iterator labelIt = labelsLeft.find(eventIt->label());
165 if (labelIt == labelsLeft.end()) {
166 labelIt = labelsLeft.find(eventIt->nickname());
168 if (labelIt != labelsLeft.end()) {
169 events.insert(*eventIt);
170 labelsLeft.erase(labelIt);
175 return labelsLeft.empty();
193 const set<string> & absentEvents,
197 list<Event> & simulation) {
202 getEvents(component, absentEvents, noEvents);
209 if (obsMax < obsMin) {
210 throw (
FunctionException(
"simulate",
"Please check obsMin and obsMax, they are inconsistent."));
221 }
catch (exception & e) {
222 log<LgProcess>(
"The function 'simulate' caught the exception: \n\t%1%") % e.what();
255 const set<Event> & noEvents,
257 unsigned obsMax,
unsigned depth,
258 list<Event> & simulation) {
265 if (nbObsLeft != 0) {
266 randomSimulateState(composable, mask, source, noEvents, nbObsLeft, nbObsLeft, depth, simulation);
274 "simulated 200 transitions of the model and still no observable transitions: the simulation is very likely in an unobservable deadend. Give up for the beauty of randomness."));
278 fgx(
isNotIn(noEvents.begin(), noEvents.end()),
284 if (source.outDeg() == 0) {
285 msg <<
" but it has no output events. Simulation stopped" << std::endl;
287 msg <<
" but it has only fordidden events as output events, cannot go futher. Simulation stopped" 288 << endl <<
"Output events of the last state:" << endl;
296 std::cerr <<
"WARNING: " << msg.str() << std::endl;
309 randomSimulateState(composable, mask, transition.target(), noEvents, obsMin, obsMax, depth, simulation);
331 const set<Event> & noEvents,
334 list<Event> & simulation) {
361 const set<Event> & noEvents,
364 list<Event> & simulation) {
365 randomSimulate(composable, mask, noEvents, obsMin, obsMax, simulation);
384 const set<string> & absentEvents,
388 list<Event> & simulation) {
400 if (obsMax < obsMin) {
401 throw (
FunctionException(
"simulate",
"Please check obsMin and obsMax, they are inconsistent."));
411 reallySimulate(composable, mask, noEvents, obsMin, obsMax, simulation);
412 }
catch (exception & e) {
413 log<LgProcess>(
"The function 'simulate' caught the exception: \n\t%1%") % e.what();
421 cout << endl <<
"\t[" << index <<
"]- Stop" << endl;
424 template<
typename StateIterator>
432 cout <<
"\t[" << index <<
"]- " << component.
getLabel(*first) << endl;
442 template<
typename StateIterator>
449 while(current != index)
465 if(index < 1 || index > (maxValue+1))
469 stop = (index== maxValue+1);
486 cout <<
"Initial state: " 518 template<
typename TransitionIterator>
520 TransitionIterator first,
521 TransitionIterator last)
523 cout <<
"Current State: " << component.
getLabel(first->source()) << endl;
528 cout <<
"\t[" << index <<
"]- " 529 << component.
getLabel(first->source())
531 << component.
getLabel(first->target())
533 << component.
getEvent(*first) <<
":" 545 template<
typename TransitionIterator>
547 TransitionIterator first,
548 TransitionIterator last,
unsigned index)
551 while(current != index)
570 list<Event> & simulation)
573 if(current.outDeg()==0)
575 log<LgProcess>(
"The current state is a deadlock. STOP.");
582 while(!
readResponse(cin,index,current.outDeg(),stop)) {}
588 simulation.push_back(component.
getEvent(selection));
589 cout <<
"run : " << component.
getLabel(current) <<
" -> " 590 << component.
getLabel(selection.target()) <<
" [" 591 << component.
getEvent(selection) <<
":" 594 current = selection.target();
612 list<Event> & simulation)
627 log<LgProcess>(
"The current state is a deadlock. STOP.");
634 while(!
readResponse(cin,index,current.outDeg(),stop)) {}
640 simulation.push_back(component.
getEvent(selection));
641 cout <<
"run : " << component.
getLabel(current) <<
" -> " 642 << component.
getLabel(selection.target()) <<
" [" 643 << component.
getEvent(selection) <<
":" 646 current = selection.target();
660 list<Event> & simulation)
665 log<LgProcess>(
"The interactive simulation has been aborted by the user.");
670 log<LgProcess>(
"The interactive simulation has failed as there is no valid initial state.");
687 list<Event> & simulation)
692 log<LgProcess>(
"The interactive simulation has been aborted by the user.");
697 log<LgProcess>(
"The interactive simulation has failed as there is no valid initial state.");
void randomSimulateState(ComposableModel &composable, const ObservableMask &mask, State source, const set< Event > &noEvents, unsigned obsMin, unsigned obsMax, unsigned depth, list< Event > &simulation)
unsigned numberOfInitialStates() const
Diades::Graph::Edge Transition
void printStop(unsigned index)
bool initialStateSelection(ComposableModel &model, State &result)
bool interactiveSimulation(ComposableModel &composable, const ObservableMask &mask, list< Event > &simulation)
CompositionFunctorFGx< F, G > fgx(const F &f, const G &g)
bool readResponse(istream &in, unsigned &index, unsigned maxValue, bool &stop)
void reallySimulate(ComposableModel &composable, const ObservableMask &mask, const set< Event > &noEvents, unsigned obsMin, unsigned obsMax, list< Event > &simulation)
const StateLabel & getLabel(State state) const
Component::OutputTransitionIterator OutputTransitionIterator
State getStateOfIndex(const Component &component, StateIterator first, StateIterator last, unsigned index)
void initialiseRandomGenerator()
bool simulate(ComposableModel &composable, const ObservableMask &mask, const set< string > &absentEvents, unsigned obsMin, unsigned obsMax, unsigned seed, list< Event > &simulation)
IsNotIn< InputIterator > isNotIn(InputIterator first, InputIterator last)
void randomSimulate(ComposableModel &composable, const ObservableMask &mask, const set< Event > &noEvents, unsigned obsMin, unsigned obsMax, list< Event > &simulation)
InitialStateIterator initialStateEnd() const
An observable Component defined as a automaton.
unsigned numberOfInitialStates() const
void generateStateList(const Component &component, StateIterator first, StateIterator last)
unsigned numberOfTransitions() const
OutputTransitionIterator outputTransitionEnd(State s) const
bool getEvents(const Component &component, const set< string > &labels, set< Event > &events)
InitialStateIterator initialStateBegin() const
Transition getTransitionOfIndex(const Component &component, TransitionIterator first, TransitionIterator last, unsigned index)
Random generation utilities.
Diades::Graph::OutEdgeIterator OutputTransitionIterator
Namespace of the Diades project.
ObservableEventIterator observableBegin() const
long generateRandomValue(long lower, long upper)
EventIterator eventBegin() const
Diades::Utils::ToStream< InputIterator, Diades::Utils::AlwaysTrue< typename InputIterator::reference > > toStream(InputIterator first, InputIterator last)
OutputTransitionIterator outputTransitionBegin(State s) const
const ObservableMask & mask() const
ObservableEventIterator observableEnd() const
Iterator selectRandomElement(unsigned number, Iterator first, Iterator last)
bool isObservable(const Event &e) const
const Event & getEvent(Transition t) const
const Component & component() const
EventIterator eventEnd() const
set< Event >::const_iterator EventIterator
Diades::Graph::Node State
OutputTransitionIterator outputTransitionBegin(State s) const
InitialStateIterator endOfInitialStates() const
void generateTransitionList(const Component &component, const ObservableMask &mask, TransitionIterator first, TransitionIterator last)
OutputTransitionIterator outputTransitionEnd(State s) const
InitialStateIterator beginOfInitialStates() const