9 #ifndef __DIADES__AUTOMATA__EXPERIMENTAL__MINIMIZE__HH 10 #define __DIADES__AUTOMATA__EXPERIMENTAL__MINIMIZE__HH 12 #include<unordered_map> 25 namespace Experimental {
48 template<
typename Fsm>
53 typename Fsm::EventPropertyId littleA,
59 if (bigQ0->size() <= 1) {
63 for (
auto state : bigQ0->setOfNodes()) {
64 auto transIt = machine.outputEventTransitionBegin(state, littleA);
65 if (transIt == machine.outputEventTransitionEnd(state, littleA)) {
67 if (bigQ1->isEmpty()) {
68 bigQ0prime->insertNode(state);
70 bigQ0MinusbigQ0prime->insertNode(state);
75 if (bigQ1->isEmpty()) {
76 bigQ0MinusbigQ0prime->insertNode(state);
79 if (bigQ1->findNode(transIt->target()) != bigQ1->end()) {
80 bigQ0prime->insertNode(state);
82 bigQ0MinusbigQ0prime->insertNode(state);
87 if ((bigQ0->size() == bigQ0prime->size()) ||
88 (bigQ0->size() == bigQ0MinusbigQ0prime->size())) {
90 bigQ0prime->setOfNodes().clear();
91 bigQ0MinusbigQ0prime->setOfNodes().clear();
112 template<
typename Fsm>
117 using BelStatePtr = std::shared_ptr<BelState>;
118 using EventInfo =
typename Fsm::EventPropertyId;
132 auto bs = std::make_shared<BelState>(machine);
133 bs->insertStates(machine.stateBegin(), machine.stateEnd());
134 partition.push_back(bs);
141 auto sinkState = std::make_shared<BelState>(machine);
142 partition.push_back(sinkState);
143 auto allState = std::make_shared<BelState>(machine);
144 allState->insertStates(machine.stateBegin(), machine.stateEnd());
145 partition.push_back(allState);
151 std::unordered_map<EventInfo, std::set<BelStatePtr> > bigL;
154 std::for_each(machine.eventBegin(), machine.eventEnd(),
156 bigL[e].insert(sinkState); });
159 while (!bigL.empty()) {
162 BelStatePtr bigQ1 = *(bigL.begin()->second.begin());
166 bigL.begin()->second.erase(bigL.begin()->second.begin());
167 if (bigL.begin()->second.empty()) {
168 bigL.erase(bigL.begin());
171 size_t oldPartitionSize = partition.size();
173 for (
size_t index = 0; index < oldPartitionSize; ++index)
176 auto bigQ0 = partition[index];
177 auto bigQ0prime = std::make_shared<BelState>(machine);
178 auto bigQ0MinusbigQ0prime = std::make_shared<BelState>(machine);
179 if (
splitPartition(machine, bigQ0, bigQ1, a, bigQ0prime, bigQ0MinusbigQ0prime)) {
181 partition[index] = bigQ0prime;
182 partition.push_back(bigQ0MinusbigQ0prime);
184 for (
auto littleB : machine.events()) {
185 auto & bss = bigL[littleB];
186 if (bss.find(bigQ0) != bss.end()) {
189 bss.insert(bigQ0prime);
190 bss.insert(bigQ0MinusbigQ0prime);
193 if (bigQ0prime->size() <= bigQ0MinusbigQ0prime->size()) {
194 bss.insert(bigQ0prime);
196 bss.insert(bigQ0MinusbigQ0prime);
223 template<
typename Fsm,
typename StateCreator>
226 Fsm & minimalMachine,
227 StateCreator & creator) {
229 using BsPointer = std::shared_ptr < Bs >;
231 std::vector<BsPointer> partition;
240 auto partIt = partition.begin();
241 if ((*partIt)->isEmpty()) {
244 abstract(machine, minimalMachine,
246 BsIterator(partition.end()),
334 template<
typename Fsm,
typename StateCreator>
337 Fsm & minimalMachine,
338 StateCreator & creator) {
339 if (machine.numberOfInitialStates() == 0) {
340 minimalMachine.clear();
FaultyEventStateMachine< CandidateId, EventInfoId > Fsm
void nerodePartition(const Fsm &machine, vector< std::shared_ptr< BeliefState< Fsm >>> &partition)
void minimizeDeterministicMachine(const Fsm &machine, Fsm &minimalMachine, StateCreator &creator)
Namespace of the Diades project.
bool isComplete(const Fsm &machine)
void minimize(const Fsm &machine, Fsm &minimalMachine, StateCreator &creator)
bool isDeterministic(const Fsm &machine)
bool splitPartition(const Fsm &machine, const std::shared_ptr< BeliefState< Fsm >> bigQ0, const std::shared_ptr< BeliefState< Fsm >> bigQ1, typename Fsm::EventPropertyId littleA, std::shared_ptr< BeliefState< Fsm >> bigQ0prime, std::shared_ptr< BeliefState< Fsm >> bigQ0MinusbigQ0prime)