nra2nba.cc 3.99 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
// 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"

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.
    //
32
33
34
    // 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.
35
36
37
    class nra_to_nba_worker: public tgba_reachable_iterator_depth_first
    {
    public:
38
39
      // AUT is the automate we iterate on, while A is the automaton
      // we read the acceptance conditions from.  Separating the two
40
      // makes its possible to mask AUT, as needed in dra_to_ba().
41
      nra_to_nba_worker(const const_dstar_aut_ptr& a, const_tgba_ptr aut):
42
	tgba_reachable_iterator_depth_first(aut),
43
	out_(make_tgba_digraph(aut->get_dict())),
44
45
46
	d_(a),
	num_states_(a->aut->num_states())
      {
47
	out_->copy_ap_of(aut);
48
	out_->set_single_acceptance_set();
49
	out_->prop_state_based_acc();
50
51
52
53
54
	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();
55
56
      }

57
      tgba_digraph_ptr
58
59
60
61
62
63
64
65
66
67
      result()
      {
	return out_;
      }

      void
      process_link(const state* sin, int,
		   const state* sout, int,
		   const tgba_succ_iterator* si)
      {
68
69
	int in = d_->aut->state_number(sin);
	int out = d_->aut->state_number(sout);
70

71
72
	bdd cond = si->current_condition();
	out_->new_transition(in, out, cond);
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

	// 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.
96
		out_->new_transition(in, out + shift, cond);
97

98
99
100
101
		// A transition is accepting if it is in the Li
		// set. (Löding's Fi set.)
		out_->new_acc_transition(in + shift, out + shift, cond,
					 l.get(i));
102
103
104
105
106
	      }
	  }
      }

    protected:
107
108
      tgba_digraph_ptr out_;
      const_dstar_aut_ptr d_;
109
110
111
112
113
      size_t num_states_;
    };

  }

114
115
116
  // In dra_to_dba() we call this function with a second argument
  // that is a masked version of nra->aut.
  SPOT_LOCAL
117
118
  tgba_digraph_ptr nra_to_nba(const const_dstar_aut_ptr& nra,
			      const const_tgba_ptr& aut)
119
120
  {
    assert(nra->type == Rabin);
121
    nra_to_nba_worker w(nra, aut);
122
    w.run();
123
    return scc_filter_states(w.result());
124
125
126
  }

  SPOT_API
127
  tgba_digraph_ptr nra_to_nba(const const_dstar_aut_ptr& nra)
128
129
  {
    return nra_to_nba(nra, nra->aut);
130
131
132
  }

}