twa.cc 3.15 KB
Newer Older
1
// -*- coding: utf-8 -*-
2
// Copyright (C) 2011, 2014, 2015 Laboratoire de Recherche et Developpement de
3
// l'EPITA (LRDE).
4
// Copyright (C) 2003, 2004, 2005  Laboratoire d'Informatique de Paris 6 (LIP6),
5
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
6
7
8
9
10
11
// et Marie Curie.
//
// 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
12
// the Free Software Foundation; either version 3 of the License, or
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
13
14
15
16
17
18
19
20
// (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
21
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
22

23
24
#include "twa.hh"
#include "twagraph.hh"
25
26
#include "twaalgos/gtec/gtec.hh"
#include "twaalgos/remfin.hh"
27
#include <utility>
28
29
30

namespace spot
{
31
  twa::twa(const bdd_dict_ptr& d)
32
    : iter_cache_(nullptr),
33
      dict_(d),
34
      last_support_conditions_input_(0)
35
  {
36
    props = 0U;
37
    bddaps_ = bddtrue;
38
  }
39

40
  twa::~twa()
41
  {
42
43
    for (auto* ap: aps_)
      ap->destroy();
44
45
    if (last_support_conditions_input_)
      last_support_conditions_input_->destroy();
46
    delete iter_cache_;
47
    release_named_properties();
48
  }
49
50

  bdd
51
  twa::support_conditions(const state* state) const
52
  {
53
    if (!last_support_conditions_input_
54
55
	|| last_support_conditions_input_->compare(state) != 0)
      {
56
	last_support_conditions_output_ = compute_support_conditions(state);
57
58
	if (last_support_conditions_input_)
	  last_support_conditions_input_->destroy();
59
60
61
62
63
	last_support_conditions_input_ = state->clone();
      }
    return last_support_conditions_output_;
  }

64
  state*
65
  twa::project_state(const state* s,
66
		      const const_twa_ptr& t) const
67
  {
68
    if (t.get() == this)
69
70
71
72
      return s->clone();
    return 0;
  }

73
  std::string
74
  twa::transition_annotation(const twa_succ_iterator*) const
75
76
77
78
  {
    return "";
  }

79
  bool
80
  twa::is_empty() const
81
82
83
84
  {
    // FIXME: This should be improved based on properties of the
    // automaton.  For instance we do not need couvreur99 is we know
    // the automaton is weak.
85
86
87
    auto a = shared_from_this();
    if (a->acc().uses_fin_acceptance())
      {
88
	auto aa = std::dynamic_pointer_cast<const twa_graph>(a);
89
	if (!aa)
90
	  aa = make_twa_graph(a, prop_set::all());
91
92
93
	a = remove_fin(aa);
      }
    return !couvreur99(a)->check();
94
95
  }

96
  void
97
98
  twa::set_named_prop(std::string s,
		      void* val, std::function<void(void*)> destructor)
99
100
101
102
103
104
105
106
107
108
109
110
  {
    auto p = named_prop_.emplace(std::piecewise_construct,
				 std::forward_as_tuple(s),
				 std::forward_as_tuple(val, destructor));
    if (!p.second)
      {
	p.first->second.second(p.first->second.first);
	p.first->second = std::make_pair(val, destructor);
      }
  }

  void*
111
  twa::get_named_prop_(std::string s) const
112
113
114
115
116
117
118
119
120
121
  {
    auto i = named_prop_.find(s);
    if (i == named_prop_.end())
      return nullptr;
    return i->second.first;
  }




122
}