strength.cc 2.46 KB
Newer Older
1
// -*- coding: utf-8 -*-
2
3
// Copyright (C) 2010, 2011, 2013, 2014, 2015 Laboratoire de Recherche
// et Développement de l'Epita (LRDE)
4
5
6
7
8
//
// 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
9
// the Free Software Foundation; either version 3 of the License, or
10
11
12
13
14
15
16
17
// (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
18
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
19

20
#include "strength.hh"
21
#include "misc/hash.hh"
22
#include "isweakscc.hh"
23
#include <deque>
24
25
26

namespace spot
{
27
  namespace
28
  {
29
30
31
32
33
34
35
36
    template <bool terminal>
    bool is_type_automaton(const const_twa_graph_ptr& aut, scc_info* si)
    {
      // Create an scc_info if the user did not give one to us.
      bool need_si = !si;
      if (need_si)
	si = new scc_info(aut);
      si->determine_unknown_acceptance();
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
      bool result = true;
      unsigned n = si->scc_count();
      for (unsigned i = 0; i < n; ++i)
	{
	  if (si->is_trivial(i))
	    continue;
	  bool first = true;
	  acc_cond::mark_t m = 0U;
	  for (auto src: si->states_of(i))
	    for (auto& t: aut->out(src))
	      if (si->scc_of(t.dst) == i)
		{
		  if (first)
		    {
		      first = false;
		      m = t.acc;
		    }
		  else if (m != t.acc)
		    {
		      result = false;
		      goto exit;
		    }
		}
	  if (terminal && si->is_accepting_scc(i) && !is_complete_scc(*si, i))
	    {
	      result = false;
	      break;
	    }
	}
    exit:
      if (need_si)
	delete si;
      return result;
    }
  }
73

74
75
76
77
78
  bool
  is_terminal_automaton(const const_twa_graph_ptr& aut, scc_info* si)
  {
    return aut->prop_terminal() || is_type_automaton<true>(aut, si);
  }
79

80
81
82
83
  bool
  is_weak_automaton(const const_twa_graph_ptr& aut, scc_info* si)
  {
    return aut->prop_weak() || is_type_automaton<false>(aut, si);
84
85
  }

86
  bool is_safety_mwdba(const const_twa_graph_ptr& aut)
87
  {
88
    if (!(aut->acc().is_buchi() || aut->acc().is_tt()))
89
90
91
      throw std::runtime_error
	("is_safety_mwdba() should be called on a Buchi automaton");

92
    for (auto& t: aut->edges())
93
94
      if (!aut->acc().accepting(t.acc))
	return false;
95
    return true;
96
  }
97
98
99
100



}