dupexp.cc 3.05 KB
Newer Older
1
// -*- coding: utf-8 -*-
2
// Copyright (C) 2009, 2011, 2012, 2014 Laboratoire de Recherche et
3
// Développement de l'Epita (LRDE).
Guillaume Sadegh's avatar
Guillaume Sadegh committed
4
// Copyright (C) 2003, 2004 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
25
26
27
28
#include "dupexp.hh"
#include <sstream>
#include <string>
#include <map>
#include "reachiter.hh"

29
30
31
namespace spot
{
  namespace
32
  {
33
34
    template <class T>
    class dupexp_iter: public T
35
    {
36
37
    public:
      dupexp_iter(const tgba* a)
38
	: T(a), out_(new tgba_digraph(a->get_dict()))
39
      {
40
	out_->copy_acceptance_conditions_of(a);
41
	out_->copy_ap_of(a);
42
      }
43

44
      tgba_digraph*
45
46
47
48
      result()
      {
	return out_;
      }
49

50
51
52
      virtual void
      process_state(const state*, int n, tgba_succ_iterator*)
      {
53
	unsigned ns = out_->new_state();
54
55
56
57
58
	assert(ns == static_cast<unsigned>(n) - 1);
	(void)ns;
      }

      virtual void
59
60
      process_link(const state*, int in,
		   const state*, int out,
61
		   const tgba_succ_iterator* si)
62
      {
63
64
65
	out_->new_transition(in - 1, out - 1,
			     si->current_condition(),
			     si->current_acceptance_conditions());
66
      }
67

Thomas Badie's avatar
Thomas Badie committed
68
    protected:
69
      tgba_digraph* out_;
70
    };
71

Thomas Badie's avatar
Thomas Badie committed
72
73
74
75
    template <typename T>
    class dupexp_iter_save: public dupexp_iter<T>
    {
    public:
76
      dupexp_iter_save(const tgba* a, std::vector<const state*>& relation)
77
        : dupexp_iter<T>(a), relation_(relation)
Thomas Badie's avatar
Thomas Badie committed
78
79
80
      {
      }

81
82
      virtual void
      end()
Thomas Badie's avatar
Thomas Badie committed
83
      {
84
	relation_.resize(this->seen.size());
85
	for (auto s: this->seen)
86
	  relation_[s.second - 1] = const_cast<state*>(s.first);
Thomas Badie's avatar
Thomas Badie committed
87
88
      }

89
      std::vector<const state*>& relation_;
Thomas Badie's avatar
Thomas Badie committed
90
91
    };

92
  } // anonymous
93

94
  tgba_digraph*
95
96
97
98
99
100
101
  tgba_dupexp_bfs(const tgba* aut)
  {
    dupexp_iter<tgba_reachable_iterator_breadth_first> di(aut);
    di.run();
    return di.result();
  }

102
  tgba_digraph*
103
104
105
106
107
108
109
  tgba_dupexp_dfs(const tgba* aut)
  {
    dupexp_iter<tgba_reachable_iterator_depth_first> di(aut);
    di.run();
    return di.result();
  }

110
  tgba_digraph*
111
  tgba_dupexp_bfs(const tgba* aut, std::vector<const state*>& rel)
Thomas Badie's avatar
Thomas Badie committed
112
  {
113
    dupexp_iter_save<tgba_reachable_iterator_breadth_first> di(aut, rel);
Thomas Badie's avatar
Thomas Badie committed
114
115
116
117
    di.run();
    return di.result();
  }

118
  tgba_digraph*
119
  tgba_dupexp_dfs(const tgba* aut, std::vector<const state*>& rel)
Thomas Badie's avatar
Thomas Badie committed
120
  {
121
    dupexp_iter_save<tgba_reachable_iterator_depth_first> di(aut, rel);
Thomas Badie's avatar
Thomas Badie committed
122
123
124
    di.run();
    return di.result();
  }
125
}