satmin.org 32.3 KB
Newer Older
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
1
# -*- coding: utf-8 -*-
2
#+TITLE: SAT-based Minimization of Deterministic ω-Automata
3
#+DESCRIPTION: Spot command-line tools for minimizing ω-automata
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
4
#+INCLUDE: setup.org
5
#+HTML_LINK_UP: tools.html
6

7
8
9
10
11
#+NAME: version
#+BEGIN_SRC sh :exports none
head -n 1 ../../picosat/VERSION | tr -d '\n'
#+END_SRC

12
13
This page explains how to use [[file:ltl2tgba.org][=ltl2tgba=]], [[file:dstar2tgba.org][=dstar2tgba=]], or [[file:autfilt.org][=autfilt=]]
to minimize deterministic automata using a SAT solver.
14
15
16
17
18
19

Let us first state a few facts about this minimization procedure.

1) The procedure works only on *deterministic* Büchi automata: any
   recurrence property can be converted into a deterministic Büchi
   automaton, and sometimes there are several ways of doing so.
20
2) Spot actually implements two SAT-based minimization procedures: one
21
   that builds a deterministic transition-based Büchi automaton
22
23
24
25
26
27
   (DTBA), and one that builds a deterministic transition-based
   ω-automaton with arbitrary acceptance condition (DTωA).  In
   [[file:ltl2tgba.org][=ltl2tgba=]] and [[file:dstar2tgba.org][=dstar2tgba=]], the latter procedure is restricted to
   TGBA.  In [[file:autfilt.org][=autfilt=]] it can use different and acceptance conditions
   for input and output, so you could for instance input a Rabin
   automaton, and produce a Streett automaton.
28
29
30
3) These two procedures can optionally constrain their output to
   use state-based acceptance. (They simply restrict all the outgoing
   transitions of a state to belong to the same acceptance sets.)
31
4) Spot is built using PicoSAT call_version()[:results raw].
32
   This solver was chosen for its performance, simplicity of
33
34
   integration and license compatibility.  However, it is
   still possible to use an external SAT solver (as described below).
35
5) [[file:ltl2tgba.org][=ltl2tgba=]] and [[file:dstar2tgba.org][=dstar2tgba=]] will always try to output an automaton.
36
37
38
39
40
41
42
43
   If they fail to determinize the property, they will simply output a
   nondeterministic automaton, if they managed to obtain a
   deterministic automaton but failed to minimize it (e.g., the
   requested number of states in the final automaton is too low), they
   will return that "unminimized" deterministic automaton.  There are
   only two cases where these tool will abort without returning an
   automaton: when the number of clauses output by Spot (and to be fed
   to the SAT solver) exceeds $2^{31}$, or when the SAT-solver was
44
45
   killed by a signal. [[file:autfilt.org][=autfilt --sat-minimize=]] will only output an
   automaton if the SAT-based minimization was successful.
46
47
48
49
6) Our [[https://www.lrde.epita.fr/~adl/dl/adl/baarir.14.forte.pdf][FORTE'14 paper]] describes the SAT encoding for the minimization
   of deterministic BA and TGBA.  Our [[https://www.lrde.epita.fr/~adl/dl/adl/baarir.15.lpar.pdf][LPAR'15 paper]] describes the
   generalization of the SAT encoding to deal with deterministic TωA
   with any acceptance condition.
50

51
* How to change the SAT solver used
52

53
54
55
56
By default Spot uses PicoSAT call_version()[:results raw]), this SAT-solver
is built into the Spot library, so that no temporary files are used to
store the problem.

57
The environment variable =SPOT_SATSOLVER= can be used to change the
58
59
60
61
62
63
64
65
66
SAT solver used by Spot.  This variable should describe a shell command
to run the SAT-solver on an input file called =%I= so that a model satisfying
the formula will be written in =%O=.  For instance to use [[http://www.labri.fr/perso/lsimon/glucose/][Glucose 3.0]], instead
of the builtin version of PicoSAT, define
#+BEGIN_SRC sh
export SPOT_SATSOLVER='glucose -verb=0 -model %I >%O'
#+END_SRC
We assume the SAT solver follows the input/output conventions of the
[[http://www.satcompetition.org/][SAT competition]]
67

68
* Enabling SAT-based minimization in =ltl2tgba= or =dstar2tgba=
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

Both tools follow the same interface, because they use the same
post-processing steps internally (i.e., the =spot::postprocessor=
class).

First, option =-D= should be used to declare that you are looking for
more determinism.  This will tweak the translation algorithm used by
=ltl2tgba= to improve determinism, and will also instruct the
post-processing routine used by both tools to prefer a
deterministic automaton over a smaller equivalent nondeterministic
automaton.

However =-D= is not a guarantee to obtain a deterministic automaton,
even if one exists.  For instance, =-D= fails to produce a
deterministic automaton for =GF(a <-> XXb)=.  Instead we get a 9-state
non-deterministic automaton.

#+BEGIN_SRC sh :results verbatim :exports both
87
ltl2tgba -D 'GF(a <-> XXb)' --stats='states=%s, det=%d'
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#+END_SRC
#+RESULTS:
: states=9, det=0

Option =-x tba-det= enables an additional
determinization procedure, that would otherwise not be used by =-D=
alone.  This procedure will work on any automaton that can be
represented by a DTBA; if the automaton to process use multiple
acceptance conditions, it will be degeneralized first.

On our example, =-x tba-det= successfully produces a deterministic
TBA, but a non-minimal one:

#+BEGIN_SRC sh :results verbatim :exports both
102
ltl2tgba -D -x tba-det 'GF(a <-> XXb)' --stats='states=%s, det=%d'
103
104
105
106
107
108
109
110
#+END_SRC
#+RESULTS:
: states=7, det=1

Option =-x sat-minimize= will turn-on SAT-based minimization.  It also
implies =-x tba-det=, so there is no need to supply both options.

#+BEGIN_SRC sh :results verbatim :exports both
111
ltl2tgba -D -x sat-minimize 'GF(a <-> XXb)' --stats='states=%s, det=%d'
112
113
114
115
116
117
#+END_SRC
#+RESULTS:
: states=4, det=1

We can draw it:

118
#+NAME: gfaexxb3
119
#+BEGIN_SRC sh :results verbatim :exports code
120
ltl2tgba -D -x sat-minimize 'GF(a <-> XXb)' -d
121
#+END_SRC
122
#+RESULTS: gfaexxb3
123
124
#+begin_example
digraph G {
125
  rankdir=LR
126
  node [shape="circle"]
127
128
129
  fontname="Lato"
  node [fontname="Lato"]
  edge [fontname="Lato"]
130
  node[style=filled, fillcolor="#ffffa0"] edge[arrowhead=vee, arrowsize=.7]
131
132
133
  I [label="", style=invis, width=0]
  I -> 0
  0 [label="0"]
134
135
136
137
  0 -> 1 [label=<!a &amp; !b<br/><font color="#5DA5DA">⓿</font>>]
  0 -> 2 [label=<!a &amp; b>]
  0 -> 3 [label=<a &amp; b>]
  0 -> 3 [label=<a &amp; !b<br/><font color="#5DA5DA">⓿</font>>]
138
  1 [label="1"]
139
140
141
142
  1 -> 0 [label=<a &amp; b>]
  1 -> 0 [label=<a &amp; !b<br/><font color="#5DA5DA">⓿</font>>]
  1 -> 1 [label=<!a &amp; b>]
  1 -> 1 [label=<!a &amp; !b<br/><font color="#5DA5DA">⓿</font>>]
143
  2 [label="2"]
144
145
146
147
  2 -> 0 [label=<a &amp; !b>]
  2 -> 1 [label=<!a &amp; b<br/><font color="#5DA5DA">⓿</font>>]
  2 -> 1 [label=<!a &amp; !b>]
  2 -> 3 [label=<a &amp; b<br/><font color="#5DA5DA">⓿</font>>]
148
  3 [label="3"]
149
150
151
152
  3 -> 2 [label=<!a &amp; b<br/><font color="#5DA5DA">⓿</font>>]
  3 -> 2 [label=<!a &amp; !b>]
  3 -> 3 [label=<a &amp; b<br/><font color="#5DA5DA">⓿</font>>]
  3 -> 3 [label=<a &amp; !b>]
153
154
155
}
#+end_example

156
#+BEGIN_SRC dot :file gfaexxb3.svg :var txt=gfaexxb3 :exports results
157
158
159
$txt
#+END_SRC
#+RESULTS:
160
[[file:gfaexxb3.svg]]
161

162
Clearly this automaton benefits from the transition-based
163
164
165
166
acceptance.  If we want a traditional Büchi automaton, with
state-based acceptance, we only need to add the =-B= option.  The
result will of course be slightly bigger.

167
#+NAME: gfaexxb4
168
#+BEGIN_SRC sh :results verbatim :exports code
169
ltl2tgba -BD -x sat-minimize 'GF(a <-> XXb)' -d
170
171
172
173
#+END_SRC
#+RESULTS: gfaexxb4
#+begin_example
digraph G {
174
  rankdir=LR
175
  node [shape="circle"]
176
177
178
  fontname="Lato"
  node [fontname="Lato"]
  edge [fontname="Lato"]
179
  node[style=filled, fillcolor="#ffffa0"] edge[arrowhead=vee, arrowsize=.7]
180
181
182
  I [label="", style=invis, width=0]
  I -> 0
  0 [label="0"]
183
184
185
  0 -> 0 [label=<!a &amp; b>]
  0 -> 1 [label=<!b>]
  0 -> 2 [label=<a &amp; b>]
186
187
188
  1 [label="1", peripheries=2]
  1 -> 4 [label=<!a>]
  1 -> 5 [label=<a>]
189
  2 [label="2"]
190
191
192
  2 -> 1 [label=<!b>]
  2 -> 4 [label=<!a &amp; b>]
  2 -> 5 [label=<a &amp; b>]
193
194
195
196
  3 [label="3", peripheries=2]
  3 -> 0 [label=<!a>]
  3 -> 1 [label=<a &amp; !b>]
  3 -> 2 [label=<a &amp; b>]
197
  4 [label="4"]
198
199
200
201
  4 -> 0 [label=<!a &amp; !b>]
  4 -> 1 [label=<a &amp; b>]
  4 -> 2 [label=<a &amp; !b>]
  4 -> 3 [label=<!a &amp; b>]
202
  5 [label="5"]
203
204
205
206
  5 -> 1 [label=<a &amp; b>]
  5 -> 3 [label=<!a &amp; b>]
  5 -> 4 [label=<!a &amp; !b>]
  5 -> 5 [label=<a &amp; !b>]
207
208
209
}
#+end_example

210
#+BEGIN_SRC dot :file gfaexxb4.svg :var txt=gfaexxb4 :exports results
211
212
213
$txt
#+END_SRC
#+RESULTS:
214
[[file:gfaexxb4.svg]]
215
216
217
218
219
220


There are cases where =ltl2tgba='s =tba-det= algorithm fails to produce a deterministic automaton.
In that case, SAT-based minimization is simply skipped.  For instance:

#+BEGIN_SRC sh :results verbatim :exports both
221
ltl2tgba -D -x sat-minimize 'G(F(!b & (X!a M (F!a & F!b))) U !b)' --stats='states=%s, det=%d'
222
223
#+END_SRC
#+RESULTS:
224
: states=5, det=0
225
226
227

The question, of course, is whether there exist a deterministic
automaton for this formula, in other words: is this a recurrence
228
229
property?  There are two ways to answer this question using Spot and
some help from [[http://www.ltl2dstar.de/][=ltl2dstar=]].
230
231
232
233
234
235
236
237

The first is purely syntactic.  If a formula belongs to the class of
"syntactic recurrence formulas", it expresses a syntactic property.
(Of course there are formulas that expresses a syntactic properties
without being syntactic recurrences.)  [[file:ltlfilt.org][=ltlfilt=]] can be instructed to
print only formulas that are syntactic recurrences:

#+BEGIN_SRC sh :results verbatim :exports both
238
ltlfilt --syntactic-recurrence -f 'G(F(!b & (X!a M (F!a & F!b))) U !b)'
239
240
#+END_SRC
#+RESULTS:
241
: G(F(!b & (X!a M (F!a & F!b))) U !b)
242
243
244
245
246
247
248
249
250

Since our input formula was output, it expresses a recurrence property.

The second way to check whether a formula is a recurrence is by
converting a deterministic Rabin automaton using [[file:dstar2tgba.org][=dstar2tgba=]].  The
output is guaranteed to be deterministic if and only if the input DRA
expresses a recurrence property.

#+BEGIN_SRC sh :results verbatim :exports both
251
ltlfilt --remove-wm -f 'G(F(!b & (X!a M (F!a & F!b))) U !b)' -l |
252
ltl2dstar --ltl2nba=spin:ltl2tgba@-Ds - - |
253
254
255
256
257
dstar2tgba -D --stats='input(states=%S) output(states=%s, acc-sets=%a, det=%d)'
#+END_SRC
#+RESULTS:
: input(states=11) output(states=9, acc-sets=1, det=1)

258
259
260
261
262
263
264
265
266
267
268
269
270
271
#+NAME: size
#+BEGIN_SRC sh :exports none
ltlfilt --remove-wm -f 'G(F(!b & (X!a M (F!a & F!b))) U !b)' -l |
ltl2dstar --ltl2nba=spin:ltl2tgba@-Ds - - |
dstar2tgba -D --stats=$arg
#+END_SRC

In the above command, =ltldo= is used to convert the LTL formula into
=ltl2dstar='s syntax.  Then =ltl2dstar= creates a deterministic Rabin
automaton (using =ltl2tgba= as an LTL to BA translator), and the
resulting call_size(arg="%S")[:results raw]-state DRA is converted
into a call_size(arg="%s")[:results raw]-state DTBA by =dstar2tgba=.
Since that result is deterministic, we can conclude that the formula
was a recurrence.
272
273

As far as SAT-based minimization goes, =dstar2tgba= will take the same
274
options as =ltl2tgba=.  For instance we can see that the smallest DTBA
275
has call_size(arg="%s -x sat-minimize")[:results raw] states:
276
277

#+BEGIN_SRC sh :results verbatim :exports both
278
ltlfilt --remove-wm -f 'G(F(!b & (X!a M (F!a & F!b))) U !b)' -l |
279
ltl2dstar --ltl2nba=spin:ltl2tgba@-Ds - - |
280
281
282
dstar2tgba -D -x sat-minimize --stats='input(states=%S) output(states=%s, acc-sets=%a, det=%d)'
#+END_SRC
#+RESULTS:
283
: input(states=11) output(states=4, acc-sets=1, det=1)
284
285
286

* More acceptance sets

287
The formula "=G(F(!b & (X!a M (F!a & F!b))) U !b)=" can in fact be minimized into an
288
289
290
291
292
293
294
295
296
297
even smaller automaton if we use multiple acceptance sets.

Unfortunately because =dstar2tgba= does not know the formula being
translated, and it always convert a DRA into a DBA (with a single
acceptance set) before further processing, it does not know if using
more acceptance sets could be useful to further minimize it.   This
number of acceptance sets can however be specified on the command-line
with option =-x sat-acc=M=.  For instance:

#+BEGIN_SRC sh :results verbatim :exports both
298
ltlfilt --remove-wm -f 'G(F(!b & (X!a M (F!a & F!b))) U !b)' -l |
299
ltl2dstar --ltl2nba=spin:ltl2tgba@-Ds - - |
300
301
302
dstar2tgba -D -x sat-minimize,sat-acc=2 --stats='input(states=%S) output(states=%s, acc-sets=%a, det=%d)'
#+END_SRC
#+RESULTS:
303
: input(states=11) output(states=3, acc-sets=2, det=1)
304

305
306
307
Beware that the size of the SAT problem is exponential in the number
of acceptance sets (adding one acceptance set, in the input automaton
or in the output automaton, will double the size of the problem).
308
309
310
311
312
313
314
315

The case of =ltl2tgba= is slightly different because it can remember
the number of acceptance sets used by the translation algorithm, and
reuse that for SAT-minimization even if the automaton had to be
degeneralized in the meantime for the purpose of determinization.

* Low-level details

Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
316
The following figure (from our [[https://www.lrde.epita.fr/~adl/dl/adl/baarir.14.forte.pdf][FORTE'14 paper]]) gives an overview of
317
318
319
320
the processing chains that can be used to turn an LTL formula into a
minimal DBA/DTBA/DTGBA.  The blue area at the top describes =ltl2tgba
-D -x sat-minimize=, while the purple area at the bottom corresponds
to =dstar2tgba -D -x stat-minimize=.
321

322
[[file:satmin.svg]]
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350

The picture is slightly inaccurate in the sense that both =ltl2tgba=
and =dstar2tgba= are actually using the same post-processing chain:
only the initial translation to TGBA or conversion to DBA differs, the
rest is the same.  However in the case of =dstar2tgba=, no
degeneration or determinization are needed.

Also the picture does not show what happens when =-B= is used: any
DTBA is degeneralized into a DBA, before being sent to "DTBA SAT
minimization", with a special option to request state-based output.

The WDBA-minimization boxes are able to produce minimal Weak DBA from
any TGBA representing an obligation property.  In that case using
transition-based or generalized acceptance will not allow further
reduction.  This minimal WDBA is always used when =-D= is given
(otherwise, for the default =--small= option, the minimal WDBA is only
used if it is smaller than the nondeterministic automaton it has been
built from).

The "simplify" boxes are actually simulation-based reductions, and
SCC-based simplifications.

The red boxes "not in TCONG" or "not a recurrence" correspond to
situations where the tools will produce non-deterministic automata.

The following options can be used to fine-tune this procedure:

- =-x tba-det= :: attempt a powerset construction and check if
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
                  there exists an acceptance set such that the
                  resulting DTBA is equivalent to the input.
- =-x sat-minimize= :: enable SAT-based minimization. It is the same as
     =-x sat-minimize=1= (which is the default value). It performs a dichotomy
     to find the correct automaton size.This option implies =-x tba-det=.
- =-x sat-minimize=[2|3]= :: enable SAT-based
     minimization. Let us consider each intermediate automaton as a =step=
     towards the minimal automaton and assume =N= as the size of the starting
     automaton. =2= and =3= have been implemented with the aim of not
     restarting the encoding from scratch at each step. To do so, both restart
     the encoding after =N-1-(sat-incr-steps)= states have been won. Now,
     where is the difference? They both start by encoding the research of the
     =N-1= step and then:
       - =2= uses PicoSAT assumptions. It adds =sat-incr-steps= assumptions
         (each of them removing one more state) and then checks direclty the
         =N-1-(sat-incr-steps)= step. If such automaton is found, the process is
         restarted. Otherwise, a binary search begins between =N-1= and
         =N-1-sat-incr-steps=. If not provided, =sat-incr-steps= default value
         is 6.
       - =3= checks incrementally each =N-(2+i)= step, =i= ranging from =0= to
         =sat-incr-steps=. This process is fully repeated until the minimal
         automaton is found. The last SAT problem solved correspond to the
         minimal automaton. =sat-incr-steps= defaults to 2.
     Both implies =-x tba-det=.
- =-x sat-minimize=4= :: enable SAT-based minimization. It tries to reduce the
     size of the automaton one state at a time. This option implies
     =-x tba-det=.
- =-x sat-incr-steps=N= :: set the value of =sat-incr-steps= to N. It doest not
     make sense to use it without =-x sat-minimize=2= or =-x sat-minimize=3=.
380
381
382
383
384
385
386
- =-x sat-acc=$m$= :: attempt to build a minimal DTGBA with $m$ acceptance sets.
     This options implies =-x sat-minimize=.
- =-x sat-states=$n$= :: attempt to build an equivalent DTGBA with $n$
     states.  This also implies =-x sat-minimize= but won't perform
     any loop to lower the number of states.  Note that $n$ should be
     the number of states in a complete automaton, while =ltl2tgba=
     and =dstar2tgba= both remove sink states in their output by
387
     default (use option =--complete= to output a complete automaton).
388
389
390
391
392
393
394
     Also note that even with the =--complete= option, the output
     automaton may have appear to have less states because the other
     are unreachable.
- =-x state-based= :: for all outgoing transition of each state
     to belong to the same acceptance sets.
- =-x !wdba-minimize= :: disable WDBA minimization.

395
When options =-B= and =-x sat-minimize= are both used, =-x
396
397
398
state-based= and =-x sat-acc=1= are implied.  Similarly, when option
=-S= and =-x sat-minimize= are both used, then option =-x state-based=
is implied.
399

400
401
402
403
404
405
406
407
* Using =autfilt --sat-minimize= to minimize any deterministic ω-automaton

This interface is new in Spot 1.99 and allows to minimize any
deterministic ω-automaton, regardless of the acceptance condition
used.  By default, the procedure will try to use the same acceptance
condition (or any inferior one) and produce transition-based
acceptance.

408
For our example, let us first generate a deterministic Rabin
409
410
automaton with [[http://www.ltl2dstar.de/][=ltl2dstar=]].

411
#+BEGIN_SRC sh :results silent :exports both
412
ltlfilt -f 'FGa | FGb' -l |
413
ltl2dstar --ltl2nba=spin:ltl2tgba@-Ds --output-format=hoa - - > output.hoa
414
415
416
417
418
#+END_SRC

Let's draw it:
#+NAME: autfiltsm1
#+BEGIN_SRC sh :results verbatim :exports code
419
autfilt output.hoa --dot
420
421
422
423
424
#+END_SRC
#+RESULTS: autfiltsm1
#+begin_example
digraph G {
  rankdir=LR
425
  label=<(Fin(<font color="#5DA5DA">⓿</font>) &amp; Inf(<font color="#F17CB0">❶</font>)) | (Fin(<font color="#FAA43A">❷</font>) &amp; Inf(<font color="#B276B2">❸</font>))>
426
427
428
429
430
431
432
433
  labelloc="t"
  node [shape="circle"]
  fontname="Lato"
  node [fontname="Lato"]
  edge [fontname="Lato"]
  node[style=filled, fillcolor="#ffffa0"] edge[arrowhead=vee, arrowsize=.7]
  I [label="", style=invis, width=0]
  I -> 0
434
  0 [label=<0<br/><font color="#5DA5DA">⓿</font><font color="#FAA43A">❷</font>>]
435
436
437
438
  0 -> 0 [label=<!a &amp; !b>]
  0 -> 1 [label=<a &amp; !b>]
  0 -> 2 [label=<!a &amp; b>]
  0 -> 3 [label=<a &amp; b>]
439
  1 [label=<1<br/><font color="#F17CB0">❶</font><font color="#FAA43A">❷</font>>]
440
441
442
443
  1 -> 0 [label=<!a &amp; !b>]
  1 -> 1 [label=<a &amp; !b>]
  1 -> 2 [label=<!a &amp; b>]
  1 -> 3 [label=<a &amp; b>]
444
  2 [label=<2<br/><font color="#5DA5DA">⓿</font><font color="#B276B2">❸</font>>]
445
446
447
448
  2 -> 0 [label=<!a &amp; !b>]
  2 -> 1 [label=<a &amp; !b>]
  2 -> 2 [label=<!a &amp; b>]
  2 -> 3 [label=<a &amp; b>]
449
  3 [label=<3<br/><font color="#F17CB0">❶</font><font color="#B276B2">❸</font>>]
450
451
452
453
454
455
456
  3 -> 0 [label=<!a &amp; !b>]
  3 -> 1 [label=<a &amp; !b>]
  3 -> 2 [label=<!a &amp; b>]
  3 -> 3 [label=<a &amp; b>]
}
#+end_example

457
#+BEGIN_SRC dot :file autfiltsm1.svg :var txt=autfiltsm1 :exports results
458
459
460
$txt
#+END_SRC
#+RESULTS:
461
[[file:autfiltsm1.svg]]
462
463
464
465
466
467
468
469

So this is a state-based Rabin automaton with two pairs.  If we call
=autfilt= with the =--sat-minimize= option, we can get the following
transition-based version (the output may change depending on the SAT
solver used):

#+NAME: autfiltsm2
#+BEGIN_SRC sh :results verbatim :exports code
470
autfilt --sat-minimize output.hoa --dot
471
472
#+END_SRC

473
#+BEGIN_SRC dot :file autfiltsm2.svg :var txt=autfiltsm2 :exports results
474
475
476
$txt
#+END_SRC
#+RESULTS:
477
[[file:autfiltsm2.svg]]
478
479
480
481
482

We can also attempt to build a state-based version with

#+NAME: autfiltsm3
#+BEGIN_SRC sh :results verbatim :exports code
483
autfilt -S --sat-minimize output.hoa --dot
484
485
#+END_SRC

486
#+BEGIN_SRC dot :file autfiltsm3.svg :var txt=autfiltsm3 :exports results
487
488
489
$txt
#+END_SRC
#+RESULTS:
490
[[file:autfiltsm3.svg]]
491
492
493
494
495
496
497
498
499
500
501
502
503

This is clearly smaller than the input automaton.  In this example the
acceptance condition did not change.  The SAT-based minimization only
tries to minimize the number of states, but sometime the
simplifications algorithms that are run before we attempt SAT-solving
will simplify the acceptance, because even removing a single
acceptance set can halve the run time.

You can however force a specific acceptance to be used as output.
Let's try with generalized co-Büchi for instance:

#+NAME: autfiltsm4
#+BEGIN_SRC sh :results verbatim :exports code
504
autfilt -S --sat-minimize='acc="generalized-co-Buchi 2"' output.hoa --dot
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
#+END_SRC

#+RESULTS: autfiltsm4
#+begin_example
digraph G {
  rankdir=LR
  label=<Fin(<font color="#5DA5DA">⓿</font>)|Fin(<font color="#F17CB0">❶</font>)>
  labelloc="t"
  node [shape="circle"]
  fontname="Lato"
  node [fontname="Lato"]
  edge [fontname="Lato"]
  node[style=filled, fillcolor="#ffffa0"] edge[arrowhead=vee, arrowsize=.7]
  I [label="", style=invis, width=0]
  I -> 0
  0 [label=<0<br/><font color="#5DA5DA">⓿</font>>]
  0 -> 0 [label=<a>]
  0 -> 1 [label=<!a>]
  1 [label=<1<br/><font color="#F17CB0">❶</font>>]
  1 -> 0 [label=<!b>]
  1 -> 1 [label=<b>]
}
#+end_example

529
#+BEGIN_SRC dot :file autfiltsm4.svg :var txt=autfiltsm4 :exports results
530
531
532
533
$txt
#+END_SRC

#+RESULTS:
534
[[file:autfiltsm4.svg]]
535
536
537
538
539
540
541
542


Note that instead of naming the acceptance condition, you can actually
give an acceptance formula in the [[http://adl.github.io/hoaf/#acceptance][HOA syntax]].  For example we can
attempt to create a co-Büchi automaton with

#+NAME: autfiltsm5
#+BEGIN_SRC sh :results verbatim :exports code
543
autfilt -S --sat-minimize='acc="Fin(0)"' output.hoa --dot
544
545
546
#+END_SRC
#+RESULTS: autfiltsm5

547
#+BEGIN_SRC dot :file autfiltsm5.svg :var txt=autfiltsm5 :exports results
548
549
550
551
$txt
#+END_SRC

#+RESULTS:
552
[[file:autfiltsm5.svg]]
553
554
555
556
557
558
559


When forcing an acceptance condition, you should keep in mind that the
SAT-based minimization algorithm will look for automata that have
fewer states than the original automaton (after preliminary
simplifications).  This is not always reasonable.  For instance
constructing a Streett automaton from a Rabin automaton might require
560
more states.  An upper bound on the number of state can be passed
561
562
563
564
565
566
567
568
569
570
571
572
573
574
using a =max-states=123= argument to =--sat-minimize=.

If the input automaton is transition-based, but option =-S= is used to
produce a state-based automaton, then the original automaton is
temporarily converted into an automaton with state-based acceptance to
obtain an upper bound on the number of states if you haven't specified
=max-state=.  This upper bound might be larger than the one you would
specify by hand.

Here is an example demonstrating the case where the input automaton is
smaller than the output.   Let's take this small TGBA as input:

#+NAME: autfiltsm6
#+BEGIN_SRC sh :results verbatim :exports code
575
ltl2tgba 'GFa & GFb' >output2.hoa
576
autfilt output2.hoa --dot
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
#+END_SRC

#+RESULTS: autfiltsm6
#+begin_example
digraph G {
  rankdir=LR
  label=<Inf(<font color="#5DA5DA">⓿</font>)&amp;Inf(<font color="#F17CB0">❶</font>)>
  labelloc="t"
  node [shape="circle"]
  fontname="Lato"
  node [fontname="Lato"]
  edge [fontname="Lato"]
  node[style=filled, fillcolor="#ffffa0"] edge[arrowhead=vee, arrowsize=.7]
  I [label="", style=invis, width=0]
  I -> 0
  0 [label="0"]
  0 -> 0 [label=<a &amp; b<br/><font color="#5DA5DA">⓿</font><font color="#F17CB0">❶</font>>]
  0 -> 0 [label=<!a &amp; !b>]
  0 -> 0 [label=<!a &amp; b<br/><font color="#F17CB0">❶</font>>]
  0 -> 0 [label=<a &amp; !b<br/><font color="#5DA5DA">⓿</font>>]
}
#+end_example

600
#+BEGIN_SRC dot :file autfiltsm6.svg :var txt=autfiltsm6 :exports results
601
602
603
604
$txt
#+END_SRC

#+RESULTS:
605
[[file:autfiltsm6.svg]]
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623


If we attempt to minimize it into a transition-based Büchi automaton,
with fewer states, it will fail, output no result, and return with a
non-zero exit code (because no automata where output).

#+NAME: autfiltsm7
#+BEGIN_SRC sh :results verbatim :exports both
autfilt --sat-minimize='acc="Buchi"' output2.hoa
echo $?
#+END_SRC
#+RESULTS: autfiltsm7
: 1

However if we allow more states, it will work:

#+NAME: autfiltsm8
#+BEGIN_SRC sh :results verbatim :exports code
624
autfilt --sat-minimize='acc="Buchi",max-states=3' output2.hoa --dot
625
626
#+END_SRC

627
#+BEGIN_SRC dot :file autfiltsm8.svg :var txt=autfiltsm8 :exports results
628
629
630
631
$txt
#+END_SRC

#+RESULTS:
632
[[file:autfiltsm8.svg]]
633
634


635
636
637
638
639
640
641
By default, the SAT-based minimization tries to find a smaller automaton by
performing a binary search starting from =N/2= (N being the size of the
starting automaton). After various benchmarks, this algorithm proves to be the
best. However, in some cases, other rather similar methods might be better. The
algorithm to execute and some other parameters can be set thanks to the
=--sat-minimize= option.

642
643
644
645
646
647
648
649
650
651
652
653
654
The =--sat-minimize= option takes a comma separated list of arguments
that can be any of the following:

- =acc=DOUBLEQUOTEDSTRING= :: where the =DOUBLEQUOTEDSTRING= is an
     acceptance formula in the [[http://adl.github.io/hoaf/#acceptance][HOA syntax]], or a parametrized acceptance
     name (the different [[http://adl.github.io/hoaf/#acceptance-specifications][=acc-name:= options from HOA]]).
- =max-states=N= :: where =N= is an upper-bound on the maximum
     number of states of the constructed automaton.
- =states=M= :: where =M= is a fixed number of states to use in the
     result (all the states needs not be accessible in the result,
     so the output might be smaller nonetheless).  If this option is
     used the SAT-based procedure is just used once to synthesize
     one automaton, and no further minimization is attempted.
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
- =sat-incr=[1|2]= :: =1= and =2= correspond respectively to
     =-x sat-minimize=2= and =-x sat-minimize=3= options.
     They have been implemented with the aim of not restarting the
     encoding from scratch at each step - a step is a minimized intermediate
     automaton. To do so, both restart the encoding after
     =N-1-(sat-incr-steps)= states have been won - =N= being the size of the
     starting automaton. Now, where is the difference? They both start by
     encoding the research of the =N-1= step and then:
       - =1= uses PicoSAT assumptions. It adds =steps= assumptions (each of
         them removing one more state) and then checks direclty the
         =N-1-(sat-incr-steps)= step. If such automaton is found, the process is
         restarted. Otherwise, a binary search begins between =N-1= and
         =N-1-sat-incr-steps=. If not provided, =sat-incr-steps= defaults to 6.
       - =2= checks incrementally each =N-(2+i)= step, =i= ranging from =0= to
         =sat-incr-steps=. This process is fully repeated until the minimal
         automaton is found. The last SAT problem solved correspond to the
         minimal automaton. =sat-incr-steps= defaults to 2.
     Both implies =-x tba-det=.
- =sat-incr-steps=N= :: set the value of =sat-incr-steps= to =N=.
     This is used by =sat-incr= option.
- =sat-naive= :: use the =naive= algorithm to find a smaller automaton. It starts
     from =N= and then checks =N-1=, =N-2=, etc. until the last successful
     check.
- =sat-langmap= :: Find  the lower bound of default sat-minimize procedure. This
     relies on the fact that the size of the minimal automaton is at least equal
     to the  total  number  of different languages recognized by the automaton's
     states.
682
683
684
685
686
687
688
689
690
691
692
693
694
695
- =colored= :: force all transitions (or all states if =-S= is used)
     to belong to exactly one acceptance condition.


The =colored= option is useful when used in conjunction with a parity
acceptance condition.  Indeed, the parity acceptance condition by
itself does not require that the acceptance sets form a partition of
the automaton (which is expected from parity automata).

Compare the following, where parity acceptance is used, but the
automaton is not colored:

#+NAME: autfiltsm9
#+BEGIN_SRC sh :results verbatim :exports code
696
autfilt -S --sat-minimize='acc="parity max even 3"' output2.hoa --dot
697
698
#+END_SRC

699
#+BEGIN_SRC dot :file autfiltsm9.svg :var txt=autfiltsm9 :exports results
700
701
702
703
$txt
#+END_SRC

#+RESULTS:
704
[[file:autfiltsm9.svg]]
705
706
707
708
709
710

... to the following, where the automaton is colored, i.e., each state
belong to exactly one acceptance set:

#+NAME: autfiltsm10
#+BEGIN_SRC sh :results verbatim :exports code
711
autfilt -S --sat-minimize='acc="parity max even 3",colored' output2.hoa --dot
712
713
#+END_SRC

714
#+BEGIN_SRC dot :file autfiltsm10.svg :var txt=autfiltsm10 :exports results
715
716
717
718
$txt
#+END_SRC

#+RESULTS:
719
[[file:autfiltsm10.svg]]
720
721
722
723
724
725
726
727
728
729

* Logging statistics

If the environment variable =SPOT_SATLOG= is set to the name of a
file, the minimization function will append statistics about each of
its iterations in this file.

#+BEGIN_SRC sh :results verbatim :exports both
rm -f stats.csv
export SPOT_SATLOG=stats.csv
730
ltlfilt -f 'Ga R (F!b & (c U b))' -l |
731
ltl2dstar --ltl2nba=spin:ltl2tgba@-Ds - - |
732
dstar2tgba -D -x sat-minimize,sat-acc=2 --stats='input(states=%S) output(states=%s, acc-sets=%a, det=%d)'
733
echo ==== stats.csv ====
734
735
736
cat stats.csv
#+END_SRC
#+RESULTS:
737
: input(states=11) output(states=5, acc-sets=2, det=1)
738
739
740
741
742
: ==== stats.csv ====
: input.states,target.states,reachable.states,edges,transitions,variables,clauses,enc.user,enc.sys,sat.user,sat.sys,automaton
: 10,5,,,,13600,1543042,59,3,187,0,
: 10,7,7,33,56,26656,4247441,162,7,775,0,"HOA: v1 States: 7 Start: 0 AP: 3 ""a"" ""b"" ""c"" acc-name: generalized-Buchi 2 Acceptance: 2 Inf(0)&Inf(1) properties: trans-labels explicit-labels trans-acc complete deterministic --BODY-- State: 0 [!0&!1&2] 0 {1} [!0&1] 0 {0} [!0&!1&!2] 1 {0} [0&!1&!2] 1 [0&!1&2] 2 {1} [0&1&!2] 4 [0&1&2] 4 {0} State: 1 [0&!1] 1 {0} [!0&!1&!2 | 0&1] 1 [!0&1 | !0&2] 3 {0} State: 2 [!0&!1&2] 0 {1} [!0&1] 0 {0 1} [!0&!1&!2] 1 [0&!1&2] 2 [0&!1&!2] 3 {1} [0&1] 5 {0 1} State: 3 [!1&!2] 3 [1 | 2] 3 {0} State: 4 [!0&!1&2] 0 {0 1} [!0&1] 0 {0} [!0&!1&!2] 1 [0&1] 4 {0} [0&!1&2] 5 {0} [0&!1&!2] 6 State: 5 [!0&1 | !0&2] 0 {0 1} [!0&!1&!2] 1 [0&1 | 0&2] 5 {0 1} [0&!1&!2] 6 {0} State: 6 [!0&!1&!2] 1 [!0&1&!2] 1 {0 1} [!0&1&2] 1 {1} [!0&!1&2] 3 {0 1} [0] 6 {0 1} --END--"
: 7,6,6,26,48,10512,1376507,50,0,269,0,"HOA: v1 States: 6 Start: 0 AP: 3 ""a"" ""b"" ""c"" acc-name: generalized-Buchi 2 Acceptance: 2 Inf(0)&Inf(1) properties: trans-labels explicit-labels trans-acc complete deterministic --BODY-- State: 0 [!0&!1&2] 0 {1} [!0&1] 0 {0} [!0&!1&!2] 1 [0&!1&!2] 1 {0 1} [0&!1&2] 2 {1} [0&1] 3 {0} State: 1 [t] 1 State: 2 [!0&!1&2] 0 {1} [!0&1] 0 {0} [!1&!2] 1 [0&!1&2] 2 {1} [0&1] 4 {1} State: 3 [!0&!1&2] 0 {1} [!0&1] 0 [!0&!1&!2] 1 [0&1] 3 [0&!1&2] 4 {1} [0&!1&!2] 5 {1} State: 4 [!0&!1&2 | !0&1&!2] 0 {0 1} [!0&1&2] 0 {0} [!0&!1&!2] 1 [0&1 | 0&2] 4 {0 1} [0&!1&!2] 5 State: 5 [!0&!1&!2] 1 [!0&1 | !0&2] 1 {0 1} [0] 5 {0 1} --END--"
743
744

The generated CSV file use the following columns:
745
746
- =input.states=: the number of states of the reference automaton at this step
- =target.states=: the n passed to the SAT-based minimization algorithm
747
  (it means the input automaton had n+1 states)
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
- =reachable.states=: number of reachable states in the output of
  the minimization (with any luck this can be smaller than =target.states=)
- =edges=, =transitions=: number of edges or transitions in the output
- =variables=, =clauses=: size of the SAT problem
- =enc.user=, =enc.sys=: user and system time for encoding the SAT problem
- =sat.user=, =sat.sys=: user and system time for solving the SAT problem
- =automaton=: the automaton produced in HOA format.

Times are measured with the times() function, and expressed in ticks
(usually: 1/100 of seconds).  The encoding of the automaton in the CSV
file follows RFC4180 in escaping double-quote by doubling them.

In the above example, the DRA produced by =ltl2dstar= had 11 states.
In the first line of the =stats.csv= file, you can see the
minimization function had a 10-state input, which means that
=dstar2tgba= first reduced the 11-state (complete) DRA into a 10-state
(complete) DBA before calling the SAT-based minimization.  This first
line shows the SAT-based minimization for a (complete) 5-state DTGBA
and failing to find one.  Then on the next line it looks for a 7-state
solution, finds one.  Finally, it finds a (complete) 6-state solution,
now using the 7-state version as reference automaton to further
simplify the problem.

The final output is reported with 5 states, because by default we
output trim automata. If the =--complete= option had been given, the
useless sink state would have been kept and the output automaton would
have 6 states.
775

Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
776
#+BEGIN_SRC sh :results silent :exports results
777
778
rm -f output.hoa output2.hoa
#+END_SRC
779
780
781
* Python interface

See the [[https://spot.lrde.epita.fr/ipynb/satmin.html][=satmin.ipynb=]] notebook.