/** * 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; } } } } }
/** Checks to see if NBA has only accepting (final) states. * @return true iff all states are accepting */ public bool areAllStatesFinal() { //for (typename NBA_t::iterator it=_nba.begin(); it!=_nba.end(); ++it) for (int i = 0; i < _nba._index.Count; i++) { NBA_State it = _nba[i]; if (!it.isFinal()) { return(false); } } return(true); }
/** * Remove states from the set of accepting (final) states when this is redundant. * @param sccs the SCCs of the NBA */ public void removeRedundantFinalStates(SCCs sccs) { for (int scc = 0; scc < sccs.countSCCs(); ++scc) { if (sccs[scc].cardinality() == 1) { int state_id = sccs[scc].nextSetBit(0); NBA_State state = this[state_id]; if (state.isFinal()) { if (!sccs.stateIsReachable(state_id, state_id)) { // The state is final and has no self-loop // -> the final flag is redundant state.setFinal(false); // std::cerr << "Removing final flag for " << state_id << std::endl; } } } } }