Awali
Another Weighted Automata library
ratexp_history.hh
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2021 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_RATEXP_HISTORY_HH
18 # define AWALI_RATEXP_HISTORY_HH
19 
20 # include <string>
21 
23 #include <awali/sttc/misc/map.hh>
24 #include <awali/sttc/misc/stream.hh> // format
27 
28 namespace awali {
29  namespace sttc {
30 
31  /*-------------------.
32  | ratexp_automaton. |
33  `-------------------*/
34  //Make every state in relation with a rational expression
47  template <typename RatExpSet>
48  class ratexp_history : public history_base {
49  public:
50  using ratexpset_t = RatExpSet;
51  using ratexp_t = typename ratexpset_t::value_t;
52 
53  private:
54  std::map<state_t, ratexp_t> origins_;
55  ratexpset_t rs_;
56  public:
58  : rs_(rs)
59  {}
60 
63  {
65  }
66 
67  std::ostream&
68  print_state_name(state_t s, std::ostream& o,
69  const std::string& fmt) const
70  {
71  auto i = origins().find(s);
72  o << str_escape(format(rs_, i->second, fmt));
73  return o;
74  }
75 
77  const std::map<state_t, ratexp_t>& origins() const
78  {
79  return origins_;
80  }
81 
83  origins_.erase(s);
84  return true;
85  };
86 
87  bool has_history(state_t s) const {
88  return (origins_.find(s)!=origins_.end());
89  }
90 
92  void
93  add_state(state_t s,const ratexp_t& expr)
94  {
95  origins_[s] = expr;
96  }
97 
99  return origins_[s];
100  }
101 
106  throw std::runtime_error("Origin state not available");
107  }
108 
112  std::vector<state_t> get_state_set(state_t s) {
113  throw std::runtime_error("Origin state set not available");
114  }
115  };
116 
117  }
118 }//end of ns awali::stc
119 
120 #endif // !AWALI_RATEXP_HISTORY_HH
base type for history of automata
Definition: history.hh:40
specialisation of history_base
Definition: ratexp_history.hh:48
typename ratexpset_t::value_t ratexp_t
Definition: ratexp_history.hh:51
std::ostream & print_state_name(state_t s, std::ostream &o, const std::string &fmt) const
Definition: ratexp_history.hh:68
RatExpSet ratexpset_t
Definition: ratexp_history.hh:50
bool remove_history(state_t s)
Definition: ratexp_history.hh:82
ratexp_history(const ratexpset_t &rs)
Definition: ratexp_history.hh:57
const std::map< state_t, ratexp_t > & origins() const
map between states and rational expressions
Definition: ratexp_history.hh:77
history_kind_t get_nature() const
Definition: ratexp_history.hh:62
std::vector< state_t > get_state_set(state_t s)
unsupported method : use get_ratexp
Definition: ratexp_history.hh:112
const ratexp_t & get_ratexp(state_t s)
Definition: ratexp_history.hh:98
bool has_history(state_t s) const
Definition: ratexp_history.hh:87
state_t get_state(state_t s)
unsupported method : use get_ratexp
Definition: ratexp_history.hh:105
void add_state(state_t s, const ratexp_t &expr)
set the history of state s
Definition: ratexp_history.hh:93
history_kind_t
The different kinds of history.
Definition: enums.hh:176
@ RATEXP
The state comes from a rational expression.
std::ostream & str_escape(std::ostream &os, const int c)
Definition: escape.hh:30
auto format(const ValueSet &vs, const typename ValueSet::value_t &v, Args &&... args) -> std::string
Format v via vs.print.
Definition: stream.hh:109
Main namespace of Awali.
Definition: ato.hh:22
unsigned state_t
Definition: types.hh:21