Vcsn  2.5.dev
Be Rational
compare-automaton.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <boost/range/algorithm/lexicographical_compare.hpp>
4 
5 #include <vcsn/core/automaton.hh>
6 
7 namespace vcsn
8 {
9 
10  /*---------------------------------.
11  | compare(automaton, automaton). |
12  `---------------------------------*/
13 
26  template <Automaton Lhs, Automaton Rhs>
27  int
28  compare(const Lhs& lhs, const Rhs& rhs)
29  {
31  (lhs->all_transitions(),
32  rhs->all_transitions(),
33  [&lhs, &rhs](transition_t_of<Lhs> t1, transition_t_of<Rhs> t2)
34  {
35  // First, on src.
36  if (auto res = int(lhs->src_of(t1)) - int(rhs->src_of(t2)))
37  return res;
38  // Second, on the label.
39  else if (auto res = lhs->labelset()->compare(lhs->label_of(t1),
40  rhs->label_of(t2)))
41  return res;
42  // Third, on the weight.
43  else if (auto res = lhs->weightset()->compare(lhs->weight_of(t1),
44  rhs->weight_of(t2)))
45  return res;
46  // Last, on dst.
47  else
48  return int(lhs->dst_of(t1)) - int(rhs->dst_of(t2));
49  });
50  }
51 
52  namespace dyn
53  {
54  namespace detail
55  {
57  template <Automaton Lhs, Automaton Rhs>
58  int
59  compare(const automaton& lhs, const automaton& rhs)
60  {
61  const auto& l = lhs->as<Lhs>();
62  const auto& r = rhs->as<Rhs>();
64  }
65  }
66  }
67 
69  template <Automaton Lhs, Automaton Rhs>
70  bool
71  are_equal(const Lhs& lhs, const Rhs& rhs)
72  {
73  return compare(lhs, rhs) == 0;
74  }
75 
77  template <Automaton Lhs, Automaton Rhs>
78  bool
79  less_than(const Lhs& lhs, const Rhs& rhs)
80  {
81  return compare(lhs, rhs) < 0;
82  }
83 } // namespace vcsn
return res
Definition: multiply.hh:399
int lexicographical_cmp(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Compare comp)
Lexicographical three-way comparison between two ranges.
Definition: algorithm.hh:128
int compare(const automaton &lhs, const automaton &rhs)
Bridge (compare).
Definition: a-star.hh:8
Provide a variadic mul on top of a binary mul(), and one().
Definition: fwd.hh:46
auto & as()
Extract wrapped typed automaton.
Definition: automaton.hh:37
A dyn automaton.
Definition: automaton.hh:17
bool less_than(const automaton &lhs, const automaton &rhs)
Ordering between automata.
Definition: algos.hxx:40
typename detail::transition_t_of_impl< base_t< ValueSet > >::type transition_t_of
Definition: traits.hh:65
int compare(const Lhs &lhs, const Rhs &rhs)
Comparison between lhs and rhs.
bool are_equal(const automaton &lhs, const automaton &rhs)
Whether are the same automaton.
Definition: algos.hxx:13