Exemplo n.º 1
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;
                    }
                }
Exemplo n.º 2
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
                }
            }
Exemplo n.º 3
0
        /**
         * Add a mapping
         * @param key the key
         * @param state the state
         */
        public void add(SafraTree key, DA_State state)
        {
            AbstractedKeyType akey = new AbstractedKeyType(key);
            ValueList         list = new ValueList();

            list._key   = key;
            list._state = state;
            list._next  = null;

            //typename map_type::value_type value (akey, list);

            //std::pair<typename  map_type:: iterator,bool > result = _map.insert(value);



            if (_map.ContainsKey(akey))
            {
                // there is already an element with this structure
                // -> insert list into current list

                ValueList head = _map[akey];
                list._next = head._next;
                head._next = list;

                _map[akey] = head;
            }
            else
            {
                _map.Add(akey, list);
            }

            _count++;
        }
Exemplo n.º 4
0
        /**
         * Less-than operator when ignoring the node names.
         */
        public bool structural_less_than(SafraTree other)
        {
            if (other.MAX_NODES < MAX_NODES)
            {
                return(true);
            }

            SafraTreeNode this_root  = this.getRootNode();
            SafraTreeNode other_root = other.getRootNode();

            if (this_root == null)
            {
                if (other_root != null)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                // this_root !=0
                if (other_root == null)
                {
                    return(false);
                }

                return(this_root.structural_less_than(other_root));
            }
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
0
        /** Node visitor */
        public void visit(SafraTree tree, SafraTreeNode node)
        {
            int id = node.getID();

            if (_tree_template.isRenameable(id))
            {
                // this node was created recently, so we only delete it from
                // the renameableNames, but don't mark it in restrictedNames
                _tree_template.setRenameable(id, false);
            }
            else
            {
                _tree_template.setRestricted(id);
            }

            tree.remove(node);
        }
Exemplo n.º 8
0
        /** Copy constructor. */
        public SafraTree(SafraTree other)
        {
            MAX_NODES = other.MAX_NODES;

            _nodes = new SafraTreeNode[MAX_NODES];
            for (int i = 0; i < MAX_NODES; i++)
            {
                //_nodes[i] = null;
                if (other._nodes[i] != null)
                {
                    _nodes[i] = newNode(i);
                    _nodes[i]._labeling.Assign(other._nodes[i].getLabeling());
                    _nodes[i].setFinalFlag(other._nodes[i].hasFinalFlag());
                }
            }

            copySubTree(_nodes[0], other._nodes[0]);
        }
Exemplo n.º 9
0
        /** Copy constructor. */
        public SafraTree(SafraTree other)
        {
            MAX_NODES = other.MAX_NODES;

            _nodes = new SafraTreeNode[MAX_NODES];
            for (int i = 0; i < MAX_NODES; i++)
            {
                //_nodes[i] = null;
                if (other._nodes[i] != null)
                {
                    _nodes[i] = newNode(i);
                    _nodes[i]._labeling.Assign(other._nodes[i].getLabeling());
                    _nodes[i].setFinalFlag(other._nodes[i].hasFinalFlag());
                }
            }

            copySubTree(_nodes[0], other._nodes[0]);
        }
Exemplo n.º 10
0
        /**
         * Checks equality when ignoring the node names.
         */
        public bool structural_equal_to(SafraTree other)
        {
            if (other.MAX_NODES != MAX_NODES)
            {
                return(false);
            }

            SafraTreeNode this_root  = this.getRootNode();
            SafraTreeNode other_root = other.getRootNode();

            if (this_root == null || other_root == null)
            {
                // return true if both are 0
                return(this_root == other_root);
            }

            return(this_root.structural_equal_to(other_root));
        }
Exemplo n.º 11
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();
                }
            }
        }
Exemplo n.º 12
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();
                }
            }
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
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);
            }
        }
Exemplo n.º 15
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;
                                }
                            }
                        }
                    }
                }
Exemplo n.º 16
0
 public ValueList()
 {
     _state = null;
     _next  = null;
     _key   = null;
 }
Exemplo n.º 17
0
 public AbstractedKeyType(SafraTree key)
 {
     _key = key;
 }
Exemplo n.º 18
0
 /** Node visitor */
 public void visit(SafraTree tree, SafraTreeNode node)
 {
     node.setFinalFlag(false);
 }
Exemplo n.º 19
0
 public void visit(SafraTree tree, SafraTreeNode node)
 {
     node.getLabeling().Minus(_bitset);
 }
Exemplo n.º 20
0
 public void visit(SafraTree tree, SafraTreeNode node)
 {
     node.getLabeling().Minus(_bitset);
 }
Exemplo n.º 21
0
 public static bool isMatch(SafraTreeTemplate temp, SafraTree tree)
 {
     return(temp.matches(tree));
 }
Exemplo n.º 22
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;
                                }
                            }
                        }
                    }
                }
Exemplo n.º 23
0
 public static bool abstract_equal_to(SafraTree t1, SafraTree t2)
 {
     return(t1.structural_equal_to(t2));
 }
Exemplo n.º 24
0
        /** Node visitor */
        public void visit(SafraTree tree, SafraTreeNode node)
        {
            int id = node.getID();
            if (_tree_template.isRenameable(id))
            {
                // this node was created recently, so we only delete it from
                // the renameableNames, but don't mark it in restrictedNames
                _tree_template.setRenameable(id, false);
            }
            else
            {
                _tree_template.setRestricted(id);
            }

            tree.remove(node);
        }
Exemplo n.º 25
0
 /** Node visitor */
 public void visit(SafraTree tree, SafraTreeNode node)
 {
     node.setFinalFlag(false);
 }
Exemplo n.º 26
0
 //template <typename HashFunction>
 public static void abstract_hash_code(StdHashFunction hash, SafraTree t)
 {
     //todo: implemented this method
     t.hashCode(hash, true);
 }
Exemplo n.º 27
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
                }
            }
Exemplo n.º 28
0
 //template <typename HashFunction>
 public static void abstract_hash_code(StdHashFunction hash, SafraTree t)
 {
     //todo: implemented this method
     t.hashCode(hash, true);
 }
Exemplo n.º 29
0
 public static bool isMatch(SafraTreeTemplate temp, SafraTree tree)
 {
     return temp.matches(tree);
 }
Exemplo n.º 30
0
 public static bool abstract_less_than(SafraTree t1, SafraTree t2)
 {
     return(t1.structural_less_than(t2));
 }
Exemplo n.º 31
0
 public static bool abstract_equal_to(SafraTree t1, SafraTree t2)
 {
     return t1.structural_equal_to(t2);
 }
Exemplo n.º 32
0
        /**
         * Checks equality when ignoring the node names.
         */
        public bool structural_equal_to(SafraTree other)
        {
            if (other.MAX_NODES != MAX_NODES)
            {
                return false;
            }

            SafraTreeNode this_root = this.getRootNode();
            SafraTreeNode other_root = other.getRootNode();

            if (this_root == null || other_root == null)
            {
                // return true if both are 0
                return (this_root == other_root);
            }

            return this_root.structural_equal_to(other_root);
        }
Exemplo n.º 33
0
 public static bool abstract_less_than(SafraTree t1, SafraTree t2)
 {
     return t1.structural_less_than(t2);
 }
Exemplo n.º 34
0
        /**
         * Less-than operator when ignoring the node names.
         */
        public bool structural_less_than(SafraTree other)
        {
            if (other.MAX_NODES < MAX_NODES)
            {
                return true;
            }

            SafraTreeNode this_root = this.getRootNode();
            SafraTreeNode other_root = other.getRootNode();

            if (this_root == null)
            {
                if (other_root != null)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                // this_root !=0
                if (other_root == null)
                {
                    return false;
                }

                return this_root.structural_less_than(other_root);
            }
        }
Exemplo n.º 35
0
        /**
         * Add a mapping
         * @param key the key
         * @param state the state
         */
        public void add(SafraTree key, DA_State state)
        {
            AbstractedKeyType akey = new AbstractedKeyType(key);
            ValueList list = new ValueList();

            list._key = key;
            list._state = state;
            list._next = null;

            //typename map_type::value_type value (akey, list);

            //std::pair<typename  map_type:: iterator,bool > result = _map.insert(value);

            if (_map.ContainsKey(akey))
            {
                // there is already an element with this structure
                // -> insert list into current list

                ValueList head = _map[akey];
                list._next = head._next;
                head._next = list;

                _map[akey] = head;
            }
            else
            {
                _map.Add(akey, list);
            }

            _count++;
        }
Exemplo n.º 36
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;
                    }
                }
Exemplo n.º 37
0
 public ValueList()
 {
     _state = null;
       _next = null;
       _key = null;
 }
Exemplo n.º 38
0
 public AbstractedKeyType(SafraTree key)
 {
     _key = key;
 }