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
        /** Calculate and add transitions to the successor state.
         * @param from the source stuttered_state
         * @param da_from the source DA state
         * @param elem the edge label
         */
        void calc_delta(TreeWithAcceptance from, DA_State da_from, APElement elem)
        {
            //StateMapper<SafraTree, int , ptr_hash<algo_state_t>> intermediate_state_map_t;  //, PtrComparator<algo_state_t>

            Dictionary <StateInterface, int> state_map    = new Dictionary <StateInterface, int>();
            List <StateInterface>            state_vector = new List <StateInterface>();

            StateInterface start_tree = from.getTree();

            //state_map[start_tree] = null;
            state_map.Add(start_tree, 0);
            state_vector.Add(start_tree); //push_back

#if STUTTERED_VERBOSE
            std::cerr << "Calculate from state [" << da_from->getName() << "], " << (unsigned
                                                                                     int )
                elem << ":" << std::endl;
            std::cerr << start_tree->toString() << std::endl;
#endif

            StateInterface cur_tree = start_tree;
            while (true)
            {
                StateInterface next_tree = _algo.delta(cur_tree as SafraTree, elem).getState();

                //typename intermediate_state_map_t::iterator it;
                //int it = state_map.find(next_tree);
                //if (it == state_map.end())

                if (!state_map.ContainsKey(next_tree))
                {
                    // tree doesn't yet exist...
                    // add tree
                    //state_map[next_tree] = state_vector.size();
                    state_map.Add(next_tree, state_vector.Count);
                    state_vector.Add(next_tree); //push_back

                    cur_tree = next_tree;
                    continue;
                }
                else
                {
                    // found the cycle!
                    int cycle_point = state_map[next_tree];

#if STUTTERED_VERBOSE
                    std::cerr << "-----------------------\n";
                    for (unsigned int i = 0; i < state_vector.size(); i++)
                    {
                        std::cerr << "[" << i << "] ";
                        if (cycle_point == i)
                        {
                            std::cerr << "* ";
                        }
                        std::cerr << "\n" << state_vector[i]->toString() << std::endl;
                    }
                    std::cerr << "-----------------------\n";
#endif

                    prefix_and_cycle_state_t pac = calculate_prefix_and_cycle_state(state_vector, cycle_point);

                    //DA_State da_prefix = null;
                    DA_State da_cycle = null;

                    if (pac.prefix_state != null && !(pac.prefix_state == pac.cycle_state))
                    {
                        DA_State da_prefix = add_transition(da_from, pac.prefix_state, elem);
                        da_cycle = add_transition(da_prefix, pac.cycle_state, elem);
                    }
                    else
                    {
                        da_cycle = add_transition(da_from, pac.cycle_state, elem);
                    }

                    da_cycle.edges().set(elem, da_cycle);

                    return;
                }
            }
        }
Esempio n. 3
0
        /** Calculate the prefix and the cycle state */
        prefix_and_cycle_state_t calculate_prefix_and_cycle_state(List <StateInterface> state_vector, int cycle_point)
        {
            //TreeWithAcceptance prefix_state, cycle_state;
            TreeWithAcceptance prefix_state = null;
            TreeWithAcceptance cycle_state  = null;
            int states = state_vector.Count; //.size();

            int smallest = cycle_point;

            for (int i = cycle_point + 1; i < states; i++)
            {
                if (state_vector[i] < state_vector[smallest])
                {
                    smallest = i;
                }
            }

#if STUTTERED_VERBOSE
            std::cerr << "Smallest: " << smallest << std::endl;
#endif

            cycle_state = new TreeWithAcceptance(state_vector[smallest]);
            if (!(cycle_point == 0 || cycle_point == 1))
            {
                prefix_state = new TreeWithAcceptance(state_vector[smallest]);
            }

            RabinSignature signature_prefix = null; //(typename Acceptance::signature_type*)NULL;
            if (prefix_state != null)
            {
                signature_prefix = prefix_state.getSignature();
            }
            RabinSignature signature_cycle = cycle_state.getSignature();


            bool omit_prefix = calculate_acceptance(state_vector, cycle_point, signature_prefix, signature_cycle);

            if (omit_prefix)
            {
                prefix_state = null;
            }

            //  if (_detailed_states) {
            //    std::ostringstream prefix_description;
            //    std::ostringstream cycle_description;

            //if (prefix_state) {
            //  prefix_description << "<TABLE><TR><TD>Prefix</TD><TD>Cycle (" << (smallest-cycle_point) <<")</TD></TR>"
            //             << "<TR><TD>";

            //  prefix_description << "<TABLE><TR>";
            //  for (unsigned int i=1;i<cycle_point;i++) {
            //    prefix_description << "<TD>" << state_vector[i]->toHTML() << "</TD>";
            //  }
            //  prefix_description << "</TR></TABLE></TD>";
            //}

            //cycle_description << "<TD><TABLE><TR>";
            //for (unsigned int i=cycle_point; i<state_vector.size();i++) {
            //  cycle_description << "<TD>";
            //  cycle_description << state_vector[i]->toHTML();
            //  cycle_description << "</TD>";
            //}
            //cycle_description << "</TR></TABLE></TD>";


            //if (prefix_state) {
            //  prefix_description << cycle_description.str();
            //  prefix_description << "</TR></TABLE>";

            //  prefix_state->setDescription(prefix_description.str());
            //}

            //cycle_description << "</TR></TABLE>";
            //cycle_state->setDescription("<TABLE><TR><TD>Cycle ("+
            //                boost::lexical_cast<std::string>(smallest-cycle_point) +
            //                ")</TD></TR><TR>" + cycle_description.str());
            //  }

            return(new prefix_and_cycle_state_t(prefix_state, cycle_state));
        }
Esempio n. 4
0
 public prefix_and_cycle_state_t(TreeWithAcceptance prefix_, TreeWithAcceptance cycle_)
 {
     prefix_state = prefix_;
     cycle_state  = cycle_;
 }
Esempio n. 5
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. 6
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. 7
0
 public prefix_and_cycle_state_t(TreeWithAcceptance prefix_, TreeWithAcceptance cycle_)
 {
     prefix_state = prefix_;
     cycle_state = cycle_;
 }
Esempio n. 8
0
        /** Calculate and add transitions to the successor state.
         * @param from the source stuttered_state
         * @param da_from the source DA state
         * @param elem the edge label
         */
        void calc_delta(TreeWithAcceptance from, DA_State da_from, APElement elem)
        {
            //StateMapper<SafraTree, int , ptr_hash<algo_state_t>> intermediate_state_map_t;  //, PtrComparator<algo_state_t>

            Dictionary<StateInterface, int> state_map = new Dictionary<StateInterface, int>();
            List<StateInterface> state_vector = new List<StateInterface>();

            StateInterface start_tree = from.getTree();
            //state_map[start_tree] = null;
            state_map.Add(start_tree, 0);
            state_vector.Add(start_tree); //push_back

            #if STUTTERED_VERBOSE
            std::cerr << "Calculate from state [" << da_from->getName() << "], " << (unsigned
            int )
            elem << ":" << std::endl;
            std::cerr << start_tree->toString() << std::endl;
            #endif

            StateInterface cur_tree = start_tree;
            while (true)
            {
                StateInterface next_tree = _algo.delta(cur_tree as UnionState, elem).getState();

                //typename intermediate_state_map_t::iterator it;
                //int it = state_map.find(next_tree);
                //if (it == state_map.end())

                if (!state_map.ContainsKey(next_tree))
                {
                    // tree doesn't yet exist...
                    // add tree
                    //state_map[next_tree] = state_vector.size();
                    state_map.Add(next_tree, state_vector.Count);
                    state_vector.Add(next_tree); //push_back

                    cur_tree = next_tree;
                    continue;
                }
                else
                {
                    // found the cycle!
                    int cycle_point = state_map[next_tree];

            #if STUTTERED_VERBOSE
            std::cerr << "-----------------------\n";
            for (unsigned int i=0;i<state_vector.size();i++) {
            std::cerr << "[" << i << "] ";
            if (cycle_point==i) {
            std::cerr << "* ";
            }
            std::cerr << "\n" << state_vector[i]->toString() << std::endl;
            }
            std::cerr << "-----------------------\n";
            #endif

                    prefix_and_cycle_state_t pac = calculate_prefix_and_cycle_state(state_vector, cycle_point);

                    //DA_State da_prefix = null;
                    DA_State da_cycle = null;

                    if (pac.prefix_state != null && !(pac.prefix_state == pac.cycle_state))
                    {
                        DA_State da_prefix = add_transition(da_from, pac.prefix_state, elem);
                        da_cycle = add_transition(da_prefix, pac.cycle_state, elem);
                    }
                    else
                    {
                        da_cycle = add_transition(da_from, pac.cycle_state, elem);
                    }

                    da_cycle.edges().set(elem, da_cycle);

                    return;
                }
            }
        }
Esempio n. 9
0
        /** Calculate the prefix and the cycle state */
        prefix_and_cycle_state_t calculate_prefix_and_cycle_state(List<StateInterface> state_vector, int cycle_point)
        {
            //TreeWithAcceptance prefix_state, cycle_state;
            TreeWithAcceptance prefix_state = null;
            TreeWithAcceptance cycle_state = null;
            int states = state_vector.Count; //.size();

            int smallest = cycle_point;
            for (int i = cycle_point + 1; i < states; i++)
            {
                if (state_vector[i] < state_vector[smallest])
                {
                    smallest = i;
                }
            }

            #if STUTTERED_VERBOSE
              std::cerr << "Smallest: " << smallest << std::endl;
            #endif

            cycle_state = new TreeWithAcceptance(state_vector[smallest]);
            if (!(cycle_point == 0 || cycle_point == 1))
            {
                prefix_state = new TreeWithAcceptance(state_vector[smallest]);
            }

            RabinSignature signature_prefix = null; //(typename Acceptance::signature_type*)NULL;
            if (prefix_state != null)
            {
                signature_prefix = prefix_state.getSignature();
            }
            RabinSignature signature_cycle = cycle_state.getSignature();

            bool omit_prefix = calculate_acceptance(state_vector, cycle_point, signature_prefix, signature_cycle);

            if (omit_prefix)
            {
                //prefix_state.reset();
            }

            //  if (_detailed_states) {
            //    std::ostringstream prefix_description;
            //    std::ostringstream cycle_description;

            //if (prefix_state) {
            //  prefix_description << "<TABLE><TR><TD>Prefix</TD><TD>Cycle (" << (smallest-cycle_point) <<")</TD></TR>"
            //             << "<TR><TD>";

            //  prefix_description << "<TABLE><TR>";
            //  for (unsigned int i=1;i<cycle_point;i++) {
            //    prefix_description << "<TD>" << state_vector[i]->toHTML() << "</TD>";
            //  }
            //  prefix_description << "</TR></TABLE></TD>";
            //}

            //cycle_description << "<TD><TABLE><TR>";
            //for (unsigned int i=cycle_point; i<state_vector.size();i++) {
            //  cycle_description << "<TD>";
            //  cycle_description << state_vector[i]->toHTML();
            //  cycle_description << "</TD>";
            //}
            //cycle_description << "</TR></TABLE></TD>";

            //if (prefix_state) {
            //  prefix_description << cycle_description.str();
            //  prefix_description << "</TR></TABLE>";

            //  prefix_state->setDescription(prefix_description.str());
            //}

            //cycle_description << "</TR></TABLE>";
            //cycle_state->setDescription("<TABLE><TR><TD>Cycle ("+
            //                boost::lexical_cast<std::string>(smallest-cycle_point) +
            //                ")</TD></TR><TR>" + cycle_description.str());
            //  }

            return new prefix_and_cycle_state_t(prefix_state, cycle_state);
        }
Esempio n. 10
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;
        }