Vcsn  2.5
Be Rational
dijkstra-node.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <limits>
4 
5 #include <boost/optional.hpp>
6 
7 #include <vcsn/ctx/traits.hh>
8 
9 namespace vcsn
10 {
11  namespace detail
12  {
22  template <Automaton Aut>
24  {
25  using automaton_t = Aut;
36  public:
37  dijkstra_node() = default;
38 
39  dijkstra_node(const automaton_t& aut, state_t state,
40  boost::optional<weight_t> weight, state_t parent,
41  unsigned depth = std::numeric_limits<unsigned>::max())
42  : depth_{depth}
43  , state_{state}
44  , parent_{parent}
45  , weight_{weight}
46  , ws_{aut->weightset().get()}
47  {}
48 
50  bool
51  operator<(const dijkstra_node& other) const
52  {
53  if (!weight_)
54  return true;
55  else if (!other.weight_)
56  return false;
57  else
58  return ws_->less(*weight_, *other.weight_);
59  }
60 
63  weight_t
64  get_weight() const
65  {
66  return weight_ ? *weight_ : ws_->max();
67  }
68 
69  void
71  {
72  weight_ = weight;
73  }
74 
75  state_t
76  get_state() const
77  {
78  return state_;
79  }
80 
81  unsigned
82  get_depth() const
83  {
84  return depth_;
85  }
86 
87  void
88  set_depth(unsigned depth)
89  {
90  depth_ = depth;
91  }
92 
93  void
95  {
96  parent_ = parent;
97  }
98 
99  state_t
100  get_parent() const
101  {
102  return parent_;
103  }
104 
105  private:
106  unsigned depth_;
109  boost::optional<weight_t> weight_;
111  };
112  }
113 }
Definition: a-star.hh:8
void set_depth(unsigned depth)
weight_t get_weight() const
If there is no weight in the node then its weight is the weightset&#39;s maximum.
typename detail::state_t_of_impl< base_t< ValueSet > >::type state_t_of
Definition: traits.hh:64
void set_weight(weight_t weight)
value_impl< detail::weight_tag > weight
Definition: fwd.hh:34
typename detail::weightset_t_of_impl< base_t< ValueSet > >::type weightset_t_of
Definition: traits.hh:67
state_t_of< automaton_t > state_t
typename detail::weight_t_of_impl< base_t< ValueSet > >::type weight_t_of
Definition: traits.hh:66
unsigned get_depth() const
boost::optional< weight_t > weight_
bool operator<(const dijkstra_node &other) const
Compare weights, used to order nodes in the shortest path heap.
void set_parent(state_t parent)
Dijkstra Node implementation.
const weightset_t_of< automaton_t > * weightset_ptr
We have 2 alternatives to raw pointer:
weight_t_of< automaton_t > weight_t
dijkstra_node(const automaton_t &aut, state_t state, boost::optional< weight_t > weight, state_t parent, unsigned depth=std::numeric_limits< unsigned >::max())