1 #ifndef __DIADES__AUTOMATA__COMPONENT__HH 2 #define __DIADES__AUTOMATA__COMPONENT__HH 7 #include <unordered_set> 8 #include <unordered_map> 12 #include <boost/archive/text_oarchive.hpp> 13 #include <boost/archive/text_iarchive.hpp> 14 #include <boost/serialization/vector.hpp> 15 #include <boost/serialization/set.hpp> 16 #include <boost/serialization/map.hpp> 60 static string typeName() {
return "Automata::Component"; }
136 _name(defaultComponentName),
141 _transitionsWithTarget(),
142 _transitionsWithSource(),
145 _eventOfTransition(),
149 _eventOfTransition.
init(_behav);
150 _labelOfState.
init(_behav);
151 _isInitial.
init(_behav,0);
174 return this == &component;
186 return !(*
this == component);
194 virtual void clear();
208 void setId(
int identifier) { _id = identifier; }
228 return (_behav.
empty());
248 require(Exception, !name.empty(),
"setName: invalid name");
250 ensure(Exception, !_name.empty(),
"setName");
257 ensure(Exception, !_name.empty(),
"name");
286 return _events.size();
305 require(Exception,t.valid(),
"getEvent: invalid transition");
306 require(Exception,&t.owner() == &
_behav,
"getEvent: the transition does not belong to this component");
307 ensure(Exception,_eventOfTransition[t].
isValid(),
"getEvent returns an invalid event");
308 return _eventOfTransition[t];
330 return _events.begin();
340 return _events.end();
351 return _events.find(e) != _events.end();
364 _normalEvents.erase(e);
365 _faultyEvents.insert(e);
375 return _faultyEvents.find(e) != _faultyEvents.end();
398 return _faultyEvents.begin();
408 return _faultyEvents.end();
421 _faultyEvents.erase(e);
422 _normalEvents.insert(e);
431 return _normalEvents.find(e) != _normalEvents.end();
453 return _normalEvents.begin();
463 return _normalEvents.end();
523 require(Exception,state.valid(),
"getLabel: invalid state");
524 require(Exception,&state.owner() == &
_behav,
"getLabel: the state does not belong to this component");
525 return _labelOfState[state];
536 unordered_map< StateLabel, State >::const_iterator it;
537 it = _stateOfLabel.find(label);
538 require(Exception,it != _stateOfLabel.end(),
"getState: no such a state");
556 void deleteState(StateIterator start, StateIterator end);
590 if(state.valid() && (&state.owner() == &
_behav))
592 _initial.insert(state);
593 _isInitial[state] = 1;
604 if(state.valid() && (&state.owner() == &
_behav))
606 _initial.erase(state);
607 _isInitial[state] = 0;
639 return _initial.begin();
649 return _initial.end();
661 return _initial.size();
673 return (state.valid()) && (&state.owner() == &
_behav) && (_isInitial[state] == 1);
723 Transition
newTransition(
const StateLabel & source,
const StateLabel & target,
Event event);
749 void deleteTransition(EventTransitionIterator start, EventTransitionIterator end);
758 require(Exception, _events.find(e) != _events.end(),
759 "beginOfSourceStateOfEvent: the event does not belong to the component");
760 return _sourceWithEvent[e.
id()].begin();
770 require(Exception, _events.find(e) != _events.end(),
771 "endOfSourceStateOfEvent: the event does not belong to the component");
772 return _sourceWithEvent[e.
id()].end();
783 require(Exception, _events.find(e) != _events.end(),
784 "beginOfTargetStateOfEvent: the event does not belong to the component");
785 return _targetWithEvent[e.
id()].begin();
795 require(Exception, _events.find(e) != _events.end(),
796 "endOfTargetStateOfEvent: the event does not belong to the component");
797 return _targetWithEvent[e.
id()].end();
807 require(Exception, _events.find(e) != _events.end(),
808 "eventTransitionBegin: the event does not belong to the component");
809 return _transitionsWithEvent[e.
id()].begin();
818 require(Exception, _events.find(e) != _events.end(),
819 "eventTransitionEnd: the event does not belong to the component");
820 return _transitionsWithEvent[e.
id()].end();
833 require(Exception, e.
isValid(),
"outputEventTransitionBegin: the event is invalid");
834 require(Exception, _events.find(e) != _events.end(),
835 Msg(
"outputEventTransitionBegin: the event '%1%' does not belong to the component") % e);
836 require(Exception,s.valid(),
"outputEventTransitionBegin: invalid state");
837 require(Exception,&s.owner() == &
_behav,
"outputEventTransitionBegin: the state does not belong to this component");
838 return _transitionsWithSource[e.
id()][s].begin();
851 require(Exception, _events.find(e) != _events.end(),
852 Msg(
"outputEventTransitionEnd: the event '%1%' does not belong to the component")% e);
853 require(Exception,s.valid(),
"outputEventTransitionEnd: invalid state");
854 require(Exception,&s.owner() == &
_behav,
"outputEventTransitionEnd: the state does not belong to this component");
855 return _transitionsWithSource[e.
id()][s].end();
868 require(Exception, _events.find(e) != _events.end(),
869 Msg(
"inputEventTransitionBegin: the event '%1%' does not belong to the component") % e);
870 require(Exception,s.valid(),
"inputEventTransitionBegin: invalid state");
871 require(Exception,&s.owner() == &
_behav,
"inputEventTransitionBegin: the state does not belong to this component");
872 return _transitionsWithTarget[e.
id()][s].begin();
885 require(Exception, _events.find(e) != _events.end(),
886 Msg(
"inputEventTransitionEnd: the event '%1%' does not belong to the component")% e);
887 require(Exception,s.valid(),
"inputEventTransitionEnd: invalid state");
888 require(Exception,&s.owner() == &
_behav,
"inputEventTransitionEnd: the state does not belong to this component");
889 return _transitionsWithTarget[e.
id()][s].end();
915 require(Exception, s.valid(),
"outputTransitionBegin: the state is not valid");
916 require(Exception, &s.owner() == &
_behav,
"outputTransitionBegin: the state does not belong to the component");
917 return s.outEdgeBegin();
926 require(Exception, s.valid(),
"outputTransitionEnd: the state is not valid");
927 require(Exception, &s.owner() == &
_behav,
"outputTransitionEnd: the state does not belong to the component");
928 return s.outEdgeEnd();
937 require(Exception, s.valid(),
"inputTransitionBegin: the state is not valid");
938 require(Exception, &s.owner() == &
_behav,
"inputTransitionBegin: the state does not belong to the component");
939 return s.inEdgeBegin();
949 require(Exception, s.valid(),
"inputTransitionEnd: the state is not valid");
950 require(Exception, &s.owner() == &
_behav,
"inputTransitionEnd: the state does not belong to the component");
951 return s.inEdgeEnd();
992 virtual void determine(
const Component * comp,
const unordered_set<State> & acceptors,
993 unordered_set<State> & newAcceptors);
1036 const set<Event> & projectedEvents);
1052 const set<Event> & projectedEvents,
1070 const set<Event> & projectedEvents,
1071 const unordered_set<State> & acceptors,
1072 unordered_set<State> & newAcceptors);
1092 const set<Event> & projectedEvents,
1113 const set<Event> & projectedEvents,
1114 BeliefState & nextBs,
const unordered_set<State> & acceptors,
bool & presenceOfAcceptors)
const;
1153 bool minimize(unordered_set<State> & acceptors);
1198 vector< BeliefState * > & partition);
1255 virtual bool import(
const string & filename);
1367 map<
string, set<string> > & maskEvents);
1380 template<
typename InputIterator>
1383 for(; first!= last; ++first)
1389 template<
typename InputIterator>
1392 for(; first!= last; ++first)
1399 template<
typename InputIterator,
typename Predicate>
1402 for(; first!= last; ++first)
1412 struct GetEvent:
public unary_function<Transition,Event>
1425 typedef enum{NonPredecessor,Predecessor}
Status;
1430 return (*_map)[s]==NonPredecessor;
1441 template<
typename InputIterator>
1447 states.insert(states.end(),first,last);
1448 for(; first!= last; ++first)
1450 status[*first]= Status::Predecessor;
1452 while(!states.empty())
1460 if(status[it->source()] == Status::NonPredecessor)
1462 status[it->source()] = Status::Predecessor;
1463 states.push_back(it->source());
virtual bool component2dot(const string &fileName) const
bool containsEvent(const Event &e) const
Graph::Graph & behaviour()
NodeIterator initValue(NodeIterator begin, NodeIterator end, ConstReference value)
bool sanityCheck(string &log) const
set< Event > _faultyEvents
const Component * ConstPointer
virtual bool parseDesCompFaultyEvents(istream &stream)
bool isInitial(State state) const
virtual bool parseDesCompMaskedEvents(istream &stream, unsigned number, map< string, set< string > > &maskEvents)
Diades::Graph::EdgeMap< Event > _eventOfTransition
unsigned numberOfEvents() const
Diades::Utils::Exception< Component > Exception
OutputEventTransitionIterator outputEventTransitionBegin(State s, Event e) const
Diades::Graph::Edge Transition
virtual bool parseDesCompStates(istream &stream)
GraphIterator< Edge > EdgeIterator
Diades::Graph::NodeMap< int > _isInitial
void setNormal(const Event &e)
void setId(int identifier)
static const string defaultComponentName
EventIterator faultyEventBegin() const
EdgeSizeType numberOfEdges() const
StateIterator stateBegin() const
void init(Graph &g, SizeType capacity=0, ValueType dflt=ValueType())
bool operator!=(const Component &component) const
bool isFaulty(const Event &e) const
void splitPartition2(const BeliefState *bigQ0, const BeliefState *bigQ1, Event littleA, BeliefState *bigQ0prime, BeliefState *bigQ0MinusbigQ0prime, State sinkState) const
const StateLabel & getLabel(State state) const
EventTransitionIterator eventTransitionEnd(const Event &e) const
vector< unordered_set< State > > _targetWithEvent
virtual bool parseDesCompObservableEvents(istream &stream)
#define ensure(Exception, expr, message)
const set< Event > & faultyEvents() const
StateIterator stateEnd() const
vector< list< Transition > > _transitionsWithEvent
Diades::Graph::NodeMap< StateLabel > _labelOfState
LabelledStateIterator endOfSourceStateOfEvent(const Event &e) const
InputTransitionIterator inputTransitionBegin(State s) const
OutputEventTransitionIterator outputEventTransitionEnd(State s, Event e) const
void reachableStates(const BeliefState &bs, Event event, const set< Event > &projectedEvents, BeliefState &nextBs) const
TransitionIterator transitionEnd() const
unordered_set< State >::const_iterator LabelledStateIterator
void deleteState(State state)
unordered_set< State >::const_iterator InitialStateIterator
virtual bool parseDesCompName(istream &stream)
InitialStateIterator initialStateEnd() const
bool isNormal(const Event &e) const
Diades::Graph::NodeIterator StateIterator
EventIterator faultyEventEnd() const
const Event & operator()(Transition t) const
void deleteTransition(Transition t)
InputEventTransitionIterator inputEventTransitionEnd(State s, Event e) const
unsigned numberOfInitialStates() const
virtual bool importDesCompModel(const string &filename)
LabelledStateIterator endOfTargetStateOfEvent(const Event &e) const
void setName(const string &name)
set< Event > _normalEvents
const string & name() const
bool isDeterministic() const
static string typeName()
the name by default
unsigned numberOfTransitions() const
ConstPointer getPointer() const
const set< Event > & normalEvents() const
GraphIterator< Node > NodeIterator
InputTransitionIterator inputTransitionEnd(State s) const
InitialStateIterator initialStateBegin() const
void setInitial(State state)
unsigned numberOfStates() const
State getState(const StateLabel &label) const
list< Transition >::const_iterator EventTransitionIterator
void init(Graph &g, SizeType capacity=0, ValueType dflt=ValueType())
EventIterator normalEventBegin() const
#define require(Exception, expr, message)
LabelledStateIterator beginOfSourceStateOfEvent(const Event &e) const
Diades::Graph::OutEdgeIterator OutputTransitionIterator
EventTransitionIterator eventTransitionBegin(const Event &e) const
Namespace of the Diades project.
void splitPartition(const BeliefState *bigQ0, const BeliefState *bigQ1, Event littleA, BeliefState *bigQ0prime, BeliefState *bigQ0MinusbigQ0prime) const
const Graph::Graph & behaviour() const
EventIterator eventBegin() const
vector< Diades::Graph::NodeMap< unordered_set< Transition > > > _transitionsWithSource
virtual bool project(const Component *comp, const set< Event > &projectedEvents)
virtual bool parseDesCompNormalEvents(istream &stream)
OutputTransitionIterator outputTransitionBegin(State s) const
State mergeStates(BeliefState &states)
list< Edge >::iterator OutEdgeIterator
EventIterator normalEventEnd() const
NonPredecessorFunctor(NodeMap< Status > *mapPredecessor)
Diades::Graph::Graph _behav
Diades::Utils::Log log(Log::Level level, const char *msg)
LabelledStateIterator beginOfTargetStateOfEvent(const Event &e) const
Diades::Graph::InEdgeIterator InputTransitionIterator
TransitionIterator transitionBegin() const
unordered_set< Transition >::const_iterator OutputEventTransitionIterator
const Event & getEvent(Transition t) const
Diades::Graph::EdgeIterator TransitionIterator
void purgeNonPredecessors(Component &comp, InputIterator first, InputIterator last)
virtual bool exportDesCompModel(const string &filename) const
void insertEvent(const Event &event)
vector< unordered_set< State > > _sourceWithEvent
EventIterator eventEnd() const
set< Event >::const_iterator EventIterator
vector< Diades::Graph::NodeMap< unordered_set< Transition > > > _transitionsWithTarget
Diades::Graph::Node State
void unsetInitial(State state)
list< Edge >::iterator InEdgeIterator
Transition newTransition(State source, State target, Event event)
void setAllInitialStates()
unordered_map< StateLabel, State > _stateOfLabel
bool operator==(const Component &component) const
const set< Event > & events() const
bool operator()(State s) const
unordered_set< Transition >::const_iterator InputEventTransitionIterator
void nerodePartition(vector< BeliefState * > &partition) const
void replaceEvent(const Event &e1, const Event &e2)
virtual void mergeInfoStates(const vector< const Component *> &components, const vector< State > &states, State currentState)
virtual bool parseDesCompTransitions(istream &stream)
NodeSizeType numberOfNodes() const
void setFaulty(const Event &e)
GetEvent(const Component &component)
OutputTransitionIterator outputTransitionEnd(State s) const
void clearAllInitialStates()
unordered_set< State > _initial
InputEventTransitionIterator inputEventTransitionBegin(State s, Event e) const
virtual void determine(const Component *comp, const unordered_set< State > &acceptors, unordered_set< State > &newAcceptors)