taatgba.hh 6.04 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Copyright (C) 2009 Laboratoire d'Informatique de Paris
// 6 (LIP6), 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
#ifndef SPOT_TGBA_TAATGBA_HH
# define SPOT_TGBA_TAATGBA_HH
24
25

#include <set>
Damien Lefortier's avatar
Damien Lefortier committed
26
#include <iosfwd>
27
28
29
30
31
32
33
34
35
#include <vector>
#include "misc/hash.hh"
#include "ltlast/formula.hh"
#include "bdddict.hh"
#include "tgba.hh"

namespace spot
{
  /// \brief A Transition-based Alternating Automaton (TAA).
36
  class taa_tgba : public tgba
37
38
  {
  public:
39
    taa_tgba(bdd_dict* dict);
40
41
42
43
44
45
46
47
48
49
50
51
52
53

    struct transition;
    typedef std::list<transition*> state;
    typedef std::set<state*> state_set;

    /// Explicit transitions.
    struct transition
    {
      bdd condition;
      bdd acceptance_conditions;
      const state_set* dst;
    };

    void set_init_state(const std::string& state);
54
    void set_init_state(const std::vector<std::string>& state);
55
56
57
58
59
60
61
62
63
64

    transition*
    create_transition(const std::string& src,
		      const std::vector<std::string>& dst);
    transition*
    create_transition(const std::string& src, const std::string& dst);

    void add_condition(transition* t, const ltl::formula* f);
    void add_acceptance_condition(transition* t, const ltl::formula* f);

Damien Lefortier's avatar
Damien Lefortier committed
65
66
67
    /// \brief Output a TAA.
    void output(std::ostream& os) const;

68
    /// TGBA interface.
69
    virtual ~taa_tgba();
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
    virtual spot::state* get_init_state() const;
    virtual tgba_succ_iterator*
    succ_iter(const spot::state* local_state,
	      const spot::state* global_state = 0,
	      const tgba* global_automaton = 0) const;
    virtual bdd_dict* get_dict() const;

    /// \brief Format the state as a string for printing.
    ///
    /// If state is a spot::state_set of only one element, then the
    /// string corresponding to state->get_state() is returned.
    ///
    /// Otherwise a string composed of each string corresponding to
    /// each state->get_state() in the spot::state_set is returned,
    /// e.g. like {string_1,...,string_n}.
    virtual std::string format_state(const spot::state* state) const;

    virtual bdd all_acceptance_conditions() const;
    virtual bdd neg_acceptance_conditions() const;

  protected:
    virtual bdd compute_support_conditions(const spot::state* state) const;
    virtual bdd compute_support_variables(const spot::state* state) const;

    typedef Sgi::hash_map<
95
      const std::string, taa_tgba::state*, string_hash
96
97
98
      > ns_map;

    typedef Sgi::hash_map<
99
      const taa_tgba::state*, std::string, ptr_hash<taa_tgba::state>
100
101
      > sn_map;

102
    typedef std::vector<taa_tgba::state_set*> ss_vec;
103
104
105
106
107
108
109

    ns_map name_state_map_;
    sn_map state_name_map_;
    bdd_dict* dict_;
    mutable bdd all_acceptance_conditions_;
    mutable bool all_acceptance_conditions_computed_;
    bdd neg_acceptance_conditions_;
110
    taa_tgba::state_set* init_;
111
112
113
114
    ss_vec state_set_vec_;

  private:
    // Disallow copy.
115
116
    taa_tgba(const taa_tgba& other);
    taa_tgba& operator=(const taa_tgba& other);
117

118
    /// \brief Return the taa_tgba::state for \a name, creating it if it
119
120
    /// does not exist.  The first state added is the initial state
    /// which can be overridden with set_init_state.
121
    taa_tgba::state* add_state(const std::string& name);
122
123

    /// \brief Return the taa::state_set for \a names.
124
    taa_tgba::state_set* add_state_set(const std::vector<std::string>& names);
Damien Lefortier's avatar
Damien Lefortier committed
125
126

    /// \brief Format a taa::state_set as a string for printing.
127
    std::string format_state_set(const taa_tgba::state_set* ss) const;
128
129
130
131
132
133
  };

  /// Set of states deriving from spot::state.
  class state_set : public spot::state
  {
  public:
134
    state_set(const taa_tgba::state_set* s, bool delete_me = false)
135
      : s_(s), delete_me_(delete_me)
136
137
138
139
140
141
142
143
144
    {
    }

    virtual int compare(const spot::state*) const;
    virtual size_t hash() const;
    virtual state_set* clone() const;

    virtual ~state_set()
    {
145
146
      if (delete_me_)
	delete s_;
147
148
    }

149
    const taa_tgba::state_set* get_state() const;
150
  private:
151
    const taa_tgba::state_set* s_;
152
    bool delete_me_;
153
154
155
156
157
  };

  class taa_succ_iterator : public tgba_succ_iterator
  {
  public:
158
    taa_succ_iterator(const taa_tgba::state_set* s, bdd all_acc);
Damien Lefortier's avatar
Damien Lefortier committed
159
    virtual ~taa_succ_iterator();
160
161
162
163
164
165
166
167
168
169

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

    virtual state_set* current_state() const;
    virtual bdd current_condition() const;
    virtual bdd current_acceptance_conditions() const;

  private:
170
171
    /// Those typedefs are used to generate all possible successors in
    /// the constructor using a cartesian product.
172
    typedef taa_tgba::state::const_iterator iterator;
173
174
175
    typedef std::pair<iterator, iterator> iterator_pair;
    typedef std::vector<iterator_pair> bounds_t;
    typedef Sgi::hash_multimap<
176
177
      const spot::state_set*, taa_tgba::transition*, state_ptr_hash,
      state_ptr_equal> seen_map;
178
179
180
181
182
183
184
185
186
187
188
189

    struct distance_sort :
      public std::binary_function<const iterator_pair&,
				  const iterator_pair&, bool>
    {
      bool
      operator()(const iterator_pair& lhs, const iterator_pair& rhs) const
      {
	return std::distance(lhs.first, lhs.second) <
	       std::distance(rhs.first, rhs.second);
      }
    };
190

191
192
    std::vector<taa_tgba::transition*>::const_iterator i_;
    std::vector<taa_tgba::transition*> succ_;
193
    bdd all_acceptance_conditions_;
Damien Lefortier's avatar
Damien Lefortier committed
194
    seen_map seen_;
195
196
197
  };
}

198
#endif // SPOT_TGBA_TAATGBA_HH