nra2nba.cc 4.04 KB
Newer Older
1
// -*- coding: utf-8 -*-
2 3
// Copyright (C) 2013, 2014, 2015 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
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
//
// 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
      // AUT is the automaton we iterate on, while A is the automaton
39
      // 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_twa_ptr aut):
42
	tgba_reachable_iterator_depth_first(aut),
43
	out_(make_twa_graph(aut->get_dict())),
44 45 46
	d_(a),
	num_states_(a->aut->num_states())
      {
47
	out_->copy_ap_of(aut);
48
	out_->set_buchi();
49
	out_->prop_state_based_acc();
50
	out_->new_states(num_states_ * (d_->accpair_count + 1));
51 52 53 54 55
	// This converts the initial state of aut (not a->aut) into a
	// state number in a->aut.
	auto i = aut->get_init_state();
	out_->set_init_state(a->aut->state_number(i));
	i->destroy();
56 57
      }

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

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

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

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

99 100 101 102
		// 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));
103 104 105 106 107
	      }
	  }
      }

    protected:
108
      twa_graph_ptr out_;
109
      const_dstar_aut_ptr d_;
110 111 112 113 114
      size_t num_states_;
    };

  }

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

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

}