acccompl.cc 2.35 KB
Newer Older
1
2
3
4
5
6
7
8
// -*- coding: utf-8 -*-
// Copyright (C) 2012 Laboratoire de Recherche et Developpement de
// 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
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
21
22
23

#include "acccompl.hh"

namespace spot
{
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
24
25
26
27
  // If ALL = a!b!c + !ab!c + !a!bc", the negation of ACC = a!b!c is
  // RES = bc.   We do that by computing ALL-ACC and enumerating
  // all positive variables in the remaining products.
  bdd acc_compl::complement(const bdd& acc)
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  {
    bdd_cache_t::const_iterator it = cache_.find(acc);
    if (it != cache_.end())
      return it->second;

    bdd res = bddtrue;
    bdd n = all_ - acc;

    while (n != bddfalse)
    {
      bdd cond = bdd_satone(n);
      bdd oldcond = cond;
      n -= cond;

      while (bdd_high(cond) == bddfalse)
        cond = bdd_low(cond);

      // Here we want to keep only the current one.
      // tmp is only useful to keep the value and cache it.
      bdd tmp = bdd_ithvar(bdd_var(cond));
      res &= tmp;
    }

    cache_[acc] = res;

    return res;
  }

Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
56
  bdd acc_compl::reverse_complement(const bdd& acc)
57
  {
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
58
59
    // We are sure that if we have no acceptance condition the result
    // is all_.
60
61
62
63
    if (acc == bddtrue)
      return all_;

    // Since we never cache a unique positive bdd, we can reuse the
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
64
65
66
    // same cache.  In fact the only kind of acc we will receive in
    // this method, are a conjunction of positive acceptance
    // conditions.  (i.e., "ab" and not "a!b + !ab")
67
68
69
70
71
72
73
74
    bdd_cache_t::const_iterator it = cache_.find(acc);
    if (it != cache_.end())
      return it->second;

    bdd res = all_;
    bdd cond = acc;
    while (cond != bddtrue)
    {
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
75
      res &= bdd_nithvar(bdd_var(cond));
76
77
78
79
80
81
82
83
84
      cond = bdd_high(cond);
    }

    cache_[acc] = res;

    return res;
  }

} // End namespace spot.