Esempio n. 1
0
        // --- private functions ----

        /** Add a transition from DA states da_from to stuttered_state to for edge elem.
         * If the state does not yet exist in the DA, create it.
         * @param da_from the from state in the DA
         * @param to the target state
         * @param elem the edge label
         */
        DA_State add_transition(DA_State da_from, TreeWithAcceptance to, APElement elem)
        {
            DA_State da_to = _state_mapper.find(to);

            if (da_to == null)
            {
                da_to = _da_result.newState();
                to.generateAcceptance(da_to.acceptance());
                if (_detailed_states)
                {
                    //    da_to.setDescription(to->toHTML());
                }

                _state_mapper.add(to, da_to);
                _unprocessed.Push(new KeyValuePair <TreeWithAcceptance, DA_State>(to, da_to));
            }

#if STUTTERED_VERBOSE
            std::cerr << da_from->getName() << " -> " << da_to->getName() << std::endl;
#endif

            da_from.edges().set(elem, da_to);

            return(da_to);
        }
Esempio n. 2
0
        //typedef typename DA_t::state_type da_state_t;
        //typedef typename Algorithm_t::state_t algo_state_t;
        //typedef typename Algorithm_t::result_t algo_result_t;
        //typedef TreeWithAcceptance<algo_state_t, typename Acceptance::signature_type> stuttered_state_t;
        //typedef typename stuttered_state_t::ptr stuttered_state_ptr_t;
        //typedef std::pair<stuttered_state_ptr_t, da_state_t*> unprocessed_value_t;
        //typedef std::stack<unprocessed_value_t> unprocessed_stack_t;
        /** Convert the NBA to the DA */
        public void convert()
        {
            APSet ap_set = _da_result.getAPSet();

            if (_algo.checkEmpty())
            {
                _da_result.constructEmpty();
                return;
            }

            _algo.prepareAcceptance(_da_result.acceptance());

            TreeWithAcceptance s_start = new TreeWithAcceptance(_algo.getStartState());
            DA_State start_state = _da_result.newState();
            s_start.generateAcceptance(start_state.acceptance());
            if (_detailed_states)
            {
                //start_state->setDescription(s_start->toHTML());
                start_state.setDescription("hahahahah");
            }

            _state_mapper.add(s_start, start_state);
            _da_result.setStartState(start_state);

            Stack<KeyValuePair<TreeWithAcceptance, DA_State>> unprocessed;
            _unprocessed.Push(new KeyValuePair<TreeWithAcceptance, DA_State>(s_start, start_state));

            bool all_insensitive = _stutter_information.isCompletelyInsensitive();
            BitSet partial_insensitive = _stutter_information.getPartiallyInsensitiveSymbols();

            while (_unprocessed.Count > 0)
            {
                KeyValuePair<TreeWithAcceptance, DA_State> top = _unprocessed.Pop();
                //_unprocessed.pop();

                TreeWithAcceptance from = top.Key;
                DA_State da_from = top.Value;

                //for (APSet::element_iterator it_elem=ap_set.all_elements_begin();it_elem!=ap_set.all_elements_end();++it_elem)
                for (int it_elem = ap_set.all_elements_begin(); it_elem != ap_set.all_elements_end(); ++it_elem)
                {
                    APElement elem = new APElement(it_elem);

                    if (da_from.edges().get(elem) == null)
                    {
                        // the edge was not yet calculated...

                        if (!all_insensitive && partial_insensitive.get(it_elem) == null)
                        {

                            // can't stutter for this symbol, do normal step
                            UnionState next_tree = _algo.delta(from.getTree() as UnionState, elem).getState();
                            TreeWithAcceptance next_state = new TreeWithAcceptance(next_tree);
                            add_transition(da_from, next_state, elem);

                            continue;
                        }

                        // normal stuttering...

                        calc_delta(from, da_from, elem);

                        if (_limit != 0 && _da_result.size() > _limit)
                        {
                            //THROW_EXCEPTION(LimitReachedException, "");
                            throw new Exception("LimitReachedException");

                        }
                    }
                }
            }
        }
Esempio n. 3
0
        //typedef typename DA_t::state_type da_state_t;
        //typedef typename Algorithm_t::state_t algo_state_t;
        //typedef typename Algorithm_t::result_t algo_result_t;
        //typedef TreeWithAcceptance<algo_state_t, typename Acceptance::signature_type> stuttered_state_t;
        //typedef typename stuttered_state_t::ptr stuttered_state_ptr_t;

        //typedef std::pair<stuttered_state_ptr_t, da_state_t*> unprocessed_value_t;
        //typedef std::stack<unprocessed_value_t> unprocessed_stack_t;

        /** Convert the NBA to the DA */
        public void convert()
        {
            APSet ap_set = _da_result.getAPSet();

            if (_algo.checkEmpty())
            {
                _da_result.constructEmpty();
                return;
            }

            _algo.prepareAcceptance(_da_result.acceptance());

            TreeWithAcceptance s_start     = new TreeWithAcceptance(_algo.getStartState());
            DA_State           start_state = _da_result.newState();

            s_start.generateAcceptance(start_state.acceptance());
            if (_detailed_states)
            {
                //start_state->setDescription(s_start->toHTML());
                start_state.setDescription("hahahahah");
            }

            _state_mapper.add(s_start, start_state);
            _da_result.setStartState(start_state);

            Stack <KeyValuePair <TreeWithAcceptance, DA_State> > unprocessed;

            _unprocessed.Push(new KeyValuePair <TreeWithAcceptance, DA_State>(s_start, start_state));

            bool   all_insensitive     = _stutter_information.isCompletelyInsensitive();
            BitSet partial_insensitive = _stutter_information.getPartiallyInsensitiveSymbols();

            while (_unprocessed.Count > 0)
            {
                KeyValuePair <TreeWithAcceptance, DA_State> top = _unprocessed.Pop();
                //_unprocessed.pop();

                TreeWithAcceptance from    = top.Key;
                DA_State           da_from = top.Value;

                //for (APSet::element_iterator it_elem=ap_set.all_elements_begin();it_elem!=ap_set.all_elements_end();++it_elem)
                for (int it_elem = ap_set.all_elements_begin(); it_elem != ap_set.all_elements_end(); ++it_elem)
                {
                    APElement elem = new APElement(it_elem);

                    if (da_from.edges().get(elem) == null)
                    {
                        // the edge was not yet calculated...

                        if (!all_insensitive && partial_insensitive.get(it_elem) == null)
                        {
                            // can't stutter for this symbol, do normal step
                            SafraTree          next_tree  = _algo.delta(from.getTree() as SafraTree, elem).getState();
                            TreeWithAcceptance next_state = new TreeWithAcceptance(next_tree);
                            add_transition(da_from, next_state, elem);

                            continue;
                        }

                        // normal stuttering...

                        calc_delta(from, da_from, elem);

                        if (_limit != 0 && _da_result.size() > _limit)
                        {
                            //THROW_EXCEPTION(LimitReachedException, "");
                            throw new Exception("LimitReachedException");
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        // --- private functions ----
        /** Add a transition from DA states da_from to stuttered_state to for edge elem.
         * If the state does not yet exist in the DA, create it.
         * @param da_from the from state in the DA
         * @param to the target state
         * @param elem the edge label
         */
        DA_State add_transition(DA_State da_from, TreeWithAcceptance to, APElement elem)
        {
            DA_State da_to = _state_mapper.find(to);

            if (da_to == null)
            {
                da_to = _da_result.newState();
                to.generateAcceptance(da_to.acceptance());
                if (_detailed_states)
                {
                    //    da_to.setDescription(to->toHTML());
                }

                _state_mapper.add(to, da_to);
                _unprocessed.Push(new KeyValuePair<TreeWithAcceptance, DA_State>(to, da_to));
            }

            #if STUTTERED_VERBOSE
              std::cerr << da_from->getName() << " -> " << da_to->getName() << std::endl;
            #endif

            da_from.edges().set(elem, da_to);

            return da_to;
        }