DiaDes  0.1
DIAgnosis of Discrete-Event System
Determine.hh
Go to the documentation of this file.
1 
9 #ifndef __DIADES__AUTOMATA__DETERMINE__HH
10 #define __DIADES__AUTOMATA__DETERMINE__HH
11 
12 #include<list>
19 
20 
21 namespace Diades
22 {
23  namespace Automata
24  {
25  namespace Experimental
26  {
33  template<typename Fsm>
34  bool
35  isDeterministic(const Fsm & machine) {
36  using State = typename Fsm::State;
37  using Transition = typename Fsm::Transition;
38  return std::find_if(machine.stateBegin(), machine.stateEnd(),
39  [&](State s) {
40  return std::find_if(machine.outputTransitionBegin(s), machine.outputTransitionEnd(s),
41  [&](Transition t) {
42  auto evt = machine.getEvent(t);
43  return (++machine.outputEventTransitionBegin(s, evt)) !=
44  machine.outputEventTransitionEnd(s, evt);
45  }) != machine.outputTransitionEnd(s);
46  }) == machine.stateEnd();
47  }
48 
63  template<typename Fsm, typename StateCreator>
64  void
65  determine(const Fsm & machine,
66  Fsm & deterministicMachine,
67  StateCreator & creator)
68  {
70  &machine != &deterministicMachine,
71  "determine: the determination algorithm cannot be applied on the current StateMachine");
72  deterministicMachine.clear();
73  deterministicMachine.setName("deterministic_" + machine.name());
74  deterministicMachine.copyEventPropertyIds(machine);
75  if (machine.isEmpty() || machine.numberOfInitialStates() == 0) {
76  return;
77  }
78  typedef BeliefState<Fsm> FsmBs;
80  BeliefStateTable bsTable;
81  std::list<typename FsmBs::SharedPtr> bs;
82  std::list<typename Fsm::State> states;
83  bs.push_back(std::make_shared<FsmBs>(machine));
84  bs.back()->insertStates(machine.initialStateBegin(), machine.initialStateEnd());
85  bool found = !bs.back()->isEmpty();
86 
87  if (found) {
88  bool result;
89  typename Fsm::State initialState;
90  std::tie(initialState,result) = creator.newState(*bs.back());
91 
92 
93 
94 
95  states.push_back(bsTable.insertIfNotFound(*bs.back().get(), initialState, found));
96  deterministicMachine.setInitial(initialState);
97 
98  while (!bs.empty()) {
99  auto currentBs = bs.front();
100  auto sourceState = states.front();
101  for (auto & event : machine.events()) {
102  typename FsmBs::SharedPtr newBs = currentBs->nextBeliefState(event);
103  if (newBs->isEmpty()) {
104  newBs.reset();
105  } else {
106  auto targetState = bsTable.getInfo(*newBs.get(),found);
107  if (!found) {
108  std::tie(targetState,result) = creator.newState(*newBs.get());
109  targetState = bsTable.insertIfNotFound(*newBs.get(),targetState,found);
110  bs.push_back(newBs);
111  states.push_back(targetState);
112  } else {
113  newBs.reset();
114  }
115  deterministicMachine.newTransition(sourceState, targetState, event);
116  }
117  }
118  bs.front().reset();
119  bs.pop_front();
120  states.pop_front();
121  }
122  }
123  }
124  }
125  }
126 }
127 
128 
129 
130 #endif /* __DIADES__AUTOMATA__DETERMINE__HH */
131 
Diades::Graph::Edge Transition
Definition: Component.hh:46
FaultyEventStateMachine< CandidateId, EventInfoId > Fsm
StIndexes states
Definition: Run.cc:266
void determine(const Fsm &machine, Fsm &deterministicMachine, StateCreator &creator)
Definition: Determine.hh:65
AutFsm::State State
Definition: Run.cc:72
AutFsm::Transition Transition
Definition: Run.cc:73
#define require(Exception, expr, message)
Definition: Assertion.hh:90
Namespace of the Diades project.
bool isDeterministic(const Fsm &machine)
Definition: Determine.hh:35
Diades::Graph::Node State
Definition: BeliefState.hh:36