OpenLibrary
std_alg.hpp
1 
2 /**************************************************
3  * standard version of A* routing algorithm *
4  * with no heuristic *
5  * Author: MichaƂ Walenciak *
6  * Creation date: 23.08.2012 *
7  **************************************************/
8 
9 #include <deque>
10 
11 #include "base.hpp"
12 #include "std_types.hpp"
13 
14 
15 namespace ol
16 {
17  namespace Router
18  {
19  namespace
20  {
21  //standard sorting algorithm:
22  //points are sorted by their's age - typical fifo
23  template<class PointT>
24  class SortingContainer: public std::deque<PointT *>
25  {
26  public:
27  SortingContainer(): std::deque<PointT *>() {}
28  virtual ~SortingContainer() {}
29 
30  void insert(PointT *item)
31  {
32  this->push_back(item);
33  }
34 
35  PointT* first()
36  {
37  PointT *result = this->front();
38 
39  this->pop_front();
40 
41  return result;
42  }
43  };
44  }
45 
46  template<class PointT, class ClosedSetT, FlagsT flags = 0>
47  class StdAStar: public AStar<PointT, OpenSet<PointT, SortingContainer<PointT>>, ClosedSetT, flags>
48  {
49  public:
50  StdAStar() {}
51  virtual ~StdAStar() {}
52 
53  protected:
55 
56  virtual typename AStarBase::FScoreT heuristic_cost_estimate(const PointT *p1, const PointT *p2) const override
57  {
58  const typename AStarBase::FScoreT dist = AStarBase::distance(p1, p2);
59 
60  return dist;
61  }
62 
63  virtual std::vector<PointT *> get_neighbours(PointT *p) override
64  {
65  std::vector<PointT *> result;
66  result.reserve(8);
67 
68  result.push_back( new PointT(p->x + 0, p->y - 1, p) );
69  result.push_back( new PointT(p->x + 1, p->y - 1, p) );
70  result.push_back( new PointT(p->x + 1, p->y + 0, p) );
71  result.push_back( new PointT(p->x + 1, p->y + 1, p) );
72  result.push_back( new PointT(p->x + 0, p->y + 1, p) );
73  result.push_back( new PointT(p->x - 1, p->y + 1, p) );
74  result.push_back( new PointT(p->x - 1, p->y + 0, p) );
75  result.push_back( new PointT(p->x - 1, p->y - 1, p) );
76 
77  return std::move(result);
78  }
79  };
80  }
81 }
Definition: base.hpp:86
Definition: std_alg.hpp:47
Definition: debug.hpp:45