ltl2tgba.cc 26.5 KB
Newer Older
1
// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Laboratoire
2
3
// d'Informatique de Paris 6 (LIP6), dpartement Systmes Rpartis
// Coopratifs (SRC), Universit Pierre et Marie Curie.
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//
// 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 2 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 Spot; see the file COPYING.  If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.

22
#include <iostream>
23
#include <iomanip>
24
#include <cassert>
25
26
#include <fstream>
#include <string>
27
#include <cstdlib>
28
#include "ltlvisit/destroy.hh"
29
#include "ltlvisit/contain.hh"
30
#include "ltlvisit/tostring.hh"
31
#include "ltlvisit/apcollect.hh"
32
#include "ltlast/allnodes.hh"
33
#include "ltlparse/public.hh"
34
#include "tgbaalgos/ltl2tgba_lacim.hh"
35
#include "tgbaalgos/ltl2tgba_fm.hh"
36
#include "tgba/bddprint.hh"
37
#include "tgbaalgos/save.hh"
38
#include "tgbaalgos/dotty.hh"
39
#include "tgbaalgos/lbtt.hh"
40
#include "tgba/tgbatba.hh"
41
#include "tgba/tgbaproduct.hh"
42
#include "tgbaalgos/reducerun.hh"
43
#include "tgbaparse/public.hh"
44
#include "tgbaalgos/dupexp.hh"
45
#include "tgbaalgos/neverclaim.hh"
46
#include "tgbaalgos/reductgba_sim.hh"
47
#include "tgbaalgos/replayrun.hh"
48
#include "tgbaalgos/rundotdec.hh"
49

50
#include "tgbaalgos/stats.hh"
51
#include "tgbaalgos/scc.hh"
52
53
#include "tgbaalgos/emptiness_stats.hh"

54
55
56
void
syntax(char* prog)
{
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
57
  std::cerr << "Usage: "<< prog << " [OPTIONS...] formula" << std::endl
58
            << "       "<< prog << " -F [OPTIONS...] file" << std::endl
59
            << "       "<< prog << " -X [OPTIONS...] file" << std::endl
Alexandre Duret-Lutz's avatar
spacing    
Alexandre Duret-Lutz committed
60
	    << std::endl
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
61
	    << "Options:" << std::endl
62
63
	    << "  -0    produce minimal output dedicated to the paper"
	    << std::endl
martinez's avatar
martinez committed
64
	    << "  -a    display the acceptance_conditions BDD, not the "
65
	    << "reachability graph"
66
	    << std::endl
martinez's avatar
martinez committed
67
	    << "  -A    same as -a, but as a set" << std::endl
68
69
	    << "  -b    display the automaton in the format of spot"
            << std::endl
70
71
	    << "  -c    enable language containment checks (implies -f)"
	    << std::endl
martinez's avatar
martinez committed
72
	    << "  -d    turn on traces during parsing" << std::endl
73
74
	    << "  -D    degeneralize the automaton as a TBA" << std::endl
	    << "  -DS   degeneralize the automaton as an SBA" << std::endl
75
76
77
	    << "  -e[ALGO]  emptiness-check, expect and compute an "
	    << "accepting run" << std::endl
	    << "  -E[ALGO]  emptiness-check, expect no accepting run"
78
	    << std::endl
martinez's avatar
martinez committed
79
80
            << "  -f    use Couvreur's FM algorithm for translation"
	    << std::endl
81
82
83
84
	    << "  -fr1  use -r1 (see below) at each step of FM" << std::endl
	    << "  -fr2  use -r2 (see below) at each step of FM" << std::endl
	    << "  -fr3  use -r3 (see below) at each step of FM" << std::endl
	    << "  -fr4  use -r4 (see below) at each step of FM" << std::endl
85
86
87
	    << "  -fr5  use -r5 (see below) at each step of FM" << std::endl
	    << "  -fr6  use -r6 (see below) at each step of FM" << std::endl
	    << "  -fr7  use -r7 (see below) at each step of FM" << std::endl
88
	    << "  -fr8  use -r8 (see below) at each step of FM" << std::endl
martinez's avatar
martinez committed
89
            << "  -F    read the formula from the file" << std::endl
90
	    << "  -g    graph the accepting run on the automaton (requires -e)"
91
	    << std::endl
92
93
	    << "  -G    graph the accepting run seen as an automaton "
	    << " (requires -e)" << std::endl
94
95
	    << "  -k    display statistics on the TGBA instead of dumping it"
	    << std::endl
96
97
	    << "  -K    dump the graph of SCCs in dot format" << std::endl
	    << "  -KV   verbosely dump the graph of SCCs in dot format"
98
	    << std::endl
martinez's avatar
martinez committed
99
            << "  -L    fair-loop approximation (implies -f)" << std::endl
100
	    << "  -m    try to reduce accepting runs, in a second pass"
101
	    << std::endl
martinez's avatar
martinez committed
102
103
	    << "  -N    display the never clain for Spin "
	    << "(implies -D)" << std::endl
martinez's avatar
martinez committed
104
            << "  -p    branching postponement (implies -f)" << std::endl
105
106
	    << "  -Pfile  multiply the formula with the automaton from `file'."
	    << std::endl
martinez's avatar
martinez committed
107
	    << "  -r    display the relation BDD, not the reachability graph"
108
	    << std::endl
martinez's avatar
martinez committed
109
110
	    << "  -r1   reduce formula using basic rewriting" << std::endl
	    << "  -r2   reduce formula using class of eventuality and "
111
	    << "and universality" << std::endl
martinez's avatar
martinez committed
112
	    << "  -r3   reduce formula using implication between "
113
	    << "sub-formulae" << std::endl
114
115
116
	    << "  -r4   reduce formula using all above rules" << std::endl
	    << "  -r5   reduce formula using tau03" << std::endl
	    << "  -r6   reduce formula using tau03+" << std::endl
117
118
	    << "  -r7   reduce formula using tau03+ and -r1" << std::endl
	    << "  -r8   reduce formula using tau03+ and -r4" << std::endl
martinez's avatar
martinez committed
119
120
	    << "  -rd   display the reduce formula" << std::endl
	    << "  -R    same as -r, but as a set" << std::endl
121
	    << "  -R1q  merge states using direct simulation "
martinez's avatar
martinez committed
122
	    << "(use -L for more reduction)"
123
	    << std::endl
124
	    << "  -R1t  remove transitions using direct simulation "
martinez's avatar
martinez committed
125
	    << "(use -L for more reduction)"
126
	    << std::endl
127
128
	    << "  -R2q  merge states using delayed simulation" << std::endl
	    << "  -R2t  remove transitions using delayed simulation"
129
	    << std::endl
130
131
132
	    << "  -R3   use SCC to reduce the automata" << std::endl
	    << "  -Rd   display the simulation relation" << std::endl
	    << "  -RD   display the parity game (dot format)" << std::endl
martinez's avatar
martinez committed
133
	    << "  -s    convert to explicit automata, and number states "
134
	    << "in DFS order" << std::endl
martinez's avatar
martinez committed
135
	    << "  -S    convert to explicit automata, and number states "
136
	    << "in BFS order" << std::endl
martinez's avatar
martinez committed
137
	    << "  -t    display reachable states in LBTT's format" << std::endl
138
139
140
141
            << "  -U[PROPS]  consider atomic properties of the formula as "
	    << "exclusive events, and" << std::endl
	    << "        PROPS as unobservables events (implies -f)"
	    << std::endl
martinez's avatar
martinez committed
142
143
144
	    << "  -v    display the BDD variables used by the automaton"
	    << std::endl
            << "  -x    try to produce a more deterministic automata "
145
	    << "(implies -f)" << std::endl
martinez's avatar
martinez committed
146
	    << "  -X    do not compute an automaton, read it from a file"
147
	    << std::endl
martinez's avatar
martinez committed
148
	    << "  -y    do not merge states with same symbolic representation "
149
150
151
	    << "(implies -f)" << std::endl
	    << std::endl
	    << "Where ALGO should be one of:" << std::endl
152
153
154
155
156
157
	    << "  Cou99(OPTIONS) (the default)" << std::endl
	    << "  CVWY90(OPTIONS)" << std::endl
	    << "  GV04(OPTIONS)" << std::endl
	    << "  SE05(OPTIONS)" << std::endl
	    << "  Tau03(OPTIONS)" << std::endl
	    << "  Tau03_opt(OPTIONS)" << std::endl;
158
159
160
161
162
163
164
165
  exit(2);
}

int
main(int argc, char** argv)
{
  int exit_code = 0;

166
  bool debug_opt = false;
167
  bool paper_opt = false;
168
  enum { NoDegen, DegenTBA, DegenSBA } degeneralize_opt = NoDegen;
169
  bool fm_opt = false;
170
  int fm_red = spot::ltl::Reduce_None;
171
  bool fm_exprop_opt = false;
172
  bool fm_symb_merge_opt = true;
173
  bool file_opt = false;
174
  int output = 0;
175
  int formula_index = 0;
176
177
  const char* echeck_algo = 0;
  spot::emptiness_check_instantiator* echeck_inst = 0;
178
  enum { NoneDup, BFS, DFS } dupexp = NoneDup;
179
  bool expect_counter_example = false;
180
  bool from_file = false;
181
  int reduc_aut = spot::Reduce_None;
182
  int redopt = spot::ltl::Reduce_None;
183
184
  bool display_reduce_form = false;
  bool display_rel_sim = false;
185
  bool display_parity_game = false;
186
  bool post_branching = false;
187
  bool fair_loop_approx = false;
188
  bool graph_run_opt = false;
189
  bool graph_run_tgba_opt = false;
190
  bool opt_reduce = false;
191
  bool containment = false;
192
193
  spot::ltl::environment& env(spot::ltl::default_environment::instance());
  spot::ltl::atomic_prop_set* unobservables = 0;
194
195
  spot::tgba_explicit* system = 0;
  spot::tgba* product = 0;
196
  spot::tgba* product_to_free = 0;
197
  spot::bdd_dict* dict = new spot::bdd_dict();
198

199
  for (;;)
200
    {
201
      if (argc < formula_index + 2)
202
	syntax(argv[0]);
203
204
205

      ++formula_index;

206
207
208
209
210
      if (!strcmp(argv[formula_index], "-0"))
	{
	  paper_opt = true;
	}
      else if (!strcmp(argv[formula_index], "-a"))
211
212
213
	{
	  output = 2;
	}
214
      else if (!strcmp(argv[formula_index], "-A"))
215
	{
216
	  output = 4;
217
	}
218
      else if (!strcmp(argv[formula_index], "-b"))
219
	{
220
	  output = 7;
221
	}
222
223
224
225
226
      else if (!strcmp(argv[formula_index], "-c"))
	{
	  containment = true;
	  fm_opt = true;
	}
227
      else if (!strcmp(argv[formula_index], "-d"))
228
229
230
	{
	  debug_opt = true;
	}
231
232
      else if (!strcmp(argv[formula_index], "-D"))
	{
233
234
235
236
237
	  degeneralize_opt = DegenTBA;
	}
      else if (!strcmp(argv[formula_index], "-DS"))
	{
	  degeneralize_opt = DegenSBA;
238
	}
239
      else if (!strncmp(argv[formula_index], "-e", 2))
240
        {
241
242
243
244
245
246
247
248
249
250
251
252
253
	  echeck_algo = 2 + argv[formula_index];
	  if (!*echeck_algo)
	    echeck_algo = "Cou99";

	  const char* err;
	  echeck_inst =
	    spot::emptiness_check_instantiator::construct(echeck_algo, &err);
	  if (!echeck_inst)
	    {
	      std::cerr << "Failed to parse argument of -e near `"
			<< err <<  "'" << std::endl;
	      exit(2);
	    }
254
255
256
          expect_counter_example = true;
          output = -1;
        }
257
      else if (!strncmp(argv[formula_index], "-E", 2))
258
        {
259
260
261
262
263
264
265
266
267
268
269
270
271
	  const char* echeck_algo = 2 + argv[formula_index];
	  if (!*echeck_algo)
	    echeck_algo = "Cou99";

	  const char* err;
	  echeck_inst =
	    spot::emptiness_check_instantiator::construct(echeck_algo, &err);
	  if (!echeck_inst)
	    {
	      std::cerr << "Failed to parse argument of -e near `"
			<< err <<  "'" << std::endl;
	      exit(2);
	    }
272
273
274
          expect_counter_example = false;
          output = -1;
        }
275
276
277
278
      else if (!strcmp(argv[formula_index], "-f"))
	{
	  fm_opt = true;
	}
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
      else if (!strcmp(argv[formula_index], "-fr1"))
	{
	  fm_opt = true;
	  fm_red |= spot::ltl::Reduce_Basics;
	}
      else if (!strcmp(argv[formula_index], "-fr2"))
	{
	  fm_opt = true;
	  fm_red |= spot::ltl::Reduce_Eventuality_And_Universality;
	}
      else if (!strcmp(argv[formula_index], "-fr3"))
	{
	  fm_opt = true;
	  fm_red |= spot::ltl::Reduce_Syntactic_Implications;
	}
      else if (!strcmp(argv[formula_index], "-fr4"))
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
	{
	  fm_opt = true;
 	  fm_red |= spot::ltl::Reduce_Basics
	    | spot::ltl::Reduce_Eventuality_And_Universality
	    | spot::ltl::Reduce_Syntactic_Implications;
	}
      else if (!strcmp(argv[formula_index], "-fr5"))
	{
	  fm_opt = true;
	  fm_red |= spot::ltl::Reduce_Containment_Checks;
	}
      else if (!strcmp(argv[formula_index], "-fr6"))
	{
	  fm_opt = true;
	  fm_red |= spot::ltl::Reduce_Containment_Checks_Stronger;
	}
      else if (!strcmp(argv[formula_index], "-fr7"))
312
313
314
315
	{
	  fm_opt = true;
	  fm_red |= spot::ltl::Reduce_All;
	}
316
317
318
319
      else if (!strcmp(argv[formula_index], "-F"))
	{
	  file_opt = true;
	}
320
321
322
323
      else if (!strcmp(argv[formula_index], "-g"))
	{
	  graph_run_opt = true;
	}
324
325
326
327
      else if (!strcmp(argv[formula_index], "-G"))
	{
	  graph_run_tgba_opt = true;
	}
328
329
330
331
      else if (!strcmp(argv[formula_index], "-k"))
	{
	  output = 9;
	}
332
333
334
335
      else if (!strcmp(argv[formula_index], "-K"))
	{
	  output = 10;
	}
336
337
338
339
      else if (!strcmp(argv[formula_index], "-KV"))
	{
	  output = 11;
	}
340
341
342
343
344
      else if (!strcmp(argv[formula_index], "-L"))
	{
	  fair_loop_approx = true;
	  fm_opt = true;
	}
345
346
      else if (!strcmp(argv[formula_index], "-m"))
	{
347
	  opt_reduce = true;
348
	}
martinez's avatar
martinez committed
349
350
      else if (!strcmp(argv[formula_index], "-N"))
	{
351
	  degeneralize_opt = DegenSBA;
martinez's avatar
martinez committed
352
353
	  output = 8;
	}
354
355
356
357
358
      else if (!strcmp(argv[formula_index], "-p"))
	{
	  post_branching = true;
	  fm_opt = true;
	}
359
360
361
362
      else if (!strncmp(argv[formula_index], "-P", 2))
	{
	  spot::tgba_parse_error_list pel;
	  system = spot::tgba_parse(argv[formula_index] + 2,
363
				    pel, dict, env, env, debug_opt);
364
365
	  if (spot::format_tgba_parse_errors(std::cerr,
					     argv[formula_index] + 2, pel))
366
367
	    return 2;
	  system->merge_transitions();
368
369
370

	  if (!paper_opt)
	    std::clog << argv[formula_index] + 2 << " read" << std::endl;
371
	}
372
373
      else if (!strcmp(argv[formula_index], "-r"))
	{
374
375
	  output = 1;
	}
376
377
378
379
380
381
      else if (!strcmp(argv[formula_index], "-r1"))
	{
	  redopt |= spot::ltl::Reduce_Basics;
	}
      else if (!strcmp(argv[formula_index], "-r2"))
	{
382
	  redopt |= spot::ltl::Reduce_Eventuality_And_Universality;
383
384
385
	}
      else if (!strcmp(argv[formula_index], "-r3"))
	{
386
	  redopt |= spot::ltl::Reduce_Syntactic_Implications;
387
388
389
	}
      else if (!strcmp(argv[formula_index], "-r4"))
	{
390
391
392
 	  redopt |= spot::ltl::Reduce_Basics
	    | spot::ltl::Reduce_Eventuality_And_Universality
	    | spot::ltl::Reduce_Syntactic_Implications;
393
	}
394
395
      else if (!strcmp(argv[formula_index], "-r5"))
	{
396
	  redopt |= spot::ltl::Reduce_Containment_Checks;
397
398
399
	}
      else if (!strcmp(argv[formula_index], "-r6"))
	{
400
	  redopt |= spot::ltl::Reduce_Containment_Checks_Stronger;
401
402
403
404
405
	}
      else if (!strcmp(argv[formula_index], "-r7"))
	{
	  redopt |= spot::ltl::Reduce_All;
	}
406
407
408
      else if (!strcmp(argv[formula_index], "-R"))
	{
	  output = 3;
409
	}
martinez's avatar
martinez committed
410
411
412
413
414
415
416
417
418
      else if (!strcmp(argv[formula_index], "-R1q"))
	{
	  reduc_aut |= spot::Reduce_quotient_Dir_Sim;
	}
      else if (!strcmp(argv[formula_index], "-R1t"))
	{
	  reduc_aut |= spot::Reduce_transition_Dir_Sim;
	}
      else if (!strcmp(argv[formula_index], "-R2q"))
419
	{
martinez's avatar
martinez committed
420
	  reduc_aut |= spot::Reduce_quotient_Del_Sim;
421
	}
martinez's avatar
martinez committed
422
      else if (!strcmp(argv[formula_index], "-R2t"))
423
	{
martinez's avatar
martinez committed
424
	  reduc_aut |= spot::Reduce_transition_Del_Sim;
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
	}
      else if (!strcmp(argv[formula_index], "-R3"))
	{
	  reduc_aut |= spot::Reduce_Scc;
	}
      else if (!strcmp(argv[formula_index], "-rd"))
	{
	  display_reduce_form = true;
	}
      else if (!strcmp(argv[formula_index], "-Rd"))
	{
	  display_rel_sim = true;
	}
      else if (!strcmp(argv[formula_index], "-RD"))
	{
	  display_parity_game = true;
	}
442
443
444
445
446
447
448
449
      else if (!strcmp(argv[formula_index], "-s"))
	{
	  dupexp = DFS;
	}
      else if (!strcmp(argv[formula_index], "-S"))
	{
	  dupexp = BFS;
	}
450
451
452
453
      else if (!strcmp(argv[formula_index], "-t"))
	{
	  output = 6;
	}
454
455
456
457
458
      else if (!strncmp(argv[formula_index], "-U", 2))
	{
	  unobservables = new spot::ltl::atomic_prop_set;
	  fm_opt = true;
	  // Parse -U's argument.
459
	  const char* tok = strtok(argv[formula_index] + 2, ", \t;");
460
461
462
463
	  while (tok)
	    {
	      unobservables->insert
		(static_cast<spot::ltl::atomic_prop*>(env.require(tok)));
464
	      tok = strtok(0, ", \t;");
465
466
	    }
	}
467
468
469
470
      else if (!strcmp(argv[formula_index], "-v"))
	{
	  output = 5;
	}
471
472
473
474
475
      else if (!strcmp(argv[formula_index], "-x"))
	{
	  fm_opt = true;
	  fm_exprop_opt = true;
	}
476
477
478
479
      else if (!strcmp(argv[formula_index], "-X"))
	{
	  from_file = true;
	}
480
481
482
483
484
      else if (!strcmp(argv[formula_index], "-y"))
	{
	  fm_opt = true;
	  fm_symb_merge_opt = false;
	}
485
486
487
488
      else
	{
	  break;
	}
489
490
    }

491
  if ((graph_run_opt || graph_run_tgba_opt)
492
      && (!echeck_inst || !expect_counter_example))
493
    {
494
      std::cerr << argv[0] << ": error: -g and -G require -e." << std::endl;
495
496
497
      exit(1);
    }

498
499
500
501
  std::string input;

  if (file_opt)
    {
502
      if (strcmp(argv[formula_index], "-"))
503
	{
504
	  std::ifstream fin(argv[formula_index]);
505
	  if (!fin)
506
507
508
509
	    {
	      std::cerr << "Cannot open " << argv[formula_index] << std::endl;
	      exit(2);
	    }
510

511
	  if (!std::getline(fin, input, '\0'))
512
513
514
515
516
517
	    {
	      std::cerr << "Cannot read " << argv[formula_index] << std::endl;
	      exit(2);
	    }
	}
      else
518
	{
519
	  std::getline(std::cin, input, '\0');
520
521
522
523
524
525
526
	}
    }
  else
    {
      input = argv[formula_index];
    }

527
528
529
530
531
532
533
534
  spot::ltl::formula* f = 0;
  if (!from_file)
    {
      spot::ltl::parse_error_list pel;
      f = spot::ltl::parse(input, pel, env, debug_opt);
      exit_code = spot::ltl::format_parse_errors(std::cerr, input, pel);
    }
  if (f || from_file)
535
    {
536
537
538
539
      spot::tgba_bdd_concrete* concrete = 0;
      spot::tgba* to_free = 0;
      spot::tgba* a = 0;

540
541
542
      if (from_file)
	{
	  spot::tgba_parse_error_list pel;
543
	  spot::tgba_explicit* e;
544
545
	  to_free = a = e = spot::tgba_parse(input, pel, dict,
					     env, env, debug_opt);
546
	  if (spot::format_tgba_parse_errors(std::cerr, input, pel))
547
548
549
550
551
	    {
	      delete to_free;
	      delete dict;
	      return 2;
	    }
552
	  e->merge_transitions();
553
	}
554
      else
555
	{
556
	  if (redopt != spot::ltl::Reduce_None)
557
	    {
558
559
560
	      spot::ltl::formula* t = spot::ltl::reduce(f, redopt);
	      spot::ltl::destroy(f);
	      f = t;
561
562
	      if (display_reduce_form)
		std::cout << spot::ltl::to_string(f) << std::endl;
563
	    }
564

565
	  if (fm_opt)
566
	    to_free = a = spot::ltl_to_tgba_fm(f, dict, fm_exprop_opt,
567
					       fm_symb_merge_opt,
568
					       post_branching,
569
					       fair_loop_approx, unobservables,
570
					       fm_red, containment);
571
572
573
	  else
	    to_free = a = concrete = spot::ltl_to_tgba_lacim(f, dict);
	}
574

575
      spot::tgba_tba_proxy* degeneralized = 0;
576

577
578
      unsigned int n_acc = a->number_of_acceptance_conditions();
      if (echeck_inst
579
	  && degeneralize_opt == NoDegen
580
581
	  && n_acc > 1
	  && echeck_inst->max_acceptance_conditions() < n_acc)
582
583
	degeneralize_opt = DegenTBA;
      if (degeneralize_opt == DegenTBA)
584
	a = degeneralized = new spot::tgba_tba_proxy(a);
585
586
      else if (degeneralize_opt == DegenSBA)
	a = degeneralized = new spot::tgba_sba_proxy(a);
587

588
589
590
591
      spot::tgba_reduc* aut_red = 0;
      if (reduc_aut != spot::Reduce_None)
	{
	  a = aut_red = new spot::tgba_reduc(a);
592
593
594
595

	  if (reduc_aut & spot::Reduce_Scc)
	    aut_red->prune_scc();

martinez's avatar
martinez committed
596
597
598
599
	  if (reduc_aut & (spot::Reduce_quotient_Dir_Sim |
			   spot::Reduce_transition_Dir_Sim |
			   spot::Reduce_quotient_Del_Sim |
			   spot::Reduce_transition_Del_Sim))
600
	    {
martinez's avatar
martinez committed
601
602
603
604
605
	      spot::direct_simulation_relation* rel_dir = 0;
	      spot::delayed_simulation_relation* rel_del = 0;

	      if (reduc_aut & (spot::Reduce_quotient_Dir_Sim |
			       spot::Reduce_transition_Dir_Sim))
606
607
608
609
610
611
612
613
		{
		  rel_dir =
		    spot::get_direct_relation_simulation(a,
							 std::cout,
							 display_parity_game);
		  assert(rel_dir);
		}
	      if (reduc_aut & (spot::Reduce_quotient_Del_Sim |
martinez's avatar
martinez committed
614
				    spot::Reduce_transition_Del_Sim))
615
616
617
618
619
620
621
		{
		  rel_del =
		    spot::get_delayed_relation_simulation(a,
							  std::cout,
							  display_parity_game);
		  assert(rel_del);
		}
622
623

	      if (display_rel_sim)
martinez's avatar
martinez committed
624
625
626
627
628
629
		{
		  if (rel_dir)
		    aut_red->display_rel_sim(rel_dir, std::cout);
		  if (rel_del)
		    aut_red->display_rel_sim(rel_del, std::cout);
		}
630

martinez's avatar
martinez committed
631
632
633
634
635
636
637
638
639
640
641
642
643
	      if (reduc_aut & spot::Reduce_quotient_Dir_Sim)
		aut_red->quotient_state(rel_dir);
	      if (reduc_aut & spot::Reduce_transition_Dir_Sim)
		aut_red->delete_transitions(rel_dir);
	      if (reduc_aut & spot::Reduce_quotient_Del_Sim)
		aut_red->quotient_state(rel_del);
	      if (reduc_aut & spot::Reduce_transition_Del_Sim)
		aut_red->delete_transitions(rel_del);

	      if (rel_dir)
		spot::free_relation_simulation(rel_dir);
	      if (rel_del)
		spot::free_relation_simulation(rel_del);
644
645
646
	    }
	}

647
648
649
650
651
652
653
654
655
656
657
658
659
      spot::tgba_explicit* expl = 0;
      switch (dupexp)
	{
	case NoneDup:
	  break;
	case BFS:
	  a = expl = tgba_dupexp_bfs(a);
	  break;
	case DFS:
	  a = expl = tgba_dupexp_dfs(a);
	  break;
	}

660
661
      spot::tgba* product_degeneralized = 0;

662
      if (system)
663
664
        {
          a = product = product_to_free = new spot::tgba_product(system, a);
665
666
667
668
669
670

	  unsigned int n_acc = a->number_of_acceptance_conditions();
	  if (echeck_inst
	      && degeneralize_opt == NoDegen
	      && n_acc > 1
	      && echeck_inst->max_acceptance_conditions() < n_acc)
671
672
673
674
675
676
677
678
            degeneralize_opt = DegenTBA;
          if (degeneralize_opt == DegenTBA)
            a = product = product_degeneralized =
                                            new spot::tgba_tba_proxy(product);
          else if (degeneralize_opt == DegenSBA)
            a = product = product_degeneralized =
                                            new spot::tgba_sba_proxy(product);
        }
679

680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
      if (echeck_inst
	  && (a->number_of_acceptance_conditions()
	      < echeck_inst->min_acceptance_conditions()))
	{
	  if (!paper_opt)
	    {
	      std::cerr << echeck_algo << " requires at least "
			<< echeck_inst->min_acceptance_conditions()
			<< " acceptance conditions." << std::endl;
	      exit(1);
	    }
	  else
	    {
	      std::cout << std::endl;
	      exit(0);
	    }
	}

698
699
      switch (output)
	{
700
701
702
	case -1:
	  /* No output.  */
	  break;
703
704
705
706
	case 0:
	  spot::dotty_reachable(std::cout, a);
	  break;
	case 1:
707
708
709
	  if (concrete)
	    spot::bdd_print_dot(std::cout, concrete->get_dict(),
				concrete->get_core_data().relation);
710
711
	  break;
	case 2:
712
713
714
	  if (concrete)
	    spot::bdd_print_dot(std::cout, concrete->get_dict(),
				concrete->
715
				get_core_data().acceptance_conditions);
716
717
	  break;
	case 3:
718
719
720
	  if (concrete)
	    spot::bdd_print_set(std::cout, concrete->get_dict(),
				concrete->get_core_data().relation);
721
722
	  break;
	case 4:
723
724
725
	  if (concrete)
	    spot::bdd_print_set(std::cout, concrete->get_dict(),
				concrete->
726
				get_core_data().acceptance_conditions);
727
	  break;
728
	case 5:
729
	  a->get_dict()->dump(std::cout);
730
	  break;
731
732
733
	case 6:
	  spot::lbtt_reachable(std::cout, a);
	  break;
734
735
736
	case 7:
	  spot::tgba_save_reachable(std::cout, a);
	  break;
737
	case 8:
738
739
740
741
742
743
744
	  {
	    assert(degeneralize_opt == DegenSBA);
	    const spot::tgba_sba_proxy* s =
	      static_cast<const spot::tgba_sba_proxy*>(degeneralized);
	    spot::never_claim_reachable(std::cout, s, f);
	    break;
	  }
745
746
	case 9:
	  stats_reachable(a).dump(std::cout);
747
748
749
	  build_scc_stats(a).dump(std::cout);
	  break;
	case 10:
750
751
752
753
	  dump_scc_dot(a, std::cout, false);
	  break;
	case 11:
	  dump_scc_dot(a, std::cout, true);
754
	  break;
755
756
757
	default:
	  assert(!"unknown output option");
	}
758

759
      if (echeck_inst)
760
	{
761
762
763
	  spot::emptiness_check* ec = echeck_inst->instantiate(a);
	  bool search_many = echeck_inst->options().get("repeated");
	  assert(ec);
764
765
766
	  do
	    {
	      spot::emptiness_check_result* res = ec->check();
767
768
769
              if (paper_opt)
                {
                  std::ios::fmtflags old = std::cout.flags();
770
                  std::cout << std::left << std::setw(25)
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
                            << echeck_algo << ", ";
                  spot::tgba_statistics a_size =
                                        spot::stats_reachable(ec->automaton());
                  std::cout << std::right << std::setw(10)
                            << a_size.states << ", "
                            << std::right << std::setw(10)
                            << a_size.transitions << ", ";
                  std::cout <<
                            ec->automaton()->number_of_acceptance_conditions()
                            << ", ";
                  const spot::ec_statistics* ecs =
                        dynamic_cast<const spot::ec_statistics*>(ec);
                  if (ecs)
                    std::cout << std::right << std::setw(10)
                              << ecs->states() << ", "
                              << std::right << std::setw(10)
                              << ecs->transitions() << ", "
                              << std::right << std::setw(10)
                              << ecs->max_depth();
                  else
791
                    std::cout << "no stats, , ";
792
793
794
795
796
797
798
799
800
801
802
803
                  if (res)
                    std::cout << ", accepting run found";
                  else
                    std::cout << ", no accepting run found";
                  std::cout << std::endl;
                  std::cout << std::setiosflags(old);
                }
              else
                {
                  if (!graph_run_opt && !graph_run_tgba_opt)
                    ec->print_stats(std::cout);
                  if (expect_counter_example != !!res &&
804
		      (!expect_counter_example || ec->safe()))
805
806
807
                    exit_code = 1;

                  if (!res)
808
                    {
809
                      std::cout << "no accepting run found";
810
                      if (!ec->safe() && expect_counter_example)
811
812
                        {
                          std::cout << " even if expected" << std::endl;
813
814
                          std::cout << "this may be due to the use of the bit"
                                    << " state hashing technique" << std::endl;
815
816
817
818
819
820
                          std::cout << "you can try to increase the heap size "
                                    << "or use an explicit storage"
                                    << std::endl;
                        }
                      std::cout << std::endl;
                      break;
821
                    }
822
823
                  else
                    {
824

825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
                      spot::tgba_run* run = res->accepting_run();
                      if (!run)
                        {
                          std::cout << "an accepting run exists" << std::endl;
                        }
                      else
                        {
                          if (opt_reduce)
                            {
                              spot::tgba_run* redrun =
                                spot::reduce_run(res->automaton(), run);
                              delete run;
                              run = redrun;
                            }
                          if (graph_run_opt)
                            {
                              spot::tgba_run_dotty_decorator deco(run);
                              spot::dotty_reachable(std::cout, a, &deco);
                            }
                          else if (graph_run_tgba_opt)
                            {
                              spot::tgba* ar = spot::tgba_run_to_tgba(a, run);
                              spot::dotty_reachable(std::cout, ar);
                              delete ar;
                            }
                          else
                            {
                              spot::print_tgba_run(std::cout, a, run);
                              if (!spot::replay_tgba_run(std::cout, a, run,
                                                                        true))
                                exit_code = 1;
                            }
                          delete run;
                        }
                    }
                }
861
862
	      delete res;
	    }
863
	  while (search_many);
864
	  delete ec;
martinez's avatar
martinez committed
865
866
	}

867
868
      if (f)
        spot::ltl::destroy(f);
869
870
      delete product_degeneralized;
      delete product_to_free;
871
      delete system;
872
873
      delete expl;
      delete aut_red;
874
      delete degeneralized;
875
      delete to_free;
876
      delete echeck_inst;
877
878
879
880
881
882
    }
  else
    {
      exit_code = 1;
    }

883
884
885
886
887
888
889
890
  if (unobservables)
    {
      for (spot::ltl::atomic_prop_set::iterator i =
	     unobservables->begin(); i != unobservables->end(); ++i)
	spot::ltl::destroy(*i);
      delete unobservables;
    }

891
892
893
894
  assert(spot::ltl::atomic_prop::instance_count() == 0);
  assert(spot::ltl::unop::instance_count() == 0);
  assert(spot::ltl::binop::instance_count() == 0);
  assert(spot::ltl::multop::instance_count() == 0);
895
  delete dict;
896
897
  return exit_code;
}