taproduct.hh 5.84 KB
Newer Older
1
// -*- coding: utf-8 -*-
2
3
// Copyright (C) 2011, 2012, 2013, 2014, 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
13
14
15
16
17
// (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
18
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
19

20
#pragma once
21

22
23
#include <spot/ta/ta.hh>
#include <spot/kripke/kripke.hh>
24
25
26
27

namespace spot
{

28
  /// \ingroup ta_emptiness_check
29
  /// \brief A state for spot::ta_product.
30
  ///
Ala-Eddine Ben-Salem's avatar
Ala-Eddine Ben-Salem committed
31
  /// This state is in fact a pair of state: the state from the TA
32
  /// automaton and that of Kripke structure.
33
  class SPOT_API state_ta_product : public state
34
35
36
37
  {
  public:
    /// \brief Constructor
    /// \param ta_state The state from the ta automaton.
38
    /// \param kripke_state The state from Kripke structure.
39
    state_ta_product(const state* ta_state, const state* kripke_state) :
40
41
42
43
44
45
46
47
48
49
      ta_state_(ta_state), kripke_state_(kripke_state)
    {
    }

    /// Copy constructor
    state_ta_product(const state_ta_product& o);

    virtual
    ~state_ta_product();

50
    const state*
51
52
53
54
55
    get_ta_state() const
    {
      return ta_state_;
    }

56
    const state*
57
58
59
60
61
62
    get_kripke_state() const
    {
      return kripke_state_;
    }

    virtual int
63
    compare(const state* other) const override;
64
    virtual size_t
65
    hash() const override;
66
    virtual state_ta_product*
67
    clone() const override;
68
69

  private:
70
71
    const state* ta_state_; ///< State from the ta automaton.
    const state* kripke_state_; ///< State from the kripke structure.
72
73
74
  };

  /// \brief Iterate over the successors of a product computed on the fly.
75
  class SPOT_API ta_succ_iterator_product : public ta_succ_iterator
76
77
  {
  public:
78
79
    ta_succ_iterator_product(const state_ta_product* s, const ta* t,
        const kripke* k);
80
81
82
83
84

    virtual
    ~ta_succ_iterator_product();

    // iteration
85
86
87
    virtual bool first() override;
    virtual bool next() override;
    virtual bool done() const override;
88
89

    // inspection
90
91
92
    virtual state_ta_product* dst() const override;
    virtual bdd cond() const override;
    virtual acc_cond::mark_t acc() const override;
93

Ala-Eddine Ben-Salem's avatar
Ala-Eddine Ben-Salem committed
94
    /// \brief Return true if the changeset of the current transition is empty
95
    bool is_stuttering_transition() const;
96

97
  protected:
98
99
    //@{
    /// Internal routines to advance to the next successor.
100
101
    void step_();
    bool next_non_stuttering_();
102

Ala-Eddine Ben-Salem's avatar
Ala-Eddine Ben-Salem committed
103
    /// \brief Move to the next successor in the kripke structure
104
105
106
    void
    next_kripke_dest();

107
108
109
110
111
112
113
    //@}

  protected:
    const state_ta_product* source_;
    const ta* ta_;
    const kripke* kripke_;
    ta_succ_iterator* ta_succ_it_;
114
    twa_succ_iterator* kripke_succ_it_;
115
    const state_ta_product* current_state_;
116
    bdd current_condition_;
117
    acc_cond::mark_t current_acceptance_conditions_;
118
    bool is_stuttering_transition_;
119
    bdd kripke_source_condition;
120
    const state* kripke_current_dest_state;
121
122
123

  };

124
  /// \ingroup ta_emptiness_check
Ala-Eddine Ben-Salem's avatar
Ala-Eddine Ben-Salem committed
125
126
  /// \brief A lazy product between a Testing automaton and a Kripke structure.
  /// (States are computed on the fly.)
127
  class SPOT_API ta_product final: public ta
128
129
  {
  public:
Ala-Eddine Ben-Salem's avatar
Ala-Eddine Ben-Salem committed
130
131
132
    /// \brief Constructor.
    /// \param testing_automaton The TA component in the product.
    /// \param kripke_structure The Kripke component in the product.
133
134
    ta_product(const const_ta_ptr& testing_automaton,
	       const const_kripke_ptr& kripke_structure);
135
136
137
138

    virtual
    ~ta_product();

139
    virtual ta::const_states_set_t
140
    get_initial_states_set() const override;
141
142

    virtual ta_succ_iterator_product*
143
    succ_iter(const spot::state* s) const override;
144

145
    virtual ta_succ_iterator_product*
146
    succ_iter(const spot::state* s, bdd changeset) const override;
147

148
    bdd_dict_ptr
149
150
151
    get_dict() const;

    virtual std::string
152
    format_state(const spot::state* s) const override;
153
154

    virtual bool
155
    is_accepting_state(const spot::state* s) const override;
156
157

    virtual bool
158
    is_livelock_accepting_state(const spot::state* s) const override;
159
160

    virtual bool
161
    is_initial_state(const spot::state* s) const override;
162

Ala-Eddine Ben-Salem's avatar
Ala-Eddine Ben-Salem committed
163
    /// \brief Return true if the state \a s has no succeseurs
164
    /// in the TA automaton (the TA component of the product automaton)
165
    bool
166
167
    is_hole_state_in_ta_component(const spot::state* s) const;

168
    virtual bdd
169
    get_state_condition(const spot::state* s) const override;
170
171

    virtual void
172
    free_state(const spot::state* s) const override;
173

174
    const const_ta_ptr&
175
176
177
178
179
    get_ta() const
    {
      return ta_;
    }

180
    const const_kripke_ptr&
181
182
183
184
185
    get_kripke() const
    {
      return kripke_;
    }

186
  private:
187
    bdd_dict_ptr dict_;
188
189
    const_ta_ptr ta_;
    const_kripke_ptr kripke_;
190
191

    // Disallow copy.
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
192
193
    ta_product(const ta_product&) = delete;
    ta_product& operator=(const ta_product&) = delete;
194
195
  };

196

197
198
199
200
201
202
203
204
  typedef std::shared_ptr<ta_product> ta_product_ptr;
  typedef std::shared_ptr<const ta_product> const_ta_product_ptr;
  inline ta_product_ptr product(const const_ta_ptr& testing_automaton,
				const const_kripke_ptr& kripke_structure)
  {
    return std::make_shared<ta_product>(testing_automaton, kripke_structure);
  }

205
206
  class SPOT_API ta_succ_iterator_product_by_changeset :
    public ta_succ_iterator_product
207
208
209
  {
  public:
    ta_succ_iterator_product_by_changeset(const state_ta_product* s,
210
211
					  const ta* t, const kripke* k,
					  bdd changeset);
212

213
214
215
    /// \brief Move to the next successor in the Kripke structure
    void next_kripke_dest();
  };
216
}