nra2nba.cc 4.28 KB
Newer Older
1
2
// -*- coding: utf-8 -*-
// Copyright (C) 2013, 2014 Laboratoire de Recherche et Développement de
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
// 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 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 "public.hh"
#include "tgbaalgos/reachiter.hh"
#include "tgbaalgos/sccfilter.hh"
#include "ltlast/constant.hh"

namespace spot
{
  namespace
  {
    // Christof Löding's Diploma Thesis: Methods for the
    // Transformation of ω-Automata: Complexity and Connection to
    // Second Order Logic.  Section 3.4.3: Rabin to Büchi.
    //
33
34
35
    // However beware that the {...,(Ei,Fi),...} pairs used by Löding
    // are reversed compared to the {...,(Li,Ui),...} pairs used by
    // several other people.  We have Ei=Ui and Fi=Li.
36
37
38
    class nra_to_nba_worker: public tgba_reachable_iterator_depth_first
    {
    public:
39
40
      // AUT is the automate we iterate on, while A is the automaton
      // we read the acceptance conditions from.  Separating the two
41
      // makes its possible to mask AUT, as needed in dra_to_ba().
42
43
      nra_to_nba_worker(const dstar_aut* a, const tgba* aut):
	tgba_reachable_iterator_depth_first(aut),
44
	out_(new tgba_digraph(aut->get_dict())),
45
46
47
48
	d_(a),
	num_states_(a->aut->num_states())
      {
	bdd_dict* bd = out_->get_dict();
49
	bd->register_all_variables_of(aut, out_);
50
51
52
53
54

	// Invent a new acceptance set for the degeneralized automaton.
	int accvar =
	  bd->register_acceptance_variable(ltl::constant::true_instance(),
					   out_);
55
56
	out_->set_bprop(tgba_digraph::StateBasedAcc);

57
58
	acc_ = bdd_ithvar(accvar);
	out_->set_acceptance_conditions(acc_);
59
60
61
62
63
	out_->new_states(num_states_ * (d_->accpair_count + 1));

	auto i = aut->get_init_state();
	out_->set_init_state(a->aut->state_number(i));
	i->destroy();
64
65
      }

66
      tgba_digraph*
67
68
69
70
71
72
73
74
75
76
      result()
      {
	return out_;
      }

      void
      process_link(const state* sin, int,
		   const state* sout, int,
		   const tgba_succ_iterator* si)
      {
77
78
	int in = d_->aut->state_number(sin);
	int out = d_->aut->state_number(sout);
79

80
81
	bdd cond = si->current_condition();
	out_->new_transition(in, out, cond);
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

	// Create one clone of the automaton per accepting pair,
	// removing states from the Ui part of the (Li, Ui) pairs.
	// (Or the Ei part of Löding's (Ei, Fi) pairs.)
	bitvect& l = d_->accsets->at(2 * in);
	bitvect& u = d_->accsets->at(2 * in + 1);
	for (size_t i = 0; i < d_->accpair_count; ++i)
	  {
	    int shift = num_states_ * (i + 1);
	    // In the Ui set. (Löding's Ei set.)
	    if (!u.get(i))
	      {
		// Transition t1 is a non-deterministic jump
		// from the original automaton to the i-th clone.
		//
		// Transition t2 constructs the clone.
		//
		// Löding creates transition t1 regardless of the
		// acceptance set.  We restrict it to the non-Li
		// states.  Both his definition and this
		// implementation create more transitions than needed:
		// we do not need more than one transition per
		// accepting cycle.
105
		out_->new_transition(in, out + shift, cond);
106

107
108
109
110
		bdd acc = bddfalse;
		if (l.get(i))	// In the Li set. (Löding's Fi set.)
		  acc = acc_;
		out_->new_transition(in + shift, out + shift, cond, acc);
111
112
113
114
115
	      }
	  }
      }

    protected:
116
      tgba_digraph* out_;
117
118
119
120
121
122
123
      const dstar_aut* d_;
      size_t num_states_;
      bdd acc_;
    };

  }

124
125
126
  // In dra_to_dba() we call this function with a second argument
  // that is a masked version of nra->aut.
  SPOT_LOCAL
127
  tgba_digraph* nra_to_nba(const dstar_aut* nra, const tgba* aut)
128
129
  {
    assert(nra->type == Rabin);
130
    nra_to_nba_worker w(nra, aut);
131
    w.run();
132
133
    auto res1 = w.result();
    auto res2 = scc_filter_states(res1);
134
135
136
137
138
    delete res1;
    return res2;
  }

  SPOT_API
139
  tgba_digraph* nra_to_nba(const dstar_aut* nra)
140
141
  {
    return nra_to_nba(nra, nra->aut);
142
143
144
  }

}