Awali
Another Weighted Automata library
partition_history.hh
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2022 Sylvain Lombardy, Victor Marsault, Jacques Sakarovitch
3 //
4 // Awali is a free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef AWALI_PARTITION_HISTORY_HH
18 # define AWALI_PARTITION_HISTORY_HH
19 
20 # include <map>
21 # include <set>
22 
24 
25 # include <stdexcept>
26 
27 namespace awali {
28  namespace sttc {
29 
30  //Make every state in relation with the set of states of another automaton
41  template <typename Autb>
42  class partition_history final : public history_base
43  {
44  public:
45  //the subsets of source states are std::set of states
46  using state_set_t = std::set<state_t>;
47 
48  private:
49  std::map<state_t, state_set_t> origins_;
50  Autb from_;
51 
52  public:
53  partition_history(const Autb& source)
54  : from_(source)
55  {}
56 
58  history_kind_t get_nature() const override
59  {
61  }
62 
63  bool has_history(state_t s) const override {
64  return (origins_.find(s)!=origins_.end());
65  }
66 
67  bool remove_history(state_t s) override {
68  return origins_.erase(s);
69  }
70 
71  std::ostream&
72  print_state_name(state_t s, std::ostream& o,
73  const std::string& fmt) const override
74  {
75  const auto& set = origins_.at(s);
76  const char* separator = "{";
77  for (auto origin_state : set)
78  {
79  o << separator;
80  from_->print_state_history(origin_state , o, fmt);
81  separator = ", ";
82  }
83  return o << "}";
84  }
85 
87  const std::map<state_t, state_set_t>& origins() const
88  {
89  return origins_;
90  }
91 
93  void
95  {
96  origins_[s] = set;
97  }
98 
103  throw std::runtime_error("Origin state not available");
104  }
105 
106  std::vector<state_t> get_state_set(state_t s) override {
107  std::vector<state_t> v(origins_[s].begin(),origins_[s].end());
108  return v;
109  }
110 
111  }; // class
112 
113 }}//end of ns awali::stc
114 
115 #endif // !AWALI_PARTITION_HISTORY_HH
base type for history of automata
Definition: history.hh:40
specialisation of history_base
Definition: partition_history.hh:43
std::ostream & print_state_name(state_t s, std::ostream &o, const std::string &fmt) const override
Definition: partition_history.hh:72
void add_state(state_t s, const state_set_t &set)
set the history of state s
Definition: partition_history.hh:94
bool has_history(state_t s) const override
Definition: partition_history.hh:63
const std::map< state_t, state_set_t > & origins() const
map between states of the automaton and subsets of states of the source
Definition: partition_history.hh:87
state_t get_state(state_t) override
unsupported method : use get_state_set
Definition: partition_history.hh:102
history_kind_t get_nature() const override
Definition: partition_history.hh:58
partition_history(const Autb &source)
Definition: partition_history.hh:53
std::set< state_t > state_set_t
Definition: partition_history.hh:46
bool remove_history(state_t s) override
Definition: partition_history.hh:67
std::vector< state_t > get_state_set(state_t s) override
Definition: partition_history.hh:106
history_kind_t
The different kinds of history.
Definition: enums.hh:178
@ PARTITION
The state is a set of states of another automaton.
Main namespace of Awali.
Definition: ato.hh:22
unsigned state_t
Definition: types.hh:21