/**
         * Constructor
         * @param ltl The LTL formula
         * @param options the LTL2DSTAR options
         * @param sched a reference back to the scheduler
         */

        public LTL2DSTAR_Tree_Streett(LTLFormula ltl, BuchiAutomata ba,
                                      LTL2DSTAR_Options options,
                                      LTL2DSTAR_Scheduler sched) :
            base(ltl, ba, options, sched)
        {
            generateTree();
        }
        /**
         * Constructor
         * @param ltl The LTL formula
         * @param options the LTL2DSTAR options
         * @param sched a reference back to the scheduler
         */

        public LTL2DSTAR_Tree_Rabin(LTLFormula ltl, BuchiAutomata ba, LTL2DSTAR_Options options, LTL2DSTAR_Scheduler sched)
            : base(ltl, ba, options, sched)
        {
            _tree_normal = null;
            _tree_union  = null;
            generateTree();
        }
Exemple #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);
        }
        /** Type of a vector over the children */
        //typedef std::vector<LTL2DSTAR_Tree*> child_vector;

        /**
         * Constructor
         * @param ltl The LTL formula
         * @param options the LTL2DSTAR options
         * @param sched a reference back to the scheduler
         */
        protected LTL2DSTAR_Tree(LTLFormula ltl, BuchiAutomata ba, LTL2DSTAR_Options options, LTL2DSTAR_Scheduler sched)
        {
            _ltl          = ltl;
            buchiAutomata = ba;
            _options      = options;
            _sched        = sched;

            children = new List <LTL2DSTAR_Tree>();
        }
        /**
         * Constructor
         * @param ltl The LTL formula
         * @param options the LTL2DSTAR options
         * @param sched a reference back to the scheduler
         */

        public LTL2DSTAR_Tree_Union(LTLFormula ltl, BuchiAutomata ba, LTL2DSTAR_Options options, LTL2DSTAR_Scheduler sched) :
            base(ltl, ba, options, sched)
        {
            _left_tree  = null;
            _right_tree = null; //(0)

            _left = _ltl.getSubFormula(_ltl.getRootNode().getLeft());

            _right = _ltl.getSubFormula(_ltl.getRootNode().getRight());

            generateTree();
        }
Exemple #6
0
        /**
         * Generate a DRA for an LTL formula using scheck
         * @param ltl the formula
         * @param scheck_path the path to the scheck executable
         * @return a shared_ptr to the generated DRA (on failure returns a ptr to 0)
         */
        //template <class DRA>
        //typename DRA::shared_ptr
        public DRA ltl2dra(LTLFormula ltl, BuchiAutomata buchiAutomata)
        {
            LTLFormula ltl_;
            LTLFormula ltl_for_scheck = null;

            bool safe = false;

            if (ltl.isSafe())
            {
                safe = true;
                ltl_ = ltl.negate();
                ltl_for_scheck = ltl_;
            }
            else if (ltl.isCoSafe())
            {
                ltl_for_scheck = ltl;
            }
            else
            {
                if (_only_syn)
                {
                    // Not syntactically safe -> abort
                    //typename
                    //DRA::shared_ptr p;
                    //return p;
                    return null;
                }
            }

            //    std::cerr<< "Calling scheck with "
            //	     <<ltl_for_scheck->toStringPrefix() << " : " << safe << std::endl;

            //NBA nba = ltl2dba(ltl_for_scheck, buchiAutomata); //, scheck_path, _only_syn

            NBA nba = LTL2NBA.ltl2nba(ltl_for_scheck, buchiAutomata); //, scheck_path, _only_syn

            if (nba == null)
            {
                //typename
                //DRA::shared_ptr p;
                //return p;

                return null;
            }

            //    nba->print(std::cerr);

            // safe -> negate DRA
            return DBA2DRA.dba2dra(nba, safe);
            //    return dba2dra<DRA>(*nba, safe);
            // nba is auto-destructed
            //<NBA_t,DRA>
        }
        /**
         * Generate a DRA for an LTL formula using scheck
         * @param ltl the formula
         * @param scheck_path the path to the scheck executable
         * @return a shared_ptr to the generated DRA (on failure returns a ptr to 0)
         */
        //template <class DRA>
        //typename DRA::shared_ptr
        public DRA ltl2dra(LTLFormula ltl, BuchiAutomata buchiAutomata)
        {
            LTLFormula ltl_;
            LTLFormula ltl_for_scheck = null;

            bool safe = false;

            if (ltl.isSafe())
            {
                safe           = true;
                ltl_           = ltl.negate();
                ltl_for_scheck = ltl_;
            }
            else if (ltl.isCoSafe())
            {
                ltl_for_scheck = ltl;
            }
            else
            {
                if (_only_syn)
                {
                    // Not syntactically safe -> abort
                    //typename
                    //DRA::shared_ptr p;
                    //return p;
                    return(null);
                }
            }

            //    std::cerr<< "Calling scheck with "
            //	     <<ltl_for_scheck->toStringPrefix() << " : " << safe << std::endl;

            //NBA nba = ltl2dba(ltl_for_scheck, buchiAutomata); //, scheck_path, _only_syn

            NBA nba = LTL2NBA.ltl2nba(ltl_for_scheck, buchiAutomata); //, scheck_path, _only_syn

            if (nba == null)
            {
                //typename
                //DRA::shared_ptr p;
                //return p;

                return(null);
            }

            //    nba->print(std::cerr);

            // safe -> negate DRA
            return(DBA2DRA.dba2dra(nba, safe));
            //    return dba2dra<DRA>(*nba, safe);
            // nba is auto-destructed
            //<NBA_t,DRA>
        }
Exemple #8
0
        public NBA ltl2nba(LTLFormula ltl, BuchiAutomata buchiAutomata, bool exception_on_failure)
        {
            //Debug.Assert(_ltl2nba != null);

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

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

            return(nba);
        }
Exemple #9
0
        public NBA ltl2nba(LTLFormula ltl, BuchiAutomata buchiAutomata, bool exception_on_failure)
        {
            //Debug.Assert(_ltl2nba != null);

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

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

            return nba;
        }
        //
        /** Check the LTLFormula syntacticly for
        *  stutter insensitiveness */
        //public void checkLTL(bool hasNextStep) //LTLFormula ltl
        public void checkLTL(LTLFormula ltl)
        {
            if (ltl.hasNextStep())
            //if(hasNextStep)
            {
                _completelyStutterInsensitive = false;
                _partiallyStutterInsensitive = false;
            }
            else
            {
                _completelyStutterInsensitive = true;
                _partiallyStutterInsensitive = false;
            }

            _hasCheckedLTL = true;
        }
        /** Check the LTLFormula syntacticly for
         *  stutter insensitiveness */
        //public void checkLTL(bool hasNextStep) //LTLFormula ltl
        public void checkLTL(LTLFormula ltl) //
        {
            if (ltl.hasNextStep())
            //if(hasNextStep)
            {
                _completelyStutterInsensitive = false;
                _partiallyStutterInsensitive  = false;
            }
            else
            {
                _completelyStutterInsensitive = true;
                _partiallyStutterInsensitive  = false;
            }

            _hasCheckedLTL = true;
        }
        /**
         * Generate a DRA/DSA for the LTL formula
         */
        public DRA calculate(LTLFormula ltl, BuchiAutomata ba, LTL2DSTAR_Options ltl_opt)
        {
            LTLFormula ltl_p = (ltl.toPNF());

            //if (ltl_opt.verbose_scheduler) {
            //  std::cerr << ltl_p->toStringInfix() << std::endl;
            //}

            LTL2DSTAR_Tree_Start root = new LTL2DSTAR_Tree_Start(ltl_p, ba, ltl_opt, this);

            //if (ltl_opt.verbose_scheduler) {
            //  root.printTree(std::cerr);
            //}

            root.calculate();

            DRA result = root._automaton;

            if (result != null)
            {
                result.setComment(root._comment); //+ getTimingInformation()
            }
            return(result);
        }
 /** Check for partial stutter insensitiveness for a LTL formula.
  *  @param ltl the LTL formula
  *  @param llt2nba the LTL2NBA translator, has to provide function ltl2nba(ltl)
  */
 public void checkPartial(LTLFormula ltl, BuchiAutomata ba, LTL2DRA ltl2nba)
 {
     checkNBAs(ltl2nba.ltl2nba(ltl, ba), ltl2nba.ltl2nba(ltl.negate().toPNF(), ba));//true
 }
Exemple #14
0
 /**
  * Convert an LTL formula to an NBA using the specified LTL2NBA translator
  * @param ltl the formula
  * @param exception_on_failure if false, on error a null pointer is returned
  * @return a shared_ptr to the created NBA
  */
 public NBA ltl2nba(LTLFormula ltl, BuchiAutomata buchiAutomata)
 {
     return ltl2nba(ltl, buchiAutomata, false);
 }
Exemple #15
0
 /** Copy constructor (not deep) */
 public LTLFormula(LTLFormula other)
 {
     _root  = other._root;
     _apset = other._apset;
 }
Exemple #16
0
 /**
  * Get a LTLFormula_ptr for the subformula rooted at subroot
  */
 public LTLFormula getSubFormula(LTLNode subroot)
 {
     LTLFormula sub = new LTLFormula(subroot, _apset);
     return sub;
 }
        /** Type of a vector over the children */
        //typedef std::vector<LTL2DSTAR_Tree*> child_vector;
        /**
         * Constructor
         * @param ltl The LTL formula
         * @param options the LTL2DSTAR options
         * @param sched a reference back to the scheduler
         */
        protected LTL2DSTAR_Tree(LTLFormula ltl, BuchiAutomata ba, LTL2DSTAR_Options options, LTL2DSTAR_Scheduler sched)
        {
            _ltl = ltl;
            buchiAutomata = ba;
            _options = options;
            _sched = sched;

            children = new List<LTL2DSTAR_Tree>();
        }
Exemple #18
0
        /**
         * Get a LTLFormula_ptr for the subformula rooted at subroot
         */
        public LTLFormula getSubFormula(LTLNode subroot)
        {
            LTLFormula sub = new LTLFormula(subroot, _apset);

            return(sub);
        }
 /**
  * Constructor
  * @param ltl The LTL formula
  * @param options the LTL2DSTAR options
  * @param sched a reference back to the scheduler
  */
 public LTL2DSTAR_Tree_Streett(LTLFormula ltl, BuchiAutomata ba,
            LTL2DSTAR_Options options,
            LTL2DSTAR_Scheduler sched)
     : base(ltl, ba, options, sched)
 {
     generateTree();
 }
        /**
         * Constructor
         * @param ltl The LTL formula
         * @param options the LTL2DSTAR options
         * @param sched a reference back to the scheduler
         */
        public LTL2DSTAR_Tree_Union(LTLFormula ltl, BuchiAutomata ba, LTL2DSTAR_Options options, LTL2DSTAR_Scheduler sched)
            : base(ltl, ba, options, sched)
        {
            _left_tree = null;
            _right_tree = null; //(0)

            _left = _ltl.getSubFormula(_ltl.getRootNode().getLeft());

            _right = _ltl.getSubFormula(_ltl.getRootNode().getRight());

            generateTree();
        }
Exemple #21
0
        /**
         * Convert an LTL formula to an NBA
         * @param ltl
         * @return a pointer to the created NBA (caller gets ownership).
         */
        public static NBA ltl2nba(LTLFormula ltl, BuchiAutomata buchiAutomata)
        {
            // Create canonical APSet (with 'p0', 'p1', ... as AP)
            //LTLFormula ltl_canonical = ltl.copy();
            //APSet canonical_apset = ltl.getAPSet().createCanonical();
               // ltl_canonical.switchAPSet(canonical_apset);

            //AnonymousTempFile spin_outfile;
            //std::vector<std::string> arguments;
            //arguments.push_back("-f");
            //arguments.push_back(ltl_canonical->toStringInfix());

            //arguments.insert(arguments.end(), _arguments.begin(),_arguments.end());

            //const char *program_path=_path.c_str();

            //RunProgram spin(program_path,
            //        arguments,
            //        false,
            //        0,
            //        &spin_outfile,
            //        0);

            //int rv=spin.waitForTermination();
            //if (rv==0) {
            //  NBA_t *result_nba(new NBA_t(canonical_apset));

            //  FILE *f=spin_outfile.getInFILEStream();
            //  if (f==NULL) {
            //throw Exception("");
            //  }

            //  int rc=nba_parser_promela::parse(f, result_nba);
            //  fclose(f);

            //  if (rc!=0) {
            //throw Exception("Couldn't parse PROMELA file!");
            //  }

            NBA result_nba = new NBA(ltl.getAPSet());

            ////////////////////////////////////////////////////////////
            //todo: create the NBA from the BA
            //
            //
            ////////////////////////////////////////////////////////////
            NBABuilder builder = new NBABuilder(result_nba);
            //int current_state = 0;
            //bool current_state_valid=false;

            //foreach (string state in buchiAutomata.States)
            //{

            //    if (buchiAutomata.InitialStates.Contains(state))
            //    {
            //        int current_state = builder.findOrAddState(state);
            //        if (buchiAutomata.InitialStates.Contains(state))
            //        {
            //            builder.setStartState(current_state);
            //        }
            //    }
            //}

            foreach (string state in buchiAutomata.States)
            {
                //if (!buchiAutomata.InitialStates.Contains(state))
                {
                    ////s.AppendLine(state);
                    //if (current_state_valid) {
                    //    builder.addAdditionalNameToState(state, current_state);
                    //}
                    //else
                    //{
                    int current_state = builder.findOrAddState(state);
                    //std::string& label=$1;
                    //if (label.find("accept") != std::string::npos) {
                    if (state.EndsWith(Constants.ACCEPT_STATE))
                    {
                        builder.setFinal(current_state);
                    }
                    //if (label.find("accept_all") != std::string ::npos)
                    //{
                    //    // dirty hack: accept_all + skip -> trueloop
                    //    builder.setFinal(current_state);
                    //    builder.addEdge(current_state, current_state, std::string ("t"));
                    //}

                    if (buchiAutomata.InitialStates.Contains(state))
                    {
                        builder.setStartState(current_state);
                    }
                    //current_state_valid = true;
                    //}
                }
            }

            //s.AppendLine("Transitions");
            foreach (Transition transition in buchiAutomata.Transitions)
            {
                int from = builder.findOrAddState(transition.FromState);
                int to = builder.findOrAddState(transition.ToState);
                builder.addEdge(from, to, transition.labels);
            }

            // switch back to original APSet
            //result_nba.switchAPSet(ltl.getAPSet());

            //todo:
            //construct the NBA here

            return result_nba;
        }
 /** Check for partial stutter insensitiveness for a LTL formula.
  *  @param ltl the LTL formula
  *  @param llt2nba the LTL2NBA translator, has to provide function ltl2nba(ltl)
  */
 public void checkPartial(LTLFormula ltl, BuchiAutomata ba, LTL2DRA ltl2nba)
 {
     checkNBAs(ltl2nba.ltl2nba(ltl, ba), ltl2nba.ltl2nba(ltl.negate().toPNF(), ba));//true
 }
        /** Check for partial stutter insensitiveness for a LTL formula, using an
         *  already calculated NBA.
         *  @param nba an NBA for the positive formula
         *  @param ltl_neg the negated LTL formula (in PNF)
         *  @param llt2nba the LTL2NBA translator, has to provide function ltl2nba(ltl)
         */

        public void checkPartial(NBA nba, BuchiAutomata ba, LTLFormula ltl_neg, LTL2DRA ltl2nba)
        {
            checkNBAs(nba, ltl2nba.ltl2nba(ltl_neg, ba));
        }
        /**
          * Generate a DRA/DSA for the LTL formula
          */
        public DRA calculate(LTLFormula ltl, BuchiAutomata ba, LTL2DSTAR_Options ltl_opt)
        {
            LTLFormula ltl_p = (ltl.toPNF());

            //if (ltl_opt.verbose_scheduler) {
            //  std::cerr << ltl_p->toStringInfix() << std::endl;
            //}

            LTL2DSTAR_Tree_Start root = new LTL2DSTAR_Tree_Start(ltl_p, ba, ltl_opt, this);

            //if (ltl_opt.verbose_scheduler) {
            //  root.printTree(std::cerr);
            //}

            root.calculate();

            DRA result = root._automaton;
            if (result != null)
            {
                result.setComment(root._comment); //+ getTimingInformation()
            }
            return result;
        }
 /**
  * Constructor
  * @param ltl The LTL formula
  * @param options the LTL2DSTAR options
  * @param sched a reference back to the scheduler
  */
 public LTL2DSTAR_Tree_Rabin(LTLFormula ltl, BuchiAutomata ba, LTL2DSTAR_Options options, LTL2DSTAR_Scheduler sched)
     : base(ltl, ba, options, sched)
 {
     _tree_normal = null;
     _tree_union = null;
     generateTree();
 }
Exemple #26
0
 /** Deep copy */
 public LTLFormula copy()
 {
     LTLFormula copy_p = new LTLFormula(_root.copy(), _apset);
     return copy_p;
 }
Exemple #27
0
/**
 * Convert an LTL formula to an NBA using the specified LTL2NBA translator
 * @param ltl the formula
 * @param exception_on_failure if false, on error a null pointer is returned
 * @return a shared_ptr to the created NBA
 */
        public NBA ltl2nba(LTLFormula ltl, BuchiAutomata buchiAutomata)
        {
            return(ltl2nba(ltl, buchiAutomata, false));
        }
Exemple #28
0
 /** Copy constructor (not deep) */
 public LTLFormula(LTLFormula other)
 {
     _root = other._root;
     _apset = other._apset;
 }
Exemple #29
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;
        }
Exemple #30
0
        /** Deep copy */
        public LTLFormula copy()
        {
            LTLFormula copy_p = new LTLFormula(_root.copy(), _apset);

            return(copy_p);
        }
 /** Check for partial stutter insensitiveness for a LTL formula, using an
  *  already calculated NBA.
  *  @param nba an NBA for the positive formula
  *  @param ltl_neg the negated LTL formula (in PNF)
  *  @param llt2nba the LTL2NBA translator, has to provide function ltl2nba(ltl)
  */
 public void checkPartial(NBA nba, BuchiAutomata ba, LTLFormula ltl_neg, LTL2DRA ltl2nba)
 {
     checkNBAs(nba, ltl2nba.ltl2nba(ltl_neg, ba));
 }
        /** The output format */
        //enum {OUT_v2, OUT_NBA, OUT_DOT, OUT_PLUGIN} flag_output;



        public static DRA ConvertBA2DRA(BuchiAutomata BA, Node LTLHeadNode)
        {
            /** Flag: Convert LTL->DRA->NBA? */
            //bool flag_dra2nba;

            /** Flag: Print the NBA afert LTL->NBA? */
            //bool flag_print_ltl_nba;

            /** Flag: Use limiting with scheduler? */
            bool flag_sched_limits;

            /** The limiting factor for the scheduler (alpha) */
            double alpha;

            /** The options for Safra's algorithm */
            Options_Safra opt_safra = new Options_Safra();

            /** The options for LTL2DSTAR */
            LTL2DSTAR_Options opt_ltl2dstar = new LTL2DSTAR_Options();

            opt_ltl2dstar.opt_safra = opt_safra;

            //            std::map<std::string, std::string> defaults;
            //defaults["--ltl2nba"]="--ltl2nba=spin:ltl2ba";
            //defaults["--automata"]="--automata=rabin";
            //defaults["--output"]="--output=automaton";
            //defaults["--detailed-states"]="--detailed-states=no";
            //defaults["--safra"]="--safra=all";
            //defaults["--bisimulation"]="--bisimulation=yes";
            //defaults["--opt-acceptance"]="--opt-acceptance=yes";
            //defaults["--union"]="--union=yes";
            //defaults["--alpha"]="--alpha=10.0";
            //defaults["--stutter"]="--stutter=yes";
            //defaults["--partial-stutter"]="--partial-stutter=no";
            ////      defaults["--scheck"]=""; // scheck disabled
            ///
            ///
            // default values...
            //flag_dra2nba = false;
            flag_sched_limits = false;

            alpha = 1.0;

            // options not yet covered
            //flag_print_ltl_nba = false;
            //flag_stat_nba = false;

            //if (isRabin)
            //{
            opt_ltl2dstar.automata = automata_type.RABIN;
            //}
            //else
            //{
            //    opt_ltl2dstar.automata = automata_type.STREETT;
            //}
            opt_safra.opt_all();
            opt_safra.stutter   = false;
            opt_ltl2dstar.bisim = false;


            opt_safra.opt_rename = false;

            LTLFormula ltl = LTLPrefixParser.parse(LTLHeadNode);
            //APSet ap_set = ltl.getAPSet();

            //Debug.Assert(ltl2nba != null);
            LTL2DRA ltl2dra = new LTL2DRA(opt_safra); //, ltl2nba.get()


            //if (opt_ltl2dstar.automata == automata_type.ORIGINAL_NBA)
            //{
            //    // We just generate the NBA for the LTL formula
            //    // and print it

            //    NBA nba = ltl2dra.ltl2nba(ltl);
            //    if (nba == null)
            //    {
            //        throw new Exception("Can't generate NBA for LTL formula");
            //    }

            //    //if (flag_output==OUT_DOT) {
            //    //  nba->print_dot(out);
            //    //} else {
            //    //  nba->print_lbtt(out);
            //    //}
            //    //return 0;
            //}



            LTL2DSTAR_Scheduler ltl2dstar_sched = new LTL2DSTAR_Scheduler(ltl2dra, flag_sched_limits, alpha);

            //ltl2dstar_sched.flagStatNBA(flag_stat_nba);
            ltl2dstar_sched.flagStatNBA(false);

            opt_ltl2dstar.opt_safra = opt_safra;
            DRA dra = ltl2dstar_sched.calculate(ltl, BA, opt_ltl2dstar);

            //if (!dra.isCompact()) {
            //  dra.makeCompact();
            //}

            if (dra == null)
            {
                throw new Exception("Couldn't generate DRA!");
            }

            //if (!dra.isCompact()) {
            //  dra.makeCompact();
            //}


            return(dra);
        }
Exemple #33
0
        /**
         * Convert an LTL formula to an NBA
         * @param ltl
         * @return a pointer to the created NBA (caller gets ownership).
         */

        public static NBA ltl2nba(LTLFormula ltl, BuchiAutomata buchiAutomata)
        {
            // Create canonical APSet (with 'p0', 'p1', ... as AP)
            //LTLFormula ltl_canonical = ltl.copy();
            //APSet canonical_apset = ltl.getAPSet().createCanonical();
            // ltl_canonical.switchAPSet(canonical_apset);


            //AnonymousTempFile spin_outfile;
            //std::vector<std::string> arguments;
            //arguments.push_back("-f");
            //arguments.push_back(ltl_canonical->toStringInfix());

            //arguments.insert(arguments.end(), _arguments.begin(),_arguments.end());

            //const char *program_path=_path.c_str();

            //RunProgram spin(program_path,
            //        arguments,
            //        false,
            //        0,
            //        &spin_outfile,
            //        0);

            //int rv=spin.waitForTermination();
            //if (rv==0) {
            //  NBA_t *result_nba(new NBA_t(canonical_apset));

            //  FILE *f=spin_outfile.getInFILEStream();
            //  if (f==NULL) {
            //throw Exception("");
            //  }

            //  int rc=nba_parser_promela::parse(f, result_nba);
            //  fclose(f);

            //  if (rc!=0) {
            //throw Exception("Couldn't parse PROMELA file!");
            //  }

            NBA result_nba = new NBA(ltl.getAPSet());

            ////////////////////////////////////////////////////////////
            //todo: create the NBA from the BA
            //
            //
            ////////////////////////////////////////////////////////////
            NBABuilder builder = new NBABuilder(result_nba);

            //int current_state = 0;
            //bool current_state_valid=false;

            //foreach (string state in buchiAutomata.States)
            //{

            //    if (buchiAutomata.InitialStates.Contains(state))
            //    {
            //        int current_state = builder.findOrAddState(state);
            //        if (buchiAutomata.InitialStates.Contains(state))
            //        {
            //            builder.setStartState(current_state);
            //        }
            //    }
            //}

            foreach (string state in buchiAutomata.States)
            {
                //if (!buchiAutomata.InitialStates.Contains(state))
                {
                    ////s.AppendLine(state);
                    //if (current_state_valid) {
                    //    builder.addAdditionalNameToState(state, current_state);
                    //}
                    //else
                    //{
                    int current_state = builder.findOrAddState(state);
                    //std::string& label=$1;
                    //if (label.find("accept") != std::string::npos) {
                    if (state.EndsWith(Constants.ACCEPT_STATE))
                    {
                        builder.setFinal(current_state);
                    }
                    //if (label.find("accept_all") != std::string ::npos)
                    //{
                    //    // dirty hack: accept_all + skip -> trueloop
                    //    builder.setFinal(current_state);
                    //    builder.addEdge(current_state, current_state, std::string ("t"));
                    //}

                    if (buchiAutomata.InitialStates.Contains(state))
                    {
                        builder.setStartState(current_state);
                    }
                    //current_state_valid = true;
                    //}
                }
            }

            //s.AppendLine("Transitions");
            foreach (Transition transition in buchiAutomata.Transitions)
            {
                int from = builder.findOrAddState(transition.FromState);
                int to   = builder.findOrAddState(transition.ToState);
                builder.addEdge(from, to, transition.labels);
            }


            // switch back to original APSet
            //result_nba.switchAPSet(ltl.getAPSet());


            //todo:
            //construct the NBA here

            return(result_nba);
        }