ltl2tgba.cc 39.5 KB
Newer Older
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
1
2
// Copyright (C) 2007, 2008, 2009, 2010 Laboratoire de Recherche et
// Dveloppement de l'Epita (LRDE).
Guillaume Sadegh's avatar
Guillaume Sadegh committed
3
4
// Copyright (C) 2003, 2004, 2005, 2006, 2007 Laboratoire d'Informatique de
// Paris 6 (LIP6), dpartement Systmes Rpartis
5
// Coopratifs (SRC), Universit Pierre et Marie Curie.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//
// 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.

24
#include <iostream>
25
#include <iomanip>
26
#include <cassert>
27
28
#include <fstream>
#include <string>
29
#include <cstdlib>
30
#include "ltlvisit/contain.hh"
31
#include "ltlvisit/tostring.hh"
32
#include "ltlvisit/apcollect.hh"
33
#include "ltlast/allnodes.hh"
34
#include "ltlparse/public.hh"
35
#include "tgbaalgos/ltl2tgba_lacim.hh"
36
#include "tgbaalgos/ltl2tgba_fm.hh"
37
#include "tgbaalgos/ltl2taa.hh"
38
#include "tgba/bddprint.hh"
39
#include "tgbaalgos/save.hh"
40
#include "tgbaalgos/dotty.hh"
41
#include "tgbaalgos/lbtt.hh"
42
#include "tgba/tgbatba.hh"
43
#include "tgba/tgbasgba.hh"
44
#include "tgba/tgbaproduct.hh"
45
#include "tgba/futurecondcol.hh"
46
#include "tgbaalgos/reducerun.hh"
47
#include "tgbaparse/public.hh"
48
#include "neverparse/public.hh"
49
#include "tgbaalgos/dupexp.hh"
Felix Abecassis's avatar
Felix Abecassis committed
50
#include "tgbaalgos/minimize.hh"
51
#include "tgbaalgos/neverclaim.hh"
52
#include "tgbaalgos/reductgba_sim.hh"
53
#include "tgbaalgos/replayrun.hh"
54
#include "tgbaalgos/rundotdec.hh"
55
#include "tgbaalgos/sccfilter.hh"
56
#include "tgbaalgos/safety.hh"
57
#include "tgbaalgos/eltl2tgba_lacim.hh"
58
#include "tgbaalgos/gtec/gtec.hh"
59
#include "eltlparse/public.hh"
60
#include "misc/timer.hh"
61

62
#include "tgbaalgos/stats.hh"
63
#include "tgbaalgos/scc.hh"
64
65
#include "tgbaalgos/emptiness_stats.hh"

66
67
68
69
70
71
72
73
74
75
76
77
std::string
ltl_defs()
{
  std::string s = "\
X=(0 1 true	   \
   1 2 $0	   \
   accept 2)	   \
U=(0 0 $0	   \
   0 1 $1	   \
   accept 1)	   \
G=(0 0 $0)	   \
F=U(true, $0)	   \
78
79
80
W=G($0)|U($0, $1)  \
R=!U(!$0, !$1)     \
M=F($0)&R($0, $1)";
81
82
83
  return s;
}

84
85
86
void
syntax(char* prog)
{
87
88
89
90
91
  // Display the supplied name unless it appears to be a libtool wrapper.
  char* slash = strrchr(prog, '/');
  if (slash && (strncmp(slash + 1, "lt-", 3) == 0))
    prog = slash + 4;

92
  std::cerr << "Usage: "<< prog << " [-f|-l|-le|-taa] [OPTIONS...] formula"
93
	    << std::endl
94
            << "       "<< prog << " [-f|-l|-le|-taa] -F [OPTIONS...] file"
95
	    << std::endl
96
            << "       "<< prog << " -X [OPTIONS...] file" << std::endl
Alexandre Duret-Lutz's avatar
spacing    
Alexandre Duret-Lutz committed
97
	    << std::endl
98

99
100
            << "Translate an LTL formula into an automaton, or read the "
	    << "automaton from a file." << std::endl
101
102
103
104
	    << "Optionally multiply this automaton by another"
	    << " automaton read from a file." << std::endl
            << "Output the result in various formats, or perform an emptiness "
            << "check." << std::endl
105
	    << std::endl
106
107
108

            << "Input options:" << std::endl
            << "  -F    read the formula from a file, not from the command line"
109
	    << std::endl
110
	    << "  -X    do not compute an automaton, read it from a file"
111
	    << std::endl
112
113
	    << "  -XN   do not compute an automaton, read it from a"
	    << " neverclaim file" << std::endl
114
115
	    << "  -Pfile  multiply the formula automaton with the automaton"
	    << " from `file'"
116
	    << std::endl
117
118
119
	    << std::endl

	    << "Translation algorithm:" << std::endl
120
            << "  -f    use Couvreur's FM algorithm for LTL"
121
	    << "(default)"
122
	    << std::endl
123
            << "  -l    use Couvreur's LaCIM algorithm for LTL "
124
	    << std::endl
125
126
127
	    << "  -le   use Couvreur's LaCIM algorithm for ELTL"
	    << std::endl
            << "  -taa  use Tauriainen's TAA-based algorithm for LTL"
martinez's avatar
martinez committed
128
	    << std::endl
129
130
131
	    << std::endl

	    << "Options for Couvreur's FM algorithm (-f):" << std::endl
132
133
134
135
	    << "  -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
136
137
138
	    << "  -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
139
140
141
142
143
            << "  -L    fair-loop approximation (implies -f)" << std::endl
            << "  -p    branching postponement (implies -f)" << std::endl
            << "  -U[PROPS]  consider atomic properties of the formula as "
	    << "exclusive events, and" << std::endl
	    << "        PROPS as unobservables events (implies -f)"
144
	    << std::endl
145
146
147
148
            << "  -x    try to produce a more deterministic automaton "
	    << "(implies -f)" << std::endl
	    << "  -y    do not merge states with same symbolic representation "
	    << "(implies -f)" << std::endl
149
	    << std::endl
150

151
152
	    << "Options for Couvreur's LaCIM algorithm (-l or -le):"
	    << std::endl
153
154
	    << "  -a    display the acceptance_conditions BDD, not the "
	    << "reachability graph"
155
	    << std::endl
156
	    << "  -A    same as -a, but as a set" << std::endl
157
158
	    << "  -lo   pre-define standard LTL operators as automata "
	    << "(implies -le)" << std::endl
159
	    << "  -r    display the relation BDD, not the reachability graph"
160
	    << std::endl
161
	    << "  -R    same as -r, but as a set" << std::endl
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
162
163
	    << "  -R3b  symbolically prune unaccepting SCC from BDD relation"
	    << std::endl
164
	    << std::endl
165
166

	    << "Options for Tauriainen's TAA-based algorithm (-taa):"
167
	    << std::endl
168
	    << "  -c    enable language containment checks (implies -taa)"
169
	    << std::endl
170
	    << std::endl
171
172

	    << "Formula simplification (before translation):"
173
	    << std::endl
martinez's avatar
martinez committed
174
175
	    << "  -r1   reduce formula using basic rewriting" << std::endl
	    << "  -r2   reduce formula using class of eventuality and "
176
	    << "universality" << std::endl
martinez's avatar
martinez committed
177
	    << "  -r3   reduce formula using implication between "
178
	    << "sub-formulae" << std::endl
179
180
181
	    << "  -r4   reduce formula using all above rules" << std::endl
	    << "  -r5   reduce formula using tau03" << std::endl
	    << "  -r6   reduce formula using tau03+" << std::endl
182
	    << "  -r7   reduce formula using tau03+ and -r4" << std::endl
183
184
185
186
187
188
189
190
191
192
193
194
195
196
	    << "  -rd   display the reduced formula" << std::endl
	    << std::endl

	    << "Automaton degeneralization (after translation):"
	    << std::endl
            << "  -lS   move generalized acceptance conditions to states "
	    << "(SGBA)" << std::endl
	    << "  -D    degeneralize the automaton as a TBA" << std::endl
	    << "  -DS   degeneralize the automaton as an SBA" << std::endl
	    << std::endl


	    << "Automaton simplifications (after translation):"
	    << std::endl
197
	    << "  -R1q  merge states using direct simulation "
martinez's avatar
martinez committed
198
	    << "(use -L for more reduction)"
199
	    << std::endl
200
	    << "  -R1t  remove transitions using direct simulation "
martinez's avatar
martinez committed
201
	    << "(use -L for more reduction)"
202
	    << std::endl
203
204
	    << "  -R2q  merge states using delayed simulation" << std::endl
	    << "  -R2t  remove transitions using delayed simulation"
205
	    << std::endl
206
	    << "  -R3   use SCC to reduce the automata" << std::endl
207
	    << "  -R3f  clean more acceptance conditions than -R3" << std::endl
208
209
210
	    << "          "
	    << "(prefer -R3 over -R3f if you degeneralize with -D, -DS, or -N)"
	    << std::endl
211
212
	    << "  -Rd   display the simulation relation" << std::endl
	    << "  -RD   display the parity game (dot format)" << std::endl
Felix Abecassis's avatar
Felix Abecassis committed
213
            << "  -Rm   attempt to minimize the automata" << std::endl
214
	    << std::endl
215

216
217
218
219
220
            << "Automaton conversion:"
            << "  -M    convert into a deterministic minimal monitor "
	    << "(implies -R3 or R3b)" << std::endl
	    << std::endl

221
222
223
224
	    << "Options for performing emptiness checks:" << std::endl
	    << "  -e[ALGO]  run emptiness check, expect and compute an "
	    << "accepting run" << std::endl
	    << "  -E[ALGO]  run emptiness check, expect no accepting run"
martinez's avatar
martinez committed
225
	    << std::endl
226
227
228
229
	    << "  -C    compute an accepting run (Counterexample) if it exists"
	    << std::endl
	    << "  -CR   compute and replay an accepting run (implies -C)"
	    << std::endl
230
	    << "  -g    graph the accepting run on the automaton (requires -e)"
231
	    << std::endl
232
233
234
	    << "  -G    graph the accepting run seen as an automaton "
	    << " (requires -e)" << std::endl
	    << "  -m    try to reduce accepting runs, in a second pass"
235
236
	    << std::endl
	    << "Where ALGO should be one of:" << std::endl
237
238
239
240
241
	    << "  Cou99(OPTIONS) (the default)" << std::endl
	    << "  CVWY90(OPTIONS)" << std::endl
	    << "  GV04(OPTIONS)" << std::endl
	    << "  SE05(OPTIONS)" << std::endl
	    << "  Tau03(OPTIONS)" << std::endl
242
243
244
245
246
247
248
249
250
251
252
253
254
	    << "  Tau03_opt(OPTIONS)" << std::endl
	    << std::endl

	    << "If no emptiness check is run, the automaton will be output "
	    << "in dot format" << std::endl << "by default.  This can be "
	    << "changed with the following options." << std::endl
	    << std::endl

	    << "Output options (if no emptiness check):" << std::endl
	    << "  -b    output the automaton in the format of spot"
            << std::endl
            << "  -FC   dump the automaton showing future conditions on states"
	    << std::endl
255
256
257
	    << "  -k    display statistics on the automaton (size and SCCs)"
	    << std::endl
	    << "  -ks   display statistics on the automaton (size only)"
258
259
260
261
262
263
264
265
	    << std::endl
	    << "  -K    dump the graph of SCCs in dot format" << std::endl
	    << "  -KV   verbosely dump the graph of SCCs in dot format"
	    << std::endl
	    << "  -N    output the never clain for Spin (implies -D)"
	    << std::endl
	    << "  -NN   output the never clain for Spin, with commented states"
	    << " (implies -D)" << std::endl
266
267
	    << "  -O    tell whether the automaton is a safety automaton"
	    << std::endl
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
	    << "  -t    output automaton in LBTT's format" << std::endl
	    << std::endl

	    << "Miscellaneous options:" << std::endl
	    << "  -0    produce minimal output dedicated to the paper"
	    << std::endl
	    << "  -d    turn on traces during parsing" << std::endl
	    << "  -s    convert to explicit automata, and number states "
	    << "in DFS order" << std::endl
	    << "  -S    convert to explicit automata, and number states "
	    << "in BFS order" << std::endl
            << "  -T    time the different phases of the translation"
	    << std::endl
	    << "  -v    display the BDD variables used by the automaton"
	    << std::endl;
283
284
285
286
287
288
289
290
  exit(2);
}

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

291
  bool debug_opt = false;
292
  bool paper_opt = false;
293
  enum { NoDegen, DegenTBA, DegenSBA } degeneralize_opt = NoDegen;
294
  enum { TransitionLabeled, StateLabeled } labeling_opt = TransitionLabeled;
295
  enum { TransFM, TransLaCIM, TransLaCIM_ELTL, TransLaCIM_ELTL_ops, TransTAA }
296
    translation = TransFM;
297
  int fm_red = spot::ltl::Reduce_None;
298
  bool fm_exprop_opt = false;
299
  bool fm_symb_merge_opt = true;
300
  bool file_opt = false;
301
  int output = 0;
302
  int formula_index = 0;
303
304
  const char* echeck_algo = 0;
  spot::emptiness_check_instantiator* echeck_inst = 0;
305
  enum { NoneDup, BFS, DFS } dupexp = NoneDup;
306
  bool expect_counter_example = false;
307
308
  bool accepting_run = false;
  bool accepting_run_replay = false;
309
  bool from_file = false;
310
  bool read_neverclaim = false;
311
  int reduc_aut = spot::Reduce_None;
312
  int redopt = spot::ltl::Reduce_None;
313
  bool scc_filter_all = false;
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
314
  bool symbolic_scc_pruning = false;
315
316
  bool display_reduce_form = false;
  bool display_rel_sim = false;
317
  bool display_parity_game = false;
318
  bool post_branching = false;
319
  bool fair_loop_approx = false;
320
  bool graph_run_opt = false;
321
  bool graph_run_tgba_opt = false;
322
  bool opt_reduce = false;
Felix Abecassis's avatar
Felix Abecassis committed
323
  bool opt_minimize = false;
324
  bool opt_monitor = false;
325
  bool containment = false;
326
  bool show_fc = false;
327
  bool spin_comments = false;
328
329
  spot::ltl::environment& env(spot::ltl::default_environment::instance());
  spot::ltl::atomic_prop_set* unobservables = 0;
330
  spot::tgba_explicit_string* system = 0;
331
  spot::tgba* product = 0;
332
  spot::tgba* product_to_free = 0;
333
  spot::bdd_dict* dict = new spot::bdd_dict();
334
335
  spot::timer_map tm;
  bool use_timer = false;
336

337
  for (;;)
338
    {
339
      if (argc < formula_index + 2)
340
	syntax(argv[0]);
341
342
343

      ++formula_index;

344
345
346
347
348
      if (!strcmp(argv[formula_index], "-0"))
	{
	  paper_opt = true;
	}
      else if (!strcmp(argv[formula_index], "-a"))
349
350
351
	{
	  output = 2;
	}
352
      else if (!strcmp(argv[formula_index], "-A"))
353
	{
354
	  output = 4;
355
	}
356
      else if (!strcmp(argv[formula_index], "-b"))
357
	{
358
	  output = 7;
359
	}
360
361
362
      else if (!strcmp(argv[formula_index], "-c"))
	{
	  containment = true;
363
	  translation = TransTAA;
364
	}
365
366
367
368
369
370
371
372
373
      else if (!strcmp(argv[formula_index], "-C"))
	{
	  accepting_run = true;
	}
      else if (!strcmp(argv[formula_index], "-CR"))
	{
	  accepting_run = true;
	  accepting_run_replay = true;
	}
374
      else if (!strcmp(argv[formula_index], "-d"))
375
376
377
	{
	  debug_opt = true;
	}
378
379
      else if (!strcmp(argv[formula_index], "-D"))
	{
380
381
382
383
384
	  degeneralize_opt = DegenTBA;
	}
      else if (!strcmp(argv[formula_index], "-DS"))
	{
	  degeneralize_opt = DegenSBA;
385
	}
386
      else if (!strncmp(argv[formula_index], "-e", 2))
387
        {
388
389
390
391
392
393
394
395
396
397
398
399
400
	  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);
	    }
401
402
403
          expect_counter_example = true;
          output = -1;
        }
404
      else if (!strncmp(argv[formula_index], "-E", 2))
405
        {
406
407
408
409
410
411
412
413
414
415
416
417
418
	  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);
	    }
419
420
421
          expect_counter_example = false;
          output = -1;
        }
422
423
      else if (!strcmp(argv[formula_index], "-f"))
	{
424
	  translation = TransFM;
425
	}
426
427
      else if (!strcmp(argv[formula_index], "-fr1"))
	{
428
	  translation = TransFM;
429
430
431
432
	  fm_red |= spot::ltl::Reduce_Basics;
	}
      else if (!strcmp(argv[formula_index], "-fr2"))
	{
433
	  translation = TransFM;
434
435
436
437
	  fm_red |= spot::ltl::Reduce_Eventuality_And_Universality;
	}
      else if (!strcmp(argv[formula_index], "-fr3"))
	{
438
	  translation = TransFM;
439
440
441
	  fm_red |= spot::ltl::Reduce_Syntactic_Implications;
	}
      else if (!strcmp(argv[formula_index], "-fr4"))
442
	{
443
	  translation = TransFM;
444
445
446
447
448
449
 	  fm_red |= spot::ltl::Reduce_Basics
	    | spot::ltl::Reduce_Eventuality_And_Universality
	    | spot::ltl::Reduce_Syntactic_Implications;
	}
      else if (!strcmp(argv[formula_index], "-fr5"))
	{
450
	  translation = TransFM;
451
452
453
454
	  fm_red |= spot::ltl::Reduce_Containment_Checks;
	}
      else if (!strcmp(argv[formula_index], "-fr6"))
	{
455
	  translation = TransFM;
456
457
458
	  fm_red |= spot::ltl::Reduce_Containment_Checks_Stronger;
	}
      else if (!strcmp(argv[formula_index], "-fr7"))
459
	{
460
	  translation = TransFM;
461
462
	  fm_red |= spot::ltl::Reduce_All;
	}
463
464
465
466
      else if (!strcmp(argv[formula_index], "-F"))
	{
	  file_opt = true;
	}
467
468
469
470
      else if (!strcmp(argv[formula_index], "-FC"))
	{
	  show_fc = true;
	}
471
472
      else if (!strcmp(argv[formula_index], "-g"))
	{
473
	  accepting_run = true;
474
475
	  graph_run_opt = true;
	}
476
477
      else if (!strcmp(argv[formula_index], "-G"))
	{
478
	  accepting_run = true;
479
480
	  graph_run_tgba_opt = true;
	}
481
482
483
484
      else if (!strcmp(argv[formula_index], "-k"))
	{
	  output = 9;
	}
485
486
487
488
      else if (!strcmp(argv[formula_index], "-ks"))
	{
	  output = 12;
	}
489
490
491
492
      else if (!strcmp(argv[formula_index], "-K"))
	{
	  output = 10;
	}
493
494
495
496
      else if (!strcmp(argv[formula_index], "-KV"))
	{
	  output = 11;
	}
497
498
499
500
      else if (!strcmp(argv[formula_index], "-l"))
	{
	  translation = TransLaCIM;
	}
501
502
503
504
505
506
507
508
509
510
      else if (!strcmp(argv[formula_index], "-le"))
	{
	  /* -lo is documented to imply -le, so do not overwrite it. */
	  if (translation != TransLaCIM_ELTL_ops)
	    translation = TransLaCIM_ELTL;
	}
      else if (!strcmp(argv[formula_index], "-lo"))
	{
	  translation = TransLaCIM_ELTL_ops;
	}
511
512
513
      else if (!strcmp(argv[formula_index], "-L"))
	{
	  fair_loop_approx = true;
514
	  translation = TransFM;
515
	}
516
517
518
519
      else if (!strcmp(argv[formula_index], "-lS"))
	{
	  labeling_opt = StateLabeled;
	}
520
521
      else if (!strcmp(argv[formula_index], "-m"))
	{
522
	  opt_reduce = true;
523
	}
martinez's avatar
martinez committed
524
525
      else if (!strcmp(argv[formula_index], "-N"))
	{
526
	  degeneralize_opt = DegenSBA;
martinez's avatar
martinez committed
527
528
	  output = 8;
	}
529
530
531
532
533
534
      else if (!strcmp(argv[formula_index], "-NN"))
	{
	  degeneralize_opt = DegenSBA;
	  output = 8;
	  spin_comments = true;
	}
535
536
537
538
      else if (!strcmp(argv[formula_index], "-O"))
	{
	  output = 13;
	}
539
540
541
      else if (!strcmp(argv[formula_index], "-p"))
	{
	  post_branching = true;
542
	  translation = TransFM;
543
	}
544
545
      else if (!strncmp(argv[formula_index], "-P", 2))
	{
546
547
	  tm.start("reading -P's argument");

548
549
	  spot::tgba_parse_error_list pel;
	  system = spot::tgba_parse(argv[formula_index] + 2,
550
				    pel, dict, env, env, debug_opt);
551
552
	  if (spot::format_tgba_parse_errors(std::cerr,
					     argv[formula_index] + 2, pel))
553
554
	    return 2;
	  system->merge_transitions();
555

556
	  tm.stop("reading -P's argument");
557
	}
558
559
      else if (!strcmp(argv[formula_index], "-r"))
	{
560
561
	  output = 1;
	}
562
563
564
565
566
567
      else if (!strcmp(argv[formula_index], "-r1"))
	{
	  redopt |= spot::ltl::Reduce_Basics;
	}
      else if (!strcmp(argv[formula_index], "-r2"))
	{
568
	  redopt |= spot::ltl::Reduce_Eventuality_And_Universality;
569
570
571
	}
      else if (!strcmp(argv[formula_index], "-r3"))
	{
572
	  redopt |= spot::ltl::Reduce_Syntactic_Implications;
573
574
575
	}
      else if (!strcmp(argv[formula_index], "-r4"))
	{
576
577
578
 	  redopt |= spot::ltl::Reduce_Basics
	    | spot::ltl::Reduce_Eventuality_And_Universality
	    | spot::ltl::Reduce_Syntactic_Implications;
579
	}
580
581
      else if (!strcmp(argv[formula_index], "-r5"))
	{
582
	  redopt |= spot::ltl::Reduce_Containment_Checks;
583
584
585
	}
      else if (!strcmp(argv[formula_index], "-r6"))
	{
586
	  redopt |= spot::ltl::Reduce_Containment_Checks_Stronger;
587
588
589
590
591
	}
      else if (!strcmp(argv[formula_index], "-r7"))
	{
	  redopt |= spot::ltl::Reduce_All;
	}
592
593
594
      else if (!strcmp(argv[formula_index], "-R"))
	{
	  output = 3;
595
	}
martinez's avatar
martinez committed
596
597
598
599
600
601
602
603
604
      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"))
605
	{
martinez's avatar
martinez committed
606
	  reduc_aut |= spot::Reduce_quotient_Del_Sim;
607
	}
martinez's avatar
martinez committed
608
      else if (!strcmp(argv[formula_index], "-R2t"))
609
	{
martinez's avatar
martinez committed
610
	  reduc_aut |= spot::Reduce_transition_Del_Sim;
611
612
613
614
615
	}
      else if (!strcmp(argv[formula_index], "-R3"))
	{
	  reduc_aut |= spot::Reduce_Scc;
	}
616
617
618
619
620
      else if (!strcmp(argv[formula_index], "-R3f"))
	{
	  reduc_aut |= spot::Reduce_Scc;
	  scc_filter_all = true;
	}
621
622
      else if (!strcmp(argv[formula_index], "-R3b"))
	{
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
623
	  symbolic_scc_pruning = true;
624
	}
625
626
627
628
629
630
631
632
633
634
635
636
      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;
	}
Felix Abecassis's avatar
Felix Abecassis committed
637
638
639
640
      else if (!strcmp(argv[formula_index], "-Rm"))
        {
          opt_minimize = true;
        }
641
642
643
644
      else if (!strcmp(argv[formula_index], "-M"))
        {
          opt_monitor = true;
        }
645
646
647
648
649
650
651
652
      else if (!strcmp(argv[formula_index], "-s"))
	{
	  dupexp = DFS;
	}
      else if (!strcmp(argv[formula_index], "-S"))
	{
	  dupexp = BFS;
	}
653
654
655
656
      else if (!strcmp(argv[formula_index], "-t"))
	{
	  output = 6;
	}
657
658
659
660
      else if (!strcmp(argv[formula_index], "-T"))
	{
	  use_timer = true;
	}
661
662
663
664
      else if (!strcmp(argv[formula_index], "-taa"))
	{
	  translation = TransTAA;
	}
665
666
667
      else if (!strncmp(argv[formula_index], "-U", 2))
	{
	  unobservables = new spot::ltl::atomic_prop_set;
668
	  translation = TransFM;
669
	  // Parse -U's argument.
670
	  const char* tok = strtok(argv[formula_index] + 2, ", \t;");
671
672
673
674
	  while (tok)
	    {
	      unobservables->insert
		(static_cast<spot::ltl::atomic_prop*>(env.require(tok)));
675
	      tok = strtok(0, ", \t;");
676
677
	    }
	}
678
679
680
681
      else if (!strcmp(argv[formula_index], "-v"))
	{
	  output = 5;
	}
682
683
      else if (!strcmp(argv[formula_index], "-x"))
	{
684
	  translation = TransFM;
685
686
	  fm_exprop_opt = true;
	}
687
688
689
690
      else if (!strcmp(argv[formula_index], "-X"))
	{
	  from_file = true;
	}
691
692
693
694
695
      else if (!strcmp(argv[formula_index], "-XN"))
	{
	  from_file = true;
	  read_neverclaim = true;
	}
696
697
      else if (!strcmp(argv[formula_index], "-y"))
	{
698
	  translation = TransFM;
699
700
	  fm_symb_merge_opt = false;
	}
701
702
703
704
      else
	{
	  break;
	}
705
706
    }

707
  if ((graph_run_opt || graph_run_tgba_opt)
708
      && (!echeck_inst || !expect_counter_example))
709
    {
710
      std::cerr << argv[0] << ": error: -g and -G require -e." << std::endl;
711
712
713
      exit(1);
    }

714
715
716
717
  std::string input;

  if (file_opt)
    {
718
      tm.start("reading formula");
719
      if (strcmp(argv[formula_index], "-"))
720
	{
721
	  std::ifstream fin(argv[formula_index]);
722
	  if (!fin)
723
724
725
726
	    {
	      std::cerr << "Cannot open " << argv[formula_index] << std::endl;
	      exit(2);
	    }
727

728
	  if (!std::getline(fin, input, '\0'))
729
730
731
732
733
734
	    {
	      std::cerr << "Cannot read " << argv[formula_index] << std::endl;
	      exit(2);
	    }
	}
      else
735
	{
736
	  std::getline(std::cin, input, '\0');
737
	}
738
      tm.stop("reading formula");
739
740
741
742
743
744
    }
  else
    {
      input = argv[formula_index];
    }

745
  spot::ltl::formula* f = 0;
746
  if (!from_file) // Reading a formula, not reading an automaton from a file.
747
    {
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
775
776
777
778
779
780
781
782
783
784
785
786
787
788
      switch (translation)
	{
	case TransFM:
	case TransLaCIM:
	case TransTAA:
	  {
	    spot::ltl::parse_error_list pel;
	    tm.start("parsing formula");
	    f = spot::ltl::parse(input, pel, env, debug_opt);
	    tm.stop("parsing formula");
	    exit_code = spot::ltl::format_parse_errors(std::cerr, input, pel);
	  }
	  break;
	case TransLaCIM_ELTL:
	  {
	    spot::eltl::parse_error_list p;
	    tm.start("parsing formula");
	    f = spot::eltl::parse_string(input, p, env, false);
	    tm.stop("parsing formula");
	    exit_code = spot::eltl::format_parse_errors(std::cerr, p);
	  }
	  break;
	case TransLaCIM_ELTL_ops:
	  {
	    // Call the LTL parser first to handle operators such as
	    // [] or <> and rewrite the output as a string with G or F.
	    // Then prepend definitions of usual LTL operators, and parse
	    // the result again as an ELTL formula.
	    spot::ltl::parse_error_list pel;
	    tm.start("parsing formula");
	    f = spot::ltl::parse(input, pel, env, debug_opt);
	    input = ltl_defs();
	    input += "%";
	    input += spot::ltl::to_string(f, true);
	    f->destroy();
	    spot::eltl::parse_error_list p;
	    f = spot::eltl::parse_string(input, p, env, debug_opt);
	    tm.stop("parsing formula");
	    exit_code = spot::eltl::format_parse_errors(std::cerr, p);
	  }
	  break;
789
	}
790
791
    }
  if (f || from_file)
792
    {
793
794
795
796
      spot::tgba_bdd_concrete* concrete = 0;
      spot::tgba* to_free = 0;
      spot::tgba* a = 0;

797
798
      if (from_file)
	{
799
	  spot::tgba_explicit_string* e;
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
	  if (!read_neverclaim)
	    {
	      spot::tgba_parse_error_list pel;
	      tm.start("parsing automaton");
	      to_free = a = e = spot::tgba_parse(input, pel, dict,
						 env, env, debug_opt);
	      tm.stop("parsing automaton");
	      if (spot::format_tgba_parse_errors(std::cerr, input, pel))
		{
		  delete to_free;
		  delete dict;
		  return 2;
		}
	    }
	  else
815
	    {
816
	      spot::neverclaim_parse_error_list pel;
817
	      tm.start("parsing neverclaim");
818
819
	      to_free = a = e = spot::neverclaim_parse(input, pel, dict,
						       env, debug_opt);
820
	      tm.stop("parsing neverclaim");
821
822
823
824
825
	      if (spot::format_neverclaim_parse_errors(std::cerr, input, pel))
		{
		  delete to_free;
		  delete dict;
		  return 2;
826
		}
827
	    }
828
	  e->merge_transitions();
829
	}
830
      else
831
	{
832
	  if (redopt != spot::ltl::Reduce_None)
833
	    {
834
	      tm.start("reducing formula");
835
	      spot::ltl::formula* t = spot::ltl::reduce(f, redopt);
836
	      f->destroy();
837
	      tm.stop("reducing formula");
838
	      f = t;
839
840
	      if (display_reduce_form)
		std::cout << spot::ltl::to_string(f) << std::endl;
841
	    }
842

843
	  tm.start("translating formula");
844
845
846
847
848
849
850
851
	  switch (translation)
	    {
	    case TransFM:
	      a = spot::ltl_to_tgba_fm(f, dict, fm_exprop_opt,
				       fm_symb_merge_opt,
				       post_branching,
				       fair_loop_approx,
				       unobservables,
852
				       fm_red);
853
854
855
856
857
	      break;
	    case TransTAA:
	      a = spot::ltl_to_taa(f, dict, containment);
	      break;
	    case TransLaCIM:
858
859
860
861
862
	      a = concrete = spot::ltl_to_tgba_lacim(f, dict);
	      break;
	    case TransLaCIM_ELTL:
	    case TransLaCIM_ELTL_ops:
	      a = concrete = spot::eltl_to_tgba_lacim(f, dict);
863
864
	      break;
	    }
865
	  tm.stop("translating formula");
866
	  to_free = a;
867
	}
868

869
870
871
872
873
874
875
876
      if (opt_monitor && ((reduc_aut & spot::Reduce_Scc) == 0))
	{
	  if (dynamic_cast<spot::tgba_bdd_concrete*>(a))
	    symbolic_scc_pruning = true;
	  else
	    reduc_aut |= spot::Reduce_Scc;
	}

Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
      if (symbolic_scc_pruning)
        {
	  spot::tgba_bdd_concrete* bc =
	    dynamic_cast<spot::tgba_bdd_concrete*>(a);
	  if (!bc)
	    {
	      std::cerr << ("Error: Automaton is not symbolic: cannot "
			    "prune SCCs symbolically.\n"
			    "       Try -R3 instead of -R3b, or use "
			    "another translation.")
			<< std::endl;
	      exit(2);
	    }
	  else
	    {
	      tm.start("reducing A_f w/ symbolic SCC pruning");
	      if (bc)
		bc->delete_unaccepting_scc();
	      tm.stop("reducing A_f w/ symbolic SCC pruning");
	    }
	}

899
900
901
902
903
904
      // Remove dead SCCs and useless acceptance conditions before
      // degeneralization.
      spot::tgba* aut_scc = 0;
      if (reduc_aut & spot::Reduce_Scc)
	{
	  tm.start("reducing A_f w/ SCC");
905
	  a = aut_scc = spot::scc_filter(a, scc_filter_all);
906
907
908
	  tm.stop("reducing A_f w/ SCC");
	}

909
      spot::tgba_tba_proxy* degeneralized = 0;
910
      spot::tgba_sgba_proxy* state_labeled = 0;
911

912
913
      unsigned int n_acc = a->number_of_acceptance_conditions();
      if (echeck_inst
914
	  && degeneralize_opt == NoDegen
915
916
	  && n_acc > 1
	  && echeck_inst->max_acceptance_conditions() < n_acc)
917
918
	degeneralize_opt = DegenTBA;
      if (degeneralize_opt == DegenTBA)
919
	a = degeneralized = new spot::tgba_tba_proxy(a);
920
921
      else if (degeneralize_opt == DegenSBA)
	a = degeneralized = new spot::tgba_sba_proxy(a);
922
923
924
925
      else if (labeling_opt == StateLabeled)
      {
        a = state_labeled = new spot::tgba_sgba_proxy(a);
      }
926

Felix Abecassis's avatar
Felix Abecassis committed
927
928
      spot::tgba_explicit* minimized = 0;
      if (opt_minimize)
929
930
931
932
933
934
935
936
937
938
939
940
941
	{
	  tm.start("WDBA-minimization");
	  minimized = minimize(a);
	  tm.stop("WDBA-minimization");
	  tm.start("WDBA-check");
	  // If A is a safety automaton, the WDBA minimization
	  // must be correct.
	  if (is_safety_automaton(a))
	    {
	      a = minimized;
	    }
	  else // We don't know if A is a safety automaton.
	    {
942
943
944
945
946
947
948
949
950
	      if (!f)
		{
		  std::cerr << "Error: Without a formula I cannot make "
			    << "sure that the automaton built with -Rm\n"
			    << "       is correct." << std::endl;
		  exit(2);
		}
	      // Let's make sure that A recognizes the same language
	      // as MINIMIZED.
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
	      spot::ltl::formula* neg =
		spot::ltl::unop::instance(spot::ltl::unop::Not, f->clone());
	      spot::tgba* n = spot::ltl_to_tgba_fm(neg, dict, fm_exprop_opt,
						   fm_symb_merge_opt,
						   post_branching,
						   fair_loop_approx,
						   unobservables, fm_red);
	      neg->destroy();
	      spot::tgba* nscc = spot::scc_filter(n, true);
	      // If the negation is a safety automaton,
	      // then the minimization is correct.
	      if (is_safety_automaton(n))
		{
		  a = minimized;
		}
	      else
		{
		  spot::tgba* p = new spot::tgba_product(minimized, nscc);
		  spot::emptiness_check* ec = couvreur99(p);
		  spot::emptiness_check_result* res = ec->check();
		  if (!res)
		    {
		      delete ec;
		      delete p;
		      spot::tgba* nm = minimize(nscc);
		      p = new spot::tgba_product(a, nm);
		      ec = couvreur99(p);
		      res = ec->check();
		      if (!res)
			{
			  // Finally, we are now sure that it was safe
			  // to minimize the automaton.
			  a = minimized;
			}
		      delete nm;
		    }
		  delete res;
		  delete ec;
		  delete p;
		}
	      delete nscc;
	      delete n;
	    }
	  tm.stop("WDBA-check");
	}
Felix Abecassis's avatar
Felix Abecassis committed
996

997
998
999
1000
1001
1002
1003
      if (opt_monitor)
	{
	  tm.start("Monitor minimization");
	  a = minimized = minimize(a, true);
	  tm.stop("Monitor minimization");
	}

1004
1005
1006
      spot::tgba_reduc* aut_red = 0;
      if (reduc_aut != spot::Reduce_None)
	{
1007
	  if (reduc_aut & ~spot::Reduce_Scc)
1008
	    {
1009
	      tm.start("reducing A_f w/ sim.");
1010
	      a = aut_red = new spot::tgba_reduc(a);
martinez's avatar
martinez committed
1011
1012

	      if (reduc_aut & (spot::Reduce_quotient_Dir_Sim |
1013
1014
1015
			       spot::Reduce_transition_Dir_Sim |
			       spot::Reduce_quotient_Del_Sim |
			       spot::Reduce_transition_Del_Sim))
1016
		{
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
		  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))
		    {
		      rel_dir =
			spot::get_direct_relation_simulation
			  (a, std::cout, display_parity_game);
		      assert(rel_dir);
		    }
		  if (reduc_aut & (spot::Reduce_quotient_Del_Sim |
					spot::Reduce_transition_Del_Sim))
		    {
		      rel_del =
			spot::get_delayed_relation_simulation
			  (a, std::cout, display_parity_game);
		      assert(rel_del);
		    }

		  if (display_rel_sim)
		    {
		      if (rel_dir)
			aut_red->display_rel_sim(rel_dir, std::cout);
		      if (rel_del)
			aut_red->display_rel_sim(rel_del, std::cout);
		    }

		  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);
1053

martinez's avatar
martinez committed
1054
		  if (rel_dir)
1055
		    spot::free_relation_simulation(rel_dir);
martinez's avatar
martinez committed
1056
		  if (rel_del)
1057
		    spot::free_relation_simulation(rel_del);
martinez's avatar
martinez committed
1058
		}
1059
	      tm.stop("reducing A_f w/ sim.");
1060
1061
1062
	    }
	}

1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
      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;
	}

1076
1077
      spot::tgba* product_degeneralized = 0;

1078
      if (system)
1079
1080
        {
          a = product = product_to_free = new spot::tgba_product(system, a);
1081
1082
1083
1084
1085
1086

	  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)
1087
1088
1089
1090
1091
1092
1093
1094
            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);
        }
1095

1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
      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);
	    }
	}