public static bool isMatch(SafraTreeTemplate temp, SafraTree tree) { return temp.matches(tree); }
/** * Search for a mapping, fuzzily * @param result the query * @return the corresponding state or NULL otherwise */ public DA_State find(SafraTreeTemplate result) { //map_type::const_iterator it; AbstractedKeyType search_key = new AbstractedKeyType(result.getState()); //it = _map.find(search_key); if (_map.ContainsKey(search_key)) { ValueList list = _map[search_key]; int count = 0; while (list != null) { // check to see if we are compatible if (SafraTreeCandidateMatcher.isMatch(result, list._key)) { //std::cerr << "Found: "<< count << std::endl; return list._state; } // std::cerr << "Tree: "<< *list->_tree; list = list._next; count++; } // std::cerr << "Not found: "<< count << std::endl; } // not found return null; }
public STVisitor_check_children_vertical(SafraTreeTemplate tree_template) { _tree_template = tree_template; }
public STVisitor_remove_subtree(SafraTreeTemplate tree_template) { _tree_template = tree_template; }
/** * Constructor. * @param final_states the states that are accepting (final) in the NBA * @param tree_template the tree template to keep track of new nodes */ public STVisitor_check_finalset(BitSet final_states, SafraTreeTemplate tree_template) { _final_states = final_states; _tree_template = tree_template; }
/** * Constructor * @param nba_states_with_all_succ_final A BitSet with the indizes of the * NBA states that only have accepting (final) * successors. * @param tree_template SafraTreeTemplate to keep track of removed nodes */ public STVisitor_check_for_succ_final(BitSet nba_states_with_all_succ_final, SafraTreeTemplate tree_template) { _success = false; _nba_states_with_all_succ_final = nba_states_with_all_succ_final; _tree_template = tree_template; }
/** * Get the next Safra tree using the * transition function as described by Safra. * @param tree the original tree * @param elem the edge label * @return a SafraTreeTemplate containing the new tree and * bookkeeping which states were created/deleted. */ SafraTreeTemplate process(SafraTree tree, APElement elem) { // Make copy of original tree SafraTree cur = new SafraTree(tree); SafraTreeTemplate tree_template = new SafraTreeTemplate(cur); STVisitor_reset_final_flag stv_reset_flag = new STVisitor_reset_final_flag(); cur.walkTreePostOrder(stv_reset_flag); ////#if NBA2DRA_POWERSET_FIRST // STVisitor_powerset stv_powerset = new STVisitor_powerset(_nba, elem); // cur.walkTreePostOrder(stv_powerset); // STVisitor_check_finalset stv_final = new STVisitor_check_finalset(_nba_analysis.getFinalStates(), tree_template); // cur.walkTreePostOrder(stv_final); //#else /////////generate new child STVisitor_check_finalset stv_final = new STVisitor_check_finalset(_nba_analysis.getFinalStates(), tree_template); cur.walkTreePostOrder(stv_final); //////////change the old label to new label using powerset STVisitor_powerset stv_powerset = new STVisitor_powerset(_nba, elem); cur.walkTreePostOrder(stv_powerset); //#endif /* * Optimization: ACCEPTING_TRUE_LOOPS */ if (_options.opt_accloop)///////////how to decide the value? { if (cur.getRootNode() != null) { SafraTreeNode root = cur.getRootNode(); if (_nba_analysis.getStatesWithAcceptingTrueLoops().intersects(root.getLabeling())) { // True Loop STVisitor_remove_subtree stv_remove = new STVisitor_remove_subtree(tree_template); cur.walkChildrenPostOrder(stv_remove, root); root.getLabeling().clear(); int canonical_true_loop = _nba_analysis.getStatesWithAcceptingTrueLoops().nextSetBit(0); root.getLabeling().set(canonical_true_loop); root.setFinalFlag(true); return(tree_template); } } } //check if the younger child has the same labels of older ones. If so, remove the same labels from younger child STVisitor_check_children_horizontal stv_horizontal = new STVisitor_check_children_horizontal();/////////note sth wrong cur.walkTreePostOrder(stv_horizontal); //check if a node becomes empty. If so, remove it. STVisitor_check_children_horizontal.STVisitor_check_children_vertical.STVisitor_remove_empty stv_empty = new STVisitor_check_children_horizontal.STVisitor_check_children_vertical.STVisitor_remove_empty(tree_template); cur.walkTreePostOrder(stv_empty); //check if a node's children's labels union is same with itself's. If so, remove the children and mark this node. STVisitor_check_children_horizontal.STVisitor_check_children_vertical stv_vertical = new STVisitor_check_children_horizontal.STVisitor_check_children_vertical(tree_template); cur.walkTreePostOrder(stv_vertical); /* * Optimization: REORDER */ if (_options.opt_reorder)//////// { if (stv_reorder == null) { stv_reorder = new STVisitor_check_children_horizontal.STVisitor_check_children_vertical.STVisitor_reorder_children(_nba_analysis.getReachability(), cur.getNodeMax()); } cur.walkTreePostOrder(stv_reorder); } /* * Optimization: ALL SUCCESSORS ARE ACCEPTING */ if (_options.opt_accsucc)//////// { STVisitor_check_children_horizontal.STVisitor_check_children_vertical.STVisitor_check_for_succ_final stv_succ = new STVisitor_check_children_horizontal.STVisitor_check_children_vertical.STVisitor_check_for_succ_final(_nba_analysis.getStatesWithAllSuccAccepting(), tree_template); cur.walkTreePostOrder(stv_succ); if (stv_succ.wasSuccessful()) { #if NBA2DRA_MERGE if (stv_succ.wasMerged()) { SafrasAlgorithmInternal::STVisitor_remove_empty stv_empty; cur.walkTreePostOrder(stv_empty); SafrasAlgorithmInternal::STVisitor_check_children_vertical stv_vertical; cur.walkTreePostOrder(stv_vertical); } #endif // NBA2DRA_MERGE } } return(tree_template); }