tgbaexplicit.hh 4.93 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
  class tgba_explicit: public tgba
38
39
  {
  public:
40
    tgba_explicit(bdd_dict* dict);
41
42
43

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

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

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

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

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

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

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

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

86
87
    virtual bdd all_acceptance_conditions() const;
    virtual bdd neg_acceptance_conditions() const;
88

89
  protected:
90
91
92
    virtual bdd compute_support_conditions(const spot::state* state) const;
    virtual bdd compute_support_variables(const spot::state* state) const;

93
    state* add_state(const std::string& name);
94
    bdd get_acceptance_condition(const ltl::formula* f);
95

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

  private:
    // Disallow copy.
    tgba_explicit(const tgba_explicit& other);
    tgba_explicit& tgba_explicit::operator=(const tgba_explicit& other);
112
113
114
  };


115
  /// States used by spot::tgba_explicit.
116
117
118
119
120
121
122
123
124
  class state_explicit : public spot::state
  {
  public:
    state_explicit(const tgba_explicit::state* s)
      : state_(s)
    {
    }

    virtual int compare(const spot::state* other) const;
125
    virtual size_t hash() const;
126
127
    virtual state_explicit* clone() const;

128
129
130
131
132
133
134
135
136
137
    virtual ~state_explicit()
    {
    }

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


138
  /// Successor iterators used by spot::tgba_explicit.
139
  class tgba_explicit_succ_iterator: public tgba_succ_iterator
140
141
  {
  public:
142
    tgba_explicit_succ_iterator(const tgba_explicit::state* s, bdd all_acc);
143
144
145
146
147
148
149
150

    virtual
    ~tgba_explicit_succ_iterator()
    {
    }

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

153
154
    virtual state_explicit* current_state() const;
    virtual bdd current_condition() const;
155
    virtual bdd current_acceptance_conditions() const;
156
157
158
159

  private:
    const tgba_explicit::state* s_;
    tgba_explicit::state::const_iterator i_;
160
    bdd all_acceptance_conditions_;
161
162
163
164
165
  };

}

#endif // SPOT_TGBA_TGBAEXPLICIT_HH