Beispiel #1
0
        /** Node visitor */
        public void visit(SafraTree tree, SafraTreeNode node)
        {
            BitSet new_labeling = new BitSet();

            BitSet old_labeling = node.getLabeling();

            for (int i = old_labeling.nextSetBit(0); i != -1; i = old_labeling.nextSetBit(i + 1))
            {
                new_labeling.Union(_nba[i].getEdge(_elem));//////////////generate new label.
            }

            node.getLabeling().Assign(new_labeling);
        }
Beispiel #2
0
        /** */
        public void visit(SafraTree tree, SafraTreeNode node)
        {
            if (_final_states.intersects(node.getLabeling()))//////////if this node has the state in accepting states of NBA
            {
                BitSet q_and_f = new BitSet(_final_states);
                q_and_f.Intersect(node.getLabeling());////////////////get the intersect of the label and the accepting states

                SafraTreeNode new_child = tree.newNode();
                node.addAsYoungestChild(new_child);

                _tree_template.setRenameable(new_child.getID());

                new_child.getLabeling().Assign(q_and_f);
            }
        }
Beispiel #3
0
                /** Node visitor */
                public void visit(SafraTree tree, SafraTreeNode node)
                {
                    bool all_final = true;

                    //for (BitSetIterator it=BitSetIterator(node->getLabeling());it!=BitSetIterator::end(node->getLabeling());++it)
                    //BitSet label_this = node.getLabeling();
                    //for (int it = 0; it < label_this.Count; it++)
                    for (int it = BitSetIterator.start(node.getLabeling()); it != BitSetIterator.end(node.getLabeling()); it = BitSetIterator.increment(node.getLabeling(), it))
                    {
                        ////	if (!_nba_states_with_all_succ_final.get(*it)) {
                        if (!_nba_states_with_all_succ_final.get(it))
                        {
                            all_final = false;
                            break;
                        }
                    }

                    if (all_final)
                    {
                        // remove all children of node & set final flag
                        STVisitor_remove_subtree stv_remove = new STVisitor_remove_subtree(_tree_template);
                        tree.walkChildrenPostOrder(stv_remove, node);

                        node.setFinalFlag();

                        _success = true;
                    }
                }
Beispiel #4
0
            /** Node visitor */
            public void visit(SafraTree tree, SafraTreeNode node)
            {
                if (node.getChildCount() == 0)
                {
                    return;
                }

                BitSet labeling_union = new BitSet();
                //for (SafraTreeNode::child_iterator it=node->children_begin();it!=node->children_end();++it)
                SafraTreeNode it = node.children_begin();

                while (it != node.children_end())
                {
                    labeling_union.Union(it.getLabeling());
                    it = it.increment();
                }

                if (labeling_union == node.getLabeling())
                {
                    // The union of the labelings of the children is exactly the
                    // same as the labeling of the parent ->
                    //  remove children
                    STVisitor_remove_subtree stv_remove = new STVisitor_remove_subtree(_tree_template);
                    tree.walkChildrenPostOrder(stv_remove, node);

                    node.setFinalFlag(true);///////////should be "+ i", means in Li
                }
            }
Beispiel #5
0
        /** Node visitor */
        public void visit(SafraTree tree, SafraTreeNode node)
        {
            if (node.getChildCount() <= 1)
            {
                return;
            }

            BitSet already_seen = new BitSet();
            bool   first        = true;
            //for (SafraTreeNode::child_iterator it=node->children_begin();it!=node->children_end();++it)
            SafraTreeNode it = node.children_begin();

            while (it != node.children_end())
            {
                SafraTreeNode cur_child = it;
                if (first)
                {
                    already_seen = new BitSet(cur_child.getLabeling()); ////////////get the NBA states in child
                    first        = false;
                    it           = it.increment();                      ////////note added
                }
                else
                {
                    BitSet current = new BitSet(cur_child.getLabeling());

                    BitSet intersection = new BitSet(already_seen); // make copy
                    if (intersection.intersects(current))
                    {
                        // There are some labels, which occur in older brothers,
                        // remove them from current node and its children
                        STVisitor_subtract_labeling stv_sub = new STVisitor_subtract_labeling(intersection);
                        tree.walkSubTreePostOrder(stv_sub, cur_child);
                    }

                    already_seen.Union(current);
                    it = it.increment();
                }
            }
        }
Beispiel #6
0
        /**
         * Compare two subtrees to see if they match (taking into account the renameableNames
         * and the restrictedNames).
         */
        public bool matches(SafraTreeNode this_node, SafraTreeNode other_node)
        {
            Debug.Assert(this_node != null && other_node != null);

            if (this_node == null || other_node == null)
            {
                return(false);
            }

            if (!renameableNames().get(this_node.getID()))
            {
                // this is not a new node, so we require a perfect match..
                if (other_node.getID() != this_node.getID())
                {
                    return(false);
                }
            }
            else
            {
                // we are flexible with the id, as long as the id wasn't removed
                //  in the tree
                if (restrictedNames().get(other_node.getID()))
                {
                    return(false);
                }
            }

            Debug.Assert(this_node.getLabeling() == other_node.getLabeling());
            Debug.Assert(this_node.hasFinalFlag() == other_node.hasFinalFlag());

            // this node looks good, now the children
            SafraTreeNode this_child  = this_node.getOldestChild();
            SafraTreeNode other_child = other_node.getOldestChild();

            while (this_child != null && other_child != null)
            {
                if (!matches(this_child, other_child))
                {
                    return(false);
                }

                this_child  = this_child.getYoungerBrother();
                other_child = other_child.getYoungerBrother();
            }
            Debug.Assert(this_child == null && other_child == null);

            return(true);
        }
Beispiel #7
0
                /** Node visitor */
                public void visit(SafraTree tree, SafraTreeNode node)
                {
                    if (node.getLabeling().isEmpty())
                    {
                        int id = node.getID();
                        if (_tree_template.isRenameable(id))
                        {
                            // this node was created recently, so we only delete it in
                            // renameableNames, but don't mark it in restrictedNodes
                            _tree_template.setRenameable(id, false);
                        }
                        else
                        {
                            _tree_template.setRestricted(id);
                        }

                        tree.remove(node);
                    }
                }
Beispiel #8
0
            /** Node visitor */
            public void visit(SafraTree tree, SafraTreeNode node)
            {
                if (node.getChildCount() == 0) { return; }

                BitSet labeling_union = new BitSet();
                //for (SafraTreeNode::child_iterator it=node->children_begin();it!=node->children_end();++it)
                SafraTreeNode it = node.children_begin();
                while (it != node.children_end())
                {
                    labeling_union.Union(it.getLabeling());
                    it = it.increment();
                }

                if (labeling_union == node.getLabeling())
                {
                    // The union of the labelings of the children is exactly the
                    // same as the labeling of the parent ->
                    //  remove children
                    STVisitor_remove_subtree stv_remove = new STVisitor_remove_subtree(_tree_template);
                    tree.walkChildrenPostOrder(stv_remove, node);

                    node.setFinalFlag(true);///////////should be "+ i", means in Li
                }
            }
Beispiel #9
0
 public void visit(SafraTree tree, SafraTreeNode node)
 {
     node.getLabeling().Minus(_bitset);
 }
Beispiel #10
0
        /** Node visitor */
        public void visit(SafraTree tree, SafraTreeNode node)
        {
            BitSet new_labeling = new BitSet();

            BitSet old_labeling = node.getLabeling();
            for (int i = old_labeling.nextSetBit(0); i != -1; i = old_labeling.nextSetBit(i + 1))
            {
                new_labeling.Union(_nba[i].getEdge(_elem));//////////////generate new label.
            }

            node.getLabeling().Assign(new_labeling);
        }
Beispiel #11
0
        /** */
        public void visit(SafraTree tree, SafraTreeNode node)
        {
            if (_final_states.intersects(node.getLabeling()))//////////if this node has the state in accepting states of NBA
            {
                BitSet q_and_f = new BitSet(_final_states);
                q_and_f.Intersect(node.getLabeling());////////////////get the intersect of the label and the accepting states

                SafraTreeNode new_child = tree.newNode();
                node.addAsYoungestChild(new_child);

                _tree_template.setRenameable(new_child.getID());

                new_child.getLabeling().Assign(q_and_f);
            }
        }
Beispiel #12
0
                /** Node visitor */
                public void visit(SafraTree tree, SafraTreeNode node)
                {
                    if (node.getLabeling().isEmpty())
                    {
                        int id = node.getID();
                        if (_tree_template.isRenameable(id))
                        {
                            // this node was created recently, so we only delete it in
                            // renameableNames, but don't mark it in restrictedNodes
                            _tree_template.setRenameable(id, false);
                        }
                        else
                        {
                            _tree_template.setRestricted(id);
                        }

                        tree.remove(node);
                    }
                }
Beispiel #13
0
                /** Node visitor */
                public void visit(SafraTree tree, SafraTreeNode node)
                {
                    bool all_final = true;
                    //for (BitSetIterator it=BitSetIterator(node->getLabeling());it!=BitSetIterator::end(node->getLabeling());++it)
                    //BitSet label_this = node.getLabeling();
                    //for (int it = 0; it < label_this.Count; it++)
                    for (int it = BitSetIterator.start(node.getLabeling()); it != BitSetIterator.end(node.getLabeling()); it = BitSetIterator.increment(node.getLabeling(), it))
                    {
                        ////	if (!_nba_states_with_all_succ_final.get(*it)) {
                        if (!_nba_states_with_all_succ_final.get(it))
                        {
                            all_final = false;
                            break;
                        }
                    }

                    if (all_final)
                    {
                        // remove all children of node & set final flag
                        STVisitor_remove_subtree stv_remove = new STVisitor_remove_subtree(_tree_template);
                        tree.walkChildrenPostOrder(stv_remove, node);

                        node.setFinalFlag();

                        _success = true;
                    }
                }
Beispiel #14
0
                /** Node visitor */
                public void visit(SafraTree tree, SafraTreeNode node)
                {
                    if (node.getChildCount() <= 1)
                    {
                        return;
                    }

                    int i = 0;
                    //for (SafraTreeNode::child_iterator it= node->children_begin(); it!=node->children_end();++it)
                    SafraTreeNode it = node.children_begin();

                    while (it != node.children_end())
                    {
                        BitSet reachable_this = _node_reachability[it.getID()];
                        reachable_this.clear();
                        _node_order[it.getID()] = i++;

                        BitSet label_this = it.getLabeling();
                        //for (BitSetIterator label_it(label_this); label_it != BitSetIterator::end(label_this); ++label_it)
                        for (int label_it = 0; label_it < label_this.Count; label_it++)
                        {
                            reachable_this.Union(_nba_reachability[label_it]);
                        }

                        //      std::cerr << "reachability_this: "<<reachable_this << std::endl;
                        it = it.increment();
                    }


                    // reorder...
                    //    std::cerr << "Sorting!" << std::endl;

                    // Bubble sort, ough!
                    bool finished = false;

                    while (!finished)
                    {
                        finished = true;

                        for (SafraTreeNode a = node.getOldestChild(); a != null && a.getYoungerBrother() != null; a = a.getYoungerBrother())
                        {
                            SafraTreeNode b = a.getYoungerBrother();

                            BitSet reach_a = _node_reachability[a.getID()];
                            BitSet reach_b = _node_reachability[b.getID()];

                            if (reach_a.intersects(reach_b))
                            {
                                // a and b are not independant...
                                // --> keep relative order...
                                System.Diagnostics.Debug.Assert(_node_order[a.getID()] < _node_order[b.getID()]);
                            }
                            else
                            {
                                // a and b are independant...
                                if (!(a.getLabeling() < b.getLabeling()))
                                {
                                    // swap
                                    node.swapChildren(a, b);
                                    a        = b;
                                    finished = false;
                                }
                            }
                        }
                    }
                }
Beispiel #15
0
 public void visit(SafraTree tree, SafraTreeNode node)
 {
     node.getLabeling().Minus(_bitset);
 }