accmap.hh 3.09 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// -*- coding: utf-8 -*-
// Copyright (C) 2014  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
// 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/>.

20
#pragma once
21

22
#include <bddx.h>
23
24
25
#include <spot/misc/hash.hh>
#include <spot/tl/formula.hh>
#include <spot/twa/twagraph.hh>
26
27
28

namespace spot
{
29
  class acc_mapper_common
30
  {
31
  protected:
32
    bdd_dict_ptr dict_;
33
    twa_graph_ptr aut_;
34

35
    acc_mapper_common(const twa_graph_ptr& aut)
36
      : dict_(aut->get_dict()), aut_(aut)
37
38
    {
    }
39
40
41
42
  };

  class acc_mapper_string: public acc_mapper_common
  {
43
    std::unordered_map<std::string, unsigned> map_;
44
45

  public:
46
    acc_mapper_string(const twa_graph_ptr& aut)
47
      : acc_mapper_common(aut)
48
49
50
    {
    }

51
52
53
54
55
56
    // Declare an acceptance name.
    bool declare(const std::string& name)
    {
      auto i = map_.find(name);
      if (i != map_.end())
	return true;
57
      auto v = aut_->acc().add_set();
58
59
60
61
      map_[name] = v;
      return true;
    }

62
    std::pair<bool, acc_cond::mark_t> lookup(std::string name) const
63
64
65
    {
       auto p = map_.find(name);
       if (p == map_.end())
66
67
	 return std::make_pair(false, 0U);
       return std::make_pair(true, aut_->acc().marks({p->second}));
68
    }
69
70
  };

71
72
73

  // The acceptance sets are named using count consecutive integers.
  class acc_mapper_consecutive_int: public acc_mapper_common
74
75
  {
  public:
76
    acc_mapper_consecutive_int(const twa_graph_ptr& aut, unsigned count)
77
      : acc_mapper_common(aut)
78
    {
79
80
      std::vector<unsigned> vmap(count);
      aut->acc().add_sets(count);
81
    }
82

83
    std::pair<bool, acc_cond::mark_t> lookup(unsigned n)
84
    {
85
86
      if (n < aut_->acc().num_sets())
	return std::make_pair(true, aut_->acc().marks({n}));
87
      else
88
	return std::make_pair(false, 0U);
89
90
91
92
93
94
95
96
    }
  };

  // The acceptance sets are named using count integers, but we do not
  // assume the numbers are necessarily consecutive.
  class acc_mapper_int: public acc_mapper_consecutive_int
  {
    unsigned used_;
97
    std::map<unsigned, acc_cond::mark_t> map_;
98
99

  public:
100
    acc_mapper_int(const twa_graph_ptr& aut, unsigned count)
101
      : acc_mapper_consecutive_int(aut, count), used_(0)
102
103
104
    {
    }

105
    std::pair<bool, acc_cond::mark_t> lookup(unsigned n)
106
107
108
109
    {
       auto p = map_.find(n);
       if (p != map_.end())
	 return std::make_pair(true, p->second);
110
       if (used_ < aut_->acc().num_sets())
111
	 {
112
	   auto res = aut_->acc().marks({used_++});
113
114
115
	   map_[n] = res;
	   return std::make_pair(true, res);
	 }
116
       return std::make_pair(false, 0U);
117
    }
118
119
  };
}