-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuchi.c
723 lines (654 loc) · 21.9 KB
/
buchi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
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
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
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
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
/***** ltl2ba : buchi.c *****/
/* Written by Denis Oddoux, LIAFA, France */
/* Copyright (c) 2001 Denis Oddoux */
/* Modified by Paul Gastin, LSV, France */
/* Copyright (c) 2007 Paul Gastin */
/* */
/* This program 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 2 of the License, or */
/* (at your option) any later version. */
/* */
/* This program 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, write to the Free Software */
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/
/* */
/* Based on the translation algorithm by Gastin and Oddoux, */
/* presented at the 13th International Conference on Computer Aided */
/* Verification, CAV 2001, Paris, France. */
/* Proceedings - LNCS 2102, pp. 53-65 */
/* */
/* Send bug-reports and/or questions to Paul Gastin */
/* http://www.lsv.ens-cachan.fr/~gastin */
#include "ltl2ba.h"
void print_c_buchi();
void print_json_buchi();
/********************************************************************\
|* Structures and shared variables *|
\********************************************************************/
extern GState **init, *gstates;
extern struct rusage tr_debut, tr_fin;
extern struct timeval t_diff;
extern int tl_verbose, tl_stats, tl_simp_diff, tl_simp_fly, tl_simp_scc, tl_type,
init_size, *final;
extern void put_uform(void);
extern int gstate_id;
extern FILE *tl_out;
BState *bstack, *bstates, *bremoved;
BScc *scc_stack;
int accept, bstate_count = 0, btrans_count = 0, rank;
/********************************************************************\
|* Simplification of the generalized Buchi automaton *|
\********************************************************************/
void free_bstate(BState *s) /* frees a state and its transitions */
{
free_btrans(s->trans->nxt, s->trans, 1);
tfree(s);
}
BState *remove_bstate(BState *s, BState *s1) /* removes a state */
{
BState *prv = s->prv;
s->prv->nxt = s->nxt;
s->nxt->prv = s->prv;
free_btrans(s->trans->nxt, s->trans, 0);
s->trans = (BTrans *)0;
s->nxt = bremoved->nxt;
bremoved->nxt = s;
s->prv = s1;
for(s1 = bremoved->nxt; s1 != bremoved; s1 = s1->nxt)
if(s1->prv == s)
s1->prv = s->prv;
return prv;
}
void copy_btrans(BTrans *from, BTrans *to) {
to->to = from->to;
copy_set(from->pos, to->pos, 1);
copy_set(from->neg, to->neg, 1);
}
int simplify_btrans() /* simplifies the transitions */
{
BState *s;
BTrans *t, *t1;
int changed = 0;
if(tl_stats) getrusage(RUSAGE_SELF, &tr_debut);
for (s = bstates->nxt; s != bstates; s = s->nxt)
for (t = s->trans->nxt; t != s->trans;) {
t1 = s->trans->nxt;
copy_btrans(t, s->trans);
while((t == t1) || (t->to != t1->to) ||
!included_set(t1->pos, t->pos, 1) ||
!included_set(t1->neg, t->neg, 1))
t1 = t1->nxt;
if(t1 != s->trans) {
BTrans *free = t->nxt;
t->to = free->to;
copy_set(free->pos, t->pos, 1);
copy_set(free->neg, t->neg, 1);
t->nxt = free->nxt;
if(free == s->trans) s->trans = t;
free_btrans(free, 0, 0);
changed++;
}
else
t = t->nxt;
}
if(tl_stats) {
getrusage(RUSAGE_SELF, &tr_fin);
timeval_subtract (&t_diff, &tr_fin.ru_utime, &tr_debut.ru_utime);
fprintf(tl_out, "\nSimplification of the Buchi automaton - transitions: %i.%06is",
t_diff.tv_sec, t_diff.tv_usec);
fprintf(tl_out, "\n%i transitions removed\n", changed);
}
return changed;
}
int same_btrans(BTrans *s, BTrans *t) /* returns 1 if the transitions are identical */
{
return((s->to == t->to) &&
same_sets(s->pos, t->pos, 1) &&
same_sets(s->neg, t->neg, 1));
}
void remove_btrans(BState *to)
{ /* redirects transitions before removing a state from the automaton */
BState *s;
BTrans *t;
int i;
for (s = bstates->nxt; s != bstates; s = s->nxt)
for (t = s->trans->nxt; t != s->trans; t = t->nxt)
if (t->to == to) { /* transition to a state with no transitions */
BTrans *free = t->nxt;
t->to = free->to;
copy_set(free->pos, t->pos, 1);
copy_set(free->neg, t->neg, 1);
t->nxt = free->nxt;
if(free == s->trans) s->trans = t;
free_btrans(free, 0, 0);
}
}
void retarget_all_btrans()
{ /* redirects transitions before removing a state from the automaton */
BState *s;
BTrans *t;
for (s = bstates->nxt; s != bstates; s = s->nxt)
for (t = s->trans->nxt; t != s->trans; t = t->nxt)
if (!t->to->trans) { /* t->to has been removed */
t->to = t->to->prv;
if(!t->to) { /* t->to has no transitions */
BTrans *free = t->nxt;
t->to = free->to;
copy_set(free->pos, t->pos, 1);
copy_set(free->neg, t->neg, 1);
t->nxt = free->nxt;
if(free == s->trans) s->trans = t;
free_btrans(free, 0, 0);
}
}
while(bremoved->nxt != bremoved) { /* clean the 'removed' list */
s = bremoved->nxt;
bremoved->nxt = bremoved->nxt->nxt;
tfree(s);
}
}
int all_btrans_match(BState *a, BState *b) /* decides if the states are equivalent */
{
BTrans *s, *t;
/* the states have to be both final or both non final,
* or at least one of them has to be in a trivial SCC
* (incoming == -1), as the acceptance condition of
* such a state can be modified without changing the
* language of the automaton
*/
if (((a->final == accept) || (b->final == accept)) &&
(a->final + b->final != 2 * accept) /* final condition of a and b differs */
&& a->incoming >=0 /* a is not in a trivial SCC */
&& b->incoming >=0) /* b is not in a trivial SCC */
return 0; /* states can not be matched */
for (s = a->trans->nxt; s != a->trans; s = s->nxt) {
/* all transitions from a appear in b */
copy_btrans(s, b->trans);
t = b->trans->nxt;
while(!same_btrans(s, t))
t = t->nxt;
if(t == b->trans) return 0;
}
for (s = b->trans->nxt; s != b->trans; s = s->nxt) {
/* all transitions from b appear in a */
copy_btrans(s, a->trans);
t = a->trans->nxt;
while(!same_btrans(s, t))
t = t->nxt;
if(t == a->trans) return 0;
}
return 1;
}
int simplify_bstates() /* eliminates redundant states */
{
BState *s, *s1, *s2;
int changed = 0;
if(tl_stats) getrusage(RUSAGE_SELF, &tr_debut);
for (s = bstates->nxt; s != bstates; s = s->nxt) {
if(s->trans == s->trans->nxt) { /* s has no transitions */
s = remove_bstate(s, (BState *)0);
changed++;
continue;
}
bstates->trans = s->trans;
bstates->final = s->final;
s1 = s->nxt;
while(!all_btrans_match(s, s1))
s1 = s1->nxt;
if(s1 != bstates) { /* s and s1 are equivalent */
/* we now want to remove s and replace it by s1 */
if(s1->incoming == -1) { /* s1 is in a trivial SCC */
s1->final = s->final; /* change the final condition of s1 to that of s */
/* We may have to update the SCC status of s1
* stored in s1->incoming, because we will retarget the incoming
* transitions of s to s1.
*
* If both s1 and s are in trivial SCC, then retargeting
* the incoming transitions does not change the status of s1,
* it remains in a trivial SCC.
*
* If s1 was in a trivial SCC, but s was not, then
* s1 has to have a transition to s that corresponds to a
* self-loop of s (as both states have the same outgoing transitions).
* But then, s1 will not remain a trivial SCC after retargeting.
* In particular, afterwards the final condition of s1 may not be
* changed anymore.
*
* If both s1 and s are in non-trivial SCC, merging does not
* change the SCC status of s1.
*
* If we are here, s1->incoming==1 and thus s1 forms a trivial SCC.
* We therefore can set the status of s1 to that of s,
* which correctly handles the first two cases above.
*/
s1->incoming = s->incoming;
}
s = remove_bstate(s, s1);
changed++;
}
}
retarget_all_btrans();
/*
* As merging equivalent states can change the 'final' attribute of
* the remaining state, it is possible that now there are two
* different states with the same id and final values.
* This would lead to multiply-defined labels in the generated neverclaim.
* We iterate over all states and assign new ids (previously unassigned)
* to these states to disambiguate.
* Fix from ltl3ba.
*/
for (s = bstates->nxt; s != bstates; s = s->nxt) { /* For all states s*/
for (s2 = s->nxt; s2 != bstates; s2 = s2->nxt) { /* and states s2 to the right of s */
if(s->final == s2->final && s->id == s2->id) { /* if final and id match */
s->id = ++gstate_id; /* disambiguate by assigning unused id */
}
}
}
if(tl_stats) {
getrusage(RUSAGE_SELF, &tr_fin);
timeval_subtract (&t_diff, &tr_fin.ru_utime, &tr_debut.ru_utime);
fprintf(tl_out, "\nSimplification of the Buchi automaton - states: %i.%06is",
t_diff.tv_sec, t_diff.tv_usec);
fprintf(tl_out, "\n%i states removed\n", changed);
}
return changed;
}
int bdfs(BState *s) {
BTrans *t;
BScc *c;
BScc *scc = (BScc *)tl_emalloc(sizeof(BScc));
scc->bstate = s;
scc->rank = rank;
scc->theta = rank++;
scc->nxt = scc_stack;
scc_stack = scc;
s->incoming = 1;
for (t = s->trans->nxt; t != s->trans; t = t->nxt) {
if (t->to->incoming == 0) {
int result = bdfs(t->to);
scc->theta = min(scc->theta, result);
}
else {
for(c = scc_stack->nxt; c != 0; c = c->nxt)
if(c->bstate == t->to) {
scc->theta = min(scc->theta, c->rank);
break;
}
}
}
if(scc->rank == scc->theta) {
if(scc_stack == scc) { /* s is alone in a scc */
s->incoming = -1;
for (t = s->trans->nxt; t != s->trans; t = t->nxt)
if (t->to == s)
s->incoming = 1;
}
scc_stack = scc->nxt;
}
return scc->theta;
}
void simplify_bscc() {
BState *s;
rank = 1;
scc_stack = 0;
if(bstates == bstates->nxt) return;
for(s = bstates->nxt; s != bstates; s = s->nxt)
s->incoming = 0; /* state color = white */
bdfs(bstates->prv);
for(s = bstates->nxt; s != bstates; s = s->nxt)
if(s->incoming == 0)
remove_bstate(s, 0);
}
/********************************************************************\
|* Generation of the Buchi automaton *|
\********************************************************************/
BState *find_bstate(GState **state, int final, BState *s)
{ /* finds the corresponding state, or creates it */
if((s->gstate == *state) && (s->final == final)) return s; /* same state */
s = bstack->nxt; /* in the stack */
bstack->gstate = *state;
bstack->final = final;
while(!(s->gstate == *state) || !(s->final == final))
s = s->nxt;
if(s != bstack) return s;
s = bstates->nxt; /* in the solved states */
bstates->gstate = *state;
bstates->final = final;
while(!(s->gstate == *state) || !(s->final == final))
s = s->nxt;
if(s != bstates) return s;
s = bremoved->nxt; /* in the removed states */
bremoved->gstate = *state;
bremoved->final = final;
while(!(s->gstate == *state) || !(s->final == final))
s = s->nxt;
if(s != bremoved) return s;
s = (BState *)tl_emalloc(sizeof(BState)); /* creates a new state */
s->gstate = *state;
s->id = (*state)->id;
s->incoming = 0;
s->final = final;
s->trans = emalloc_btrans(); /* sentinel */
s->trans->nxt = s->trans;
s->nxt = bstack->nxt;
bstack->nxt = s;
return s;
}
int next_final(int *set, int fin) /* computes the 'final' value */
{
if((fin != accept) && in_set(set, final[fin + 1]))
return next_final(set, fin + 1);
return fin;
}
void make_btrans(BState *s) /* creates all the transitions from a state */
{
int state_trans = 0;
GTrans *t;
BTrans *t1;
BState *s1;
if(s->gstate->trans)
for(t = s->gstate->trans->nxt; t != s->gstate->trans; t = t->nxt) {
int fin = next_final(t->final, (s->final == accept) ? 0 : s->final);
BState *to = find_bstate(&t->to, fin, s);
for(t1 = s->trans->nxt; t1 != s->trans;) {
if(tl_simp_fly &&
(to == t1->to) &&
included_set(t->pos, t1->pos, 1) &&
included_set(t->neg, t1->neg, 1)) { /* t1 is redondant */
BTrans *free = t1->nxt;
t1->to->incoming--;
t1->to = free->to;
copy_set(free->pos, t1->pos, 1);
copy_set(free->neg, t1->neg, 1);
t1->nxt = free->nxt;
if(free == s->trans) s->trans = t1;
free_btrans(free, 0, 0);
state_trans--;
}
else if(tl_simp_fly &&
(t1->to == to ) &&
included_set(t1->pos, t->pos, 1) &&
included_set(t1->neg, t->neg, 1)) /* t is redondant */
break;
else
t1 = t1->nxt;
}
if(t1 == s->trans) {
BTrans *trans = emalloc_btrans();
trans->to = to;
trans->to->incoming++;
copy_set(t->pos, trans->pos, 1);
copy_set(t->neg, trans->neg, 1);
trans->nxt = s->trans->nxt;
s->trans->nxt = trans;
state_trans++;
}
}
if(tl_simp_fly) {
if(s->trans == s->trans->nxt) { /* s has no transitions */
free_btrans(s->trans->nxt, s->trans, 1);
s->trans = (BTrans *)0;
s->prv = (BState *)0;
s->nxt = bremoved->nxt;
bremoved->nxt = s;
for(s1 = bremoved->nxt; s1 != bremoved; s1 = s1->nxt)
if(s1->prv == s)
s1->prv = (BState *)0;
return;
}
bstates->trans = s->trans;
bstates->final = s->final;
s1 = bstates->nxt;
while(!all_btrans_match(s, s1))
s1 = s1->nxt;
if(s1 != bstates) { /* s and s1 are equivalent */
free_btrans(s->trans->nxt, s->trans, 1);
s->trans = (BTrans *)0;
s->prv = s1;
s->nxt = bremoved->nxt;
bremoved->nxt = s;
for(s1 = bremoved->nxt; s1 != bremoved; s1 = s1->nxt)
if(s1->prv == s)
s1->prv = s->prv;
return;
}
}
s->nxt = bstates->nxt; /* adds the current state to 'bstates' */
s->prv = bstates;
s->nxt->prv = s;
bstates->nxt = s;
btrans_count += state_trans;
bstate_count++;
}
/********************************************************************\
|* Display of the Buchi automaton *|
\********************************************************************/
void print_buchi(BState *s) /* dumps the Buchi automaton */
{
BTrans *t;
if(s == bstates) return;
print_buchi(s->nxt); /* begins with the last state */
fprintf(tl_out, "state ");
if(s->id == -1)
fprintf(tl_out, "init");
else {
if(s->final == accept)
fprintf(tl_out, "accept");
else
fprintf(tl_out, "T%i", s->final);
fprintf(tl_out, "_%i", s->id);
}
fprintf(tl_out, "\n");
for(t = s->trans->nxt; t != s->trans; t = t->nxt) {
if (empty_set(t->pos, 1) && empty_set(t->neg, 1))
fprintf(tl_out, "1");
print_set(t->pos, 1);
if (!empty_set(t->pos, 1) && !empty_set(t->neg, 1)) fprintf(tl_out, " & ");
print_set(t->neg, 2);
fprintf(tl_out, " -> ");
if(t->to->id == -1)
fprintf(tl_out, "init\n");
else {
if(t->to->final == accept)
fprintf(tl_out, "accept");
else
fprintf(tl_out, "T%i", t->to->final);
fprintf(tl_out, "_%i\n", t->to->id);
}
}
}
void print_spin_buchi() {
BTrans *t;
BState *s;
int accept_all = 0, init_count = 0;
if(bstates->nxt == bstates) { /* empty automaton */
fprintf(tl_out, "never { /* ");
put_uform();
fprintf(tl_out, " */\n");
fprintf(tl_out, "T0_init:\n");
fprintf(tl_out, "\tfalse;\n");
fprintf(tl_out, "}\n");
return;
}
if(bstates->nxt->nxt == bstates && bstates->nxt->id == 0) { /* true */
fprintf(tl_out, "never { /* ");
put_uform();
fprintf(tl_out, " */\n");
fprintf(tl_out, "accept_init:\n");
fprintf(tl_out, "\tif\n");
fprintf(tl_out, "\t:: (1) -> goto accept_init\n");
fprintf(tl_out, "\tfi;\n");
fprintf(tl_out, "}\n");
return;
}
fprintf(tl_out, "never { /* ");
put_uform();
fprintf(tl_out, " */\n");
for(s = bstates->prv; s != bstates; s = s->prv) {
/* s->id == 0 means s is an accepting well */
if(s->id == 0) { /* accept_all at the end */
accept_all = 1;
continue;
}
/* The state is an accepting state */
if(s->final == accept)
fprintf(tl_out, "accept_");
else fprintf(tl_out, "T%i_", s->final);
/* The state is the initial state */
if(s->id == -1)
fprintf(tl_out, "init:\n");
else fprintf(tl_out, "S%i:\n", s->id);
/* The state has no possible transitions */
if(s->trans->nxt == s->trans) {
fprintf(tl_out, "\tfalse;\n");
continue;
}
fprintf(tl_out, "\tif\n");
for(t = s->trans->nxt; t != s->trans; t = t->nxt) {
BTrans *t1;
fprintf(tl_out, "\t:: (");
spin_print_set(t->pos, t->neg);
for(t1 = t; t1->nxt != s->trans; )
if (t1->nxt->to->id == t->to->id &&
t1->nxt->to->final == t->to->final) {
fprintf(tl_out, ") || (");
spin_print_set(t1->nxt->pos, t1->nxt->neg);
t1->nxt = t1->nxt->nxt;
}
else t1 = t1->nxt;
fprintf(tl_out, ") -> goto ");
if(t->to->final == accept)
fprintf(tl_out, "accept_");
else fprintf(tl_out, "T%i_", t->to->final);
if(t->to->id == 0)
fprintf(tl_out, "all\n");
else if(t->to->id == -1)
fprintf(tl_out, "init\n");
else fprintf(tl_out, "S%i\n", t->to->id);
}
fprintf(tl_out, "\tfi;\n");
}
if(accept_all) {
fprintf(tl_out, "accept_all:\n");
fprintf(tl_out, "\tskip\n");
}
fprintf(tl_out, "}\n");
}
/********************************************************************\
|* Main method *|
\********************************************************************/
void mk_buchi()
{/* generates a Buchi automaton from the generalized Buchi automaton */
int i;
BState *s = (BState *)tl_emalloc(sizeof(BState));
GTrans *t;
BTrans *t1;
accept = final[0] - 1;
if(tl_stats) getrusage(RUSAGE_SELF, &tr_debut);
bstack = (BState *)tl_emalloc(sizeof(BState)); /* sentinel */
bstack->nxt = bstack;
bremoved = (BState *)tl_emalloc(sizeof(BState)); /* sentinel */
bremoved->nxt = bremoved;
bstates = (BState *)tl_emalloc(sizeof(BState)); /* sentinel */
bstates->nxt = s;
bstates->prv = s;
s->nxt = bstates; /* creates (unique) inital state */
s->prv = bstates;
s->id = -1;
s->incoming = 1;
s->final = 0;
s->gstate = 0;
s->trans = emalloc_btrans(); /* sentinel */
s->trans->nxt = s->trans;
for(i = 0; i < init_size; i++)
if(init[i])
for(t = init[i]->trans->nxt; t != init[i]->trans; t = t->nxt) {
int fin = next_final(t->final, 0);
BState *to = find_bstate(&t->to, fin, s);
for(t1 = s->trans->nxt; t1 != s->trans;) {
if(tl_simp_fly &&
(to == t1->to) &&
included_set(t->pos, t1->pos, 1) &&
included_set(t->neg, t1->neg, 1)) { /* t1 is redondant */
BTrans *free = t1->nxt;
t1->to->incoming--;
t1->to = free->to;
copy_set(free->pos, t1->pos, 1);
copy_set(free->neg, t1->neg, 1);
t1->nxt = free->nxt;
if(free == s->trans) s->trans = t1;
free_btrans(free, 0, 0);
}
else if(tl_simp_fly &&
(t1->to == to ) &&
included_set(t1->pos, t->pos, 1) &&
included_set(t1->neg, t->neg, 1)) /* t is redondant */
break;
else
t1 = t1->nxt;
}
if(t1 == s->trans) {
BTrans *trans = emalloc_btrans();
trans->to = to;
trans->to->incoming++;
copy_set(t->pos, trans->pos, 1);
copy_set(t->neg, trans->neg, 1);
trans->nxt = s->trans->nxt;
s->trans->nxt = trans;
}
}
while(bstack->nxt != bstack) { /* solves all states in the stack until it is empty */
s = bstack->nxt;
bstack->nxt = bstack->nxt->nxt;
if(!s->incoming) {
free_bstate(s);
continue;
}
make_btrans(s);
}
retarget_all_btrans();
if(tl_stats) {
getrusage(RUSAGE_SELF, &tr_fin);
timeval_subtract (&t_diff, &tr_fin.ru_utime, &tr_debut.ru_utime);
fprintf(tl_out, "\nBuilding the Buchi automaton : %i.%06is",
t_diff.tv_sec, t_diff.tv_usec);
fprintf(tl_out, "\n%i states, %i transitions\n", bstate_count, btrans_count);
}
if(tl_verbose) {
fprintf(tl_out, "\nBuchi automaton before simplification\n");
print_buchi(bstates->nxt);
if(bstates == bstates->nxt)
fprintf(tl_out, "empty automaton, refuses all words\n");
}
if(tl_simp_diff) {
simplify_btrans();
if(tl_simp_scc) simplify_bscc();
while(simplify_bstates()) { /* simplifies as much as possible */
simplify_btrans();
if(tl_simp_scc) simplify_bscc();
}
if(tl_verbose) {
fprintf(tl_out, "\nBuchi automaton after simplification\n");
print_buchi(bstates->nxt);
if(bstates == bstates->nxt)
fprintf(tl_out, "empty automaton, refuses all words\n");
fprintf(tl_out, "\n");
}
}
switch (tl_type) {
case OT_C:
print_c_buchi();
break;
case OT_JSON:
print_json_buchi();
break;
default:
print_spin_buchi();
}
}