strength.cc 2.85 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
    template <bool terminal, bool set = false>
    bool is_type_automaton(const twa_graph_ptr& aut, scc_info* si)
31
32
33
34
35
36
    {
      // 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
      bool is_weak = true;
      bool is_term = true;
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
      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)
		    {
58
		      is_weak = false;
59
60
61
62
63
		      goto exit;
		    }
		}
	  if (terminal && si->is_accepting_scc(i) && !is_complete_scc(*si, i))
	    {
64
65
66
	      is_term = false;
	      if (!set)
		break;
67
68
69
70
71
	    }
	}
    exit:
      if (need_si)
	delete si;
72
73
74
75
76
77
78
      if (set)
	{
	  if (terminal)
	    aut->prop_terminal(is_term && is_weak);
	  aut->prop_weak(is_weak);
	}
      return is_weak && is_term;
79
80
    }
  }
81

82
83
84
  bool
  is_terminal_automaton(const const_twa_graph_ptr& aut, scc_info* si)
  {
85
86
87
    return (aut->prop_terminal() ||
	    is_type_automaton<true>(std::const_pointer_cast<twa_graph>(aut),
				    si));
88
  }
89

90
91
92
  bool
  is_weak_automaton(const const_twa_graph_ptr& aut, scc_info* si)
  {
93
94
95
96
97
98
99
100
    return (aut->prop_weak() ||
	    is_type_automaton<false>(std::const_pointer_cast<twa_graph>(aut),
				     si));
  }

  void check_strength(const twa_graph_ptr& aut, scc_info* si)
  {
    is_type_automaton<true, true>(aut, si);
101
102
  }

103
  bool is_safety_mwdba(const const_twa_graph_ptr& aut)
104
  {
105
    if (!(aut->acc().is_buchi() || aut->acc().is_tt()))
106
107
108
      throw std::runtime_error
	("is_safety_mwdba() should be called on a Buchi automaton");

109
    for (auto& t: aut->edges())
110
111
      if (!aut->acc().accepting(t.acc))
	return false;
112
    return true;
113
  }
114
115
116
117



}