Ejemplo n.º 1
0
# 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 this program.  If not, see <http://www.gnu.org/licenses/>.

import spot
import sys
import itertools

# make sure that we are not allowed to build the sum of two automata with
# different dictionaries.

aut1 = spot.translate('Xa')
aut2 = spot.translate('Xb', dict=spot.make_bdd_dict())

try:
    spot.sum(aut1, aut2)
    exit(2)
except RuntimeError:
    pass


opts = spot.option_map()
opts.set('output', spot.OUTPUTLTL)
opts.set('tree_size_min', 15)
opts.set('tree_size_max', 15)
opts.set('wf', False)
opts.set('seed', 0)
opts.set('simplification_level', 0)
Ejemplo n.º 2
0
F(P_rbt1.observe)&& F(P_Rbt1.plus || P_Rbt1.moins || P_Rbt1.stop)&&
F(P_Rbt3.plus || P_Rbt3.moins || P_Rbt3.stop) && F(P_Rbt2.plus ||
P_Rbt2.moins || P_Rbt2.stop))-> G((F "map[0]==1") && (F "map[1]==1")
&& (F "map[2]==1") && (F "map[3]==1") && (F "map[4]==1") && (F
"map[5]==1") && (F "map[6]==1") && (F "map[7]==1") && (F "map[8]==1")
&& (F "map[9]==1") && (F "map[0]==2") && (F "map[1]==2") && (F
"map[2]==2") && (F "map[3]==2") && (F "map[4]==2") && (F "map[5]==2")
&& (F "map[6]==2") && (F "map[7]==2") && (F "map[8]==2") && (F
"map[9]==2") && (F "map[0]==3") && (F "map[1]==3") && (F "map[2]==3")
&& (F "map[3]==3") && (F "map[4]==3") && (F "map[5]==3") && (F
"map[6]==3") && (F "map[7]==3") && (F "map[8]==3") && (F
"map[9]==3")))"""

e = spot.default_environment.instance()
pf = spot.parse_infix_psl(f, e)
d = spot.make_bdd_dict()

spot.unblock_signal(signal.SIGALRM)
spot.unblock_signal(signal.SIGTERM)
os.setpgrp()
child = os.fork()
if child != 0:
    signal.signal(signal.SIGALRM, alarm_handler)
    signal.alarm(2)
    os.waitpid(child, 0)
    # If the child returns, before we get the alarm it's a bug.
    exit(1)

# This is expected to take WAY more than 2s.
print("Before")
spot.ltl_to_tgba_fm(pf.f, d, True)
Ejemplo n.º 3
0
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# 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 this program.  If not, see <http://www.gnu.org/licenses/>.

import spot

# make sure that we are not allowed to build the product of two automata with
# different dictionaries.

aut1 = spot.translate('Xa')
aut2 = spot.translate('Xb', dict=spot.make_bdd_dict())

try:
    spot.product(aut1, aut2)
    exit(2)
except RuntimeError:
    pass

try:
    spot.otf_product(aut1, aut2)
    exit(2)
except RuntimeError:
    pass
Ejemplo n.º 4
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
Ejemplo n.º 5
0
res = []
while c != buddy.bddtrue:
    var = buddy.bdd_var(c)
    h = buddy.bdd_high(c)
    if h == buddy.bddfalse:
        res.append(-var)
        c = buddy.bdd_low(c)
    else:
        res.append(var)
        c = h

assert res == [0, -1]

res2 = []
for i in run.aut.ap():
    res2.append((i, run.aut.register_ap(i)))
assert str(res2) == '[(a, 0), (b, 1)]'

f = spot.bdd_to_formula(b)
assert f._is(spot.op_And)
assert f[0]._is(spot.op_ap)
assert f[1]._is(spot.op_Not)
assert f[1][0]._is(spot.op_ap)
assert str(f) == 'a & !b'

try:
    f = spot.bdd_to_formula(b, spot.make_bdd_dict())
    sys.exit(2)
except RuntimeError as e:
    assert "not in the dictionary" in str(e)
Ejemplo n.º 6
0
# (at your option) any later version.
#
# 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 this program.  If not, see <http://www.gnu.org/licenses/>.

# This file tests various error conditions on the twa API

import spot
from buddy import bddtrue

aut = spot.make_twa_graph(spot.make_bdd_dict())

try:
    print(aut.to_str())
    exit(2)
except RuntimeError as e:
    assert "no state" in str(e)

try:
    aut.set_init_state(2)
except ValueError as e:
    assert "nonexisting" in str(e)

try:
    aut.set_univ_init_state([2, 1])
except ValueError as e:
Ejemplo n.º 7
0
while c != buddy.bddtrue:
    var = buddy.bdd_var(c)
    h = buddy.bdd_high(c)
    if h == buddy.bddfalse:
        res.append(-var)
        c = buddy.bdd_low(c)
    else:
        res.append(var)
        c = h

assert res == [0, -1]

res2 = []
for i in run.aut.ap():
    res2.append((i, run.aut.register_ap(i)))
assert str(res2) == '[(a, 0), (b, 1)]'


f = spot.bdd_to_formula(b)
assert f._is(spot.op_And)
assert f[0]._is(spot.op_ap)
assert f[1]._is(spot.op_Not)
assert f[1][0]._is(spot.op_ap)
assert str(f) == 'a & !b'

try:
    f = spot.bdd_to_formula(b, spot.make_bdd_dict())
    sys.exit(2)
except RuntimeError as e:
    assert "not in the dictionary" in str(e)
Ejemplo n.º 8
0
import abc
import sys
import re

from autotapmc.utils.Parser import parse, Operator

ops = {
    '!': Operator('!', 1, 3, 0),
    '&': Operator('&', 2, 1, 0),
    '|': Operator('|', 2, 1, 0)
}

re_splitter = r'(\s+|\(|\)|\&|\||!)'

#产生默认的BDD描述
default_bdd_dict = spot.make_bdd_dict()


class BuchiState(object):
    """ Data structure to store information in a state-based (generalized) buchi automaton """
    def __init__(self, index, description, acc):
        self.index = index
        self.acc = acc
        self.description = description


#buchi自動機的state有index,acc和描述組成


class BuchiEdge(object):
    """ Data structure to store information in a state-based (generalized) buchi automaton """
Ejemplo n.º 9
0
if len(args) != 1:
    usage(prog)


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

e = spot.default_environment.instance()

pf = spot.parse_infix_psl(args[0], e, debug_opt)
if pf.format_errors(cerr):
    exit_code = 1
f = pf.f

dict = spot.make_bdd_dict()

if f:
    if fm_opt:
        a = spot.ltl_to_tgba_fm(f, dict)
        concrete = 0
    elif taa_opt:
        a = concrete = spot.ltl_to_taa(f, dict)
    else:
        assert "unspecified translator"

    if wdba:
        a = spot.ensure_digraph(a)
        a = spot.minimize_obligation(a, f)

    del f
Ejemplo n.º 10
0
# 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 this program.  If not, see <http://www.gnu.org/licenses/>.

import os
import spot

contents = '''
HOA: v1 name: "a U b" States: 2 Start: 1 AP: 2 "a" "b" acc-name: Buchi
Acceptance: 1 Inf(0) properties: trans-labels explicit-labels state-acc
deterministic --BODY-- State: 0 {0} [t] 0 State: 1 [1] 0 [0&!1] 1 --END--
'''

filename = 'parsetgba.hoa'

out = open(filename, 'w+')
out.write(contents)
out.close()

a = spot.parse_aut(filename, spot.make_bdd_dict())

assert not a.errors

spot.print_dot(spot.get_cout(), a.aut)

del a

os.unlink(filename)