tgbaexplicit.hh 5.21 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
      const state* dest;
52
53
    };

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

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

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

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

72
73
74
75
76
    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();
77
    void merge_transitions();
78

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

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

93
94
    virtual bdd all_acceptance_conditions() const;
    virtual bdd neg_acceptance_conditions() const;
95

96
  protected:
97
98
99
    virtual bdd compute_support_conditions(const spot::state* state) const;
    virtual bdd compute_support_variables(const spot::state* state) const;

100
    bdd get_acceptance_condition(const ltl::formula* f);
101

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

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


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

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

135
136
137
138
139
140
141
142
143
144
    virtual ~state_explicit()
    {
    }

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


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

    virtual
    ~tgba_explicit_succ_iterator()
    {
    }

    virtual void first();
    virtual void next();
159
    virtual bool done() const;
160

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

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

}

#endif // SPOT_TGBA_TGBAEXPLICIT_HH