tgbaexplicit.hh 3.83 KB
Newer Older
1
2
3
#ifndef SPOT_TGBA_TGBAEXPLICIT_HH
# define SPOT_TGBA_TGBAEXPLICIT_HH

4
#include "misc/hash.hh"
5
6
7
8
9
10
11
12
13
14
15
#include <list>
#include "tgba.hh"
#include "ltlast/formula.hh"

namespace spot
{
  // Forward declarations.  See below.
  class state_explicit;
  class tgba_explicit_succ_iterator;

  /// Explicit representation of a spot::tgba.
16
  class tgba_explicit: public tgba
17
18
  {
  public:
19
    tgba_explicit(bdd_dict* dict);
20
21
22

    struct transition;
    typedef std::list<transition*> state;
23
24

    /// Explicit transitions (used by spot::tgba_explicit).
25
26
27
    struct transition
    {
      bdd condition;
28
      bdd accepting_conditions;
29
30
31
      state* dest;
    };

32
33
    void set_init_state(const std::string& state);

34
35
36
37
    transition*
    create_transition(const std::string& source, const std::string& dest);

    void add_condition(transition* t, ltl::formula* f);
38
    void add_neg_condition(transition* t, ltl::formula* f);
39
40
    /// This assumes that all variables in \a f are known from dict.
    void add_conditions(transition* t, bdd f);
41
42
43
    void declare_accepting_condition(ltl::formula* f);
    bool has_accepting_condition(ltl::formula* f) const;
    void add_accepting_condition(transition* t, ltl::formula* f);
44
45
    /// This assumes that all accepting conditions in \a f are known from dict.
    void add_accepting_conditions(transition* t, bdd f);
46
    void complement_all_accepting_conditions();
47
48
49
50
51

    // tgba interface
    virtual ~tgba_explicit();
    virtual spot::state* get_init_state() const;
    virtual tgba_succ_iterator*
52
53
54
    succ_iter(const spot::state* local_state,
	      const spot::state* global_state = 0,
	      const tgba* global_automaton = 0) const;
55
    virtual bdd_dict* get_dict() const;
56
57
    virtual std::string format_state(const spot::state* state) const;

58
59
60
    virtual bdd all_accepting_conditions() const;
    virtual bdd neg_accepting_conditions() const;

61
  protected:
62
63
64
    virtual bdd compute_support_conditions(const spot::state* state) const;
    virtual bdd compute_support_variables(const spot::state* state) const;

65
    state* add_state(const std::string& name);
66
67
    bdd get_condition(ltl::formula* f);
    bdd get_accepting_condition(ltl::formula* f);
68

69
70
71
72
    typedef Sgi::hash_map<const std::string, tgba_explicit::state*,
			  string_hash> ns_map;
    typedef Sgi::hash_map<const tgba_explicit::state*, std::string,
			  ptr_hash<tgba_explicit::state> > sn_map;
73
74
    ns_map name_state_map_;
    sn_map state_name_map_;
75
    bdd_dict* dict_;
76
    tgba_explicit::state* init_;
77
78
79
    mutable bdd all_accepting_conditions_;
    bdd neg_accepting_conditions_;
    mutable bool all_accepting_conditions_computed_;
80
81
82
83
84

  private:
    // Disallow copy.
    tgba_explicit(const tgba_explicit& other);
    tgba_explicit& tgba_explicit::operator=(const tgba_explicit& other);
85
86
87
  };


88
  /// States used by spot::tgba_explicit.
89
90
91
92
93
94
95
96
97
  class state_explicit : public spot::state
  {
  public:
    state_explicit(const tgba_explicit::state* s)
      : state_(s)
    {
    }

    virtual int compare(const spot::state* other) const;
98
    virtual size_t hash() const;
99
100
    virtual state_explicit* clone() const;

101
102
103
104
105
106
107
108
109
110
    virtual ~state_explicit()
    {
    }

    const tgba_explicit::state* get_state() const;
  private:
    const tgba_explicit::state* state_;
  };


111
  /// Successor iterators used by spot::tgba_explicit.
112
  class tgba_explicit_succ_iterator: public tgba_succ_iterator
113
114
  {
  public:
115
    tgba_explicit_succ_iterator(const tgba_explicit::state* s, bdd all_acc);
116
117
118
119
120
121
122
123

    virtual
    ~tgba_explicit_succ_iterator()
    {
    }

    virtual void first();
    virtual void next();
124
    virtual bool done() const;
125

126
127
128
    virtual state_explicit* current_state() const;
    virtual bdd current_condition() const;
    virtual bdd current_accepting_conditions() const;
129
130
131
132

  private:
    const tgba_explicit::state* s_;
    tgba_explicit::state::const_iterator i_;
133
    bdd all_accepting_conditions_;
134
135
136
137
138
  };

}

#endif // SPOT_TGBA_TGBAEXPLICIT_HH