complete.cc 3.07 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
// -*- coding: utf-8 -*-
// Copyright (C) 2013 Laboratoire de Recherche et Développement
// de l'Epita.
//
// 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 3 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 this program.  If not, see <http://www.gnu.org/licenses/>.

#include "complete.hh"
#include "reachiter.hh"
#include "ltlast/constant.hh"

namespace spot
{

  namespace
  {
    class tgbacomplete_iter:
      public tgba_reachable_iterator_depth_first_stack
    {
      bdd_dict* dict_;
      tgba_explicit_number* out_;
      bdd addacc_;

      typedef state_explicit_number::transition trans;
    public:
      tgbacomplete_iter(const tgba* a)
	: tgba_reachable_iterator_depth_first_stack(a),
	  dict_(a->get_dict()),
	  out_(new tgba_explicit_number(dict_)),
	  addacc_(bddfalse)
      {
	dict_->register_all_variables_of(a, out_);

	if (a->number_of_acceptance_conditions() == 0)
	  {
	    const ltl::formula* t = ltl::constant::true_instance();
	    int accvar =
	      dict_->register_acceptance_variable(t, out_);
	    addacc_ = bdd_ithvar(accvar);
	    out_->set_acceptance_conditions(addacc_);
	  }
	else
	  {
	    out_->set_acceptance_conditions(a->all_acceptance_conditions());
	  }
      }

      tgba_explicit_number*
      result()
      {
	return out_;
      }

      void
      end()
      {
	out_->merge_transitions();
	// create a sink state if needed.
	if (out_->has_state(0))
	  {
	    trans* t = out_->create_transition(0, 0);
	    t->condition = bddtrue;
	  }
      }

      void process_state(const state*, int n,
			 tgba_succ_iterator* i)
      {
	// add a transition to a sink state if the state is not complete.
	bdd all = bddtrue;
83
84
85
86
87
88
89
	bdd acc = bddfalse;
	i->first();
	// In case the automaton use state-based acceptance, propagate
	// the acceptance of the first transition to the one we add.
	if (!i->done())
	  acc = i->current_acceptance_conditions();
	for (; !i->done(); i->next())
90
91
92
93
94
	  all -= i->current_condition();
	if (all != bddfalse)
	  {
	    trans* t = out_->create_transition(n, 0);
	    t->condition = all;
95
	    t->acceptance_conditions = acc | addacc_;
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
	  }
      }

      void
      process_link(const state*, int in,
		   const state*, int out,
		   const tgba_succ_iterator* si)
      {
	assert(in > 0);
	assert(out > 0);
	trans* t1 = out_->create_transition(in, out);

	t1->condition = si->current_condition();
	t1->acceptance_conditions =
	  si->current_acceptance_conditions() | addacc_;
      }

    };

  } // anonymous

  tgba_explicit_number* tgba_complete(const tgba* aut)
  {
    tgbacomplete_iter ci(aut);
    ci.run();
    return ci.result();
  }
}