#!/bin/sh
# -*- coding: utf-8 -*-
# Copyright (C) 2013 Laboratoire de Recherche et Développement
# de l'Epita (LRDE).
#
# 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 <http://www.gnu.org/licenses/>.

. ./defs
set -e

# Skip if $SATSOLVE is not installed.
(${SATSOLVER-glucose} --help >/dev/null 2>&1) || exit 77

ltl2tgba=../../bin/ltl2tgba
ltlcross=../../bin/ltlcross

cat >formulas <<'EOF'
XXa
GF(a -> XXXb)
F(p & XF(q & XF(r & XFs)))
F(q & X(p U r))
F(p & X(q & XFr))
p U (q & X(r U s))
G(a -> Fb) & G(c -> Fd)
GFa & GFb
GFa | GFb | GFc
GFa
a U b U c U d
G(a -> Fb) & Gc
(Ga -> Fb) & (G!a -> F!b)
p U (q & X(r & F(s & XF(u & XF(v & XFw)))))
G(a -> Fb) & G(b -> Fc)
G(a -> Fb) & G(!a -> F!b)
GFp && GFq && GF r && GF u
GF(a <-> XXXb)
G(p -> q U r)
GF(a <-> XXb)
G!c & G(a -> Fb) & G(b -> Fc)
G(a -> XXXb)
G(a -> Fb)
G(a U b U !a U !b)
(p U q U r) || (q U r U p) || (r U p U q)
X((a M F((!c & !b) | (c & b))) W (G!c U b))
X(((a & b) R (!a U !c)) R b)
XXG(Fa U Xb)
(!a M !b) W F!c
(b & Fa & GFc) R a
(a R (b W a)) W G(!a M (c | b))
(Fa W b) R (Fc | !a)
X(G(!a M !b) | G(a | G!a))
Fa W Gb
Ga | GFb
G((G!a & ((!b & X!c) | (b & Xc))) | (Fa & ((!b & Xc) | (b & X!c))))
a M G(F!b | X!a)
G!a R XFb
XF(!a | GFb)
G(F!a U !a) U Xa
(a | G(a M !b)) W Fc
Fa W Xb
X(a R ((!b & F!c) M X!a))
XG!a R Fb
GFc | (a & Fb)
X(a R (Fb R F!b))
G(Xa M Fa)
X(Gb | GFa)
X(Gc | XG((b & Ga) | (!b & F!a)))
Ga R Fb
G(a U (b | X((!c & !a) | (a & c))))
XG((G!a & F!b) | (Fa & (a | Gb)))
(a U X!a) | XG(!b & XFc)
X(G!a | GFa)
G(G!a | F!c | G!b)
EOF

$ltlcross -F formulas \
  --timeout=60 \
  "$ltl2tgba --det --lbtt %f >%T" \
  "$ltl2tgba --det --lbtt -x tba-det %f >%T" \
  "$ltl2tgba --det --lbtt -x sat-acc=1  %f >%T" \
  "$ltl2tgba --det --lbtt -x sat-acc=3 %f >%T" \
  "$ltl2tgba --det --lbtt -x sat-states=3 %f >%T" \
  "$ltl2tgba --det --lbtt -x sat-minimize %f >%T" \
  "$ltl2tgba --det --lbtt -x sat-minimize=2 %f >%T" \
  --json=det.json
