Example #1
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++;
        }
Example #2
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);
        }
Example #3
0
        public DA_State newState()
        {
            DA_State state = new DA_State(this, _index.Count);

            _index.Add(state);
            _acceptance.addState(state.getName());
            return(state);
        }
Example #4
0
        /** Calculate the successor state.
         * @param from_state The from state
         * @param elem The edge label
         * @return result_t the shared_ptr of the successor state
         */
        public ResultStateInterface <UnionState> delta(UnionState from_state, APElement elem)
        {
            DA_State state1_to = _da_1[from_state.da_state_1].edges().get(elem);
            DA_State state2_to = _da_2[from_state.da_state_2].edges().get(elem);

            UnionState to = createState(state1_to.getName(), state2_to.getName());

            return(new UnionState_Result(to));
        }
Example #5
0
        /**
         * Print the DA in DOT format to the output stream.
         * This functions expects that the DA is compact.
         * @param da_type a string specifying the type of automaton ("DRA", "DSA").
         * @param out the output stream
         */
        public Graph AutomatonToDot()
        {
            Graph g = new Graph("graph");

            g.Directed = true;


            APSet ap_set = getAPSet();
            Dictionary <int, string> stateToNumber = new Dictionary <int, string>();

            for (int i_state = 0; i_state < this.size(); i_state++)
            {
                //out << "\"" << i_state << "\" [";

                Node d = formatStateForDOT(i_state, g);
                stateToNumber.Add(i_state, d.Id);
            }

            //out << "]\n"; // close parameters for state

            for (int i_state = 0; i_state < this.size(); i_state++)
            {
                // transitions

                DA_State cur_state = this.get(i_state);
                if (cur_state.hasOnlySelfLoop())
                {
                    // get first to-state, as all the to-states are the same
                    DA_State to = cur_state.edges().get(new APElement(ap_set.all_elements_begin()));

                    //out << "\"" << i_state << "\" -> \"" << to->getName();
                    //out << "\" [label=\" true\", color=blue]\n";

                    Edge edge = g.AddEdge(stateToNumber[i_state], "\u03A3", stateToNumber[to.getName()]);
                    //edge.Attr.Color = Color.Blue;
                }
                else
                {
                    //for (APSet::element_iterator el_it=ap_set.all_elements_begin();el_it!=ap_set.all_elements_end();++el_it)
                    for (int el_it = ap_set.all_elements_begin(); el_it != ap_set.all_elements_end(); ++el_it)
                    {
                        APElement label          = new APElement(el_it);
                        DA_State  to_state       = cur_state.edges().get(label);
                        int       to_state_index = to_state.getName();
                        //out << "\"" << i_state << "\" -> \"" << to_state_index;
                        //out << "\" [label=\" " << label.toString(getAPSet(), false) << "\"]\n";


                        Edge edge = g.AddEdge(stateToNumber[i_state], label.toString(getAPSet(), false), stateToNumber[to_state_index]);
                        //edge.Attr.Color = Color.Blue;
                    }
                }
            }

            return(g);
        }
Example #6
0
        /**
         * Constructor.
         * @param ap_set the underlying APSet.
         */
        //template <typename Label, template <typename N> class EdgeContainer, typename AcceptanceCondition>
        public DA(APSet ap_set)
        {
            //_state_count = 0;
            _ap_set      = ap_set;
            _start_state = null;
            _is_compact  = true;

            //added by ly
            _index = new List <DA_State>();
            //_start_state
            //_acceptance??
            _acceptance = new RabinAcceptance();
        }
Example #7
0
        /** Make this automaton into an never accepting automaton */
        public void constructEmpty()
        {
            DA_State n = this.newState();

            setStartState(n);

            //for (APSet::element_iterator it_elem= DA<Label,EdgeContainer,RabinAcceptance>::getAPSet().all_elements_begin();it_elem!=DA<Label,EdgeContainer,RabinAcceptance>::getAPSet().all_elements_end();++it_elem)
            APSet ap_set = getAPSet();

            for (int it_elem = ap_set.all_elements_begin(); it_elem != ap_set.all_elements_end(); ++it_elem)
            {
                APElement label = new APElement(it_elem);
                n.edges().addEdge(label, n);
            }
        }
Example #8
0
        /**
         * Compares two states 'less-than' using the
         * coloring, uses the bisimulation
         * equivalence relation to determine
         * equality.
         */
        //bool operator()(int state_x, int state_y)
        public bool comp(int state_x, int state_y)
        {
            int cx = _coloring.state2color(state_x);
            int cy = _coloring.state2color(state_y);

            if (cx < cy)
            {
                return(true);
            }
            else if (cx > cy)
            {
                return(false);
            }


            //for (APSet::element_iterator label= _dra.getAPSet().all_elements_begin();label!=_dra.getAPSet().all_elements_end();++label)
            for (int label = _dra.getAPSet().all_elements_begin(); label != _dra.getAPSet().all_elements_end(); ++label)
            {
                DA_State to_x = _dra[state_x].edges().get(new APElement(label));
                DA_State to_y = _dra[state_y].edges().get(new APElement(label));

                int ctx = _coloring.state2color(to_x.getName());
                int cty = _coloring.state2color(to_y.getName());

                if (ctx < cty)
                {
                    return(true);
                }
                else if (ctx > cty)
                {
                    return(false);
                }
            }

            // we get here only if x and y are equal with this
            // coloring -> return false
            return(false);
        }
Example #9
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");
                        }
                    }
                }
            }
        }
Example #10
0
        public List <int> MakeOneMove(int stateIndex, Valuation env, string evt)
        {
            DA_State   state      = this._index[stateIndex];
            List <int> returnList = new List <int>();

            if (state.hasOnlySelfLoop())
            {
                // get first to-state, as all the to-states are the same
                DA_State to = state.edges().get(new APElement(_ap_set.all_elements_begin()));
                returnList.Add(to.Index);
                return(returnList);
            }

            //Transition[] trans = fromTransitions[state];

            //foreach (Transition tran in trans)
            for (int el_it = _ap_set.all_elements_begin(); el_it != _ap_set.all_elements_end(); ++el_it)
            {
                APElement label          = new APElement(el_it);
                DA_State  to_state       = state.edges().get(label);
                int       to_state_index = to_state.Index;

                //bool toAdd = true;
                //for (int i = 0; i < _ap_set.size(); i++)
                bool toAdd = true;
                for (int i = 0; i < _ap_set.size(); i++)
                {
                    ////If the transition is labelled with Sigma, there should not be any other labels.
                    //if (label.IsSigmal)
                    //{
                    //    //if(!returnList.Contains(tran.ToState))
                    //    {
                    //        returnList.Add(tran.ToState);
                    //    }
                    //    break;
                    //}

                    string labelstring = _ap_set.getAP(i);
                    //If the labed is negated, e.g., !eat0.
                    if (!label.get(i))
                    {
                        if (!DeclarationDatabase.ContainsKey(labelstring)) //If the label is an event.
                        {
                            //if the label says that this event can not happen, the event is eat0 and the label is !eat0.
                            if (labelstring == evt)
                            {
                                toAdd = false;
                                break;
                            }
                        }
                        else //If the label is a proposition.
                        {
                            ExpressionValue v = EvaluatorDenotational.Evaluate(DeclarationDatabase[labelstring], env);

                            //liuyang: v must be a boolconstant, 20/04/2009
                            Debug.Assert(v is BoolConstant);
                            //if (v is BoolConstant)
                            //{
                            if ((v as BoolConstant).Value)
                            {
                                toAdd = false;
                                break;
                            }
                            //}
                        }
                    }
                    else //if (!label.Negated)
                    {
                        if (!DeclarationDatabase.ContainsKey(labelstring)) //If the label is an event.
                        {
                            if (labelstring != evt)
                            {
                                toAdd = false;
                                break;
                            }
                        }
                        else //If the label is a proposition.
                        {
                            ExpressionValue v = EvaluatorDenotational.Evaluate(DeclarationDatabase[labelstring], env);

                            //liuyang: v must be a boolconstant, 20/04/2009
                            Debug.Assert(v is BoolConstant);
                            //if (v is BoolConstant)
                            //{
                            if (!(v as BoolConstant).Value)
                            {
                                toAdd = false;
                                break;
                            }
                            //}
                        }
                    }
                }

                if (toAdd && !returnList.Contains(to_state_index))
                {
                    returnList.Add(to_state_index);
                }
            }

            return(returnList);
        }
Example #11
0
        /** Output state label for DOT printing.
         * @param out the output stream
         * @param state_index the state index
         */
        public Node formatStateForDOT(int state_index, Graph g)
        {
            DA_State cur_state = this.get(state_index);

            bool has_pos = false, has_neg = false;

            //std::ostringstream acc_sig;
            string acc_sig = "";

            for (int pair_index = 0; pair_index < this.acceptance().size(); pair_index++)
            {
                if (this.acceptance().isStateInAcceptance_L(pair_index, state_index))
                {
                    acc_sig += " +" + pair_index;
                    has_pos  = true;
                }

                if (this.acceptance().isStateInAcceptance_U(pair_index, state_index))
                {
                    acc_sig += " -" + pair_index;
                    has_neg  = true;
                }
            }

            string label = state_index + "\r\n" + acc_sig.Trim();


            //out << "label= \"" << state_index;
            //if (acc_sig.str().length()!=0) {
            //  out  << "\\n" << acc_sig.str();
            //}
            Node d = g.AddNode(label);

            //if (!has_pos && !has_neg)
            //{
            //    //out << ", shape=circle";
            //    d.Attr.Shape = Shape.DoubleCircle;
            //}
            //else
            //{
            //    //out << ", shape=box";
            //    d.Attr.Shape = Shape.Box;
            //}
            d.Attr.Shape = Shape.Box;

            if (this.getStartState() == cur_state)
            {
                ////out << ", style=filled, color=black, fillcolor=grey";
                //d.Attr.AddStyle(Style.Filled);
                //d.Attr.Color = Color.Black;
                //d.Attr.FillColor = Color.Gray;

                Node temp = g.AddNode("init-" + label);

                //temp.Attr.Shape = Shape.InvHouse;
                temp.Attr.LineWidth = 0;
                temp.Attr.Color     = Color.White;
                temp.LabelText      = "";
                g.AddEdge("init-" + label, label);
                d.Attr.FillColor = Color.Gray;
            }

            return(d);
        }
Example #12
0
        public static void dba2dra(NBA nba, DRA dra_result, bool complement)
        {
            //complement=false
            DRA   dra    = dra_result;
            APSet ap_set = dra.getAPSet();;

            dra.acceptance().newAcceptancePair();

            for (int i = 0; i < nba.size(); i++)
            {
                dra.newState();

                if (complement)
                {
                    // Final states -> U_0, all states -> L_0
                    if (nba[i].isFinal())
                    {
                        dra.acceptance().stateIn_U(0, i);
                    }
                    dra.acceptance().stateIn_L(0, i);
                }
                else
                {
                    // Final states -> L_0, U_0 is empty
                    if (nba[i].isFinal())
                    {
                        dra.acceptance().stateIn_L(0, i);
                    }
                }
            }

            if (nba.getStartState() != null)
            {
                dra.setStartState(dra[nba.getStartState().getName()]);
            }

            DA_State sink_state = null;

            for (int i = 0; i < nba.size(); i++)
            {
                NBA_State nba_state = nba[i];
                DA_State  dra_from  = dra[i];

                //for (APSet::element_iterator label=ap_set->all_elements_begin();label!=ap_set->all_elements_end(); ++label)
                for (int label = ap_set.all_elements_begin(); label != ap_set.all_elements_end(); ++label)
                {
                    BitSet to = nba_state.getEdge(new APElement(label));

                    int to_cardinality = 0;
                    if (to != null)
                    {
                        to_cardinality = to.cardinality();
                    }


                    DA_State dra_to = null;
                    if (to == null || to_cardinality == 0)
                    {
                        // empty to -> go to sink state
                        if (sink_state == null)
                        {
                            // we have to create the sink
                            sink_state = dra.newState();

                            // if we complement, we have to add the sink to
                            // L_0
                            if (complement)
                            {
                                sink_state.acceptance().addTo_L(0);
                            }
                        }
                        dra_to = sink_state;
                    }
                    else if (to_cardinality == 1)
                    {
                        int to_index = to.nextSetBit(0);

                        //	  std::cerr << "to: " << to_index << std::endl;

                        dra_to = dra[to_index];
                    }
                    else
                    {
                        // to_cardinality>1 !
                        throw new IllegalArgumentException("NBA is no DBA!");
                    }

                    dra_from.edges().addEdge(new APElement(label), dra_to);
                }
            }

            if (sink_state != null)
            {
                // there is a sink state
                // make true-loop from sink state to itself
                //for (APSet::element_iterator label=ap_set->all_elements_begin();label!=ap_set->all_elements_end();++label) {
                for (int label = ap_set.all_elements_begin(); label != ap_set.all_elements_end(); ++label)
                {
                    sink_state.edges().addEdge(new APElement(label), sink_state);
                }
            }
        }
Example #13
0
        /**
         * Generate a new DRA from a coloring
         */
        DRA generateDRAfromColoring(DRA oldDRA, Coloring coloring, bool detailedStates)
        {
            DRA newDRA = oldDRA.createInstance(oldDRA.getAPSet()) as DRA;


            newDRA.acceptance().newAcceptancePairs(oldDRA.acceptance().size());

            for (int color = 0; color < coloring.countColors(); ++color)
            {
                newDRA.newState();
            }

            int old_start_state   = oldDRA.getStartState().getName();
            int start_state_color = coloring.state2color(old_start_state);

            newDRA.setStartState(newDRA.get(start_state_color));

            APSet apset = newDRA.getAPSet();

            for (int color = 0; color < coloring.countColors(); ++color)
            {
                DA_State new_state = newDRA.get(color);

                int old_state_representative = coloring.color2state(color);

                DA_State old_state = oldDRA[old_state_representative];

                if (detailedStates)
                {
                    BitSet old_states = coloring.color2states(color);

                    // create new description...
                    if (old_states.cardinality() == 1)
                    {
                        if (old_state.hasDescription())
                        {
                            new_state.setDescription(old_state.getDescription());
                        }
                    }
                    else
                    {
                        //std::ostringstream s;
                        //s << "<TABLE BORDER=\"1\" CELLBORDER=\"0\"><TR><TD>{</TD>";
                        StringBuilder s = new StringBuilder(@"<TABLE BORDER=\""1\"" CELLBORDER=\""0\""><TR><TD>{</TD>");

                        bool first = true;
                        for (int it = BitSetIterator.start(old_states); it != BitSetIterator.end(old_states); it = BitSetIterator.increment(old_states, it))
                        {
                            if (first)
                            {
                                first = false;
                            }
                            else
                            {
                                s.Append("<TD>,</TD>");
                            }

                            s.Append("<TD>");
                            if (!oldDRA[it].hasDescription())
                            {
                                s.Append(it);
                            }
                            else
                            {
                                s.Append(oldDRA[it].getDescription());
                            }
                            s.Append("</TD>");
                        }
                        s.Append("<TD>}</TD></TR></TABLE>");

                        new_state.setDescription(s.ToString());
                        ;
                    }
                }

                // Create appropriate acceptance conditions
                int old_state_index = old_state.getName();
                for (int i = 0; i < oldDRA.acceptance().size(); ++i)
                {
                    if (oldDRA.acceptance().isStateInAcceptance_L(i, old_state_index))
                    {
                        new_state.acceptance().addTo_L(i);
                    }

                    if (oldDRA.acceptance().isStateInAcceptance_U(i, old_state_index))
                    {
                        new_state.acceptance().addTo_U(i);
                    }
                }

                //for (APSet::element_iterator label=apset.all_elements_begin();label!=apset.all_elements_end();++label)
                for (int label = apset.all_elements_begin(); label != apset.all_elements_end(); ++label)
                {
                    DA_State old_to = old_state.edges().get(new APElement(label));

                    int to_color = coloring.state2color(old_to.getName());

                    new_state.edges().addEdge(new APElement(label), newDRA.get(to_color));
                }
            }

            return(newDRA);
        }
Example #14
0
 public ValueList()
 {
     _state = null;
       _next = null;
       _key = null;
 }
Example #15
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++;
        }
Example #16
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;
        }
Example #17
0
        ///**
        //* Get the index for a state.
        //*/
        //public int getIndexForState(DA_State state)
        //{
        //    //return _index.get_index(state);

        //    for (int i = 0; i < _index.Count; i++)
        //    {
        //        DA_State s = _index[i];
        //        if (state == s)
        //        {
        //            return i;
        //        }
        //    }

        //    return -1;
        //}

        /** Set the start state. */
        public void setStartState(DA_State state)
        {
            _start_state = state;
        }
Example #18
0
        /**
         * Generate a DA using the Algorithm
         * Throws LimitReachedException if a limit is set (>0) and
         * there are more states in the generated DA than the limit.
         * @param algo the algorithm
         * @param da_result the DA where the result is stored
         *        (has to have same APSet as the nba)
         * @param limit a limit for the number of states (0 disables the limit).
         */
        public void convert(SafraAlgorithm algo, DRA da_result, int limit)
        {
            /** The hash map from DA_State to StateInterface */
            StateMapper <StateInterface, DA_State> state_mapper = new StateMapper <StateInterface, DA_State>();
            APSet ap_set = da_result.getAPSet();////////////************where dose this dra have ap_set?


            if (algo.checkEmpty())
            {
                da_result.constructEmpty();
                return;
            }

            //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;

            //* Creates new acceptance pairs according to da_result's acceptance.
            algo.prepareAcceptance(da_result.acceptance());////*********don't understand well

            StateInterface start       = algo.getStartState();
            DA_State       start_state = da_result.newState();/////************?? what is in this newState?

            start.generateAcceptance(start_state.acceptance());
            if (_detailed_states)
            {
                start_state.setDescription(start.toHTML());
            }

            state_mapper.add(start, start_state);
            da_result.setStartState(start_state);

            //typedef std::pair<algo_state_t, da_state_t*> unprocessed_value;

            Stack <KeyValuePair <StateInterface, DA_State> > unprocessed = new Stack <KeyValuePair <StateInterface, DA_State> >();

            unprocessed.Push(new KeyValuePair <StateInterface, DA_State>(start, start_state));

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

                StateInterface cur  = top.Key;   //safratreeNode
                DA_State       from = top.Value; //DA_state

                //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) ///from 0 to 2^ap_set.size
                {
                    APElement elem = new APElement(it_elem);                                                     /////////set simpleBitset = it_elem

                    ResultStateInterface <SafraTree> result = algo.delta(cur as SafraTree, elem);                /////get a new safraTree through elem


                    DA_State to = state_mapper.find(result.getState());

                    if (to == null)////////////////result is not in state mapper.
                    {
                        to = da_result.newState();
                        result.getState().generateAcceptance(to.acceptance());

                        if (_detailed_states)
                        {
                            to.setDescription(result.getState().toHTML());
                        }

                        state_mapper.add(result.getState(), to);
                        unprocessed.Push(new KeyValuePair <StateInterface, DA_State>(result.getState(), to));
                    }

                    from.edges().set(elem, to);//////////////add this edge.
                    if (limit != 0 && da_result.size() > limit)
                    {
                        throw new LimitReachedException("");
                    }
                }
            }
        }
Example #19
0
        /**
         * Generate a DA using the Algorithm
         * Throws LimitReachedException if a limit is set (>0) and
         * there are more states in the generated DA than the limit.
         * @param algo the algorithm
         * @param da_result the DA where the result is stored
         *        (has to have same APSet as the nba)
         * @param limit a limit for the number of states (0 disables the limit).
         */
        public void convert(DAUnionAlgorithm algo, DRA da_result, int limit)
        {
            StateMapper <StateInterface, DA_State> state_mapper = new StateMapper <StateInterface, DA_State>();
            APSet ap_set = da_result.getAPSet();

            if (algo.checkEmpty())
            {
                da_result.constructEmpty();
                return;
            }

            //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;

            algo.prepareAcceptance(da_result.acceptance());

            StateInterface start       = algo.getStartState();
            DA_State       start_state = da_result.newState();

            start.generateAcceptance(start_state.acceptance());
            if (_detailed_states)
            {
                start_state.setDescription(start.toHTML());
            }

            state_mapper.add(start, start_state);
            da_result.setStartState(start_state);

            //typedef std::pair<algo_state_t, da_state_t*> unprocessed_value;

            Stack <KeyValuePair <StateInterface, DA_State> > unprocessed = new Stack <KeyValuePair <StateInterface, DA_State> >();

            unprocessed.Push(new KeyValuePair <StateInterface, DA_State>(start, start_state));

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

                StateInterface cur  = top.Key;
                DA_State       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);

                    ResultStateInterface <UnionState> result = algo.delta(cur as UnionState, elem);


                    DA_State to = state_mapper.find(result.getState());

                    if (to == null)
                    {
                        to = da_result.newState();
                        result.getState().generateAcceptance(to.acceptance());

                        if (_detailed_states)
                        {
                            to.setDescription(result.getState().toHTML());
                        }

                        state_mapper.add(result.getState(), to);
                        unprocessed.Push(new KeyValuePair <StateInterface, DA_State>(result.getState(), to));
                    }

                    from.edges().set(elem, to);

                    if (limit != 0 && da_result.size() > limit)
                    {
                        throw new LimitReachedException("");
                    }
                }
            }
        }
Example #20
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;
                }
            }
        }
Example #21
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;
                }
            }
        }
Example #22
0
 public ValueList()
 {
     _state = null;
     _next  = null;
     _key   = null;
 }