#!/bin/sh
# -*- coding: utf-8 -*-
# Copyright (C) 2009, 2010, 2012, 2014-2023 Laboratoire de
# Recherche et Développement de l'Epita (LRDE).
# Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
# département Systèmes Répartis Coopératifs (SRC), Université Pierre
# et Marie Curie.
#
# This file is part of Spot, a model checking library.
#
# Spot is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# 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 .
. ./defs
set -e
cat >input <<\EOF
HOA: v1
States: 3
Start: 0
AP: 3 "a" "b" "F\\G"
acc-name: generalized-Buchi 2
Acceptance: 2 Inf(0)&Inf(1)
properties: trans-labels explicit-labels state-acc deterministic
controllable-AP: 0 2
--BODY--
State: 0 {0 1}
[0&!1] 1
State: 1 {0}
[2] 2
State: 2
[t] 0
--END--
EOF
run 0 autfilt --hoa input > stdout
diff stdout input
test `autfilt -c --is-weak input` = 0
autfilt -H1.1 -v --is-weak input | grep properties: | tee props
cat >expected.props <input <<\EOF
HOA: v1
States: 2
Start: 0
AP: 2 "a" "b"
acc-name: Buchi
Acceptance: 1 Inf(0)
properties: trans-labels explicit-labels trans-acc
controllable-AP: /* empty */
--BODY--
State: 0
[0&1] 1 {0}
[!1] 1
[0&!1] 1 {0}
State: 1
[!1] 0
[1&0] 0 {0}
[0&!1] 0 {0}
--END--
EOF
cat >expected <<\EOF
HOA: v1
States: 2
Start: 0
AP: 2 "a" "b"
acc-name: Buchi
Acceptance: 1 Inf(0)
properties: trans-labels explicit-labels trans-acc
controllable-AP:
--BODY--
State: 0
[!1] 1
[0] 1 {0}
State: 1
[!1] 0
[0] 0 {0}
--END--
EOF
run 0 autfilt --merge-transitions --hoa input > stdout
cat stdout
run 0 autfilt -F stdout --isomorph expected
# Likewise, with a randomly generated TGBA.
run 0 randaut -Q 20 a b -e 0.2 -a 0.2 -A 2 --hoa | tee input
# the first read-write can renumber the states
run 0 autfilt --hoa --merge-transitions input > stdout
run 0 autfilt -F input --isomorph stdout
# But this second output should be the same as the first
run 0 autfilt --hoa stdout > stdout2
diff stdout stdout2
# Find formula that can be translated into a 3-state automaton, and
# exercise both %M and %m. The nonexistant file should never be
# open, because the input stream is infinite and autfilt should
# stop after 10 automata.
randltl -n -1 a b | ltl2tgba |
autfilt -F - -F nonexistant --states=3 --edges=..10 --acc-sets=1.. \
--name='%M, %S states' --stats='<%m>, %e, %a' -n 10 > output
cat >expected <, 5, 1
, 5, 1
, 4, 1
, 4, 1
, 4, 1
, 6, 1
<(a & !b & (b | (!b M F!a))) | (!a & (b | (!b & (b W Ga)))), 3 states>, 5, 1
<(a & (a U !b)) | (!a & (!a R b)), 3 states>, 5, 1
, 4, 1
, 3, 1
EOF
diff output expected
cat >input <expected <32 edges, 64->33 transitions"
States: 10
Start: 0
AP: 1 "a"
acc-name: generalized-Buchi 3
Acceptance: 3 Inf(0)&Inf(1)&Inf(2)
properties: trans-labels explicit-labels
--BODY--
State: 0
[t] 0 {0}
[!0] 1 {0}
[!0] 2 {0 2}
[0] 3 {0 2}
[!0] 4 {0 1}
[!0] 5 {0 1}
[!0] 6 {0 1 2}
[!0] 7 {0 1}
[!0] 8 {0 1}
[!0] 9 {0 1 2}
State: 1 {0 2}
[0] 3
State: 2
[!0] 2 {0 2}
[!0] 6 {0 1 2}
[!0] 9 {0 1 2}
State: 3
[!0] 1 {0 2}
[!0] 2 {0 2}
[0] 3 {0 2}
[!0] 5 {0 1 2}
[!0] 6 {0 1 2}
[!0] 8 {0 1 2}
[!0] 9 {0 1 2}
State: 4
[!0] 4 {1}
[!0] 5 {1}
[!0] 6 {1 2}
[!0] 7 {1}
[!0] 8 {1}
[!0] 9 {1 2}
State: 5
State: 6 {1 2}
[!0] 6
[!0] 9
State: 7
[0] 0 {0}
[0] 3 {0 2}
State: 8 {0 2}
[0] 3
State: 9
--END--
EOF
autfilt --merge -Hm input --name="%E->%e edges, %T->%t transitions" > output
diff output expected
ltl2tgba -x degen-lskip=1 --ba > tmp.hoa < output
cat >expected <input <output
cat >expected < 3
subgraph cluster_0 {
color=green
id="SCC0"
1 [label="s1", peripheries=2]
}
subgraph cluster_1 {
color=green
id="SCC1"
0 [label="s0", peripheries=2]
}
subgraph cluster_2 {
color=black
id="SCC2"
3 [label="s3"]
}
0 -> 0 [label="b", id="E1", tooltip="\\\\E\n#1"]
1 -> 1 [label="a", id="E2", tooltip="\\\\E\n#2"]
2 [label="s2"]
3 -> 1 [label="a", id="E3", tooltip="\\\\E\n#3"]
3 -> 0 [label="b", id="E4", tooltip="\\\\E\n#4"]
}
EOF
diff output expected
test 1 = `autfilt -H input --complete | autfilt --is-complete --count`
# The SPOT_DEFAULT_FORMAT envvar should be ignored if --dot is given.
# --dot=k should be ignored when not applicable.
SPOT_DEFAULT_FORMAT=hoa ltl2tgba --dot=ak 'GFa & GFb' >output
cat output
cat >expected < 0
0 [label="0"]
0 -> 0 [label="!a & !b"]
0 -> 0 [label="a & !b\n{0}"]
0 -> 0 [label="!a & b\n{1}"]
0 -> 0 [label="a & b\n{0,1}"]
}
EOF
diff output expected
ltl2tgba -d'bani(foo)' 'GFa & GFb' >output
cat output
cat >expected < 0
0 [label="0"]
0 -> 0 [label="!a & !b", id="E1", tooltip="\\\\E\n#1"]
0 -> 0 [label="a & !b\n⓿", id="E2", tooltip="\\\\E\n#2"]
0 -> 0 [label="!a & b\n❶", id="E3", tooltip="\\\\E\n#3"]
0 -> 0 [label="a & b\n⓿❶", id="E4", tooltip="\\\\E\n#4"]
}
EOF
diff output expected
ltl2tgba -dbang 'GFa & GFb' >output
cat output
cat >expected < 0
0 [label="0"]
0 -> 0 [label=""]
0 -> 0 [label="⓿"]
0 -> 0 [label="❶"]
0 -> 0 [label="⓿❶"]
}
EOF
diff output expected
SPOT_DOTDEFAULT=bra ltl2tgba --dot='Ae.f(Lato)' 'GFa & GFb' >output
cat output
zero='⓿'
one='❶'
cat >expected <[gen. Büchi 2]>
labelloc="t"
node [shape="ellipse",width="0.5",height="0.5"]
fontname="Lato"
node [fontname="Lato"]
edge [fontname="Lato"]
I [label="", style=invis, width=0]
I -> 0
0 [label=<0>]
0 -> 0 [label=]
0 -> 0 [label=$zero>]
0 -> 0 [label=$one>]
0 -> 0 [label=$zero$one>]
}
EOF
diff output expected
cat >in <expected < 0
0 [label="0"]
0 -> 1 [label="!a & !b", taillabel="0"]
0 -> 2 [label="a & !b", taillabel="1"]
0 -> 3 [label="!a & b", taillabel="2"]
0 -> 4 [label="a & b", taillabel="3"]
1 [label="test me\n⓿❸"]
1 -> 1 [label="!a & !b", taillabel="0"]
1 -> 2 [label="a & !b", taillabel="1"]
1 -> 6 [label="!a & b", taillabel="2"]
1 -> 7 [label="a & b", taillabel="3"]
2 [label="2\n⓿❷❸"]
2 -> 1 [label="!a & !b", taillabel="0"]
2 -> 2 [label="a & !b", taillabel="1"]
2 -> 6 [label="!a & b", taillabel="2"]
2 -> 7 [label="a & b", taillabel="3"]
3 [label="3\n❸"]
3 -> 5 [label="1", taillabel="0"]
4 [label="hihi\n❷❸"]
4 -> 5 [label="1", taillabel="0"]
5 [label="5\n❶❸"]
5 -> 5 [label="1", taillabel="0"]
6 [label="6\n⓿"]
6 -> 8 [label="!a & !b", taillabel="0"]
6 -> 6 [label="!a & b", taillabel="1"]
6 -> 9 [label="a & !b", taillabel="2"]
6 -> 7 [label="a & b", taillabel="3"]
7 [label="7\n⓿❷"]
7 -> 8 [label="!a & !b", taillabel="0"]
7 -> 6 [label="!a & b", taillabel="1"]
7 -> 9 [label="a & !b", taillabel="2"]
7 -> 7 [label="a & b", taillabel="3"]
8 [label="8\n⓿❸"]
8 -> 8 [label="!a & !b", taillabel="0"]
8 -> 6 [label="!a & b", taillabel="1"]
8 -> 9 [label="a & !b", taillabel="2"]
8 -> 7 [label="a & b", taillabel="3"]
9 [label="9\n⓿❷❸"]
9 -> 8 [label="!a & !b", taillabel="0"]
9 -> 6 [label="!a & b", taillabel="1"]
9 -> 9 [label="a & !b", taillabel="2"]
9 -> 7 [label="a & b", taillabel="3"]
}
EOF
autfilt --dot=bao in >out
diff out expected
cat >expected2 <' >out
diff out expected2
cat >expected3 <' >out
diff out expected3
# Let's pretend that this is some used supplied input, as discussed in
# the comments of https://github.com/adl/hoaf/issues/39
cat >input <output1 && exit 1
cat >expect1 < output1b
diff output1 output1b
# Here is the scenario where the undefined states are actually states
# we wanted to remove. So we tell autfilt to fix the automaton using
# --remove-dead-states
SPOT_DEFAULT_FORMAT=hoa autfilt --remove-dead input >output2 && exit 1
cat >expect2 <output2b
cat >expect2b <input <output3
autfilt -H --remove-dead input >>output3
cat >expect3 <stderr && exit 1
grep 'print_hoa.*z' stderr
cat >input4 <output4
autfilt -H --small input4 >output4b
autfilt -H --high input4 >output4c
cat output4
cat >expect4<output5
test `autfilt --is-weak -c output4` = 1
test `autfilt --is-terminal -c output4` = 0
sed 's/\[0\]/[t]/g' expect4 > output4d
test `autfilt --is-terminal -c output4d` = 1
cat >expect5<input6 <output6
cat >expect6 <output6d
cat >expect6d < 1
0 [label="0\nb"]
0 -> 2 [label=""]
0 -> 1 [label=""]
0 -> 1 [label=""]
1 [label="1\na"]
1 -> 0 [label=""]
1 -> 1 [label=""]
2 [label="2\na", peripheries=2]
2 -> 2 [label=""]
2 -> 0 [label=""]
2 -> 1 [label=""]
}
EOF
diff output6d expect6d
run 0 autfilt -dbark input6 >output6d2
cat >expect6d2 <⓿)
[Büchi]>
labelloc="t"
node [shape="box",style="rounded",width="0.5"]
I [label="", style=invis, width=0]
I -> 1
0 [label=<0
b>]
0 -> 2 [label=<>]
0 -> 1 [label=<>]
0 -> 1 [label=<>]
1 [label=<1
a>]
1 -> 0 [label=<>]
1 -> 1 [label=<>]
2 [label=<2
⓿
a>]
2 -> 2 [label=<>]
2 -> 0 [label=<>]
2 -> 1 [label=<>]
}
EOF
diff output6d2 expect6d2
cat >input7 <output7 && exit 0
test $? -eq 2
cat >expected7 <input8 <oneline.hoa && exit 1
autfilt input8 --stats='%h' >oneline2.hoa && exit 1
autfilt input8 --stats='%H' >oneline3.hoa && exit 1
autfilt input8 --randomize --stats='%h' >oneline4.hoa && exit 1
autfilt input8 --randomize --stats='%H' >oneline5.hoa && exit 1
diff oneline.hoa oneline2.hoa
diff oneline.hoa oneline3.hoa
diff oneline.hoa oneline4.hoa && exit 1
diff oneline.hoa oneline5.hoa
cat >input9 < output9
cat >expected9 < 2
0 [label="0", peripheries=2, style="bold,rounded", color="#1F78B4"]
0 -> 0 [label="1", style=bold, color="#1F78B4"]
1 [label="1"]
1 -> 0 [label="c", style=bold, color="#FF4DA0"]
1 -> 1 [label="b & !c", style=bold, color="#FF7F00"]
2 [label="new\nline", style="bold,rounded", color="#6A3D9A"]
2 -> 0 [label="c", style=bold, color="#6A3D9A"]
2 -> 1 [label="!a & b & !c"]
2 -> 2 [label="a & !c"]
}
EOF
diff output9 expected9
autfilt -dbar input9 > output9a
style=', style="bold,rounded", color="#1F78B4"'
cat >expected9a <⓿)
[Büchi]>
labelloc="t"
node [shape="box",style="rounded",width="0.5"]
I [label="", style=invis, width=0]
I -> 2
0 [label=<0
⓿>$style]
0 -> 0 [label=<1>, style=bold, color="#1F78B4"]
1 [label=<1>]
1 -> 0 [label=, style=bold, color="#FF4DA0"]
1 -> 1 [label=, style=bold, color="#FF7F00"]
2 [label=line>, style="bold,rounded", color="#6A3D9A"]
2 -> 0 [label=, style=bold, color="#6A3D9A"]
2 -> 1 [label=]
2 -> 2 [label=]
}
EOF
diff output9a expected9a
# spot.hightlight.edges and spot.hightlight.states are not valid HOA
# v1 output, so they should only but output for HOA 1.1
autfilt input9 -H1 | autfilt -H1 | grep highlight && exit 1
autfilt input9 -H1 | autfilt -H1.1 | grep highlight && exit 1
autfilt -H1.1 input9 | autfilt -H1.1 | grep highlight
autfilt -H1.1 input9 | autfilt -dA > output9b
diff output9 output9b
test 2 = `ltl2tgba 'GFa' 'a U b' 'a U b U c'| autfilt --ap=2..3 --count`
# reading CSV with embedded automata
test 2 = `genltl --dac=1..3 | ltl2tgba --stats='%e,"%h",%s' |
dstar2tgba -F-/2 --stats='%<,%>,"%h"' |
autfilt --states=2..3 -F-/3 --stats='%<,"%h"' | wc -l`
# --dot=d
ltl2tgba 'GF(a <-> Fb)' | autfilt -B --dot=dA | grep ' (' >out
cat >expected <out
cat >expected < 0
0 [label="0 (1)"]
0 -> 0 [label="a"]
}
EOF
diff out expected
# Issue #392.
test 2 = `genltl --rv-counter-carry-linear=7|ltl2tgba -d'<10' |grep -c hidden`
f="{{!a;!b}:{{c <-> d} && {e xor f} && {m | {l && {k | {j <-> {i xor {g && h}"
f="$f}}}}} && {{n && o} | {!n && p}} && {q -> {r <-> s}}}:{[*0..1];t}}[]-> u"
ltl2tgba -f "$f" --dot=bar > out.dot
grep 'label too long' out.dot
# genltl --and-fg=32 | ltlfilt --relabel=abc | ltldo ltl3ba produces a
# few edges equivalent to a lot of transitions. The code used to
# count those transitions used to be very inefficient.
cat >andfg32.hoa <