taexplicit.cc 8.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
// Copyright (C) 2010 Laboratoire de Recherche et Developpement
// de l Epita (LRDE).
//
// 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.

#include "ltlast/atomic_prop.hh"
#include "ltlast/constant.hh"
#include "taexplicit.hh"
#include "tgba/formula2bdd.hh"
#include "misc/bddop.hh"
#include <cassert>
#include "ltlvisit/tostring.hh"

#include "tgba/bddprint.hh"


namespace spot
{

  ////////////////////////////////////////
  // ta_explicit_succ_iterator

  ta_explicit_succ_iterator::ta_explicit_succ_iterator(const state_ta_explicit* s)
  {
    transitions_ = s->get_transitions();
  }

  void
  ta_explicit_succ_iterator::first()
  {
    i_ = transitions_->begin();
  }

  void
  ta_explicit_succ_iterator::next()
  {
    ++i_;
  }

  bool
  ta_explicit_succ_iterator::done() const
  {
    return i_ == transitions_->end();
  }

  state*
  ta_explicit_succ_iterator::current_state() const
  {
    assert(!done());
    state_ta_explicit* s = (*i_)->dest;
    return s;
  }

  bdd
  ta_explicit_succ_iterator::current_condition() const
  {
    assert(!done());
    return (*i_)->condition;
  }




  ////////////////////////////////////////
  // state_ta_explicit

  state_ta_explicit::transitions*
  state_ta_explicit::get_transitions() const
  {
    return transitions_;
  }


  void
  state_ta_explicit::add_transition(state_ta_explicit::transition* t){
    if(transitions_ == 0)
      transitions_= new transitions;

    transitions_->push_back(t);

  }


  const state*
  state_ta_explicit::get_tgba_state() const
  {
    return tgba_state_;
  }

  const bdd
  state_ta_explicit::get_tgba_condition() const
  {
    return tgba_condition_;
  }

  bool
  state_ta_explicit::is_accepting_state() const
  {
    return is_accepting_state_;
  }

  bool
  state_ta_explicit::is_initial_state() const
  {
    return is_initial_state_;
  }

  void
  state_ta_explicit::set_accepting_state(bool is_accepting_state)
  {
    is_accepting_state_ = is_accepting_state;
  }

  bool
  state_ta_explicit::is_livelock_accepting_state() const
  {
    return is_livelock_accepting_state_;
  }

  void
  state_ta_explicit::set_livelock_accepting_state(bool is_livelock_accepting_state)
  {
    is_livelock_accepting_state_ = is_livelock_accepting_state;
  }

  void
  state_ta_explicit::set_initial_state(bool is_initial_state)
  {
    is_initial_state_ = is_initial_state;
  }

  int
  state_ta_explicit::compare(const spot::state* other) const
  {
    const state_ta_explicit* o = dynamic_cast<const state_ta_explicit*> (other);
    assert(o);

    int compare_value = tgba_state_->compare(o->tgba_state_);

    if (compare_value != 0)
      return compare_value;

    return tgba_condition_.id() - o->tgba_condition_.id();
  }

  size_t
  state_ta_explicit::hash() const
  {
    return wang32_hash(tgba_state_->hash()) ^ wang32_hash(tgba_condition_.id());
  }

  state_ta_explicit*
  state_ta_explicit::clone() const
  {
    return new state_ta_explicit(*this);
  }

  sscc_stack::connected_component::connected_component(int i)
  {
    index = i;
    is_accepting = false;
    is_initial = false;
  }

  sscc_stack::connected_component&
  sscc_stack::top()
  {
    return s.front();
  }

  const sscc_stack::connected_component&
  sscc_stack::top() const
  {
    return s.front();
  }

  void
  sscc_stack::pop()
  {
    // assert(rem().empty());
    s.pop_front();
  }

  void
  sscc_stack::push(int index)
  {
    s.push_front(connected_component(index));
  }

  std::list<state*>&
  sscc_stack::rem()
  {
    return top().rem;
  }

  size_t
  sscc_stack::size() const
  {
    return s.size();
  }

  bool
  sscc_stack::empty() const
  {
    return s.empty();
  }

  ////////////////////////////////////////
  // ta_explicit


  ta_explicit::ta_explicit(const tgba* tgba_) :
    tgba_(tgba_)
  {
  }

  ta_explicit::~ta_explicit()
  {
    ta::states_set_t::iterator it;
    for (it = states_set_.begin(); it != states_set_.end(); it++)
      {
        const state_ta_explicit* s = dynamic_cast<const state_ta_explicit*> (*it);
        state_ta_explicit::transitions* trans = s->get_transitions();
        state_ta_explicit::transitions::iterator it_trans;
        // We don't destroy the transitions in the state's destructor because
        // they are not cloned.
        for (it_trans = trans->begin(); it_trans != trans->end(); it_trans++)
          {
            delete *it_trans;
          }
        delete trans;
        delete s->get_tgba_state();
        delete s;
      }

  }

  state_ta_explicit*
  ta_explicit::add_state(state_ta_explicit* s)
  {
    std::pair<ta::states_set_t::iterator, bool> add_state_to_ta =
        states_set_.insert(s);

    if (is_initial_state(*add_state_to_ta.first))
      initial_states_set_.insert(*add_state_to_ta.first);

    return dynamic_cast<state_ta_explicit*> (*add_state_to_ta.first);

  }

  state_ta_explicit*
  ta_explicit::add_initial_state(state_ta_explicit* s)
  {
    s->set_initial_state(true);

    return add_state(s);

  }

  void
  ta_explicit::create_transition(state_ta_explicit* source, bdd condition, state_ta_explicit* dest)
  {
    state_ta_explicit::transition* t = new state_ta_explicit::transition;
    t->dest = dest;
    t->condition = condition;
    source->add_transition(t);

  }

  const ta::states_set_t*
  ta_explicit::get_initial_states_set() const
  {
    return &initial_states_set_;

  }

  bdd
  ta_explicit::get_state_condition(const spot::state* initial_state) const
  {
    const state_ta_explicit* sta = dynamic_cast<const state_ta_explicit*> (initial_state);
    return sta->get_tgba_condition();
  }

  bool
  ta_explicit::is_accepting_state(const spot::state* s) const
  {
    const state_ta_explicit* sta = dynamic_cast<const state_ta_explicit*> (s);
    return sta->is_accepting_state();
  }

  bool
  ta_explicit::is_initial_state(const spot::state* s) const
  {
    const state_ta_explicit* sta = dynamic_cast<const state_ta_explicit*> (s);
    return sta->is_initial_state();
  }

  bool
  ta_explicit::is_livelock_accepting_state(const spot::state* s) const
  {
    const state_ta_explicit* sta = dynamic_cast<const state_ta_explicit*> (s);
    return sta->is_livelock_accepting_state();
  }

  ta_succ_iterator*
  ta_explicit::succ_iter(const spot::state* state) const
  {
    const state_ta_explicit* s = dynamic_cast<const state_ta_explicit*> (state);
    assert(s);
    return new ta_explicit_succ_iterator(s);
  }

  bdd_dict*
  ta_explicit::get_dict() const
  {
    return tgba_->get_dict();
  }

  const tgba*
  ta_explicit::get_tgba() const
  {
    return tgba_;
  }

  std::string
  ta_explicit::format_state(const spot::state* s) const
  {
    const state_ta_explicit* sta = dynamic_cast<const state_ta_explicit*> (s);
    assert(sta);
    return tgba_->format_state(sta->get_tgba_state()) + "\n"
        + bdd_format_formula(get_dict(), sta->get_tgba_condition());

  }

  void
  ta_explicit::delete_stuttering_transitions()
  {
    ta::states_set_t::iterator it;
    for (it = states_set_.begin(); it != states_set_.end(); it++)
      {

        const state_ta_explicit* source = dynamic_cast<const state_ta_explicit*> (*it);

        state_ta_explicit::transitions* trans = source->get_transitions();
        state_ta_explicit::transitions::iterator it_trans;

        for (it_trans = trans->begin(); it_trans != trans->end();)
          {
            if (source->get_tgba_condition()
                == ((*it_trans)->dest)->get_tgba_condition())
              {
                delete *it_trans;
                it_trans = trans->erase(it_trans);
              }
            else
              {
                it_trans++;
              }
          }
      }

  }

}