public List <BitSet> getReachabilityForAllStates() { //std::vector<BitSet>* v=new std::vector<BitSet>; //v->resize(_state_to_scc.size()); List <BitSet> v = new List <BitSet>(); Ultility.resizeExact(v, _state_to_scc.Count); for (int i = 0; i < _state_to_scc.Count; ++i) { int scc = state2scc(i); BitSet reachable_sccs = _reachability[scc]; BitSet reachable_states = new BitSet(); //for (BitSetIterator it(reachable_sccs); it != BitSetIterator::end(reachable_sccs); ++it) for (int it = BitSetIterator.start(reachable_sccs); it != BitSetIterator.end(reachable_sccs); it = BitSetIterator.increment(reachable_sccs, it)) { // union with all states from the reachable scc reachable_states.Union(_sccs[it]); } v[i] = reachable_states; //std::cerr << "from "<<i<<": "<<reachable_states<<std::endl; } return(v); }
/** A shared_ptr to a TreeWithAcceptance */ //typedef boost::shared_ptr<TreeWithAcceptance<Tree,AcceptanceSignature> > ptr; /** Check if this TreeWithAcceptance is equal to another. * @param other the other TreeWithAcceptance. * @return true iff the two are equal */ public static bool operator ==(TreeWithAcceptance one, TreeWithAcceptance other) { bool?val = Ultility.NullCheck(one, other); if (val != null) { return(val.Value); } return((one._tree == other.getTree()) && (one._signature == other.getSignature())); }
/** Compare to other signature for equality. */ public static bool operator ==(RabinSignature one, RabinSignature other) { bool?val = Ultility.NullCheck(one, other); if (val != null) { return(val.Value); } return(one._L == other._L && one._U == other._U); }
/** * Check for equality. * @param other the other APElement * @return <b>true</b> if this and the other APElement are equal. */ public static bool operator ==(APElement one, APElement other) { bool?val = Ultility.NullCheck(one, other); if (val != null) { return(val.Value); } return(one.getBitSet() == other.getBitSet()); }
/** * Checks for equality. * @param other the other APMonom * @return <b>true</b> if this and the other APMonom are equal */ public static bool operator ==(APMonom one, APMonom other) { bool?val = Ultility.NullCheck(one, other); if (val != null) { return(val.Value); } return((one.getValueBits() == other.getValueBits()) && (one.getSetBits() == other.getSetBits())); }
public static bool operator ==(AbstractedKeyType one, AbstractedKeyType other) { bool?val = Ultility.NullCheck(one, other); if (val != null) { return(val.Value); } return(SafraTreeCandidateMatcher.abstract_equal_to(one._key, other._key)); }
/** Compare this state to another for equality. * @param other the other UnionState * @returns true iff the two states are equal */ public static bool operator ==(UnionState one, UnionState other) { bool?val = Ultility.NullCheck(one, other); if (val != null) { return(val.Value); } return(one.da_state_1 == other.da_state_1 && one.da_state_2 == other.da_state_2); // we don't have to check the signature as there is a // 1-on-1 mapping between <da_state_1, da_state_2> -> signature }
//add this code to class ThreeDPoint as defined previously // public static bool operator ==(SafraTreeNode a, SafraTreeNode b) { bool?val = Ultility.NullCheck(a, b); if (val != null) { return(val.Value); } if (!(a._id == b._id)) { return(false); } if (!(a._final_flag == b._final_flag)) { return(false); } if (!(a._childCount == b._childCount)) { return(false); } if (!(a._labeling == b._labeling)) { return(false); } if (!NULL_OR_EQUALID(a._parent, b._parent)) { return(false); } if (!NULL_OR_EQUALID(a._olderBrother, b._olderBrother)) { return(false); } if (!NULL_OR_EQUALID(a._youngerBrother, b._youngerBrother)) { return(false); } if (!NULL_OR_EQUALID(a._oldestChild, b._oldestChild)) { return(false); } if (!NULL_OR_EQUALID(a._youngestChild, b._youngestChild)) { return(false); } return(true); }
/** * Create a new color * @return the newly created color */ public int newColor() { _nr_of_colors++; //_color2state.resize(_nr_of_colors); Ultility.resize(_color2state, _nr_of_colors); if (_detailed) { //_color2states->resize(_nr_of_colors); Ultility.resize(_color2states, _nr_of_colors); } return(_nr_of_colors - 1); }
/** * Constructor, get initial size of the coloring from DRA. * @param dra the DRA * @param detailed Keep detailed information on the equivalence classes? */ public Coloring(DRA dra, bool detailed) //=false { _nr_of_colors = 0; _detailed = detailed; _coloring = new List <int>(); Ultility.resize(_coloring, dra.size()); _color2state = new List <int>(); //_coloring.resize(dra.size()); if (_detailed) { _color2states = new List <BitSet>(); } else { _color2states = null; } }
/** Calculate the SCCs*/ public void calculate(bool disjoint) { current_dfs_nr = 0; //_dfs_data.Clear(); // Ensure there are as many entries as there are graph-states //_dfs_data.resize(_graph.size()); //Ultility.resize(_dfs_data, _graph.size()); Ultility.resizeExact(_dfs_data, _graph.size()); scc_nr = 0; NBA_State start_state = _graph.getStartState(); if (start_state == null) { return; } if (!disjoint) { int start_idx = start_state.getName(); visit(start_idx); } else { // The Graph may be disjoint -> restart DFS on every not yet visited state for (int v = 0; v < _graph.size(); ++v) { if (_dfs_data[v] == null) //.get() { // not yet visited visit(v); } } } calculateDAG(); }
/** * Equality operator. */ public static bool operator ==(SafraTree one, SafraTree other) { bool?val = Ultility.NullCheck(one, other); if (val != null) { return(val.Value); } if (other.MAX_NODES != one.MAX_NODES) { return(false); } for (int i = 0; i < one.MAX_NODES; i++) { if (one._nodes[i] == null) { if (other._nodes[i] != null) { return(false); } } else { if (other._nodes[i] == null) { return(false); } if (!(one._nodes[i] == other._nodes[i])) { return(false); } } } return(true); }
/** * Equality check. * @param other the other APSet * @return <b>true</b> if this and the other APSet are equal */ public static bool operator ==(APSet one, APSet other) { bool?val = Ultility.NullCheck(one, other); if (val != null) { return(val.Value); } if (one.size() != other.size()) { return(false); } for (int i = 0; i < one.size(); i++) { if (!(one.getAP(i) == other.getAP(i))) { return(false); } } return(true); }
/** * 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; } } } } }
/** Calculate the stutter closure for the NBA, for all symbols. * @param nba the NBA */ public static NBA stutter_closure(NBA nba) { APSet apset = nba.getAPSet_cp(); NBA nba_result_ptr = new NBA(apset); NBA result = nba_result_ptr; int element_count = apset.powersetSize(); Debug.Assert(nba.getStartState() != null); int start_state = nba.getStartState().getName(); for (int i = 0; i < nba.size(); i++) { int st = result.nba_i_newState(); Debug.Assert(st == i); if (st == start_state) { result.setStartState(result[st]); } if (nba[st].isFinal()) { result[st].setFinal(true); } } for (int i = 0; i < nba.size(); i++) { for (int j = 0; j < element_count; j++) { int st = result.nba_i_newState(); Debug.Assert(st == nba.size() + (i * element_count) + j); result[st].addEdge(new APElement(j), result[i]); result[st].addEdge(new APElement(j), result[st]); } } List <List <BitSet> > reachable = new List <List <BitSet> >(); //reachable.resize(element_count); Ultility.resize(reachable, element_count); for (int j = 0; j < element_count; j++) { //NBAEdgeSuccessors edge_successor = new NBAEdgeSuccessors(new APElement(j)); SCCs scc = new SCCs(); GraphAlgorithms.calculateSCCs(nba, scc, true, new APElement(j)); //,edge_successor reachable[j] = scc.getReachabilityForAllStates(); #if VERBOSE std::cerr << "SCCs for " << APElement(j).toString(*apset) << std::endl; std::cerr << scc << std::endl; std::cerr << " Reachability: " << std::endl; std::vector <BitSet>& reach = *reachable[j]; for (unsigned int t = 0; t < reach.size(); t++) { std::cerr << t << " -> " << reach[t] << std::endl; } std::cerr << " ---\n"; #endif } for (int i = 0; i < nba.size(); i++) { NBA_State from = result[i]; for (int j = 0; j < element_count; j++) { BitSet result_to = new BitSet(); BitSet to = nba[i].getEdge(new APElement(j)); //for (BitSetIterator it=BitSetIterator(*to);it!=BitSetIterator::end(*to);++it) for (int it = BitSetIterator.start(to); it != BitSetIterator.end(to); it = BitSetIterator.increment(to, it)) { int to_state = it; // We can go directly to the original state result_to.set(to_state); // We can also go to the corresponding stutter state instead int stutter_state = nba.size() + (to_state * element_count) + j; result_to.set(stutter_state); // ... and then we can go directly to all the states that are j-reachable from to result_to.Union(reachable[j][to_state]); } from.getEdge(new APElement(j)).Assign(result_to); } } //for (int i=0; i<reachable.size(); ++i) { // delete reachable[i]; // } return(nba_result_ptr); }
/** Calculate the Directed Acyclical Graph (DAG) */ public void calculateDAG() { //_result._dag.Clear(); //_result._dag.resize(_result.countSCCs()); Ultility.resizeExact(_result._dag, _result.countSCCs()); //_result._reachability.resize(_result.countSCCs()); Ultility.resizeExact(_result._reachability, _result.countSCCs()); List <int> in_degree = new List <int>(_result.countSCCs()); Ultility.resizeExact(in_degree, _result.countSCCs()); for (int scc = 0; scc < _result.countSCCs(); ++scc) { _result._reachability[scc] = new BitSet(); _result._dag[scc] = new BitSet(); BitSet states_in_scc = _result[scc]; //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)) { int from_state = it; if (_labelMark == null) { //for (typename SuccessorAccess::successor_iterator succ_it=_successor_access.begin(_graph, from_state);succ_it!=_successor_access.end(_graph, from_state); ++succ_it) for (KeyValuePair <APElement, BitSet> it_set = _graph[from_state].edges_begin(); !_graph[from_state].edges_end(); it_set = _graph[from_state].increment()) { for (int succ_it = BitSetIterator.start(it_set.Value); succ_it != BitSetIterator.end(it_set.Value); succ_it = BitSetIterator.increment(it_set.Value, succ_it)) { int to_state = succ_it; int to_scc = _result.state2scc(to_state); if (to_scc != scc) { // Only successor in the DAG if not the same scc if (!_result._dag[scc].get(to_scc)) { // This SCC is a new successor, increment in_degree in_degree[to_scc]++; _result._dag[scc].set(to_scc); } } // Reachability _result._reachability[scc].set(to_scc); } } } else { BitSet it_set = _graph[from_state].getEdge(_labelMark); //for (typename SuccessorAccess::successor_iterator succ_it=_successor_access.begin(_graph, from_state);succ_it!=_successor_access.end(_graph, from_state); ++succ_it) for (int succ_it = BitSetIterator.start(it_set); succ_it != BitSetIterator.end(it_set); succ_it = BitSetIterator.increment(it_set, succ_it)) { int to_state = succ_it; int to_scc = _result.state2scc(to_state); if (to_scc != scc) { // Only successor in the DAG if not the same scc if (!_result._dag[scc].get(to_scc)) { // This SCC is a new successor, increment in_degree in_degree[to_scc]++; _result._dag[scc].set(to_scc); } } // Reachability _result._reachability[scc].set(to_scc); } } } } bool progress = true; int cnt = 0; //_result._topological_order.Clear(); //_result._topological_order.resize(_result.countSCCs()); Ultility.resizeExact(_result._topological_order, _result.countSCCs()); List <int> sort = new List <int>(_result.countSCCs()); Ultility.resizeExact(sort, _result.countSCCs()); while (progress) { progress = false; for (int scc = 0; scc < _result.countSCCs(); ++scc) { if (in_degree[scc] == 0) { sort[scc] = cnt++; progress = true; in_degree[scc] = -1; //for (BitSetIterator it_neighbors= BitSetIterator(_result._dag[scc]); it_neighbors!=BitSetIterator::end(_result._dag[scc]); ++it_neighbors) for (int it_neighbors = BitSetIterator.start(_result._dag[scc]); it_neighbors != BitSetIterator.end(_result._dag[scc]); it_neighbors = BitSetIterator.increment(_result._dag[scc], it_neighbors)) { int scc_to = it_neighbors; in_degree[scc_to]--; } } } } for (int i = 0; i < _result.countSCCs(); i++) { _result._topological_order[sort[i]] = i; } // traverse SCCs in reverse topological order for (int i = _result.countSCCs(); i > 0; --i) { int cur_scc = _result._topological_order[i - 1]; BitSet reaches = _result._reachability[cur_scc]; //for (BitSetIterator it_neighbors= BitSetIterator(_result._dag[cur_scc]); it_neighbors!=BitSetIterator::end(_result._dag[cur_scc]);++it_neighbors) { for (int it_neighbors = BitSetIterator.start(_result._dag[cur_scc]); it_neighbors != BitSetIterator.end(_result._dag[cur_scc]); it_neighbors = BitSetIterator.increment(_result._dag[cur_scc], it_neighbors)) { int scc_to = it_neighbors; reaches.Union(_result._reachability[scc_to]); } } }