tgbaexplicit.hh 5.13 KB
Newer Older
1
// Copyright (C) 2003, 2004  Laboratoire d'Informatique de Paris 6 (LIP6),
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// département Systèmes Répartis Coopératifs (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
24
#ifndef SPOT_TGBA_TGBAEXPLICIT_HH
# define SPOT_TGBA_TGBAEXPLICIT_HH

25
#include "misc/hash.hh"
26
27
28
29
30
31
32
33
34
35
36
#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.
37
  /// \ingroup tgba_representation
38
  class tgba_explicit: public tgba
39
40
  {
  public:
41
    tgba_explicit(bdd_dict* dict);
42
43
44

    struct transition;
    typedef std::list<transition*> state;
45
46

    /// Explicit transitions (used by spot::tgba_explicit).
47
48
49
    struct transition
    {
      bdd condition;
50
      bdd acceptance_conditions;
51
52
53
      state* dest;
    };

54
55
    void set_init_state(const std::string& state);

56
57
58
    transition*
    create_transition(const std::string& source, const std::string& dest);

59
    void add_condition(transition* t, const ltl::formula* f);
60
61
    /// This assumes that all variables in \a f are known from dict.
    void add_conditions(transition* t, bdd f);
62
    void declare_acceptance_condition(const ltl::formula* f);
63
64
65
66
67
68
69

    /// \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);

70
71
72
73
74
    bool has_acceptance_condition(const ltl::formula* f) const;
    void add_acceptance_condition(transition* t, const ltl::formula* f);
    /// This assumes that all acceptance conditions in \a f are known from dict.
    void add_acceptance_conditions(transition* t, bdd f);
    void complement_all_acceptance_conditions();
75
    void merge_transitions();
76

77
78
79
80
    /// Return the tgba_explicit::state for \a name, creating the state if
    /// it does not exist.
    state* add_state(const std::string& name);

81
82
83
84
    // tgba interface
    virtual ~tgba_explicit();
    virtual spot::state* get_init_state() const;
    virtual tgba_succ_iterator*
85
86
87
    succ_iter(const spot::state* local_state,
	      const spot::state* global_state = 0,
	      const tgba* global_automaton = 0) const;
88
    virtual bdd_dict* get_dict() const;
89
90
    virtual std::string format_state(const spot::state* state) const;

91
92
    virtual bdd all_acceptance_conditions() const;
    virtual bdd neg_acceptance_conditions() const;
93

94
  protected:
95
96
97
    virtual bdd compute_support_conditions(const spot::state* state) const;
    virtual bdd compute_support_variables(const spot::state* state) const;

98
    bdd get_acceptance_condition(const ltl::formula* f);
99

100
101
102
103
    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;
104
105
    ns_map name_state_map_;
    sn_map state_name_map_;
106
    bdd_dict* dict_;
107
    tgba_explicit::state* init_;
108
109
110
    mutable bdd all_acceptance_conditions_;
    bdd neg_acceptance_conditions_;
    mutable bool all_acceptance_conditions_computed_;
111
112
113
114
115

  private:
    // Disallow copy.
    tgba_explicit(const tgba_explicit& other);
    tgba_explicit& tgba_explicit::operator=(const tgba_explicit& other);
116
117
118
  };


119
  /// States used by spot::tgba_explicit.
120
  /// \ingroup tgba_representation
121
122
123
124
125
126
127
128
129
  class state_explicit : public spot::state
  {
  public:
    state_explicit(const tgba_explicit::state* s)
      : state_(s)
    {
    }

    virtual int compare(const spot::state* other) const;
130
    virtual size_t hash() const;
131
132
    virtual state_explicit* clone() const;

133
134
135
136
137
138
139
140
141
142
    virtual ~state_explicit()
    {
    }

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


143
  /// Successor iterators used by spot::tgba_explicit.
144
  /// \ingroup tgba_representation
145
  class tgba_explicit_succ_iterator: public tgba_succ_iterator
146
147
  {
  public:
148
    tgba_explicit_succ_iterator(const tgba_explicit::state* s, bdd all_acc);
149
150
151
152
153
154
155
156

    virtual
    ~tgba_explicit_succ_iterator()
    {
    }

    virtual void first();
    virtual void next();
157
    virtual bool done() const;
158

159
160
    virtual state_explicit* current_state() const;
    virtual bdd current_condition() const;
161
    virtual bdd current_acceptance_conditions() const;
162
163
164
165

  private:
    const tgba_explicit::state* s_;
    tgba_explicit::state::const_iterator i_;
166
    bdd all_acceptance_conditions_;
167
168
169
170
171
  };

}

#endif // SPOT_TGBA_TGBAEXPLICIT_HH