tgbaexplicit.hh 18.5 KB
Newer Older
Pierre PARUTTO's avatar
Pierre PARUTTO committed
1
2
3
4
5
6
// -*- encoding: utf-8 -*-
// Copyright (C) 2009, 2010, 2011, 2012 Laboratoire de Recherche et
// Développement de l'Epita.
// Copyright (C) 2003, 2004, 2006 Laboratoire d'Informatique de Paris
// 6 (LIP6), département Systèmes Répartis Coopératifs (SRC),
// Université Pierre et Marie Curie.
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//
// 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.

25
26
27
#ifndef SPOT_TGBA_TGBAEXPLICIT_HH
# define SPOT_TGBA_TGBAEXPLICIT_HH

Pierre PARUTTO's avatar
Pierre PARUTTO committed
28
#include <sstream>
29
#include <list>
Pierre PARUTTO's avatar
Pierre PARUTTO committed
30

31
#include "tgba.hh"
Pierre PARUTTO's avatar
Pierre PARUTTO committed
32
33
34
#include "tgba/formula2bdd.hh"
#include "misc/hash.hh"
#include "misc/bddop.hh"
35
#include "ltlast/formula.hh"
Pierre PARUTTO's avatar
Pierre PARUTTO committed
36
#include "ltlvisit/tostring.hh"
37
38
39

namespace spot
{
Pierre PARUTTO's avatar
Pierre PARUTTO committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  ///misc
  template<typename T>
  struct destroy_key
  {
    void destroy(T t)
    {
      (void) t;
    }
  };

  template<>
  struct destroy_key<const ltl::formula*>
  {
    void destroy(const ltl::formula* t)
    {
      t->destroy();
    }
  };
58

59
  class sba: public tgba
Pierre PARUTTO's avatar
Pierre PARUTTO committed
60
61
  {
  public:
62
    /// A State in an SBA (State-based Buchi Automaton) is accepting
Pierre PARUTTO's avatar
Pierre PARUTTO committed
63
    /// iff all outgoing transitions are accepting.
64
    virtual bool is_accepting(const spot::state* s) const = 0;
Pierre PARUTTO's avatar
Pierre PARUTTO committed
65
66
67
  };

  /// States used by spot::explicit_graph implementation
68
  /// \ingroup tgba_representation
Pierre PARUTTO's avatar
Pierre PARUTTO committed
69
  template<typename Label, typename label_hash>
70
  class state_explicit: public spot::state
71
72
  {
  public:
73
74
75
76
    state_explicit()
    {
    }

Pierre PARUTTO's avatar
Pierre PARUTTO committed
77
78
    state_explicit(const Label& l):
      label_(l)
79
80
81
    {
    }

Pierre PARUTTO's avatar
Pierre PARUTTO committed
82
    virtual ~state_explicit()
83
84
    {
    }
85

86
87
88
    void destroy() const
    {
    }
89

Pierre PARUTTO's avatar
Pierre PARUTTO committed
90
91
92
    typedef Label Label_t;
    typedef label_hash label_hash_t;

93
94
95
    struct transition
    {
      bdd condition;
96
      bdd acceptance_conditions;
Pierre PARUTTO's avatar
Pierre PARUTTO committed
97
      const state_explicit<Label, label_hash>* dest;
98
99
    };

100
101
102
    typedef std::list<transition> transitions_t;
    transitions_t successors;

Pierre PARUTTO's avatar
Pierre PARUTTO committed
103
    const Label& label() const
104
    {
Pierre PARUTTO's avatar
Pierre PARUTTO committed
105
      return label_;
106
107
    }

Pierre PARUTTO's avatar
Pierre PARUTTO committed
108
109
110
111
    bool empty() const
    {
      return successors.empty();
    }
112

Pierre PARUTTO's avatar
Pierre PARUTTO committed
113
114
115
116
117
118
119
120
121
122
123
124
125
    virtual int compare(const state* other) const
    {
      const state_explicit<Label, label_hash>* s =
	down_cast<const state_explicit<Label, label_hash>*>(other);
      assert (s);

      // Do not simply return "o - this", it might not fit in an int.
      if (s < this)
	return -1;
      if (s > this)
	return 1;
      return 0;
    }
126

Pierre PARUTTO's avatar
Pierre PARUTTO committed
127
128
129
130
131
    virtual size_t hash() const
    {
      return
	reinterpret_cast<const char*>(this) - static_cast<const char*>(0);
    }
132

Pierre PARUTTO's avatar
Pierre PARUTTO committed
133
134
135
136
137
    virtual state_explicit<Label, label_hash>*
    clone() const
    {
      return const_cast<state_explicit<Label, label_hash>*>(this);
    }
138

Pierre PARUTTO's avatar
Pierre PARUTTO committed
139
140
141
  protected:
    Label label_;
  };
142

Pierre PARUTTO's avatar
Pierre PARUTTO committed
143
144
145
146
147
148
149
150
151
152
  ///states labeled by an int
  /// \ingroup tgba_representation
  class state_explicit_number:
    public state_explicit<int, identity_hash<int> >
  {
  public:
    state_explicit_number()
      : state_explicit<int, identity_hash<int> >()
    {
    }
153

Pierre PARUTTO's avatar
Pierre PARUTTO committed
154
155
156
157
    state_explicit_number(int label)
      : state_explicit<int, identity_hash<int> >(label)
    {
    }
158

Pierre PARUTTO's avatar
Pierre PARUTTO committed
159
160
161
    virtual void destroy()
    {
    }
162

Pierre PARUTTO's avatar
Pierre PARUTTO committed
163
164
165
166
167
168
169
170
    static const int default_val;
    static std::string to_string(int l)
    {
      std::stringstream ss;
      ss << l;
      return ss.str();
    }
  };
171

Pierre PARUTTO's avatar
Pierre PARUTTO committed
172
173
174
175
176
177
178
179
180
181
  /// States labeled by a string
  /// \ingroup tgba_representation
  class state_explicit_string:
    public state_explicit<std::string, string_hash>
  {
  public:
    state_explicit_string():
      state_explicit<std::string, string_hash>()
    {
    }
182

Pierre PARUTTO's avatar
Pierre PARUTTO committed
183
184
185
186
    state_explicit_string(const std::string& label)
      : state_explicit<std::string, string_hash>(label)
    {
    }
187

Pierre PARUTTO's avatar
Pierre PARUTTO committed
188
189
190
    virtual void destroy()
    {
    }
191

Pierre PARUTTO's avatar
Pierre PARUTTO committed
192
193
194
195
196
197
    static const std::string default_val;
    static std::string to_string(const std::string& l)
    {
      return l;
    }
  };
198

Pierre PARUTTO's avatar
Pierre PARUTTO committed
199
200
201
202
203
204
205
206
207
208
  /// States labeled by a formula
  /// \ingroup tgba_representation
  class state_explicit_formula:
    public state_explicit<const ltl::formula*, ltl::formula_ptr_hash>
  {
  public:
    state_explicit_formula():
      state_explicit<const ltl::formula*, ltl::formula_ptr_hash>()
    {
    }
209

Pierre PARUTTO's avatar
Pierre PARUTTO committed
210
211
212
213
    state_explicit_formula(const ltl::formula* label)
      : state_explicit<const ltl::formula*, ltl::formula_ptr_hash>(label)
    {
    }
214

Pierre PARUTTO's avatar
Pierre PARUTTO committed
215
216
217
    virtual void destroy()
    {
    }
218

Pierre PARUTTO's avatar
Pierre PARUTTO committed
219
220
221
222
223
224
    static const ltl::formula* default_val;
    static std::string to_string(const ltl::formula* l)
    {
      return ltl::to_string(l);
    }
  };
225

226
  /// Successor iterators used by spot::tgba_explicit.
227
  /// \ingroup tgba_representation
Pierre PARUTTO's avatar
Pierre PARUTTO committed
228
  template<typename State>
229
  class tgba_explicit_succ_iterator: public tgba_succ_iterator
230
231
  {
  public:
Pierre PARUTTO's avatar
Pierre PARUTTO committed
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
    tgba_explicit_succ_iterator(const State* start,
				bdd all_acc)
      : start_(start),
	all_acceptance_conditions_(all_acc)
    {
    }

    virtual void first()
    {
      it_ = start_->successors.begin();
    }

    virtual void next()
    {
      ++it_;
    }
248

Pierre PARUTTO's avatar
Pierre PARUTTO committed
249
250
251
252
    virtual bool done() const
    {
      return it_ == start_->successors.end();
    }
253

Pierre PARUTTO's avatar
Pierre PARUTTO committed
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
    virtual State* current_state() const
    {
      assert(!done());

      //ugly but I can't see any other wayout
      const State* res = down_cast<const State*>(it_->dest);
      assert(res);

      return
	const_cast<State*>(res);
    }

    virtual bdd current_condition() const
    {
      assert(!done());
      return it_->condition;
    }

    virtual bdd current_acceptance_conditions() const
    {
      assert(!done());
275
      return it_->acceptance_conditions;
Pierre PARUTTO's avatar
Pierre PARUTTO committed
276
    }
277

278
279
280
281
282
283
    typename State::transitions_t::const_iterator
    get_iterator() const
    {
      return it_;
    }

284
  private:
Pierre PARUTTO's avatar
Pierre PARUTTO committed
285
286
    const State* start_;
    typename State::transitions_t::const_iterator it_;
287
    bdd all_acceptance_conditions_;
288
289
  };

Pierre PARUTTO's avatar
Pierre PARUTTO committed
290
291
292
293
  /// Graph implementation for automata representation
  /// \ingroup tgba_representation
  template<typename State, typename Type>
  class explicit_graph: public Type
294
295
  {
  protected:
Pierre PARUTTO's avatar
Pierre PARUTTO committed
296
297
298
299
300
    typedef Sgi::hash_map<typename State::Label_t, State,
			  typename State::label_hash_t> ls_map;
    typedef Sgi::hash_map<const State*, typename State::Label_t,
			  ptr_hash<State> > sl_map;

301
  public:
302
303
    typedef typename State::transition transition;

Pierre PARUTTO's avatar
Pierre PARUTTO committed
304
305
306
307
    explicit_graph(bdd_dict* dict)
      : ls_(),
	sl_(),
	init_(0),
308
309
310
311
	dict_(dict),
	all_acceptance_conditions_(bddfalse),
	all_acceptance_conditions_computed_(false),
	neg_acceptance_conditions_(bddtrue)
Pierre PARUTTO's avatar
Pierre PARUTTO committed
312
313
    {
    }
314

Pierre PARUTTO's avatar
Pierre PARUTTO committed
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
    State* add_default_init()
    {
      return add_state(State::default_val);
    }

    transition*
    create_transition(State* source, const State* dest)
    {
      transition t;

      t.dest = dest;
      t.condition = bddtrue;
      t.acceptance_conditions = bddfalse;

      typename State::transitions_t::iterator i =
	source->successors.insert(source->successors.end(), t);

      return &*i;
    }

    transition*
    create_transition(const typename State::Label_t& source,
		      const typename State::Label_t& dest)
    {
      // It's important that the source be created before the
      // destination, so the first source encountered becomes the
      // default initial state.
      State* s = add_state(source);
      return create_transition(s, add_state(dest));
    }

    transition*
    get_transition(const tgba_explicit_succ_iterator<State>* si)
    {
349
      return const_cast<transition*>(&(*(si->get_iterator())));
Pierre PARUTTO's avatar
Pierre PARUTTO committed
350
351
352
353
354
355
356
357
358
359
    }

    void add_condition(transition* t, const ltl::formula* f)
    {
      t->condition &= formula_to_bdd(f, dict_, this);
      f->destroy();
    }

    /// This assumes that all variables in \a f are known from dict.
    void add_conditions(transition* t, bdd f)
360
    {
Pierre PARUTTO's avatar
Pierre PARUTTO committed
361
362
      dict_->register_propositions(f, this);
      t->condition &= f;
363
364
    }

Pierre PARUTTO's avatar
Pierre PARUTTO committed
365
    bool has_acceptance_condition(const ltl::formula* f) const
366
    {
Pierre PARUTTO's avatar
Pierre PARUTTO committed
367
368
369
370
371
372
373
374
375
376
377
378
379
      return dict_->is_registered_acceptance_variable(f, this);
    }

    //old tgba explicit labelled interface
    bool has_state(const typename State::Label_t& name)
    {
      return ls_.find(name) != ls_.end();
    }

    const typename State::Label_t& get_label(const State* s) const
    {
      typename sl_map::const_iterator i = sl_.find(s);
      assert(i != sl_.end());
380
381
382
      return i->second;
    }

Pierre PARUTTO's avatar
Pierre PARUTTO committed
383
    const typename State::Label_t& get_label(const spot::state* s) const
384
    {
Pierre PARUTTO's avatar
Pierre PARUTTO committed
385
      const State* se = down_cast<const State*>(s);
386
      assert(se);
387
      return get_label(se);
388
389
    }

Pierre PARUTTO's avatar
Pierre PARUTTO committed
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
    transition*
    create_trainsition(const typename State::Label_t& source,
		       const typename State::Label_t& dest)
    {
      // It's important that the source be created before the
      // destination, so the first source encountered becomes the
      // default initial state.
      State* s = add_state(source);
      return create_transition(s, add_state(dest));
    }

    void
    complement_all_acceptance_conditions()
    {
      bdd all = this->all_acceptance_conditions();
      typename ls_map::iterator i;
      for (i = ls_.begin(); i != ls_.end(); ++i)
	{
	  typename State::transitions_t::iterator i2;
	  for (i2 = i->second.successors.begin();
	       i2 != i->second.successors.end(); ++i2)
	    i2->acceptance_conditions = all - i2->acceptance_conditions;
	}
    }

    void
    merge_transitions()
    {
      typename ls_map::iterator i;
      for (i = ls_.begin(); i != ls_.end(); ++i)
      {
	typename State::transitions_t::iterator t1;
	for (t1 = i->second.successors.begin();
	     t1 != i->second.successors.end(); ++t1)
	{
	  bdd acc = t1->acceptance_conditions;
	  const state_explicit<typename State::Label_t,
			       typename State::label_hash_t>* dest = t1->dest;

	  // Find another transition with the same destination and
	  // acceptance conditions.
	  typename State::transitions_t::iterator t2 = t1;
	  ++t2;
	  while (t2 != i->second.successors.end())
	  {
	    typename State::transitions_t::iterator t2copy = t2++;
	    if (t2copy->acceptance_conditions == acc && t2copy->dest == dest)
	    {
	      t1->condition |= t2copy->condition;
	      i->second.successors.erase(t2copy);
	    }
	  }
	}
      }
    }

446
    /// Return the state_explicit for \a name, creating the state if
447
    /// it does not exist.
Pierre PARUTTO's avatar
Pierre PARUTTO committed
448
    State* add_state(const typename State::Label_t& name)
449
    {
Pierre PARUTTO's avatar
Pierre PARUTTO committed
450
451
      typename ls_map::iterator i = ls_.find(name);
      if (i == ls_.end())
452
	{
Pierre PARUTTO's avatar
Pierre PARUTTO committed
453
454
455
	  State s(name);
	  ls_[name] = s;
	  sl_[&ls_[name]] = name;
456
457
458
459

	  // The first state we add is the inititial state.
	  // It can also be overridden with set_init_state().
	  if (!init_)
Pierre PARUTTO's avatar
Pierre PARUTTO committed
460
	    init_ = &ls_[name];
461

Pierre PARUTTO's avatar
Pierre PARUTTO committed
462
	  return &(ls_[name]);
463
	}
Pierre PARUTTO's avatar
Pierre PARUTTO committed
464
      return &(i->second);
465
    }
466

Pierre PARUTTO's avatar
Pierre PARUTTO committed
467
468
    State*
    set_init_state(const typename State::Label_t& state)
469
    {
Pierre PARUTTO's avatar
Pierre PARUTTO committed
470
      State* s = add_state(state);
471
472
473
474
      init_ = s;
      return s;
    }

Pierre PARUTTO's avatar
Pierre PARUTTO committed
475
476
477
478
    // tgba interface
    virtual ~explicit_graph()
    {
      typename ls_map::iterator i = ls_.begin();
479

Pierre PARUTTO's avatar
Pierre PARUTTO committed
480
481
482
483
484
485
486
487
488
489
490
491
      while (i != ls_.end())
      {
	typename State::Label_t s = i->first;

	// Do not erase the same state twice(Because of possible aliases).
	if (sl_.erase(&(i->second)))
	  i->second.destroy();

	++i;
	destroy_key<typename State::Label_t> dest;
	dest.destroy(s);
      }
492
493
494
495
496
497

      this->dict_->unregister_all_my_variables(this);
      // These have already been destroyed by subclasses.
      // Prevent destroying by tgba::~tgba.
      this->last_support_conditions_input_ = 0;
      this->last_support_variables_input_ = 0;
Pierre PARUTTO's avatar
Pierre PARUTTO committed
498
499
500
    }

    virtual State* get_init_state() const
501
    {
Pierre PARUTTO's avatar
Pierre PARUTTO committed
502
503
504
505
      if (!init_)
	const_cast<explicit_graph<State, Type>*>(this)->add_default_init();

      return init_;
506
507
    }

Pierre PARUTTO's avatar
Pierre PARUTTO committed
508
509
510
511
    virtual tgba_explicit_succ_iterator<State>*
    succ_iter(const spot::state* state,
	      const spot::state* global_state = 0,
	      const tgba* global_automaton = 0) const
512
    {
Pierre PARUTTO's avatar
Pierre PARUTTO committed
513
514
515
516
517
518
519
520
521
522
      const State* s = down_cast<const State*>(state);
      assert(s);

      (void) global_state;
      (void) global_automaton;

      return
	new tgba_explicit_succ_iterator<State>(s,
					       this
					       ->all_acceptance_conditions());
523
524
    }

Pierre PARUTTO's avatar
Pierre PARUTTO committed
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
    //no need?
    virtual std::string format_state(const spot::state* state) const
    {
      const State* se = down_cast<const State*>(state);
      assert(se);
      typename sl_map::const_iterator i = sl_.find(se);
      assert(i != sl_.end());
      return State::to_string(i->second);
    }

    /// old implementation in tgba_explicit_string
    /// Create an alias for a state.  Any reference to \a alias_name
    /// will act as a reference to \a real_name.
    void add_state_alias(const typename State::Label_t& alias,
			 const typename State::Label_t& real)
    {
      ls_[alias] = *(add_state(real));
    }


    /// \brief Copy the acceptance conditions of a tgba.
    ///
    /// If used, this function should be called before creating any
    /// transition.
    void copy_acceptance_conditions_of(const tgba *a)
    {
      assert(neg_acceptance_conditions_ == bddtrue);
      assert(all_acceptance_conditions_computed_ == false);
      bdd f = a->neg_acceptance_conditions();
      this->dict_->register_acceptance_variables(f, this);
      neg_acceptance_conditions_ = f;
    }

558
559

    /// Acceptance conditions handlingx
Pierre PARUTTO's avatar
Pierre PARUTTO committed
560
561
562
563
564
565
566
567
568
569
570
571
    void set_acceptance_conditions(bdd acc)
    {
      assert(neg_acceptance_conditions_ == bddtrue);
      assert(all_acceptance_conditions_computed_ == false);

      this->dict_->register_acceptance_variables(bdd_support(acc), this);
      neg_acceptance_conditions_ = compute_neg_acceptance_conditions(acc);
      all_acceptance_conditions_computed_ = true;
      all_acceptance_conditions_ = acc;
    }

    void add_acceptance_condition(transition* t, const ltl::formula* f)
572
    {
Pierre PARUTTO's avatar
Pierre PARUTTO committed
573
574
575
576
577
578
579
580
581
582
583
      bdd c = get_acceptance_condition(f);
      t->acceptance_conditions |= c;
    }

    /// This assumes that all acceptance conditions in \a f are known from
    /// dict.
    void add_acceptance_conditions(transition* t, bdd f)
    {
      bdd sup = bdd_support(f);
      this->dict_->register_acceptance_variables(sup, this);
      while (sup != bddtrue)
584
	{
Pierre PARUTTO's avatar
Pierre PARUTTO committed
585
586
	  neg_acceptance_conditions_ &= bdd_nithvar(bdd_var(sup));
	  sup = bdd_high(sup);
587
	}
Pierre PARUTTO's avatar
Pierre PARUTTO committed
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
      t->acceptance_conditions |= f;
    }

    virtual bdd all_acceptance_conditions() const
    {
      if (!all_acceptance_conditions_computed_)
      {
	all_acceptance_conditions_ =
	  compute_all_acceptance_conditions(neg_acceptance_conditions_);
	all_acceptance_conditions_computed_ = true;
      }
      return all_acceptance_conditions_;
    }

    virtual bdd_dict* get_dict() const
    {
      return this->dict_;
    }

    virtual bdd neg_acceptance_conditions() const
    {
      return neg_acceptance_conditions_;
610
611
612
613
614
    }

    void
    declare_acceptance_condition(const ltl::formula* f)
    {
Pierre PARUTTO's avatar
Pierre PARUTTO committed
615
      int v = this->dict_->register_acceptance_variable(f, this);
616
617
618
619
620
      f->destroy();
      bdd neg = bdd_nithvar(v);
      neg_acceptance_conditions_ &= neg;

      // Append neg to all acceptance conditions.
Pierre PARUTTO's avatar
Pierre PARUTTO committed
621
622
      typename explicit_graph<State, tgba>::ls_map::iterator i;
      for (i = this->ls_.begin(); i != this->ls_.end(); ++i)
623
	{
Pierre PARUTTO's avatar
Pierre PARUTTO committed
624
625
626
	  typename State::transitions_t::iterator i2;
	  for (i2 = i->second.successors.begin();
	       i2 != i->second.successors.end(); ++i2)
627
	    i2->acceptance_conditions &= neg;
628
629
630
631
632
	}

      all_acceptance_conditions_computed_ = false;
    }

Pierre PARUTTO's avatar
Pierre PARUTTO committed
633
  protected:
634

Pierre PARUTTO's avatar
Pierre PARUTTO committed
635
    bdd get_acceptance_condition(const ltl::formula* f)
636
    {
Pierre PARUTTO's avatar
Pierre PARUTTO committed
637
638
639
640
641
642
      bdd_dict::fv_map::iterator i = this->dict_->acc_map.find(f);
      assert(this->has_acceptance_condition(f));
      f->destroy();
      bdd v = bdd_ithvar(i->second);
      v &= bdd_exist(neg_acceptance_conditions_, v);
      return v;
643
644
    }

Pierre PARUTTO's avatar
Pierre PARUTTO committed
645
    virtual bdd compute_support_conditions(const spot::state* in) const
646
    {
Pierre PARUTTO's avatar
Pierre PARUTTO committed
647
648
649
      const State* s = down_cast<const State*>(in);
      assert(s);
      const typename State::transitions_t& st = s->successors;
650

Pierre PARUTTO's avatar
Pierre PARUTTO committed
651
      bdd res = bddfalse;
652

Pierre PARUTTO's avatar
Pierre PARUTTO committed
653
654
655
      typename State::transitions_t::const_iterator i;
      for (i = st.begin(); i != st.end(); ++i)
	res |= i->condition;
656

Pierre PARUTTO's avatar
Pierre PARUTTO committed
657
658
659
660
      return res;
    }

    virtual bdd compute_support_variables(const spot::state* in) const
661
    {
Pierre PARUTTO's avatar
Pierre PARUTTO committed
662
663
664
665
666
667
668
669
670
671
672
      const State* s = down_cast<const State*>(in);
      assert(s);
      const typename State::transitions_t& st = s->successors;

      bdd res = bddtrue;

      typename State::transitions_t::const_iterator i;
      for (i = st.begin(); i != st.end(); ++i)
	res &= bdd_support(i->condition);

      return res;
673
    }
674

675
676
677
678
679
680
    ls_map ls_;
    sl_map sl_;
    State* init_;

    bdd_dict* dict_;

Pierre PARUTTO's avatar
Pierre PARUTTO committed
681
682
683
    mutable bdd all_acceptance_conditions_;
    mutable bool all_acceptance_conditions_computed_;
    bdd neg_acceptance_conditions_;
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
  };

  template <typename State>
  class tgba_explicit: public explicit_graph<State, tgba>
  {
  public:
    typedef typename State::transition transition;
    typedef State state;

    tgba_explicit(bdd_dict* dict):
      explicit_graph<State,tgba>(dict)
    {
    }

    virtual ~tgba_explicit()
    {
    }
701

Pierre PARUTTO's avatar
Pierre PARUTTO committed
702
703
704
705
  private:
    // Disallow copy.
    tgba_explicit(const tgba_explicit<State>& other);
    tgba_explicit& operator=(const tgba_explicit& other);
706
  };
Pierre PARUTTO's avatar
Pierre PARUTTO committed
707

708
709
710
711
712
713
  template <typename State>
  class sba_explicit: public explicit_graph<State, sba>
  {
  public:
    typedef typename State::transition transition;
    typedef State state;
Pierre PARUTTO's avatar
Pierre PARUTTO committed
714

715
716
717
718
719
720
721
722
723
    sba_explicit(bdd_dict* dict):
      explicit_graph<State, sba>(dict)
    {
    }

    virtual ~sba_explicit()
    {
    }

724
725
    /// Assume that an accepting state has only accepting output transitions
    /// So we need only to check one to decide
726
727
728
    virtual bool is_accepting(const spot::state* s) const
    {
      tgba_explicit_succ_iterator<State>* it = this->succ_iter(s);
729
730
731
732
      it->first();

      // no transition
      if (it->done())
733
      {
734
735
	delete it;
	return false;
736
737
      }

738
      bool res = it->current_acceptance_conditions() != bddfalse;
739
740
      delete it;

741
      return res;
742
743
744
745
746
747
748
749
750
751
    }

  private:
    // Disallow copy.
    sba_explicit(const sba_explicit<State>& other);
    sba_explicit& operator=(const sba_explicit& other);
  };


  /// Typedefs for tgba
Pierre PARUTTO's avatar
Pierre PARUTTO committed
752
753
754
  typedef tgba_explicit<state_explicit_string> tgba_explicit_string;
  typedef tgba_explicit<state_explicit_formula> tgba_explicit_formula;
  typedef tgba_explicit<state_explicit_number> tgba_explicit_number;
755
756
757
758
759

  /// Typedefs for sba
  typedef sba_explicit<state_explicit_string> sba_explicit_string;
  typedef sba_explicit<state_explicit_formula> sba_explicit_formula;
  typedef sba_explicit<state_explicit_number> sba_explicit_number;
760
761
762
}

#endif // SPOT_TGBA_TGBAEXPLICIT_HH