17 #ifndef VCSN_ALGORITHMS_UNIVERSAL_HXX
18 # define VCSN_ALGORITHMS_UNIVERSAL_HXX
24 # include <vaucanson/boolean_automaton.hh>
29 # include <vaucanson/misc/usual_macros.hh>
33 namespace universal_internal {
36 template<
typename Set>
37 Set intersection_structure(
const Set& set1,
const Set& set2)
40 std::insert_iterator<Set> i(tmp, tmp.begin());
41 std::set_intersection(set1.begin(), set1.end(),
42 set2.begin(), set2.end(),
48 template<
typename Set>
49 std::set<Set> intersection_closure(
const std::set<Set>& s)
51 std::set<Set> tmp = s;
52 std::set<Set> ret = s;
56 for_all_const_(std::set<Set>, s1, tmp)
57 for_all_const_(std::set<Set>, s2, tmp)
58 ret.insert(intersection_structure(*s1, *s2));
59 } while (ret.size() != tmp.size());
64 template<typename K, typename V>
65 std::set<V> image(const std::map<K,V>& m)
68 for(
typename std::map<K,V>::const_iterator a=m.begin(); a!= m.end(); ++a)
69 ret.insert(a->second);
74 template <
class Container1,
class Container2>
75 bool includes(
const Container1& set1,
const Container2& set2)
77 return std::includes(set2.begin(), set2.end(),
78 set1.begin(), set1.end());
84 template<
typename A,
typename AI>
85 void do_universal(
const AutomataBase<A>&,
86 const Element<A,AI>& a,
89 typedef Element<A, AI> Auto;
90 AUTOMATON_TYPES(Auto);
91 AUTOMATON_FREEMONOID_TYPES(Auto);
93 typedef std::set<std::set<hstate_t> > pstate_t;
94 typedef std::set<hstate_t> state_set_t;
95 typedef std::map<hstate_t, state_set_t> map_t;
97 using namespace universal_internal;
108 hstate_t i = *automaton.initial().begin();
119 pstate_t transp_states = image(origin);
122 pstate_t univers_states(intersection_closure(transp_states));
128 for_all_const_(pstate_t, s, univers_states)
131 hstate_t new_s = u.add_state();
132 subset_label[new_s] = *s;
134 if (s->find(i) != s->end())
135 u.set_initial(new_s);
137 if (includes(*s, automaton.final()))
144 for_all_letters(a, u.series().monoid().alphabet())
147 std::set<hstate_t> delta_ret;
148 for_all_const_(state_set_t, s, subset_label[*x])
153 for (
typename automaton_t::delta_iterator dst(automaton.value(), *s);
154 ! dst.done(); dst.next())
156 monoid_elt_t w(automaton.series_of(*dst).structure().monoid(), *a);
157 if (automaton.series_of(*dst).get(w)
158 != automaton.series().semiring().wzero_)
161 delta_ret.insert(automaton.dst_of(*dst));
174 if (includes(delta_ret, subset_label[*y]))
175 u.add_letter_transition(*x, *y, *a);
179 template<
typename A,
typename AI>
191 #endif // !VCSN_ALGORITHMS_UNIVERSAL_HXX