Exemple #1
0
 def __init__(self, ltl_string, print_dot=True):
     opt=None
     #build hoa dfa string representation
     cout = spot.get_cout()
     e = spot.default_environment.instance()
     p = spot.empty_parse_error_list()
     debug_opt = False
     f = spot.parse_infix_psl(ltl_string, p, e, debug_opt)
     dict = spot.make_bdd_dict()
     print("GENERATE")
     a = spot.ltl_to_tgba_fm(f, dict)
     print("ENSURE")
     a = spot.ensure_digraph(a)
     print("MINIMIZE")
     a = spot.minimize_obligation(a, f)
     #a = degeneralized = spot.degeneralize(a)
     if print_dot:
         spot.print_dot(cout, a)
     
     hoa_string=a.to_str('hoa', opt)
     
     self.n_states=0
     self.initial_state=0
     self.accepting_states=[]
     self.transitions=[]
     self.atomic_propositions=[]
     
     hoa_string=hoa_string.split('\n')
     
     current_state=0
     i=0;
     line=None
     while line != '--END--':
         line=hoa_string[i]
         line=line.split(': ')
         if line[0]=='States':
             self.n_states=int(line[1])
             self.transitions=[[] for i in range(0,self.n_states)]
         elif line[0]=='Start':
             self.initial_state=int(line[1])
         elif line[0]=='AP':
             self.atomic_propositions=[i.strip('"') for i in line[1].split(' ')[1:]]
         elif line[0]=='State':
             line=line[1].split(' ')
             if current_state != int(line[0]):
                 print("ERROR")
             if '{' in line[-1]:
                 self.accepting_states.append(current_state)
             i+=1
             line=hoa_string[i]
             while 'State:' not in line:
                 if line == '--END--':
                     break
                 line=line.split(' ')
                 
                 transition=DnfTransitionDef(source=current_state,
                                             target=int(line[-1]),
                                             atomic_propositions=set(),
                                             vector_dnf_label=[]
                                             )
                 for conj_clause_string in line[:-1]:
                     conj_clause_rep={}
                     conj_clause_string=conj_clause_string.strip('[')
                     conj_clause_string=conj_clause_string.strip(']')
                     if conj_clause_string=='t':
                         transition.atomic_propositions=None
                         transition.vector_dnf_label=True
                         continue
                     if conj_clause_string == '|':
                         continue
                     conj_clause_string=conj_clause_string.split('&')
                     for literal_id in conj_clause_string:
                         if '!' in literal_id:
                             literal=self.atomic_propositions[int(literal_id[1:])]
                             transition.atomic_propositions.add(literal)
                             conj_clause_rep[literal]=False
                         else:
                             literal=self.atomic_propositions[int(literal_id)]
                             transition.atomic_propositions.add(literal)
                             conj_clause_rep[literal]=True
                     transition.vector_dnf_label.append(conj_clause_rep)                                                   
                 self.transitions[current_state].append(transition)
                 i+=1
                 line=hoa_string[i]
             current_state+=1
             continue
                 
         i+=1
Exemple #2
0
    elif o == '-t':
        output = 6
    elif o == '-v':
        output = 5
    else:
        usage(prog)

if len(args) != 1:
    usage(prog)


cout = spot.get_cout()
cerr = spot.get_cerr()

e = spot.default_environment.instance()
p = spot.empty_parse_error_list()

f = spot.parse(args[0], p, e, debug_opt)
if spot.format_parse_errors(cerr, args[0], p):
    exit_code = 1

dict = spot.bdd_dict()

if f:
    if fm_opt:
        a = spot.ltl_to_tgba_fm(f, dict)
        concrete = 0
    else:
        a = concrete = spot.ltl_to_tgba_lacim(f, dict)
    f.destroy()
    del f
Exemple #3
0
#
# Spot is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Spot; see the file COPYING.  If not, write to the Free
# Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.

import sys
import spot

e = spot.default_environment.instance()
p = spot.empty_parse_error_list()

l = ['GFa', 'a U (((b)) xor c)', '!(FFx <=> Fx)', 'a \/ a \/ b \/ a \/ a'];

for str1 in l:
    f = spot.parse(str1, p, e, 0)
    if spot.format_parse_errors(spot.get_cout(), str1, p):
        sys.exit(1)
    str2 = str(f)
    f.destroy()
    print str2
    # Try to reparse the stringified formula
    f = spot.parse(str2, p, e)
    if spot.format_parse_errors(spot.get_cout(), str2, p):
        sys.exit(1)
    print f