Ejemplo n.º 1
0
        /**
         * Provides an iterator pointing after the last APElement
         * in the subset represented by the APMonom <i>m</i>.
         * @param ap_set the underlying APSet
         * @param m the APMonom over which we iterate
         * @return the iterator.
         */
        public static APMonom2APElements end(APSet ap_set, APMonom m)
        {
            APMonom2APElements m2e = new APMonom2APElements(ap_set, m);

            m2e._end_marker = true;
            return(m2e);
        }
Ejemplo n.º 2
0
        public string toString(APSet ap_set, bool spaces)
        {
            if (ap_set.size() == 0)
            {
                return("\u03A3");
            }
            StringBuilder r = new StringBuilder();

            for (int i = 0; i < ap_set.size(); i++)
            {
                if (i >= 1)
                {
                    r.Append("&");
                }
                if (!this.get(i))
                {
                    r.Append("!");
                }
                else
                {
                    if (spaces)
                    {
                        r.Append(" ");
                    }
                }
                r.Append(ap_set.getAP(i));
            }
            return(r.ToString());
        }
Ejemplo n.º 3
0
        /**
         * Convert an LTL formula to a DRA.
         * @param ltl the LTL formula
         * @param options which operators are allowed
         * @return a shared_ptr to the DRA
         */
        private DRA ltl2dra(LTLFormula ltl, BuchiAutomata buchiAutomata, LTL2DSTAR_Options options)
        {
            APSet ap_set = ltl.getAPSet();

            LTLFormula ltl_pnf = ltl.toPNF();

            if (options.allow_union && ltl_pnf.getRootNode().getType() == type_t.T_OR)
            {
                LTLFormula ltl_left = ltl_pnf.getSubFormula(ltl_pnf.getRootNode().getLeft());

                LTLFormula ltl_right = ltl_pnf.getSubFormula(ltl_pnf.getRootNode().getRight());

                LTL2DSTAR_Options rec_opt = options;
                rec_opt.recursion();

                DRA dra_left  = ltl2dra(ltl_left, buchiAutomata, rec_opt);
                DRA dra_right = ltl2dra(ltl_right, buchiAutomata, rec_opt);

                return(DRA.calculateUnion(dra_left, dra_right, _safra_opt.union_trueloop) as DRA);
            }

            if (options.safety)
            {
                LTLSafetyAutomata lsa = new LTLSafetyAutomata();

                DRA safety_dra = lsa.ltl2dra(ltl, buchiAutomata);

                if (safety_dra != null)
                {
                    return(safety_dra);
                }
            }

            DRA dra = new DRA(ap_set);

            NBA nba = LTL2NBA.ltl2nba(ltl_pnf, buchiAutomata);

            if (nba == null)
            {
                throw new Exception("Couldn't create NBA from LTL formula");
            }

            NBA2DRA nba2dra = new NBA2DRA(_safra_opt);

            nba2dra.convert(nba, dra);

            if (options.optimizeAcceptance)
            {
                dra.optimizeAcceptanceCondition();
            }

            if (options.bisim)
            {
                DRAOptimizations dra_optimizer = new DRAOptimizations();
                dra = dra_optimizer.optimizeBisimulation(dra);
            }

            return(dra);
        }
Ejemplo n.º 4
0
 /** Switch the APSet to another with the same number of APs. */
 public void switchAPSet(APSet new_apset)
 {
     if (new_apset.size() != _apset.size())
     {
         throw new IllegalArgumentException("New APSet has to have the same size as the old APSet!"); //IllegalArgument
     }
     _apset = new_apset;
 }
        /** Check for partial stutter insensitiveness using
         *  the nba and the complement nba */

        public void checkNBAs(NBA nba, NBA nba_complement)
        {
            APSet apset = nba.getAPSet_cp();

            bool nba_is_smaller = (nba.size() < nba_complement.size());

            //if (_printInfo) {
            //  std::cerr << "Checking for insensitiveness" << std::endl;
            //}
            bool one_insensitive = false;
            bool all_insensitive = true;

            //for (APSet::element_iterator it=apset->all_elements_begin(); it!=apset->all_elements_end();++it)
            for (int it = apset.all_elements_begin(); it != apset.all_elements_end(); ++it)
            {
                APElement elem = new APElement(it);

                if (_partiallyInsensitive.get(it))
                {
                    // don't recheck something we already now is stutter insensitive
                    one_insensitive = true;
                    continue;
                }

                //  if (_printInfo) {
                //std::cerr << "Checking " << elem.toString(*apset) << ": ";
                //std::cerr.flush();
                //  }

                bool insensitive;
                if (nba_is_smaller)
                {
                    insensitive = is_stutter_insensitive(nba, nba_complement, elem);
                }
                else
                {
                    insensitive = is_stutter_insensitive(nba_complement, nba, elem);
                }
                if (insensitive)
                {
                    _partiallyInsensitive.set(it);
                    one_insensitive = true;
                    //if (_printInfo) {
                    //  std::cerr << "+" << std::endl;
                    //}
                }
                else
                {
                    all_insensitive = false;
                    //if (_printInfo) {
                    //  std::cerr << "-" << std::endl;
                    //}
                }
            }
            _hasCheckedNBAs = true;
            _partiallyStutterInsensitive = one_insensitive;
        }
Ejemplo n.º 6
0
        public static DRA dba2dra(NBA nba, bool complement)
        {
            APSet ap_set = nba.getAPSet();;

            DRA dra_p = new DRA(ap_set);

            dba2dra(nba, dra_p, complement);
            return(dra_p);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        public NBA(APSet apset)
        {
            //_state_count = 0;
            _apset = apset;
            _start_state = null;

            //ly: added to the source
            _index = new List<NBA_State>();
            _final_states = new BitSet();
        }
Ejemplo n.º 9
0
        public NBA(APSet apset)
        {
            //_state_count = 0;
            _apset       = apset;
            _start_state = null;

            //ly: added to the source
            _index        = new List <NBA_State>();
            _final_states = new BitSet();
        }
Ejemplo n.º 10
0
        public EdgeContainerExplicit_APElement <BitSet> _container; //<BitSet>



        /**
         * Constructor.
         * @param state the NBA_State owning this EdgeManager
         * @param apset the underlying APSet
         */
        public NBA_State_EdgeManager(NBA_State state, APSet apset)
        {
            _state     = state;
            _container = new EdgeContainerExplicit_APElement <BitSet>(apset.size());

            //for (APSet::element_iterator eit=apset.all_elements_begin(); eit!=apset.all_elements_end(); ++eit) {
            for (int i = apset.all_elements_begin(); i != apset.all_elements_end(); i++)
            {
                _container.addEdge(new APElement(i), new BitSet());
            }
        }
Ejemplo n.º 11
0
 /**
  * Constructor that generates an iterator pointing
  * to a specific APElement.
  * @param ap_set the underlying APSet
  * @param m the APMonom over which we iterate
  * @param cur_e the current APElement
  */
 public APMonom2APElements(APSet ap_set, APMonom m, APElement cur_e)
 {
     _ap_set     = ap_set;
     _m          = m;
     _cur_e      = cur_e;
     _end_marker = false;
     if (m.isFalse())
     {
         _end_marker = true;
     }
 }
Ejemplo n.º 12
0
 /**
  * Constructor that generates an iterator pointing
  * to a specific APElement.
  * @param ap_set the underlying APSet
  * @param m the APMonom over which we iterate
  * @param cur_e the current APElement
  */
 public APMonom2APElements(APSet ap_set, APMonom m, APElement cur_e)
 {
     _ap_set = ap_set;
     _m = m;
     _cur_e = cur_e;
     _end_marker = false;
     if (m.isFalse())
     {
         _end_marker = true;
     }
 }
Ejemplo n.º 13
0
        /**
         * Constructor that generates an iterator pointing to the first
         * APElement.
         * @param ap_set the underlying APSet
         * @param m the APMonom over which we iterate
         */
        public APMonom2APElements(APSet ap_set, APMonom m)
        {
            _ap_set     = ap_set;
            _m          = m;
            _cur_e      = new APElement(m.getValueBits());
            _end_marker = false;

            if (m.isFalse())
            {
                _end_marker = true;
            }
        }
Ejemplo n.º 14
0
        /**
         * Constructor that generates an iterator pointing to the first
         * APElement.
         * @param ap_set the underlying APSet
         * @param m the APMonom over which we iterate
         */
        public APMonom2APElements(APSet ap_set, APMonom m)
        {
            _ap_set = ap_set;
            _m = m;
            _cur_e = new APElement(m.getValueBits());
            _end_marker = false;

            if (m.isFalse())
            {
                _end_marker = true;
            }
        }
Ejemplo n.º 15
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();
        }
Ejemplo n.º 16
0
        /** Add an edge. */
        public void addEdge(APMonom label, NBA_State state)
        {
            APSet ap_set = _state.getGraph().getAPSet();

            APMonom2APElements start = APMonom2APElements.begin(ap_set, label);

            //for (APMonom2APElements it=APMonom2APElements::begin(ap_set, label);it!=APMonom2APElements::end(ap_set, label);++it)
            while (!start.equal(APMonom2APElements.end(ap_set, label)))///////////////***********note sth wrong here don't skip sth extra
            {
                APElement it = start._cur_e;
                addEdge(it, state);
                start.increment();
            }
        }
Ejemplo n.º 17
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);
            }
        }
Ejemplo n.º 18
0
        public static LTLFormula parse(ltl2ba.Node LTLHeadNode, APSet predefined_apset)
        {
            //    boost::char_separator<char> sep(" ");
            //ltl_seperator sep; tokenizer tokens(formula, sep);

            APSet apset = new APSet();

            //tokenizer::iterator it = tokens.begin();

            //LTLNode ltl = parse(apset, predefined_apset);

            //if (it != tokens.end())
            //{
            //    THROW_EXCEPTION(Exception, "Unexpected character(s) at end of LTL formula: '" + *it + "'");
            //}

            LTLNode ltl = TranslateLTL(LTLHeadNode, apset, predefined_apset);

            APSet apset_ = predefined_apset ?? apset;

            return new LTLFormula(ltl, apset_);
        }
Ejemplo n.º 19
0
        /** Constructor.
         * @param da_1 The first DA
         * @param da_2 the second DA
         * @param trueloop_check Check for trueloops?
         * @param detailed_states Generate detailed descriptions of the states? */
        //bool trueloop_check=true, bool detailed_states=false
        public DAUnionAlgorithm(DA da_1, DA da_2, bool trueloop_check, bool detailed_states)
        {
            _da_1 = da_1;
            _da_2 = da_2;
            _acceptance_calculator = new UnionAcceptanceCalculator(da_1.acceptance(), da_2.acceptance());
            _trueloop_check        = trueloop_check;
            _detailed_states       = detailed_states;

            if (!(_da_1.getAPSet() == _da_2.getAPSet()))
            {
                throw new IllegalArgumentException("Can't create union of DAs: APSets don't match");
            }

            APSet combined_ap = da_1.getAPSet();

            if (!_da_1.isCompact() || !_da_2.isCompact())
            {
                throw new IllegalArgumentException("Can't create union of DAs: Not compact");
            }

            _result_da = da_1.createInstance(combined_ap);
        }
Ejemplo n.º 20
0
        public static LTLFormula parse(ltl2ba.Node LTLHeadNode, APSet predefined_apset)
        {
            //    boost::char_separator<char> sep(" ");
            //ltl_seperator sep; tokenizer tokens(formula, sep);

            APSet apset = new APSet();

            //tokenizer::iterator it = tokens.begin();

            //LTLNode ltl = parse(apset, predefined_apset);

            //if (it != tokens.end())
            //{
            //    THROW_EXCEPTION(Exception, "Unexpected character(s) at end of LTL formula: '" + *it + "'");
            //}


            LTLNode ltl = TranslateLTL(LTLHeadNode, apset, predefined_apset);

            APSet apset_ = predefined_apset ?? apset;

            return(new LTLFormula(ltl, apset_));
        }
Ejemplo n.º 21
0
 /** Copy constructor (not deep) */
 public LTLFormula(LTLFormula other)
 {
     _root = other._root;
     _apset = other._apset;
 }
Ejemplo n.º 22
0
 /**
  * Constructor
  * @param root the root node
  * @param apset the underlying APSet
  */
 public LTLFormula(LTLNode root, APSet apset)
 {
     _root = root;
     _apset = apset;
 }
Ejemplo n.º 23
0
 public DRA(APSet ap_set)
     : base(ap_set)
 {
     _isStreett = false;
 }
Ejemplo n.º 24
0
 public DRA(APSet ap_set)
     : base(ap_set)
 {
     _isStreett = false;
 }
Ejemplo n.º 25
0
        private static LTLNode TranslateLTL(ltl2ba.Node CurrentNode, APSet apset, APSet predefined_apset)
        {
            if (CurrentNode == null)
            {
                return(null);
            }

            type_t nodeType = type_t.T_TRUE;

            switch ((Operator)CurrentNode.ntyp)
            {
            case Operator.ALWAYS:
                nodeType = type_t.T_GLOBALLY;
                break;

            case Operator.AND:
                nodeType = type_t.T_AND;
                break;

            case Operator.EQUIV:
                nodeType = type_t.T_EQUIV;
                break;

            case Operator.EVENTUALLY:
                nodeType = type_t.T_FINALLY;
                break;

            case Operator.FALSE:
                nodeType = type_t.T_FALSE;
                break;

            case Operator.IMPLIES:
                nodeType = type_t.T_IMPLICATE;
                break;

            case Operator.NOT:
                nodeType = type_t.T_NOT;
                break;

            case Operator.OR:
                nodeType = type_t.T_OR;
                break;

            case Operator.TRUE:
                nodeType = type_t.T_TRUE;
                break;

            case Operator.U_OPER:
                nodeType = type_t.T_UNTIL;
                break;

            case Operator.V_OPER:
                nodeType = type_t.T_RELEASE;
                break;

            case Operator.NEXT:
                nodeType = type_t.T_NEXTSTEP;
                break;

            case Operator.PREDICATE:
                nodeType = type_t.T_AP;

                string ap = CurrentNode.sym.name;
                char   ch = ap[0];

                if (ch == '"')
                {
                    //	std::cerr << ap << std::endl;
                    Debug.Assert(ap[ap.Length - 1] == '"');     // last char is "

                    if (ap.Length <= 2)
                    {
                        // empty ap!
                        throw new Exception("LTL-Parse-Error: empty quoted string");
                    }


                    ap = ap.Substring(1, ap.Length - 2);     // cut quotes
                }
                else if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
                {
                    // nop
                }
                else
                {
                    throw new Exception("LTL-Parse-Error");
                }

                int ap_i;     // the AP index

                if (predefined_apset != null)
                {
                    if ((ap_i = predefined_apset.find(ap)) != -1)
                    {
                        return(new LTLNode(ap_i));
                    }
                    else
                    {
                        // not found in predefined APSet!
                        //std::cerr << "[" << (int)s[2] << "]" << std::endl;
                        throw new Exception("Can't parse formula with this APSet!");
                    }
                }
                else
                {
                    if ((ap_i = apset.find(ap)) != -1)
                    {
                        // AP exists already
                        return(new LTLNode(ap_i));
                    }
                    else
                    {
                        // create new AP
                        ap_i = apset.addAP(ap);
                        return(new LTLNode(ap_i));
                    }
                }
                break;


            default:
                break;
            }



            LTLNode newNode = new LTLNode(nodeType, TranslateLTL(CurrentNode.lft, apset, predefined_apset),
                                          TranslateLTL(CurrentNode.rgt, apset, predefined_apset));


            return(newNode);
        }
Ejemplo n.º 26
0
 /** Copy constructor (not deep) */
 public LTLFormula(LTLFormula other)
 {
     _root  = other._root;
     _apset = other._apset;
 }
Ejemplo n.º 27
0
 /**
  * Provides an iterator pointing to the first APElement
  * in the subset represented by the APMonom <i>m</i>.
  * @param ap_set the underlying APSet
  * @param m the APMonom over which we iterate
  * @return the iterator.
  */
 public static APMonom2APElements begin(APSet ap_set, APMonom m)
 {
     return new APMonom2APElements(ap_set, m);
 }
Ejemplo n.º 28
0
 public string toString(APSet ap_set, bool spaces)
 {
     if (ap_set.size() == 0)
     {
         return "\u03A3";
     }
     StringBuilder r = new StringBuilder();
     for (int i = 0; i < ap_set.size(); i++)
     {
         if (i >= 1)
         {
             r.Append("&");
         }
         if (!this.get(i))
         {
             r.Append("!");
         }
         else
         {
             if (spaces)
             {
                 r.Append(" ");
             }
         }
         r.Append(ap_set.getAP(i));
     }
     return r.ToString();
 }
Ejemplo n.º 29
0
 /**
  * Provides an iterator pointing to the first APElement
  * in the subset represented by the APMonom <i>m</i>.
  * @param ap_set the underlying APSet
  * @param m the APMonom over which we iterate
  * @return the iterator.
  */
 public static APMonom2APElements begin(APSet ap_set, APMonom m)
 {
     return(new APMonom2APElements(ap_set, m));
 }
Ejemplo n.º 30
0
 /** Create a new instance of the automaton. */
 public override DA createInstance(APSet ap_set)
 {
     return new DRA(ap_set);
 }
Ejemplo n.º 31
0
        /** Calculate the stutter closure for the NBA, for a certain symbol.
         * @param nba the NBA
         * @param label the symbol for which to perform the stutter closure
         */

        public static NBA stutter_closure(NBA nba, APElement label)
        {
            APSet apset = nba.getAPSet_cp();

            NBA nba_result_ptr = new NBA(apset);
            NBA result         = nba_result_ptr;

            int element_count = apset.powersetSize();

            Debug.Assert(nba.getStartState() != null);
            int start_state = nba.getStartState().getName();

            for (int i = 0; i < nba.size(); i++)
            {
                int st = result.nba_i_newState();
                Debug.Assert(st == i);

                if (st == start_state)
                {
                    result.setStartState(result[st]);
                }

                if (nba[st].isFinal())
                {
                    result[st].setFinal(true);
                }
            }

            for (int i = 0; i < nba.size(); i++)
            {
                int st = result.nba_i_newState();
                Debug.Assert(st == nba.size() + i);
                result[st].addEdge(label, result[i]);
                result[st].addEdge(label, result[st]);
            }

            //List<BitSet> reachable = null;

            //NBAEdgeSuccessors edge_successor = new NBAEdgeSuccessors(label);
            SCCs scc = new SCCs();

            GraphAlgorithms.calculateSCCs(nba, scc, true, label); //,edge_successor

            List <BitSet> reachable = scc.getReachabilityForAllStates();

            //    std::cerr << "SCCs for " << label.toString(*apset) << std::endl;
            //    std::cerr << scc << std::endl;

            //    std::cerr << " Reachability: "<< std::endl;
            //    for (unsigned int t=0; t < reachable->size(); t++) {
            //      std::cerr << t << " -> " << (*reachable)[t] << std::endl;
            //    }

            //    std::cerr << "  ---\n";

            for (int i = 0; i < nba.size(); i++)
            {
                NBA_State from = result[i];

                for (int j = 0; j < element_count; j++)
                {
                    BitSet result_to = new BitSet();

                    BitSet to = nba[i].getEdge(new APElement(j));
                    if (j != label.bitset)
                    {
                        result_to = to;
                    }
                    else
                    {
                        //for (BitSetIterator it=BitSetIterator(*to);it!=BitSetIterator::end(*to);++it)
                        for (int it = BitSetIterator.start(to); it != BitSetIterator.end(to); it = BitSetIterator.increment(to, it))
                        {
                            int to_state = it;

                            // We can go directly to the original state
                            result_to.set(to_state);
                            // We can also go to the corresponding stutter state instead
                            int stutter_state = nba.size() + to_state;
                            result_to.set(stutter_state);

                            // ... and then we can go directly to all the states that are j-reachable from to
                            result_to.Union(reachable[to_state]);
                        }
                    }

                    from.getEdge(new APElement(j)).Assign(result_to);
                }
            }

            //delete reachable;

            return(nba_result_ptr);
        }
Ejemplo n.º 32
0
        /** Calculate the stutter closure for the NBA, for all symbols.
         * @param nba the NBA
         */

        public static NBA stutter_closure(NBA nba)
        {
            APSet apset = nba.getAPSet_cp();

            NBA nba_result_ptr = new NBA(apset);
            NBA result         = nba_result_ptr;

            int element_count = apset.powersetSize();

            Debug.Assert(nba.getStartState() != null);
            int start_state = nba.getStartState().getName();

            for (int i = 0; i < nba.size(); i++)
            {
                int st = result.nba_i_newState();
                Debug.Assert(st == i);

                if (st == start_state)
                {
                    result.setStartState(result[st]);
                }

                if (nba[st].isFinal())
                {
                    result[st].setFinal(true);
                }
            }

            for (int i = 0; i < nba.size(); i++)
            {
                for (int j = 0; j < element_count; j++)
                {
                    int st = result.nba_i_newState();
                    Debug.Assert(st == nba.size() + (i * element_count) + j);
                    result[st].addEdge(new APElement(j), result[i]);
                    result[st].addEdge(new APElement(j), result[st]);
                }
            }

            List <List <BitSet> > reachable = new List <List <BitSet> >();

            //reachable.resize(element_count);
            Ultility.resize(reachable, element_count);

            for (int j = 0; j < element_count; j++)
            {
                //NBAEdgeSuccessors edge_successor = new NBAEdgeSuccessors(new APElement(j));
                SCCs scc = new SCCs();
                GraphAlgorithms.calculateSCCs(nba, scc, true, new APElement(j)); //,edge_successor

                reachable[j] = scc.getReachabilityForAllStates();

#if VERBOSE
                std::cerr << "SCCs for " << APElement(j).toString(*apset) << std::endl;
                std::cerr << scc << std::endl;

                std::cerr << " Reachability: " << std::endl;
                std::vector <BitSet>& reach = *reachable[j];
                for (unsigned int t = 0; t < reach.size(); t++)
                {
                    std::cerr << t << " -> " << reach[t] << std::endl;
                }

                std::cerr << "  ---\n";
#endif
            }


            for (int i = 0; i < nba.size(); i++)
            {
                NBA_State from = result[i];

                for (int j = 0; j < element_count; j++)
                {
                    BitSet result_to = new BitSet();

                    BitSet to = nba[i].getEdge(new APElement(j));
                    //for (BitSetIterator it=BitSetIterator(*to);it!=BitSetIterator::end(*to);++it)
                    for (int it = BitSetIterator.start(to); it != BitSetIterator.end(to); it = BitSetIterator.increment(to, it))
                    {
                        int to_state = it;

                        // We can go directly to the original state
                        result_to.set(to_state);
                        // We can also go to the corresponding stutter state instead
                        int stutter_state = nba.size() + (to_state * element_count) + j;
                        result_to.set(stutter_state);

                        // ... and then we can go directly to all the states that are j-reachable from to
                        result_to.Union(reachable[j][to_state]);
                    }

                    from.getEdge(new APElement(j)).Assign(result_to);
                }
            }

            //for (int i=0; i<reachable.size(); ++i) {
            //  delete reachable[i];
            //  }

            return(nba_result_ptr);
        }
Ejemplo n.º 33
0
  public EdgeContainerExplicit_APElement<BitSet> _container; //<BitSet>

  

  /**
   * Constructor.
   * @param state the NBA_State owning this EdgeManager
   * @param apset the underlying APSet   
   */
  public NBA_State_EdgeManager(NBA_State state, APSet apset)
  {

      _state = state;
      _container = new EdgeContainerExplicit_APElement<BitSet>(apset.size());

      //for (APSet::element_iterator eit=apset.all_elements_begin(); eit!=apset.all_elements_end(); ++eit) {
      for (int i = apset.all_elements_begin(); i != apset.all_elements_end(); i++)
      {
          _container.addEdge(new APElement(i), new BitSet());
      }

  }
Ejemplo n.º 34
0
 /**
  * Constructor
  * @param root the root node
  * @param apset the underlying APSet
  */
 public LTLFormula(LTLNode root, APSet apset)
 {
     _root  = root;
     _apset = apset;
 }
Ejemplo n.º 35
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("");
                    }
                }
            }
        }
Ejemplo n.º 36
0
 /**
  * Convert to a string representation.
  * @param ap_set The underlying APSet
  * @param spaces Print spaces in front of positive AP?
  */
 public string toString(APSet ap_set)
 {
     return(toString(ap_set, true));
 }
Ejemplo n.º 37
0
 /** Create a new instance of the automaton. */
 public virtual DA createInstance(APSet ap_set)
 {
     return(null);
 }
Ejemplo n.º 38
0
 /**
  * Provides an iterator pointing after the last APElement
  * in the subset represented by the APMonom <i>m</i>.
  * @param ap_set the underlying APSet
  * @param m the APMonom over which we iterate
  * @return the iterator.
  */
 public static APMonom2APElements end(APSet ap_set, APMonom m)
 {
     APMonom2APElements m2e = new APMonom2APElements(ap_set, m);
     m2e._end_marker = true;
     return m2e;
 }
Ejemplo n.º 39
0
        /**
         * Switch the APSet to another with the same number of APs.
         */
        public void switchAPSet(APSet new_apset)
        {
            if (new_apset.size() != _apset.size())
            {
                throw new IllegalArgumentException("New APSet has to have the same size as the old APSet!");
            }

            _apset = new_apset;
        }
Ejemplo n.º 40
0
 /** Create a new instance of the automaton. */
 public override DA createInstance(APSet ap_set)
 {
     return(new DRA(ap_set));
 }
Ejemplo n.º 41
0
        public static NBA product_automaton(NBA nba_1, NBA nba_2)
        {
            Debug.Assert(nba_1.getAPSet() == nba_2.getAPSet());
            NBA product_nba = new NBA(nba_1.getAPSet_cp());

            APSet apset = nba_1.getAPSet();

            Debug.Assert(apset == nba_2.getAPSet());

            for (int s_1 = 0; s_1 < nba_1.size(); s_1++)
            {
                for (int s_2 = 0; s_2 < nba_2.size(); s_2++)
                {
                    for (int copy = 0; copy < 2; copy++)
                    {
                        int s_r = product_nba.nba_i_newState();
                        Debug.Assert(s_r == (s_1 * nba_2.size() + s_2) * 2 + copy);

                        int to_copy = copy;

                        if (copy == 0 && nba_1[s_1].isFinal())
                        {
                            to_copy = 1;
                        }
                        if (copy == 1 && nba_2[s_2].isFinal())
                        {
                            product_nba[s_r].setFinal(true);
                            to_copy = 0;
                        }

                        //for (typename APSet::element_iterator it=apset.all_elements_begin();it!=apset.all_elements_end();++it)
                        for (int it = apset.all_elements_begin(); it != apset.all_elements_end(); it++)
                        {
                            APElement label  = new APElement(it);
                            BitSet    to_s1  = nba_1[s_1].getEdge(label);
                            BitSet    to_s2  = nba_2[s_2].getEdge(label);
                            BitSet    to_set = new BitSet();
                            //for (BitSetIterator it_e_1 = BitSetIterator(*to_s1); it_e_1 != BitSetIterator::end(*to_s1); ++it_e_1)
                            //for (int it_e_1 = 0; it_e_1 != to_s1.bitset.Count; ++it_e_1)
                            for (int it_e_1 = BitSetIterator.start(to_s1); it_e_1 != BitSetIterator.end(to_s1); it_e_1 = BitSetIterator.increment(to_s1, it_e_1))
                            {
                                //for (BitSetIterator it_e_2 = BitSetIterator(*to_s2); it_e_2 != BitSetIterator::end(*to_s2); ++it_e_2)
                                //for (int it_e_2 = 0; it_e_2 != to_s2.bitset.Count; ++it_e_2)
                                for (int it_e_2 = BitSetIterator.start(to_s2); it_e_2 != BitSetIterator.end(to_s2); it_e_2 = BitSetIterator.increment(to_s2, it_e_2))
                                {
                                    int to = it_e_1 * nba_2.size() + it_e_2 * 2 + to_copy;
                                    to_set.set(to);
                                }
                            }

                            product_nba[s_r].getEdge(label).Assign(to_set);
                        }
                    }
                }
            }

            int start_1 = nba_1.getStartState().getName();
            int start_2 = nba_2.getStartState().getName();

            product_nba.setStartState(product_nba[start_1 * nba_2.size() + start_2]);

            return(product_nba);
        }
Ejemplo n.º 42
0
 /**
    * Convert to a string representation.
    * @param ap_set The underlying APSet
    * @param spaces Print spaces in front of positive AP?
    */
 public string toString(APSet ap_set)
 {
     return toString(ap_set, true);
 }
Ejemplo n.º 43
0
        private static LTLNode TranslateLTL(ltl2ba.Node CurrentNode, APSet apset, APSet predefined_apset)
        {
            if (CurrentNode == null)
            {
                return null;
            }

            type_t nodeType = type_t.T_TRUE;
            switch ((Operator) CurrentNode.ntyp)
            {
                case Operator.ALWAYS:
                    nodeType = type_t.T_GLOBALLY;
                    break;
                case Operator.AND:
                    nodeType = type_t.T_AND;
                    break;
                case Operator.EQUIV:
                    nodeType = type_t.T_EQUIV;
                    break;
                case Operator.EVENTUALLY:
                    nodeType = type_t.T_FINALLY;
                    break;
                case Operator.FALSE:
                    nodeType = type_t.T_FALSE;
                    break;
                case Operator.IMPLIES:
                    nodeType = type_t.T_IMPLICATE;
                    break;
                case Operator.NOT:
                    nodeType = type_t.T_NOT;
                    break;
                case Operator.OR:
                    nodeType = type_t.T_OR;
                    break;
                case Operator.TRUE:
                    nodeType = type_t.T_TRUE;
                    break;
                case Operator.U_OPER:
                    nodeType = type_t.T_UNTIL;
                    break;
                case Operator.V_OPER:
                    nodeType = type_t.T_RELEASE;
                    break;
                case Operator.NEXT:
                    nodeType = type_t.T_NEXTSTEP;
                    break;
                case Operator.PREDICATE:
                    nodeType = type_t.T_AP;

                    string ap = CurrentNode.sym.name;
                    char ch = ap[0];

                    if (ch == '"')
                    {
                        //	std::cerr << ap << std::endl;
                        Debug.Assert(ap[ap.Length - 1] == '"'); // last char is "

                        if (ap.Length <= 2)
                        {
                            // empty ap!
                            throw new Exception("LTL-Parse-Error: empty quoted string");
                        }

                        ap = ap.Substring(1, ap.Length - 2); // cut quotes
                    }
                    else if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
                    {
                        // nop
                    }
                    else
                    {
                        throw new Exception("LTL-Parse-Error");
                    }

                    int ap_i; // the AP index

                    if (predefined_apset != null)
                    {
                        if ((ap_i = predefined_apset.find(ap)) != -1)
                        {
                            return new LTLNode(ap_i);
                        }
                        else
                        {
                            // not found in predefined APSet!
                            //std::cerr << "[" << (int)s[2] << "]" << std::endl;
                            throw new Exception("Can't parse formula with this APSet!");
                        }
                    }
                    else
                    {
                        if ((ap_i = apset.find(ap)) != -1)
                        {
                            // AP exists already
                            return new LTLNode(ap_i);
                        }
                        else
                        {
                            // create new AP
                            ap_i = apset.addAP(ap);
                            return new LTLNode(ap_i);
                        }
                    }
                    break;

                default:
                    break;

            }

            LTLNode newNode = new LTLNode(nodeType, TranslateLTL(CurrentNode.lft, apset, predefined_apset),
                                          TranslateLTL(CurrentNode.rgt, apset, predefined_apset));

            return newNode;
        }
Ejemplo n.º 44
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");
                        }
                    }
                }
            }
        }
Ejemplo n.º 45
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("");
                    }
                }
            }
        }