Awali
Another Weighted Automata library
single_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_SINGLE_HISTORY_HH
18 # define AWALI_SINGLE_HISTORY_HH
19 
20 # include <deque>
21 # include <iostream>
22 # include <map>
23 # include <utility>
24 
26 #include <awali/sttc/ctx/traits.hh>
27 #include <awali/sttc/misc/map.hh> // has
29 # include <stdexcept>
30 
31 namespace awali {
32  namespace sttc {
33 
34  /*------------------------------.
35  | single_history<Aut, Autb>. |
36  `------------------------------*/
48  template <typename Autb>
50  {
51  public:
53  history_kind_t get_nature() const override
54  {
56  }
57 
58  single_history(const Autb& source) : from_(source)
59  {}
60 
62  return *(from_->history());
63  }
64 
65  std::ostream&
66  print_state_name(state_t s, std::ostream& o,
67  const std::string& fmt) const override
68  {
69  //o << '>';
70  from_->print_state_history(origins_[s],o,fmt);
71  return o;
72  }
73 
74 
76  const std::map<state_t, state_t>& origins() const
77  {
78  return origins_;
79  }
80 
81  bool has_history(state_t s) const override {
82  return (origins_.find(s)!=origins_.end());
83  }
84 
85  bool remove_history(state_t s) override {
86  return origins_.erase(s);
87  };
88 
90  void
91  add_state(state_t s,const state_t& sb)
92  {
93  origins_[s] = sb;
94  }
95 
96 
97  state_t get_state(state_t s) override {
98  return origins_[s];
99  }
100 
104  std::vector<state_t> get_state_set(state_t) override {
105  throw std::runtime_error("Origin state set not available");
106  }
107 
108  private:
109  // Origin automaton, supplied at construction time.
110  Autb from_;
111  mutable std::map<state_t, state_t> origins_;
112  };
113  }
114 }//end of ns awali::stc
115 
116 #endif // !AWALI_SINGLE_HISTORY_HH
base type for history of automata
Definition: history.hh:40
specialisation of history_base
Definition: single_history.hh:50
const history_base & source_history()
Definition: single_history.hh:61
const std::map< state_t, state_t > & origins() const
map between states and states of the source automaton
Definition: single_history.hh:76
single_history(const Autb &source)
Definition: single_history.hh:58
void add_state(state_t s, const state_t &sb)
set the history of state s
Definition: single_history.hh:91
state_t get_state(state_t s) override
Definition: single_history.hh:97
std::vector< state_t > get_state_set(state_t) override
unsupported method : use get_state
Definition: single_history.hh:104
history_kind_t get_nature() const override
Definition: single_history.hh:53
bool has_history(state_t s) const override
Definition: single_history.hh:81
bool remove_history(state_t s) override
Definition: single_history.hh:85
std::ostream & print_state_name(state_t s, std::ostream &o, const std::string &fmt) const override
Definition: single_history.hh:66
history_kind_t
The different kinds of history.
Definition: enums.hh:178
@ SINGLE
The states comes from a single state.
Main namespace of Awali.
Definition: ato.hh:22
unsigned state_t
Definition: types.hh:21