taexplicit.hh 6.73 KB
Newer Older
1
// -*- coding: utf-8 -*-
2
3
// Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Laboratoire
// de Recherche et Développement de l'Epita (LRDE).
4
5
6
7
8
//
// 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
9
// the Free Software Foundation; either version 3 of the License, or
10
11
12
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
13
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15
// License for more details.
16
17
//
// You should have received a copy of the GNU General Public License
18
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
19

20
#pragma once
21

22
#include <spot/misc/hash.hh>
23
#include <list>
24
#include <spot/twa/twa.hh>
25
#include <set>
26
#include <spot/tl/formula.hh>
27
#include <cassert>
28
29
#include <spot/misc/bddlt.hh>
#include <spot/ta/ta.hh>
30
31
32
33
34
35
36
37

namespace spot
{
  // Forward declarations.  See below.
  class state_ta_explicit;
  class ta_explicit_succ_iterator;
  class ta_explicit;

Ala-Eddine Ben-Salem's avatar
Ala-Eddine Ben-Salem committed
38
39
  /// Explicit representation of a spot::ta.
  /// \ingroup ta_representation
40
  class SPOT_API ta_explicit : public ta
41
42
  {
  public:
43
    ta_explicit(const const_twa_ptr& tgba,
44
		unsigned n_acc,
45
		state_ta_explicit* artificial_initial_state = nullptr);
46

47
    const_twa_ptr
48
49
50
51
52
    get_tgba() const;

    state_ta_explicit*
    add_state(state_ta_explicit* s);

53
    void
54
    add_to_initial_states_set(state* s, bdd condition = bddfalse);
55

56
57
    void
    create_transition(state_ta_explicit* source, bdd condition,
58
		      acc_cond::mark_t acceptance_conditions,
59
		      const state_ta_explicit* dest,
60
		      bool add_at_beginning = false);
61

62
63
64
65
66
    void
    delete_stuttering_transitions();
    // ta interface
    virtual
    ~ta_explicit();
67
    virtual const_states_set_t get_initial_states_set() const override;
68

69
    virtual ta_succ_iterator* succ_iter(const spot::state* s) const override;
70

71
    virtual ta_succ_iterator*
72
    succ_iter(const spot::state* s, bdd condition) const override;
73

74
    bdd_dict_ptr get_dict() const;
75
76

    virtual std::string
77
    format_state(const spot::state* s) const override;
78
79

    virtual bool
80
    is_accepting_state(const spot::state* s) const override;
81
82

    virtual bool
83
    is_livelock_accepting_state(const spot::state* s) const override;
84
85

    virtual bool
86
    is_initial_state(const spot::state* s) const override;
87
88

    virtual bdd
89
    get_state_condition(const spot::state* s) const override;
90

91
    virtual void
92
    free_state(const spot::state* s) const override;
93

94
95
    virtual spot::state*
    get_artificial_initial_state() const override
96
97
98
99
100
101
102
103
104
105
106
    {
      return (spot::state*) artificial_initial_state_;
    }

    void
    set_artificial_initial_state(state_ta_explicit* s)
    {
      artificial_initial_state_ = s;

    }

107
    void
108
    delete_stuttering_and_hole_successors(const spot::state* s);
109

110
111
112
113
114
115
    ta::states_set_t
    get_states_set()
    {
      return states_set_;
    }

116
117
  private:
    // Disallow copy.
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
118
119
    ta_explicit(const ta_explicit& other) = delete;
    ta_explicit& operator=(const ta_explicit& other) = delete;
120

121
    const_twa_ptr tgba_;
122
    state_ta_explicit* artificial_initial_state_;
123
    ta::states_set_t states_set_;
124
    ta::const_states_set_t initial_states_set_;
125
126
127
  };

  /// states used by spot::ta_explicit.
Ala-Eddine Ben-Salem's avatar
Ala-Eddine Ben-Salem committed
128
  /// \ingroup ta_representation
129
  class SPOT_API state_ta_explicit final: public spot::state
130
  {
131
#ifndef SWIG
132
133
  public:

Ala-Eddine Ben-Salem's avatar
Ala-Eddine Ben-Salem committed
134
    /// Explicit transitions.
135
136
137
    struct transition
    {
      bdd condition;
138
      acc_cond::mark_t acceptance_conditions;
139
      const state_ta_explicit* dest;
140
141
142
143
144
    };

    typedef std::list<transition*> transitions;

    state_ta_explicit(const state* tgba_state, const bdd tgba_condition,
145
146
147
148
		      bool is_initial_state = false,
		      bool is_accepting_state = false,
		      bool is_livelock_accepting_state = false,
		      transitions* trans = nullptr) :
149
150
151
152
153
154
155
      tgba_state_(tgba_state), tgba_condition_(tgba_condition),
          is_initial_state_(is_initial_state), is_accepting_state_(
              is_accepting_state), is_livelock_accepting_state_(
              is_livelock_accepting_state), transitions_(trans)
    {
    }

156
157
158
    virtual int compare(const spot::state* other) const override;
    virtual size_t hash() const override;
    virtual state_ta_explicit* clone() const override;
159

160
    virtual void destroy() const override
161
162
163
    {
    }

164
165
166
167
168
169
170
171
    virtual
    ~state_ta_explicit()
    {
    }

    transitions*
    get_transitions() const;

172
173
174
175
    // return transitions filtred by condition
    transitions*
    get_transitions(bdd condition) const;

176
    void
177
    add_transition(transition* t, bool add_at_beginning = false);
178
179
180
181
182
183
184
185
186
187
188
189
190

    const state*
    get_tgba_state() const;
    const bdd
    get_tgba_condition() const;
    bool
    is_accepting_state() const;
    void
    set_accepting_state(bool is_accepting_state);
    bool
    is_livelock_accepting_state() const;
    void
    set_livelock_accepting_state(bool is_livelock_accepting_state);
191

192
193
194
195
    bool
    is_initial_state() const;
    void
    set_initial_state(bool is_initial_state);
196

Ala-Eddine Ben-Salem's avatar
Ala-Eddine Ben-Salem committed
197
    /// \brief Return true if the state has no successors
198
199
200
    bool
    is_hole_state() const;

Ala-Eddine Ben-Salem's avatar
Ala-Eddine Ben-Salem committed
201
202
    /// \brief Remove stuttering transitions
    /// and transitions leading to states having no successors
203
204
205
206
207
    void
    delete_stuttering_and_hole_successors();

    void
    free_transitions();
208

209
    state_ta_explicit* stuttering_reachable_livelock;
210
211
212
213
214
215
216
  private:
    const state* tgba_state_;
    const bdd tgba_condition_;
    bool is_initial_state_;
    bool is_accepting_state_;
    bool is_livelock_accepting_state_;
    transitions* transitions_;
217
218
    std::unordered_map<int, transitions*, std::hash<int>>
      transitions_by_condition;
219
#endif // !SWIG
220
221
222
  };

  /// Successor iterators used by spot::ta_explicit.
223
  class SPOT_API ta_explicit_succ_iterator final: public ta_succ_iterator
224
225
226
227
  {
  public:
    ta_explicit_succ_iterator(const state_ta_explicit* s);

228
229
    ta_explicit_succ_iterator(const state_ta_explicit* s, bdd condition);

230
231
232
    virtual bool first() override;
    virtual bool next() override;
    virtual bool done() const override;
233

234
235
    virtual const state* dst() const override;
    virtual bdd cond() const override;
236

237
    virtual acc_cond::mark_t acc() const override;
238

239
240
241
242
243
  private:
    state_ta_explicit::transitions* transitions_;
    state_ta_explicit::transitions::const_iterator i_;
  };

244
245
246
  typedef std::shared_ptr<ta_explicit> ta_explicit_ptr;
  typedef std::shared_ptr<const ta_explicit> const_ta_explicit_ptr;

247
248
249
250
  inline ta_explicit_ptr
  make_ta_explicit(const const_twa_ptr& tgba,
		   unsigned n_acc,
		   state_ta_explicit* artificial_initial_state = nullptr)
251
  {
252
    return std::make_shared<ta_explicit>(tgba, n_acc, artificial_initial_state);
253
  }
254
}