tgbaexplicit.cc 4.32 KB
Newer Older
1
#include "ltlast/atomic_prop.hh"
2
#include "ltlvisit/destroy.hh"
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "tgbaexplicit.hh"
#include <cassert>

namespace spot
{

  ////////////////////////////////////////
  // tgba_explicit_succ_iterator

  tgba_explicit_succ_iterator::tgba_explicit_succ_iterator
  (const tgba_explicit::state* s)
    : s_(s)
  {
  }

18
  void
19
20
21
22
23
  tgba_explicit_succ_iterator::first()
  {
    i_ = s_->begin();
  }

24
  void
25
26
27
28
29
  tgba_explicit_succ_iterator::next()
  {
    ++i_;
  }

30
  bool
31
32
33
34
35
  tgba_explicit_succ_iterator::done()
  {
    return i_ == s_->end();
  }

36
  state_explicit*
37
38
39
40
41
  tgba_explicit_succ_iterator::current_state()
  {
    return new state_explicit((*i_)->dest);
  }

42
  bdd
43
44
45
46
47
  tgba_explicit_succ_iterator::current_condition()
  {
    return (*i_)->condition;
  }

48
  bdd
49
50
51
52
53
54
55
56
57
  tgba_explicit_succ_iterator::current_promise()
  {
    return (*i_)->promise;
  }


  ////////////////////////////////////////
  // state_explicit

58
  const tgba_explicit::state*
59
60
61
62
63
64
65
66
67
68
69
70
71
  state_explicit::get_state() const
  {
    return state_;
  }

  int
  state_explicit::compare(const spot::state* other) const
  {
    const state_explicit* o = dynamic_cast<const state_explicit*>(other);
    assert(o);
    return o->get_state() - get_state();
  }

72
73
74
75
76
77
  state_explicit*
  state_explicit::clone() const
  {
    return new state_explicit(*this);
  }

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
  ////////////////////////////////////////
  // tgba_explicit


  tgba_explicit::tgba_explicit()
    : init_(0)
  {
  }

  tgba_explicit::~tgba_explicit()
  {
    ns_map::iterator i;
    for (i = name_state_map_.begin(); i != name_state_map_.end(); ++i)
      {
	tgba_explicit::state::iterator i2;
	for (i2 = i->second->begin(); i2 != i->second->end(); ++i2)
	  delete *i2;
	delete i->second;
      }
  }
98

99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
  tgba_explicit::state*
  tgba_explicit::add_state(const std::string& name)
  {
    ns_map::iterator i = name_state_map_.find(name);
    if (i == name_state_map_.end())
      {
	tgba_explicit::state* s = new tgba_explicit::state;
	name_state_map_[name] = s;
	state_name_map_[s] = name;

	// The first state we add is the inititial state.
	if (! init_)
	  init_ = s;

	return s;
      }
    return i->second;
  }

  tgba_explicit::transition*
119
  tgba_explicit::create_transition(const std::string& source,
120
121
122
123
124
125
126
127
128
129
130
131
				   const std::string& dest)
  {
    tgba_explicit::state* s = add_state(source);
    tgba_explicit::state* d = add_state(dest);
    transition* t = new transition;
    t->dest = d;
    t->condition = bddtrue;
    t->promise = bddtrue;
    s->push_back(t);
    return t;
  }

132
  int tgba_explicit::get_condition(ltl::formula* f)
133
134
135
136
137
138
139
140
141
142
143
144
  {
    assert(dynamic_cast<ltl::atomic_prop*>(f));
    tgba_bdd_dict::fv_map::iterator i = dict_.var_map.find(f);
    int v;
    if (i == dict_.var_map.end())
      {
	v = create_node();
	dict_.var_map[f] = v;
	dict_.var_formula_map[v] = f;
      }
    else
      {
145
	ltl::destroy(f);
146
147
	v = i->second;
      }
148
    return v;
149
150
  }

151
152
153
154
155
156
157
158
159
160
161
  void tgba_explicit::add_condition(transition* t, ltl::formula* f)
  {
    t->condition &= ithvar(get_condition(f));
  }

  void tgba_explicit::add_neg_condition(transition* t, ltl::formula* f)
  {
    t->condition &= ! ithvar(get_condition(f));
  }

  int tgba_explicit::get_promise(ltl::formula* f)
162
163
164
165
166
167
168
169
170
171
172
  {
    tgba_bdd_dict::fv_map::iterator i = dict_.prom_map.find(f);
    int v;
    if (i == dict_.prom_map.end())
      {
	v = create_node();
	dict_.prom_map[f] = v;
	dict_.prom_formula_map[v] = f;
      }
    else
      {
173
	ltl::destroy(f);
174
175
	v = i->second;
      }
176
177
178
179
180
181
182
183
184
185
186
    return v;
  }

  void tgba_explicit::add_promise(transition* t, ltl::formula* f)
  {
    t->promise &= ithvar(get_promise(f));
  }

  void tgba_explicit::add_neg_promise(transition* t, ltl::formula* f)
  {
    t->promise &= ! ithvar(get_promise(f));
187
188
  }

189
  state*
190
191
192
193
194
  tgba_explicit::get_init_state() const
  {
    return new state_explicit(init_);
  }

195
  tgba_succ_iterator*
196
197
198
199
200
201
  tgba_explicit::succ_iter(const spot::state* state) const
  {
    const state_explicit* s = dynamic_cast<const state_explicit*>(state);
    assert(s);
    return new tgba_explicit_succ_iterator(s->get_state());
  }
202
203

  const tgba_bdd_dict&
204
205
206
207
208
  tgba_explicit::get_dict() const
  {
    return dict_;
  }

209
  std::string
210
211
212
213
214
215
216
217
218
219
  tgba_explicit::format_state(const spot::state* s) const
  {
    const state_explicit* se = dynamic_cast<const state_explicit*>(s);
    assert(se);
    sn_map::const_iterator i = state_name_map_.find(se->get_state());
    assert(i != state_name_map_.end());
    return i->second;
  }

}