tgbaexplicit.hh 4.74 KB
Newer Older
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Copyright (C) 2003  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
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 accepting_conditions;
50
51
52
      state* dest;
    };

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

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

    void add_condition(transition* t, ltl::formula* f);
59
    void add_neg_condition(transition* t, ltl::formula* f);
60
61
    /// This assumes that all variables in \a f are known from dict.
    void add_conditions(transition* t, bdd f);
62
63
64
    void declare_accepting_condition(ltl::formula* f);
    bool has_accepting_condition(ltl::formula* f) const;
    void add_accepting_condition(transition* t, ltl::formula* f);
65
66
    /// This assumes that all accepting conditions in \a f are known from dict.
    void add_accepting_conditions(transition* t, bdd f);
67
    void complement_all_accepting_conditions();
68
69
70
71
72

    // tgba interface
    virtual ~tgba_explicit();
    virtual spot::state* get_init_state() const;
    virtual tgba_succ_iterator*
73
74
75
    succ_iter(const spot::state* local_state,
	      const spot::state* global_state = 0,
	      const tgba* global_automaton = 0) const;
76
    virtual bdd_dict* get_dict() const;
77
78
    virtual std::string format_state(const spot::state* state) const;

79
80
81
    virtual bdd all_accepting_conditions() const;
    virtual bdd neg_accepting_conditions() const;

82
  protected:
83
84
85
    virtual bdd compute_support_conditions(const spot::state* state) const;
    virtual bdd compute_support_variables(const spot::state* state) const;

86
    state* add_state(const std::string& name);
87
88
    bdd get_condition(ltl::formula* f);
    bdd get_accepting_condition(ltl::formula* f);
89

90
91
92
93
    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;
94
95
    ns_map name_state_map_;
    sn_map state_name_map_;
96
    bdd_dict* dict_;
97
    tgba_explicit::state* init_;
98
99
100
    mutable bdd all_accepting_conditions_;
    bdd neg_accepting_conditions_;
    mutable bool all_accepting_conditions_computed_;
101
102
103
104
105

  private:
    // Disallow copy.
    tgba_explicit(const tgba_explicit& other);
    tgba_explicit& tgba_explicit::operator=(const tgba_explicit& other);
106
107
108
  };


109
  /// States used by spot::tgba_explicit.
110
111
112
113
114
115
116
117
118
  class state_explicit : public spot::state
  {
  public:
    state_explicit(const tgba_explicit::state* s)
      : state_(s)
    {
    }

    virtual int compare(const spot::state* other) const;
119
    virtual size_t hash() const;
120
121
    virtual state_explicit* clone() const;

122
123
124
125
126
127
128
129
130
131
    virtual ~state_explicit()
    {
    }

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


132
  /// Successor iterators used by spot::tgba_explicit.
133
  class tgba_explicit_succ_iterator: public tgba_succ_iterator
134
135
  {
  public:
136
    tgba_explicit_succ_iterator(const tgba_explicit::state* s, bdd all_acc);
137
138
139
140
141
142
143
144

    virtual
    ~tgba_explicit_succ_iterator()
    {
    }

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

147
148
149
    virtual state_explicit* current_state() const;
    virtual bdd current_condition() const;
    virtual bdd current_accepting_conditions() const;
150
151
152
153

  private:
    const tgba_explicit::state* s_;
    tgba_explicit::state::const_iterator i_;
154
    bdd all_accepting_conditions_;
155
156
157
158
159
  };

}

#endif // SPOT_TGBA_TGBAEXPLICIT_HH