예제 #1
0
def graph_ba(pair, opts):
    # input: TGBA
    # output: results{'graph', ''}
    #     
    results = {'mp-prop-pair':[]}
    # temp
    ltl = pair[0]
    mplist = pair[1]
    cmd_ltl3ba = './translator/ltl3ba -f ' + '\'' +tmtc.ltl_out(ltl)+ '\''
    st = time.time()
    ltl3ba = subprocess.Popen(cmd_ltl3ba,shell=True,close_fds=True,stdout=subprocess.PIPE)
    out = ltl3ba.stdout
    graph = gg.nvc2graph(out, st, opts)
    if graph:
        props = []
        for mp in mplist:
            results['mp-prop-pair'].append({'mp':tltl._simplify_all_term_in_mp(mp), 'prop':tltl.get_proplist(mp)})
        results['graph'] = graph
        # results['mplist'] = copy.deepcopy(mplist)
        # results['mpprops'] = props
        if opts.pdebug:
            print "    props:",props
        en = time.time()
        tctime = str(en-st)+'  -- ltl3ba -> Graph  Total Construction Time '
        print tctime
        results['time'] = tctime
        return results
    else:
        return False
예제 #2
0
def graph_tgba(pair, opts):
    # input: TGBA
    # output: results{'graph', 'time'}
    #     
    results = {'mp-prop-pair': []}

    ltl = pair[0]
    mp_list = pair[1]

    cmd_ltl2tgba = 'ltl2tgba --low -f ' + '\'' +tmtc.ltl_out(ltl)+ '\''
    st = time.time()
    constime = time.time()
    ltl2tgba = subprocess.Popen(cmd_ltl2tgba, shell=True, close_fds=True, stdout=subprocess.PIPE)
    out = ltl2tgba.stdout
    graph = gg.tgba2graph(out, constime, opts)
    if graph:
        props = []
        for mp in mp_list:
            results['mp-prop-pair'].append({'mp':tltl._simplify_all_term_in_mp(mp), 'prop':tltl.get_proplist(mp)})
        results['graph'] = graph
        if opts.pdebug: print "\t\tprops:", props
        en = time.time()
        tctime = str(en-st)
        print tctime + '  -- ltl2tgba -> Graph  Conversion Time '
        results['time'] = tctime
        return results
    else:
        return False
예제 #3
0
        def _make_graph_by_opts(self):
            ltl = self.pair[0]

            if opts.tgba:
                print "-- TGBA!"
                cmd_ltl2tgba = 'ltl2tgba --low -f ' + '\'' + tmtc.ltl_out(ltl) + '\''
                ltl2tgba = subprocess.Popen(cmd_ltl2tgba, shell=True, close_fds=True, stdout=subprocess.PIPE)
                out = ltl2tgba.stdout
                graph = gg.tgba2graph(out, time.time(), self.opts)
            elif opts.ltltrans:
                cmd_ltltrans = './translator/ltltrans -f ' + '\'' + tmtc.ltl_out_trans(ltl) + '\''
                ltltrans = subprocess.Popen(cmd_ltltrans, shell=True, close_fds=True, stdout=subprocess.PIPE)
                out = ltltrans.stdout
                graph = gg.ltltrans2graph(out, time.time(), self.opts)
            else:
                print "-- BA!"
                cmd_ltl3ba = './translator/ltl3ba -f ' + "'" + tmtc.ltl_out(ltl) + "'"
                ltl3ba = subprocess.Popen(cmd_ltl3ba, shell=True, close_fds=True, stdout=subprocess.PIPE)
                out = ltl3ba.stdout
                graph = gg.nvc2graph(out, time.time(), self.opts)

            return graph
예제 #4
0
def satmain(ltlmp_formula, opts):
    total_result = {'sat':False, 'time':[], 'graphs':[], 'total_wg_time':0.0 }
    print "----- Parsing ", repr(ltlmp_formula), '-----'
    char_stream = antlr3.ANTLRStringStream(ltlmp_formula)
    lexer = LTLMPLexer(char_stream)
    tokens = antlr3.CommonTokenStream(lexer)
    parser = LTLMPParser(tokens)
    r = parser.start()
    ast_root = r.tree # root of the AST(Type: CommonTree(antlr))
    if opts.showprogress:
        print "----- Parsing Done -----"

    nodes = antlr3.tree.CommonTreeNodeStream(ast_root)
    nodes.setTokenStream(tokens)
    evaltree = LTLMPTree(nodes)
    if opts.debug:
        print "----- Tree Parsing -----"
    ltlmp_root = evaltree.expr()
    if opts.showprogress:
        print "----- Tree Parsing Done -----"
        print '----- AST Parse Result -----'
        print tmtc.ltl_out(ltlmp_root)
        print '----- End AST Parse Reslt-----'
        print '----- LTLMP to Nomal Form List -----'
    # from tree_ltl
    # the pairs of (ltlmp-NF, )
    pairList = tltl.get_MPNF_list(ltlmp_root)
    
    if opts.debug:
        print '----- Printing MP-NF Result -----'
        for pair in pairList:
            print '  --',tmtc.ltl_out(pair[0]),'--'
            for mp in pair[1]:
                print '   ',tmtc.mp_out(mp)
            
    # improve LTL tree
    # TODO: this is future work

    # LTL2BA: LTL to never-claim(nvc)
    # LTL2TGBA: LTL to Transition-based Generalized BA
    # LTLTrans: 
    MPNF_List = []   # MP Normal Form  Sentence? list
    GraphList = []   # 
    MPList = []      # MP-Constraints List according to Graph
    MPPropsList = [] # Props(var) used in MP-Constraints according to Graph
    if opts.tgba:
        for pair in pairList:
            g = graph_tgba(pair, opts)
            if g:
                MPNF_List.append(g)
    elif opts.ltltrans:
        for pair in pairList:
            g = graph_ltltrans(pair, opts)
            if g:
                MPNF_List.append(g)
    else:
        for pair in pairList:
            g = graph_ba(pair, opts)
            if g:
                MPNF_List.append(g)
    if opts.showprogress:
        print '---- Weighted Graph generating ----'

    wg_st = time.time()

     
    print '  -------- temporal result ---------'
    for mpnf in MPNF_List:
        res_graph = {'nodes':0, 'edges':0, 'scclist':{'nodes':[], 'edges':[]} }
        res_graph['edges'] = nx.number_of_edges(mpnf['graph'])
        res_graph['nodes'] = nx.number_of_nodes(mpnf['graph'])
        print str(res_graph['nodes'])+'  --   Nodes'
        print str(res_graph['edges'])+'  --   Edges'
        st_gtime = time.time()
        mpnf['mdg'] = get_weighted_graph(mpnf['graph'], mpnf['mp-prop-pair'], opts)
        # print mpnf['mdg']
        en_gtime = time.time()
        res_graph['mnodes'] = nx.number_of_nodes(mpnf['mdg'])
        res_graph['medges'] = nx.number_of_edges(mpnf['mdg'])
        res_graph['time'] = str(en_gtime-st_gtime)+ ' -- Weighted Graph Generating Time: '
        mpnf['graph_result'] = res_graph
        print str(en_gtime-st_gtime)+ ' -- Weighted Graph Generating Time: '
        
    if opts.showprogress:
        print '----- end weighted Graph ----'
        
    wg_en = time.time()
    total_result['total_wg_time'] = wg_en - wg_st
    '  -- Total Weighted Graph Generating Time:  '
    print str(wg_en - wg_st) + '  -- Total Weighted Graph Generating Time:  '
    print '  -------- temporal result ---------'
    for mpnf in MPNF_List:
        print str(mpnf['graph_result']['mnodes'])+'  --   Nodes'
        print str(mpnf['graph_result']['medges'])+'  --   Edges'

    """
    if opts.pdebug:
        print ' pdebug: ---- Generated MultiDiGraph ----'
        if opts.tgba:
            print ' TGBA Acc Cond: ',MDGraphList[i].graph['acccond']
        for i in range(len(MDGraphList)):
            edges = MDGraphList[i].edges(data=True)
            for edge in edges:
                print '    [',
                print edge[0]+'  --->  '+edge[1] + '\tWeight: ', edge[2]['weight'],
                if opts.tgba:
                    print '\t',edge[2]['acc'],
                print ' ]'
                """
                
    if opts.showprogress:
        print '---- SMT input generating ----'

    # for SCC which includes 'accept' state'
    #     do SAT 
    # convert Weighted Graph to SMT-Solver Sentence
    SMTCodesExtList = []
    for mpnf in MPNF_List:
        mpnf['Code/SCC'] = get_SMTCode(mpnf['mdg'], mpnf['mp-prop-pair'], opts)
        
    if opts.showprogress:
        print '---- solving SAT ----'

    # temp
    print '  -------- temporal result ---------'
    for mpnf in MPNF_List:
        # mpnf- 'Code/SCC' - 'AccSCCs' - 'sat-time'
        for accscc in mpnf['Code/SCC']['AccSCCs']:
            print str(accscc['nodes'])+'  --  AccSCC Nodes'
            print str(accscc['edges'])+'  --  AccSCC Edges'
        print str(mpnf['graph_result']['nodes'])+'  --   Nodes'
        print str(mpnf['graph_result']['edges'])+'  --   Edges'
        
    unsat = 0
    for mpnf in MPNF_List:
        # SAT for Each MPNF
        for accscc in mpnf['Code/SCC']['AccSCCs']:
            # SAT for each SCC
            st = time.time()
            smt_result = do_sat(accscc['SMTCode'], opts)
            en = time.time()
            accscc['sat_time'] = en - st
            if smt_result['sat']:
                print "   SCC-SAT found"
                total_result['sat']=True
                return process_result(MPNF_List, total_result)
            else:
                print '      SCC-partial UNSAT'
                unsat = 1
        print '    SCC-total-UNSAT'
    if unsat ==1:
        print '  Totally UNSAT'
        total_result['sat'] = False
        return process_result(MPNF_List, total_result)
        # do SAT-checking for Each SCC
    else:
        print '  all through UNSAT, no BA/TGBA-acceptable SCC, noSMTcode'
        total_result['sat'] = False
        return process_result(MPNF_List, total_result)
예제 #5
0
def debug1(pairList):
    print '----- Printing MP-NF Result -----'
    for pair in pairList:
        print '  --', tmtc.ltl_out(pair[0]), '--'
        for mp in pair[1]:
            print '   ', tmtc.mp_out(mp)
예제 #6
0
def show_progress1(ltlmp_root):
    print '----- AST Parse Result -----'
    print tmtc.ltl_out(ltlmp_root)
    print '----- End AST Parse Reslt-----'
    print '----- LTLMP to Nomal Form List -----'