/** * Calculate the set of states that are accepting and have a true self loop. */ public void calculateAcceptingTrueLoops() { _accepting_true_loops = new BitSet(); //BitSet isAcceptingTrueLoop= *_accepting_true_loops; BitSet isAcceptingTrueLoop = _accepting_true_loops;////////changed SCCs sccs = getSCCs(); for (int scc = 0; scc < sccs.countSCCs(); ++scc) { if (sccs[scc].cardinality() == 1) { int state_id = sccs[scc].nextSetBit(0); NBA_State state = _nba[state_id]; if (!state.isFinal()) { // not final, consider next continue; } if (!sccs.successors(scc).isEmpty())//////////note here { // there are edges leaving this state, consider next continue; } bool no_empty_to = true; if (sccs.stateIsReachable(state_id, state_id)) { // state has at least one self-loop // we have to check that there is no edge with empty To //for (typename NBA_t::edge_iterator eit=state->edges_begin(); eit!=state->edges_end(); ++eit) //BitSet[] edges = state._edge_manager._container._storage; //foreach (BitSet eit in edges) for (KeyValuePair <APElement, BitSet> eit = state.edges_begin(); !state.edges_end(); eit = state.increment()) { BitSet edge = eit.Value; if (edge.isEmpty()) { // not all edges lead back to the state... no_empty_to = false; break; } } if (no_empty_to) { // When we are here the state is a final true loop isAcceptingTrueLoop.set(state_id); // std::cerr << "True Loop: " << state_id << std::endl; } } } } }
/** * Calculates BitSet which specifies which states in the NBA * only have accepting successors. */ public void calculateStatesWithAllSuccAccepting() { _allSuccAccepting = new BitSet(); BitSet result = _allSuccAccepting; SCCs sccs = getSCCs(); List <bool> scc_all_final = new List <bool>(); Ultility.resize(scc_all_final, sccs.countSCCs()); for (int i = 0; i < scc_all_final.Count; i++) { scc_all_final[i] = false; } for (int i = sccs.countSCCs(); i > 0; --i) { // go backward in topological order... int scc = (sccs.topologicalOrder())[i - 1]; BitSet states_in_scc = sccs[scc]; // check to see if all states in this SCC are final scc_all_final[scc] = true; //for (BitSetIterator it=BitSetIterator(states_in_scc);it!=BitSetIterator::end(states_in_scc);++it) for (int it = BitSetIterator.start(states_in_scc); it != BitSetIterator.end(states_in_scc); it = BitSetIterator.increment(states_in_scc, it)) { if (!_nba[it].isFinal()) { scc_all_final[scc] = false; break; } } bool might_be_final = false; if (scc_all_final[scc] == false) { if (states_in_scc.length() == 1) { // there is only one state in this scc ... int state = states_in_scc.nextSetBit(0); if (sccs.stateIsReachable(state, state) == false) { // ... and it doesn't loop to itself might_be_final = true; } } } if (scc_all_final[scc] == true || might_be_final) { // Check to see if all successors are final... bool all_successors_are_final = true; BitSet scc_succ = sccs.successors(scc); //for (BitSetIterator it=BitSetIterator(scc_succ); it!=BitSetIterator::end(scc_succ); ++it) { for (int it = BitSetIterator.start(scc_succ); it != BitSetIterator.end(scc_succ); it = BitSetIterator.increment(scc_succ, it)) { if (!scc_all_final[it]) { all_successors_are_final = false; break; } } if (all_successors_are_final) { // Add all states in this SCC to the result-set result.Or(states_in_scc); if (might_be_final) { scc_all_final[scc] = true; } } } } }