18 #ifndef VCSN_AUTOMATA_IMPLEMENTATION_BMIG_GRAPH_LETTERS_SPEC_HXX_
19 # define VCSN_AUTOMATA_IMPLEMENTATION_BMIG_GRAPH_LETTERS_SPEC_HXX_
21 # include <vaucanson/automata/implementation/bmig_graph_letters_spec.hh>
32 # define BMIGRAPH_TPARAM \
33 template <class WordValue, \
34 class SeriesValue, class Letter, class Tag, class GeometryCoords>
37 Graph<labels_are_letters, WordValue, bool, SeriesValue, Letter, Tag, GeometryCoords>
52 number_of_epsilon_(0),
67 BMIGRAPH::Graph (
unsigned initial_number_of_states,
69 : initial_bitset_(initial_number_of_states),
70 final_bitset_(initial_number_of_states),
71 number_of_epsilon_(0),
72 number_of_state_(initial_number_of_states),
73 states_(initial_number_of_states)
75 for (
unsigned i = 0; i < initial_number_of_states; ++i)
77 boost::shared_ptr<unsigned> p(
new unsigned(i));
83 BMIGRAPH::Graph (
const self_t& g)
86 initial_bitset_ = g.initial_bitset_;
87 final_bitset_ = g.final_bitset_;
88 number_of_epsilon_ = g.number_of_epsilon_;
89 number_of_state_ = g.number_of_state_;
94 typename geometry_t::transitions_geometry_map_t& map_transitions = geometry_.transitions();
95 map_transitions.clear();
97 states_.resize(g.number_of_state_);
98 for (
unsigned i = 0; i < g.number_of_state_; ++i)
100 boost::shared_ptr<unsigned> p(
new unsigned(i));
103 for (
typename graph_data_t::const_iterator i = g.graph_.begin();
106 graph_.insert(edge_data_t(states_[*i->from_],
109 for (initial_t::iterator it = g.initial_.begin(); it != g.initial_.end(); ++it)
110 initial_.insert(states_[**it]);
111 for (final_t::iterator it = g.final_.begin(); it != g.final_.end(); ++it)
112 final_.insert(states_[**it]);
114 # define VCSN_COPY_GEOMETRY(Type) \
116 typename geometry_t::Type##_geometry_map_t& map_##Type = geometry_.Type(); \
117 map_##Type.clear(); \
118 for (typename geometry_t::Type##_geometry_map_t::const_iterator i = g.geometry_.Type().begin(); \
119 i != g.geometry_.Type().end(); \
121 map_##Type[i->first] = i->second; \
123 VCSN_COPY_GEOMETRY(states)
124 VCSN_COPY_GEOMETRY(initials)
125 VCSN_COPY_GEOMETRY(finals)
126 # undef VCSN_COPY_GEOMETRY
128 for (
typename geometry_t::transitions_geometry_map_t::const_iterator i = g.geometry_.transitions().begin();
129 i != g.geometry_.transitions().end();
132 typename graph_data_t::const_iterator tmp = find_edge(states_[*i->first.value()->from_],
133 states_[*i->first.value()->to_],
134 i->first.value()->label_);
135 if (tmp != graph_.end())
136 map_transitions[htransition_t(tmp)] = i->second;
152 typename BMIGRAPH::self_t&
153 BMIGRAPH::operator= (
const self_t& g)
158 initial_bitset_ = g.initial_bitset_;
159 final_bitset_ = g.final_bitset_;
160 number_of_epsilon_ = g.number_of_epsilon_;
161 number_of_state_ = g.number_of_state_;
166 typename geometry_t::transitions_geometry_map_t& map_transitions = geometry_.transitions();
167 map_transitions.clear();
169 states_.resize(g.number_of_state_);
170 for (
unsigned i = 0; i < g.number_of_state_; ++i)
172 boost::shared_ptr<unsigned> p(
new unsigned(i));
175 for (
typename graph_data_t::const_iterator i = g.graph_.begin();
178 graph_.insert(edge_data_t(states_[*i->from_],
181 for (initial_t::iterator it = g.initial_.begin(); it != g.initial_.end(); ++it)
182 initial_.insert(states_[**it]);
183 for (final_t::iterator it = g.final_.begin(); it != g.final_.end(); ++it)
184 final_.insert(states_[**it]);
186 # define VCSN_COPY_GEOMETRY(Type) \
188 typename geometry_t::Type##_geometry_map_t& map_##Type = geometry_.Type(); \
189 map_##Type.clear(); \
190 for (typename geometry_t::Type##_geometry_map_t::const_iterator i = g.geometry_.Type().begin(); \
191 i != g.geometry_.Type().end(); \
193 map_##Type[i->first] = i->second; \
195 VCSN_COPY_GEOMETRY(states)
196 VCSN_COPY_GEOMETRY(initials)
197 VCSN_COPY_GEOMETRY(finals)
198 # undef VCSN_COPY_GEOMETRY
199 for (
typename geometry_t::transitions_geometry_map_t::const_iterator i = g.geometry_.transitions().begin();
200 i != g.geometry_.transitions().end();
203 typename graph_data_t::const_iterator tmp = find_edge(states_[*i->first.value()->from_],
204 states_[*i->first.value()->to_],
205 i->first.value()->label_);
206 if (tmp != graph_.end())
207 map_transitions[htransition_t(tmp)] = i->second;
217 typename BMIGRAPH::states_t
218 BMIGRAPH::states()
const
220 return misc::Support<states_data_t>(states_);
224 typename BMIGRAPH::edges_t
225 BMIGRAPH::edges()
const
227 return edges_t(graph_);
231 typename BMIGRAPH::initial_support_t
232 BMIGRAPH::initial ()
const
234 return initial_support_t(initial_);
238 typename BMIGRAPH::final_support_t
239 BMIGRAPH::final ()
const
241 return final_support_t(final_);
251 BMIGRAPH::has_state (
const hstate_t& s)
const
253 return s < states_.size();
257 typename BMIGRAPH::hstate_t
258 BMIGRAPH::add_state ()
260 initial_bitset_.append(
false);
261 final_bitset_.append(
false);
262 boost::shared_ptr<unsigned> p(
new unsigned(number_of_state_++));
264 states_.push_back(h);
269 typename BMIGRAPH::hstate_t
270 BMIGRAPH::get_state (
unsigned s)
const
272 precondition(s < states_.size());
273 return hstate_t(states_[s]);
278 BMIGRAPH::del_state (
const hstate_t& s)
280 precondition (has_state(s));
283 graph_.get<src>().erase(s.value());
284 graph_.get<dst>().erase(s.value());
286 if (number_of_state_ > 1 && s != (number_of_state_ - 1))
288 state_t lastone = states_.back();
289 states_[s] = lastone;
290 # define VCSN_UPDATE(Set) \
291 if (Set##bitset_[*lastone]) \
293 if (Set##bitset_[s]) \
294 Set.erase(s.value()); \
296 Set##bitset_[s] = true; \
300 if (Set##bitset_[s]) \
302 Set##bitset_[s] = false; \
303 Set.erase(s.value()); \
308 VCSN_UPDATE(initial_)
311 *lastone = *s.value();
315 initial_.erase(s.value());
316 final_.erase(s.value());
321 postcondition(states_.size() == number_of_state_);
322 initial_bitset_.resize(number_of_state_);
323 final_bitset_.resize(number_of_state_);
331 BMIGRAPH::set_initial (
const hstate_t& s,
332 const series_set_elt_value_t& v,
333 const series_set_elt_value_t& z)
335 precondition(has_state(s));
338 initial_.erase (s.value());
339 initial_bitset_[s] =
false;
343 initial_.insert (s.value());
344 initial_bitset_[s] =
true;
349 const typename BMIGRAPH::series_set_elt_value_t&
350 BMIGRAPH::get_initial(
const hstate_t& s,
const series_set_elt_value_t &)
const
352 precondition(has_state(s));
353 return initial_bitset_[s];
358 BMIGRAPH::is_initial(
const hstate_t& s,
const series_set_elt_value_t&)
const
360 precondition(has_state(s));
361 return initial_bitset_[s];
366 BMIGRAPH::clear_initial()
369 initial_bitset_.reset();
374 BMIGRAPH::set_final(
const hstate_t& s,
375 const series_set_elt_value_t& v,
376 const series_set_elt_value_t& z)
378 precondition(has_state(s));
381 final_.erase (s.value());
382 final_bitset_[s] =
false;
386 final_.insert (s.value());
387 final_bitset_[s] =
true;
392 const typename BMIGRAPH::series_set_elt_value_t&
393 BMIGRAPH::get_final(
const hstate_t& s,
const series_set_elt_value_t &)
const
395 precondition(has_state(s));
396 return final_bitset_[s];
401 BMIGRAPH::is_final(
const hstate_t& s,
const series_set_elt_value_t&)
const
403 precondition(has_state(s));
404 return final_bitset_[s];
409 BMIGRAPH::clear_final()
412 final_bitset_.reset();
421 BMIGRAPH::has_edge (
const hedge_t& h)
const
423 succ_range r = graph_.equal_range(boost::make_tuple(*h.value()->from_,
426 state_t to = h.value()->to_;
427 for (it = r.first; it != r.second && it->to_ != to; ++it)
430 return it != r.second;
434 typename BMIGRAPH::hedge_t
435 BMIGRAPH::add_edge (
const hstate_t& from,
const hstate_t& to,
const label_t& l)
437 return hedge_t (graph_.insert (edge_data_t (from.value(), to.value(), l)).first);
442 BMIGRAPH::del_edge (
const hedge_t& h)
444 precondition (has_edge(h));
445 graph_.erase(h.value());
453 typename BMIGRAPH::hstate_t
454 BMIGRAPH::src_of (
const hedge_t& h)
const
456 return hstate_t(h.value()->from_);
460 typename BMIGRAPH::hstate_t
461 BMIGRAPH::dst_of (
const hedge_t& h)
const
463 return hstate_t(h.value()->to_);
467 const typename BMIGRAPH::label_t&
468 BMIGRAPH::label_of (
const hedge_t& h)
const
470 return h.value()->label_;
475 BMIGRAPH::update(
const hedge_t& h,
const label_t& l)
477 graph_.modify(h.value(), update_hlabel<label_t>(l));
483 BMIGRAPH::exists (
const AutomataBase<S>& s)
const
485 typename WordValue::iterator it;
486 typename label_t::const_iterator r;
490 for (
typename graph_data_t::iterator i = graph_.begin(); i != graph_.end(); ++i)
494 if (!has_state(dst_of(hedge_t(i))) ||
495 !has_state(src_of(hedge_t(i))))
499 l = label_of(hedge_t(i));
500 for (r = l.begin(); r != l.end(); ++r)
503 for (it = w.begin(); it != w.end(); ++it)
504 if (!s.series().monoid().alphabet().contains(*it))
513 typename BMIGRAPH::tag_t&
521 const typename BMIGRAPH::tag_t&
522 BMIGRAPH::tag ()
const
529 typename BMIGRAPH::geometry_t&
530 BMIGRAPH::geometry ()
537 const typename BMIGRAPH::geometry_t&
538 BMIGRAPH::geometry ()
const
543 template <
class WordValue,
class SeriesValue,
544 class Letter,
class Tag,
class GeometryCoords,
class I>
546 op_tag(
const AutomataBase<I>&, BMIGRAPH &g)
551 template <
class WordValue,
class SeriesValue,
552 class Letter,
class Tag,
class GeometryCoords,
class I>
554 op_tag(
const AutomataBase<I>&, BMIGRAPH &g)
559 template <
class WordValue,
class SeriesValue,
560 class Letter,
class Tag,
class GeometryCoords,
class I>
561 typename BMIGRAPH::geometry_t&
562 op_geometry(
const AutomataBase<I>&, BMIGRAPH &g)
567 template <
class WordValue,
class SeriesValue,
568 class Letter,
class Tag,
class GeometryCoords,
class I>
569 const typename BMIGRAPH::geometry_t&
570 op_geometry(
const AutomataBase<I>&,
const BMIGRAPH &g)
576 typename BMIGRAPH::graph_data_t::const_iterator
577 BMIGRAPH::find_edge(
const state_t& from,
const state_t& to,
578 const label_t& label)
const
580 succ_range r = graph_.equal_range(::boost::make_tuple(from, label));
581 for (succ_iterator i = r.first; i != r.second; ++i)
590 # define DEFINE_DELTA_FUNCTION(FunName, DeltaKind, Target, GetElt) \
592 template <typename OutputIterator, typename Query> \
594 BMIGRAPH::FunName(OutputIterator res, \
595 const typename BMIGRAPH::hstate_t& s, \
596 const Query& query, \
597 ::vcsn::delta_kind::DeltaKind) const \
599 assertion(has_state(s)); \
600 Target##_range r = graph_.get<Target>().equal_range(s.value()); \
601 for (Target##_iterator e = r.first; e != r.second; ++e) \
602 if (query(hedge_t(graph_.project<0>(e)))) \
606 DEFINE_DELTA_FUNCTION (delta, transitions, src, hedge_t(graph_.project<0>(e)));
607 DEFINE_DELTA_FUNCTION (delta, states, src, hstate_t(e->to_));
608 DEFINE_DELTA_FUNCTION (rdelta, transitions, dst, hedge_t(graph_.project<0>(e)));
609 DEFINE_DELTA_FUNCTION (rdelta, states, dst, hstate_t(e->from_));
611 # undef DEFINE_DELTA_FUNCTION
615 # undef BMIGRAPH_TPARAM
620 #endif // !VCSN_AUTOMATA_IMPLEMENTATION_BMIG_GRAPH_IMPL_HXX_ //