Vcsn  2.8
Be Rational
dijkstra-node.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <limits>
4 
5 #include <vcsn/ctx/traits.hh>
6 
7 namespace vcsn
8 {
9  namespace detail
10  {
20  template <Automaton Aut>
22  {
23  using automaton_t = Aut;
28  public:
29  dijkstra_node() = default;
30 
31  dijkstra_node(const automaton_t& aut, state_t state,
32  state_t parent,
33  weight_t weight = weightset_t::max(),
34  unsigned depth = std::numeric_limits<unsigned>::max())
35  : depth_{depth}
36  , state_{state}
37  , parent_{parent}
38  , weight_{weight}
39  , ws_{aut->weightset().get()}
40  {}
41 
43  bool
44  operator<(const self_t& other) const
45  {
46  return ws_->less(weight_, other.weight_);
47  }
48 
51  weight_t
52  get_weight() const
53  {
54  return weight_;
55  }
56 
57  void
59  {
60  weight_ = weight;
61  }
62 
63  state_t
64  get_state() const
65  {
66  return state_;
67  }
68 
69  unsigned
70  get_depth() const
71  {
72  return depth_;
73  }
74 
75  void
76  set_depth(unsigned depth)
77  {
78  depth_ = depth;
79  }
80 
81  void
83  {
84  parent_ = parent;
85  }
86 
87  state_t
88  get_parent() const
89  {
90  return parent_;
91  }
92 
93  private:
94  unsigned depth_;
98  // We have 2 alternatives to raw pointer:
99  // - Reference: Not possible as the dijkstra node is used in a boost
100  // container that requires default contructible objects.
101  // - Shared pointer: Using the shared pointer returned by
102  // `aut->weightset()` would work but slows the algorithm down
103  // as a lot of dijkstra nodes are created. Hence, we stick
104  // with the raw pointer for now.
105  const weightset_t *ws_;
106  };
107  }
108 }
bool operator<(const self_t &other) const
Compare weights, used to order nodes in the shortest path heap.
unsigned get_depth() const
typename detail::weightset_t_of_impl< base_t< ValueSet > >::type weightset_t_of
Definition: traits.hh:67
typename detail::state_t_of_impl< base_t< ValueSet > >::type state_t_of
Definition: traits.hh:64
void set_depth(unsigned depth)
void set_weight(weight_t weight)
weight_t get_weight() const
If there is no weight in the node then its weight is the weightset&#39;s maximum.
dijkstra_node(const automaton_t &aut, state_t state, state_t parent, weight_t weight=weightset_t::max(), unsigned depth=std::numeric_limits< unsigned >::max())
state_t_of< automaton_t > state_t
weightset_t_of< automaton_t > weightset_t
Definition: a-star.hh:8
Dijkstra Node implementation.
const weightset_t * ws_
weight_t_of< automaton_t > weight_t
void set_parent(state_t parent)
typename detail::weight_t_of_impl< base_t< ValueSet > >::type weight_t_of
Definition: traits.hh:66
value_impl< detail::weight_tag > weight
Definition: fwd.hh:34