コード例 #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/>.

# This file tests various error conditions on the twa API

import spot

env = spot.declarative_environment()
env.declare("a")
env.declare("b")

f1a = spot.parse_infix_psl("a U b")
f1b = spot.parse_infix_psl("a U b", env)
assert not f1a.errors
assert not f1b.errors
# In the past, atomic propositions requires via different environments were
# never equal, but this feature was never used and we changed that in Spot 2.0
# for the sake of simplicity.
assert f1a.f == f1b.f

f2 = spot.parse_infix_psl("(a U b) U c", env)
assert f2.errors
ostr = spot.ostringstream()
f2.format_errors(ostr)
err = ostr.str()
assert "unknown atomic proposition `c'" in err
コード例 #2
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/>.

# Make sure that interdependencies between the spot and buddy wrappers
# are not problematic.
import buddy
import spot
import sys

simp = spot.tl_simplifier()

e = spot.default_environment.instance()
pf = spot.parse_infix_psl('GFa', e)
d = simp.get_dict()
a = spot.ltl_to_tgba_fm(pf.f, d)
g = spot.parse_infix_boolean('b&c', e)
b = simp.as_bdd(g.f)
buddy.bdd_printset(b)
spot.nl_cout()
del g

s0 = a.get_init_state()
it = a.succ_iter(s0)
it.first()
while not it.done():
    c = it.cond()
    sys.stdout.write("%s\n" % c)
    b &= c  # `&=' is defined only in buddy.  So if this statement works
コード例 #3
0
f = """!(G(F(P_Rbt2.observe)&& F(P_Rbt3.observe) &&
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")
コード例 #4
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 sys
import spot

e = spot.default_environment.instance()

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

for str1, isl in l:
    pf = spot.parse_infix_psl(str1, e, False)
    if pf.format_errors(spot.get_cout()):
        sys.exit(1)
    str2 = str(pf.f)
    del pf
    # Try to reparse the stringified formula
    pf = spot.parse_infix_psl(str2, e)
    if pf.format_errors(spot.get_cout()):
        sys.exit(1)
    assert isl == pf.f.is_leaf()
    del pf

assert spot.formula('a').is_leaf()
assert spot.formula('0').is_leaf()

for str1 in ['a * b', 'a xor b', 'a <-> b']:
コード例 #5
0
ファイル: declenv.py プロジェクト: mcc-petrinets/formulas
# 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

env = spot.declarative_environment()
env.declare("a")
env.declare("b")

f1a = spot.parse_infix_psl("a U b")
f1b = spot.parse_infix_psl("a U b", env)
assert not f1a.errors
assert not f1b.errors
# In the past, atomic propositions requires via different environments were
# never equal, but this feature was never used and we changed that in Spot 2.0
# for the sake of simplicity.
assert f1a.f == f1b.f

f2 = spot.parse_infix_psl("(a U b) U c", env)
assert f2.errors
ostr = spot.ostringstream()
f2.format_errors(ostr)
err = ostr.str()
assert "unknown atomic proposition `c'" in err
コード例 #6
0
ファイル: ltl_dfa.py プロジェクト: bfalacerda/ltl_sup_con
 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
コード例 #7
0
ファイル: interdep.py プロジェクト: mcc-petrinets/formulas
# 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/>.

# Make sure that interdependencies between the spot and buddy wrappers
# are not problematic.
import buddy
import spot
import sys

simp = spot.tl_simplifier()

e = spot.default_environment.instance()
pf = spot.parse_infix_psl('GFa', e)
d = simp.get_dict()
a = spot.ltl_to_tgba_fm(pf.f, d)
g = spot.parse_infix_boolean('b&c', e)
b = simp.as_bdd(g.f)
buddy.bdd_printset(b); spot.nl_cout()
del g

s0 = a.get_init_state()
it = a.succ_iter(s0)
it.first()
while not it.done():
    c = it.cond()
    sys.stdout.write("%s\n" % c)
    b &= c # `&=' is defined only in buddy.  So if this statement works
           # it means buddy can grok spot's objects.
コード例 #8
0
    elif o == '-v':
        output = 5
    elif o == '-W':
        wdba = 1
    else:
        usage(prog)

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"
コード例 #9
0
ファイル: ltl2tgba.py プロジェクト: mcc-petrinets/formulas
        output = 5
    elif o == '-W':
        wdba = 1
    else:
        usage(prog)

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"
コード例 #10
0
ファイル: ltlparse.py プロジェクト: hekmatnejad/mvspot
# 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 sys
import spot

e = spot.default_environment.instance()

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

for str1 in l:
    pf = spot.parse_infix_psl(str1, e, False)
    if pf.format_errors(spot.get_cout()):
        sys.exit(1)
    str2 = str(pf.f)
    del pf
    sys.stdout.write(str2 + "\n")
    # Try to reparse the stringified formula
    pf = spot.parse_infix_psl(str2, e)
    if pf.format_errors(spot.get_cout()):
        sys.exit(1)
    sys.stdout.write(str(pf.f) + "\n")
    del pf

assert spot.fnode_instances_check()
コード例 #11
0
ファイル: alarm.py プロジェクト: mcc-petrinets/formulas
f = """!(G(F(P_Rbt2.observe)&& F(P_Rbt3.observe) &&
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")
コード例 #12
0
def myparse(input):
    env = spot.default_environment.instance()
    pf = spot.parse_infix_psl(input, env)
    return pf.f