ltl2tgba.cc 22.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Copyright (C) 2003, 2004  Laboratoire d'Informatique de Paris 6 (LIP6),
// dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre
// et Marie Curie.
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 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
23
#include <iostream>
#include <cassert>
24
25
#include <fstream>
#include <string>
26
#include "ltlvisit/destroy.hh"
27
#include "ltlvisit/reduce.hh"
28
#include "ltlvisit/tostring.hh"
29
#include "ltlvisit/apcollect.hh"
30
31
#include "ltlast/allnodes.hh"
#include "ltlparse/public.hh"
32
#include "tgbaalgos/ltl2tgba_lacim.hh"
33
#include "tgbaalgos/ltl2tgba_fm.hh"
34
#include "tgba/bddprint.hh"
35
#include "tgbaalgos/dotty.hh"
36
#include "tgbaalgos/lbtt.hh"
37
#include "tgba/tgbatba.hh"
38
#include "tgba/tgbaproduct.hh"
39
#include "tgbaalgos/gv04.hh"
40
#include "tgbaalgos/magic.hh"
41
#include "tgbaalgos/reducerun.hh"
42
43
#include "tgbaalgos/se05.hh"
#include "tgbaalgos/tau03.hh"
44
#include "tgbaalgos/tau03opt.hh"
45
46
#include "tgbaalgos/gtec/gtec.hh"
#include "tgbaalgos/gtec/ce.hh"
47
#include "tgbaparse/public.hh"
48
#include "tgbaalgos/dupexp.hh"
49
#include "tgbaalgos/neverclaim.hh"
50
#include "tgbaalgos/reductgba_sim.hh"
51
#include "tgbaalgos/replayrun.hh"
52
#include "tgbaalgos/rundotdec.hh"
53

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
martinez's avatar
martinez committed
62
	    << "  -a    display the acceptance_conditions BDD, not the "
63
	    << "reachability graph"
64
	    << std::endl
martinez's avatar
martinez committed
65
66
	    << "  -A    same as -a, but as a set" << std::endl
	    << "  -d    turn on traces during parsing" << std::endl
67
68
	    << "  -D    degeneralize the automaton as a TBA" << std::endl
	    << "  -DS   degeneralize the automaton as an SBA" << std::endl
69
70
71
	    << "  -e[ALGO]  emptiness-check, expect and compute an "
	    << "accepting run" << std::endl
	    << "  -E[ALGO]  emptiness-check, expect no accepting run"
72
	    << std::endl
martinez's avatar
martinez committed
73
74
75
            << "  -f    use Couvreur's FM algorithm for translation"
	    << std::endl
            << "  -F    read the formula from the file" << std::endl
76
	    << "  -g    graph the accepting run on the automaton (requires -e)"
77
	    << std::endl
78
79
	    << "  -G    graph the accepting run seen as an automaton "
	    << " (requires -e)" << std::endl
martinez's avatar
martinez committed
80
            << "  -L    fair-loop approximation (implies -f)" << std::endl
81
	    << "  -m    try to reduce accepting runs, in a second pass"
82
	    << std::endl
martinez's avatar
martinez committed
83
84
	    << "  -N    display the never clain for Spin "
	    << "(implies -D)" << std::endl
martinez's avatar
martinez committed
85
            << "  -p    branching postponement (implies -f)" << std::endl
86
87
	    << "  -Pfile  multiply the formula with the automaton from `file'."
	    << std::endl
martinez's avatar
martinez committed
88
	    << "  -r    display the relation BDD, not the reachability graph"
89
	    << std::endl
martinez's avatar
martinez committed
90
91
	    << "  -r1   reduce formula using basic rewriting" << std::endl
	    << "  -r2   reduce formula using class of eventuality and "
92
	    << "and universality" << std::endl
martinez's avatar
martinez committed
93
	    << "  -r3   reduce formula using implication between "
94
	    << "sub-formulae" << std::endl
martinez's avatar
martinez committed
95
96
97
	    << "  -r4   reduce formula using all rules" << std::endl
	    << "  -rd   display the reduce formula" << std::endl
	    << "  -R    same as -r, but as a set" << std::endl
98
	    << "  -R1q  merge states using direct simulation "
martinez's avatar
martinez committed
99
	    << "(use -L for more reduction)"
100
	    << std::endl
101
	    << "  -R1t  remove transitions using direct simulation "
martinez's avatar
martinez committed
102
	    << "(use -L for more reduction)"
103
	    << std::endl
104
105
	    << "  -R2q  merge states using delayed simulation" << std::endl
	    << "  -R2t  remove transitions using delayed simulation"
106
	    << std::endl
107
108
109
	    << "  -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
110
	    << "  -s    convert to explicit automata, and number states "
111
	    << "in DFS order" << std::endl
martinez's avatar
martinez committed
112
	    << "  -S    convert to explicit automata, and number states "
113
	    << "in BFS order" << std::endl
martinez's avatar
martinez committed
114
	    << "  -t    display reachable states in LBTT's format" << std::endl
115
116
            << "  -U[PROPS]  consider atomic properties PROPS as exclusive "
	    << "events (implies -f)" << std::endl
martinez's avatar
martinez committed
117
118
119
	    << "  -v    display the BDD variables used by the automaton"
	    << std::endl
            << "  -x    try to produce a more deterministic automata "
120
	    << "(implies -f)" << std::endl
martinez's avatar
martinez committed
121
	    << "  -X    do not compute an automaton, read it from a file"
122
	    << std::endl
martinez's avatar
martinez committed
123
	    << "  -y    do not merge states with same symbolic representation "
124
125
126
	    << "(implies -f)" << std::endl
	    << std::endl
	    << "Where ALGO should be one of:" << std::endl
127
	    << "  couvreur99 (the default)" << std::endl
128
	    << "  couvreur99_shy-" << std::endl
129
130
	    << "  couvreur99_shy" << std::endl
	    << "  magic_search" << std::endl
131
	    << "  magic_search_repeated" << std::endl
132
133
134
135
	    << "  bsh_magic_search[(heap size in Mo - 10Mo by default)]"
            << std::endl
	    << "  bsh_magic_search_repeated[(heap size in MB - 10MB"
            << " by default)]" << std::endl
136
	    << "  gv04" << std::endl
137
	    << "  se05_search" << std::endl
138
139
140
141
	    << "  se05_search_repeated" << std::endl
	    << "  bsh_se05_search[(heap size in MB - 10MB by default)]"
            << std::endl
	    << "  bsh_se05_search_repeated[(heap size in MB - 10MB"
142
            << " by default)]" << std::endl
143
144
	    << "  tau03_search" << std::endl
	    << "  tau03_opt_search" << std::endl;
145
146
147
148
149
150
151
152
  exit(2);
}

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

153
  bool debug_opt = false;
154
  enum { NoDegen, DegenTBA, DegenSBA } degeneralize_opt = NoDegen;
155
  bool degeneralize_maybe = false;
156
  bool fm_opt = false;
157
  bool fm_exprop_opt = false;
158
  bool fm_symb_merge_opt = true;
159
  bool file_opt = false;
160
  int output = 0;
161
  int formula_index = 0;
162
  std::string echeck_algo;
163
  enum { None, Couvreur, Couvreur2, MagicSearch, Se05Search,
164
	 Tau03Search, Tau03OptSearch, Gv04 } echeck = None;
165
  enum { NoneDup, BFS, DFS } dupexp = NoneDup;
166
  bool couv_group = true;
167
  bool search_many = false;
168
169
  bool bit_state_hashing = false;
  int heap_size = 10*1024*1024;
170
  bool expect_counter_example = false;
171
  bool from_file = false;
172
  int reduc_aut = spot::Reduce_None;
173
  int redopt = spot::ltl::Reduce_None;
174
175
  bool display_reduce_form = false;
  bool display_rel_sim = false;
176
  bool display_parity_game = false;
177
  bool post_branching = false;
178
  bool fair_loop_approx = false;
179
  bool graph_run_opt = false;
180
  bool graph_run_tgba_opt = false;
181
  bool opt_reduce = false;
182
183
  spot::ltl::environment& env(spot::ltl::default_environment::instance());
  spot::ltl::atomic_prop_set* unobservables = 0;
184
185
186
  spot::tgba_explicit* system = 0;
  spot::tgba* product = 0;
  spot::bdd_dict* dict = new spot::bdd_dict();
187

188
  for (;;)
189
    {
190
      if (argc < formula_index + 2)
191
	syntax(argv[0]);
192
193
194

      ++formula_index;

195
196
197
198
199
200
201
202
203
      if (!strcmp(argv[formula_index], "-a"))
	{
	  output = 2;
	}
      else if (!strcmp(argv[formula_index], "-A"))
	{
	  output = 4;
	}
      else if (!strcmp(argv[formula_index], "-d"))
204
205
206
	{
	  debug_opt = true;
	}
207
208
      else if (!strcmp(argv[formula_index], "-D"))
	{
209
210
211
212
213
	  degeneralize_opt = DegenTBA;
	}
      else if (!strcmp(argv[formula_index], "-DS"))
	{
	  degeneralize_opt = DegenSBA;
214
	}
215
      else if (!strncmp(argv[formula_index], "-e", 2))
216
217
218
219
220
221
222
223
224
225
226
227
228
        {
          if (argv[formula_index][2] != 0)
            {
              char *p = strchr(argv[formula_index], '(');
              if (p && sscanf(p+1, "%d)", &heap_size) == 1)
                *p = '\0';
              echeck_algo = argv[formula_index] + 2;
            }
          else
            echeck_algo = "couvreur99";
          expect_counter_example = true;
          output = -1;
        }
229
      else if (!strncmp(argv[formula_index], "-E", 2))
230
231
232
233
234
235
236
237
238
239
240
241
242
        {
          if (argv[formula_index][2] != 0)
            {
              char *p = strchr(argv[formula_index], '(');
              if (p && sscanf(p+1, "%d)", &heap_size) == 1)
                *p = '\0';
              echeck_algo = argv[formula_index] + 2;
            }
          else
            echeck_algo = "couvreur99";
          expect_counter_example = false;
          output = -1;
        }
243
244
245
246
247
248
249
250
      else if (!strcmp(argv[formula_index], "-f"))
	{
	  fm_opt = true;
	}
      else if (!strcmp(argv[formula_index], "-F"))
	{
	  file_opt = true;
	}
251
252
253
254
      else if (!strcmp(argv[formula_index], "-g"))
	{
	  graph_run_opt = true;
	}
255
256
257
258
      else if (!strcmp(argv[formula_index], "-G"))
	{
	  graph_run_tgba_opt = true;
	}
259
260
261
262
263
      else if (!strcmp(argv[formula_index], "-L"))
	{
	  fair_loop_approx = true;
	  fm_opt = true;
	}
264
265
      else if (!strcmp(argv[formula_index], "-m"))
	{
266
	  opt_reduce = true;
267
	}
martinez's avatar
martinez committed
268
269
      else if (!strcmp(argv[formula_index], "-N"))
	{
270
	  degeneralize_opt = DegenSBA;
martinez's avatar
martinez committed
271
272
	  output = 8;
	}
273
274
275
276
277
      else if (!strcmp(argv[formula_index], "-p"))
	{
	  post_branching = true;
	  fm_opt = true;
	}
278
279
280
281
282
283
284
285
286
287
      else if (!strncmp(argv[formula_index], "-P", 2))
	{
	  spot::tgba_parse_error_list pel;
	  system = spot::tgba_parse(argv[formula_index] + 2,
				     pel, dict, env, debug_opt);
	  if (spot::format_tgba_parse_errors(std::cerr, pel))
	    return 2;
	  system->merge_transitions();
	  std::clog << argv[formula_index] + 2 << " read" << std::endl;
	}
288
289
      else if (!strcmp(argv[formula_index], "-r"))
	{
290
291
	  output = 1;
	}
292
293
294
295
296
297
      else if (!strcmp(argv[formula_index], "-r1"))
	{
	  redopt |= spot::ltl::Reduce_Basics;
	}
      else if (!strcmp(argv[formula_index], "-r2"))
	{
298
	  redopt |= spot::ltl::Reduce_Eventuality_And_Universality;
299
300
301
	}
      else if (!strcmp(argv[formula_index], "-r3"))
	{
302
	  redopt |= spot::ltl::Reduce_Syntactic_Implications;
303
304
305
306
307
	}
      else if (!strcmp(argv[formula_index], "-r4"))
	{
	  redopt |= spot::ltl::Reduce_All;
	}
308
309
310
      else if (!strcmp(argv[formula_index], "-R"))
	{
	  output = 3;
311
	}
martinez's avatar
martinez committed
312
313
314
315
316
317
318
319
320
      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"))
321
	{
martinez's avatar
martinez committed
322
	  reduc_aut |= spot::Reduce_quotient_Del_Sim;
323
	}
martinez's avatar
martinez committed
324
      else if (!strcmp(argv[formula_index], "-R2t"))
325
	{
martinez's avatar
martinez committed
326
	  reduc_aut |= spot::Reduce_transition_Del_Sim;
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
	}
      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;
	}
344
345
346
347
348
349
350
351
      else if (!strcmp(argv[formula_index], "-s"))
	{
	  dupexp = DFS;
	}
      else if (!strcmp(argv[formula_index], "-S"))
	{
	  dupexp = BFS;
	}
352
353
354
355
      else if (!strcmp(argv[formula_index], "-t"))
	{
	  output = 6;
	}
356
357
358
359
360
      else if (!strncmp(argv[formula_index], "-U", 2))
	{
	  unobservables = new spot::ltl::atomic_prop_set;
	  fm_opt = true;
	  // Parse -U's argument.
361
	  const char* tok = strtok(argv[formula_index] + 2, ", \t;");
362
363
364
365
	  while (tok)
	    {
	      unobservables->insert
		(static_cast<spot::ltl::atomic_prop*>(env.require(tok)));
366
	      tok = strtok(0, ", \t;");
367
368
	    }
	}
369
370
371
372
      else if (!strcmp(argv[formula_index], "-v"))
	{
	  output = 5;
	}
373
374
375
376
377
      else if (!strcmp(argv[formula_index], "-x"))
	{
	  fm_opt = true;
	  fm_exprop_opt = true;
	}
378
379
380
381
      else if (!strcmp(argv[formula_index], "-X"))
	{
	  from_file = true;
	}
382
383
384
385
386
      else if (!strcmp(argv[formula_index], "-y"))
	{
	  fm_opt = true;
	  fm_symb_merge_opt = false;
	}
387
388
389
390
      else
	{
	  break;
	}
391
392
    }

393
  if (echeck_algo != "")
394
    {
395
396
397
398
399
400
401
      if (echeck_algo == "couvreur99")
	{
	  echeck = Couvreur;
	}
      else if (echeck_algo == "couvreur99_shy")
	{
	  echeck = Couvreur2;
402
403
404
405
406
407
	  couv_group = true;
	}
      else if (echeck_algo == "couvreur99_shy-")
	{
	  echeck = Couvreur2;
	  couv_group = false;
408
409
410
411
	}
      else if (echeck_algo == "magic_search")
	{
	  echeck = MagicSearch;
412
	  degeneralize_maybe = true;
413
414
415
416
	}
      else if (echeck_algo == "magic_search_repeated")
	{
	  echeck = MagicSearch;
417
	  degeneralize_maybe = true;
418
	  search_many = true;
419
	}
420
421
422
      else if (echeck_algo == "bsh_magic_search")
	{
	  echeck = MagicSearch;
423
	  degeneralize_maybe = true;
424
425
426
427
428
          bit_state_hashing = true;
	}
      else if (echeck_algo == "bsh_magic_search_repeated")
	{
	  echeck = MagicSearch;
429
	  degeneralize_maybe = true;
430
          bit_state_hashing = true;
431
	  search_many = true;
432
	}
433
434
      else if (echeck_algo == "se05_search")
	{
435
	  echeck = Se05Search;
436
	  degeneralize_maybe = true;
437
438
439
	}
      else if (echeck_algo == "se05_search_repeated")
	{
440
	  echeck = Se05Search;
441
	  degeneralize_maybe = true;
442
	  search_many = true;
443
444
445
446
	}
      else if (echeck_algo == "bsh_se05_search")
	{
	  echeck = Se05Search;
447
	  degeneralize_maybe = true;
448
449
450
451
452
          bit_state_hashing = true;
	}
      else if (echeck_algo == "bsh_se05_search_repeated")
	{
	  echeck = Se05Search;
453
	  degeneralize_maybe = true;
454
          bit_state_hashing = true;
455
456
457
458
459
	  search_many = true;
	}
      else if (echeck_algo == "tau03_search")
	{
	  echeck = Tau03Search;
460
	}
461
462
463
464
      else if (echeck_algo == "tau03_opt_search")
	{
	  echeck = Tau03OptSearch;
	}
465
466
467
468
469
      else if (echeck_algo == "gv04")
	{
	  echeck = Gv04;
	  degeneralize_maybe = true;
	}
470
471
472
473
474
      else
	{
	  std::cerr << "unknown emptiness-check: " << echeck_algo << std::endl;
	  syntax(argv[0]);
	}
475
476
    }

477
478
  if ((graph_run_opt || graph_run_tgba_opt)
      && (echeck_algo == "" || !expect_counter_example))
479
    {
480
      std::cerr << argv[0] << ": error: -g and -G require -e." << std::endl;
481
482
483
      exit(1);
    }

484
485
486
487
  std::string input;

  if (file_opt)
    {
488
      if (strcmp(argv[formula_index], "-"))
489
	{
490
	  std::ifstream fin(argv[formula_index]);
491
	  if (!fin)
492
493
494
495
	    {
	      std::cerr << "Cannot open " << argv[formula_index] << std::endl;
	      exit(2);
	    }
496

497
	  if (!std::getline(fin, input, '\0'))
498
499
500
501
502
503
	    {
	      std::cerr << "Cannot read " << argv[formula_index] << std::endl;
	      exit(2);
	    }
	}
      else
504
	{
505
	  std::getline(std::cin, input, '\0');
506
507
508
509
510
511
512
	}
    }
  else
    {
      input = argv[formula_index];
    }

513
514
515
516
517
518
519
520
  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)
521
    {
522
523
524
525
      spot::tgba_bdd_concrete* concrete = 0;
      spot::tgba* to_free = 0;
      spot::tgba* a = 0;

526
527
528
      if (from_file)
	{
	  spot::tgba_parse_error_list pel;
529
530
	  spot::tgba_explicit* e;
	  to_free = a = e = spot::tgba_parse(input, pel, dict, env, debug_opt);
531
	  if (spot::format_tgba_parse_errors(std::cerr, pel))
532
533
534
535
536
	    {
	      delete to_free;
	      delete dict;
	      return 2;
	    }
537
	  e->merge_transitions();
538
	}
539
      else
540
	{
541
	  if (redopt != spot::ltl::Reduce_None)
542
	    {
543
544
545
	      spot::ltl::formula* t = spot::ltl::reduce(f, redopt);
	      spot::ltl::destroy(f);
	      f = t;
546
547
	      if (display_reduce_form)
		std::cout << spot::ltl::to_string(f) << std::endl;
548
	    }
549

550
	  if (fm_opt)
551
	    to_free = a = spot::ltl_to_tgba_fm(f, dict, fm_exprop_opt,
552
					       fm_symb_merge_opt,
553
					       post_branching,
554
					       fair_loop_approx, unobservables);
555
556
557
	  else
	    to_free = a = concrete = spot::ltl_to_tgba_lacim(f, dict);
	}
558

559
      spot::tgba_tba_proxy* degeneralized = 0;
560

561
562
563
564
565
      if (degeneralize_maybe
	  && degeneralize_opt == NoDegen
	  && a->number_of_acceptance_conditions() > 1)
	degeneralize_opt = DegenTBA;
      if (degeneralize_opt == DegenTBA)
566
	a = degeneralized = new spot::tgba_tba_proxy(a);
567
568
      else if (degeneralize_opt == DegenSBA)
	a = degeneralized = new spot::tgba_sba_proxy(a);
569

570
571
572
573
      spot::tgba_reduc* aut_red = 0;
      if (reduc_aut != spot::Reduce_None)
	{
	  a = aut_red = new spot::tgba_reduc(a);
574
575
576
577

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

martinez's avatar
martinez committed
578
579
580
581
	  if (reduc_aut & (spot::Reduce_quotient_Dir_Sim |
			   spot::Reduce_transition_Dir_Sim |
			   spot::Reduce_quotient_Del_Sim |
			   spot::Reduce_transition_Del_Sim))
582
	    {
martinez's avatar
martinez committed
583
584
585
586
587
	      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))
588
589
590
591
		rel_dir =
		  spot::get_direct_relation_simulation(a,
						       std::cout,
						       display_parity_game);
martinez's avatar
martinez committed
592
593
	      else if (reduc_aut & (spot::Reduce_quotient_Del_Sim |
				    spot::Reduce_transition_Del_Sim))
594
595
596
597
		rel_del =
		  spot::get_delayed_relation_simulation(a,
							std::cout,
							display_parity_game);
598
599

	      if (display_rel_sim)
martinez's avatar
martinez committed
600
601
602
603
604
605
		{
		  if (rel_dir)
		    aut_red->display_rel_sim(rel_dir, std::cout);
		  if (rel_del)
		    aut_red->display_rel_sim(rel_del, std::cout);
		}
606

martinez's avatar
martinez committed
607
608
609
610
611
612
613
614
615
616
617
618
619
	      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);
620
621
622
	    }
	}

623
624
625
626
627
628
629
630
631
632
633
634
635
      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;
	}

636
637
638
      if (system)
	a = product = new spot::tgba_product(system, a);

639
640
      switch (output)
	{
641
642
643
	case -1:
	  /* No output.  */
	  break;
644
645
646
647
	case 0:
	  spot::dotty_reachable(std::cout, a);
	  break;
	case 1:
648
649
650
	  if (concrete)
	    spot::bdd_print_dot(std::cout, concrete->get_dict(),
				concrete->get_core_data().relation);
651
652
	  break;
	case 2:
653
654
655
	  if (concrete)
	    spot::bdd_print_dot(std::cout, concrete->get_dict(),
				concrete->
656
				get_core_data().acceptance_conditions);
657
658
	  break;
	case 3:
659
660
661
	  if (concrete)
	    spot::bdd_print_set(std::cout, concrete->get_dict(),
				concrete->get_core_data().relation);
662
663
	  break;
	case 4:
664
665
666
	  if (concrete)
	    spot::bdd_print_set(std::cout, concrete->get_dict(),
				concrete->
667
				get_core_data().acceptance_conditions);
668
	  break;
669
	case 5:
670
	  a->get_dict()->dump(std::cout);
671
	  break;
672
673
674
	case 6:
	  spot::lbtt_reachable(std::cout, a);
	  break;
675
	case 8:
676
677
678
679
680
681
682
	  {
	    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;
	  }
683
684
685
	default:
	  assert(!"unknown output option");
	}
686

687
      spot::emptiness_check* ec = 0;
688
689
690
691
      switch (echeck)
	{
	case None:
	  break;
martinez's avatar
martinez committed
692

693
	case Couvreur:
694
695
696
	  ec = new spot::couvreur99_check(a);
	  break;

697
	case Couvreur2:
698
	  ec = new spot::couvreur99_check_shy(a, couv_group);
699
	  break;
martinez's avatar
martinez committed
700

701
702
        case MagicSearch:
          if (bit_state_hashing)
703
            ec = spot::bit_state_hashing_magic_search(a, heap_size);
704
          else
705
            ec = spot::explicit_magic_search(a);
706
          break;
707

708
709
        case Se05Search:
          if (bit_state_hashing)
710
            ec = spot::bit_state_hashing_se05_search(a, heap_size);
711
          else
712
            ec = spot::explicit_se05_search(a);
713
          break;
714
715
716
717
718
719
720
721
722
723
724
725

	case Tau03Search:
          if (a->number_of_acceptance_conditions() == 0)
            {
              std::cout << "To apply tau03_search, the automaton must have at "
                        << "least on accepting condition. Try with another "
                        << "algorithm." << std::endl;
            }
          else
            {
              ec = spot::explicit_tau03_search(a);
            }
726
          break;
727
	case Tau03OptSearch:
728
          ec = spot::explicit_tau03_opt_search(a);
729
	  break;
730
731
732
	case Gv04:
	  ec = spot::explicit_gv04_check(a);
	  break;
733
	}
martinez's avatar
martinez committed
734

735
736
737
738
739
      if (ec)
	{
	  do
	    {
	      spot::emptiness_check_result* res = ec->check();
740
	      if (!graph_run_opt && !graph_run_tgba_opt)
741
		ec->print_stats(std::cout);
742
743
	      if (expect_counter_example != !!res &&
                      (!bit_state_hashing || !expect_counter_example))
744
745
746
747
		exit_code = 1;

	      if (!res)
		{
748
749
750
751
752
753
754
755
756
757
758
                  std::cout << "no accepting run found";
                  if (bit_state_hashing && expect_counter_example)
                    {
                      std::cout << " even if expected" << std::endl;
                      std::cout << "this is maybe due to the use of the bit "
                                << "state hashing technic" << std::endl;
                      std::cout << "you can try to increase the heap size "
                                << "or use an explicit storage" << std::endl;
                    }
                  std::cout << std::endl;
                  break;
759
760
761
762
763
764
765
		}
	      else
		{

		  spot::tgba_run* run = res->accepting_run();
		  if (!run)
		    {
766
		      std::cout << "an accepting run exists" << std::endl;
767
768
769
		    }
		  else
		    {
770
		      if (opt_reduce)
771
			{
772
773
			  spot::tgba_run* redrun =
			    spot::reduce_run(res->automaton(), run);
774
			  delete run;
775
			  run = redrun;
776
			}
777
778
779
		      if (graph_run_opt)
			{
			  spot::tgba_run_dotty_decorator deco(run);
780
			  spot::dotty_reachable(std::cout, a, &deco);
781
			}
782
783
784
785
786
787
		      else if (graph_run_tgba_opt)
			{
			  spot::tgba* ar = spot::tgba_run_to_tgba(a, run);
			  spot::dotty_reachable(std::cout, ar);
			  delete ar;
			}
788
789
		      else
			{
790
791
			  spot::print_tgba_run(std::cout, a, run);
			  if (!spot::replay_tgba_run(std::cout, a, run, true))
792
793
			    exit_code = 1;
			}
794
795
796
797
798
		      delete run;
		    }
		}
	      delete res;
	    }
799
	  while (search_many);
800
	  delete ec;
martinez's avatar
martinez committed
801
802
	}

803
804
      if (f)
        spot::ltl::destroy(f);
805
806
      delete product;
      delete system;
807
808
809
      delete expl;
      delete degeneralized;
      delete aut_red;
810
      delete to_free;
811
812
813
814
815
816
817
818
819
820
    }
  else
    {
      exit_code = 1;
    }

  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);
821
  delete dict;
822
823
  return exit_code;
}