point_expander.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, <copyright holder> <email>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the <organization> nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY <copyright holder> <email> ''AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL <copyright holder> <email> BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28 
29 #ifndef POINT_EXPANDER_H
30 #define POINT_EXPANDER_H
31 
32 #define POT_HIGH 1.0e10
33 #include <algorithm>
34 #include <memory>
35 #include <queue>
36 #include <opencv/cv.h>
37 #include <unordered_set>
38 #include <map>
39 #include <eigen3/Eigen/Dense>
40 
41 namespace multi_robot_router
42 {
44 {
45  public:
50  void initialize(const cv::Mat &_map);
64  bool findGoalOnMap(const Eigen::Vector2d &_start, const uint32_t &_cycles, float *_potential, const std::map<uint32_t, Eigen::Vector2d> &_goals, const uint32_t &_optimizationSteps, Eigen::Vector2d &_foundPoint, int32_t &_segIdx, const uint32_t &_radius);
69  float getDistanceToObstacle(const Eigen::Vector2d &vec);
70 
71  private:
72  template <class T, class S, class C>
73  void clearpq(std::priority_queue<T, S, C> &q)
74  {
75  q = std::priority_queue<T, S, C>();
76  }
77  class Index
78  {
79  public:
80  Index(int index, float c, float d, float p)
81  {
82  i = index;
83  weight = c;
84  dist = d;
85  potential = p;
86  }
87 
88  Index(int x_val, int y_val, int nx, float c, float d, float p)
89  {
90  i = x_val + y_val * nx;
91  weight = c;
92  dist = d;
93  potential = p;
94  }
95 
96  Index offsetDist(int dist_x, int dist_y, int nx, int ny)
97  {
98  int x_val = (i % nx) + dist_x;
99  int y_val = (i / nx) + dist_y;
100 
101  if (x_val < 0 || x_val > nx || y_val < 0 || y_val > ny)
102  return Index(-1, -1, -1, -1);
103 
104  return Index(x_val, y_val, nx, 0, 0, 0);
105  }
106 
107  int getX(int nx)
108  {
109  return (i % nx);
110  }
111 
112  int getY(int nx)
113  {
114  return (i / nx);
115  }
116 
117  float distance(Index _p, int _nx)
118  {
119  float dx = abs(getX(_nx) - _p.getX(_nx));
120  float dy = abs(getY(_nx) - _p.getY(_nx));
121 
122  return std::sqrt(dx * dx + dy * dy);
123  }
124 
125  int i;
126  float weight;
127  float dist;
128  float cost;
129  float potential;
130  };
131 
132  struct greater1
133  {
134  bool operator()(const Index &a, const Index &b) const
135  {
136  return a.weight > b.weight;
137  }
138  };
139  std::priority_queue<Index, std::vector<Index>, greater1> queue_;
140  int nx_, ny_, ns_;
141  Index findGoal(const Index &_start, const uint32_t &_cycles, float *_potential, const std::map<uint32_t, Index> &_goals, const uint32_t &_optimizationSteps, int32_t &segIdx, const uint32_t &_radius);
142  void addPotentialExpansionCandidate(Index _current, int32_t _next_x, int32_t _next_y, float *_potential, uint32_t _distToObstacle);
143  bool isGoal(Index _p, const std::map<uint32_t, Index> &_goals, int32_t &segIdx);
144 
146  float neutral_cost_ = 1;
147 };
148 } // namespace multi_robot_router
149 #endif // VORONOI_EXPANDER_H
Index(int x_val, int y_val, int nx, float c, float d, float p)
void addPotentialExpansionCandidate(Index _current, int32_t _next_x, int32_t _next_y, float *_potential, uint32_t _distToObstacle)
bool findGoalOnMap(const Eigen::Vector2d &_start, const uint32_t &_cycles, float *_potential, const std::map< uint32_t, Eigen::Vector2d > &_goals, const uint32_t &_optimizationSteps, Eigen::Vector2d &_foundPoint, int32_t &_segIdx, const uint32_t &_radius)
searches the first occurence of a point in the goals_ list and returns the index
float getDistanceToObstacle(const Eigen::Vector2d &vec)
returns the distance to the closest obstacle for a point
void clearpq(std::priority_queue< T, S, C > &q)
void initialize(const cv::Mat &_map)
initializes the point expander with a distance map
Index findGoal(const Index &_start, const uint32_t &_cycles, float *_potential, const std::map< uint32_t, Index > &_goals, const uint32_t &_optimizationSteps, int32_t &segIdx, const uint32_t &_radius)
std::priority_queue< Index, std::vector< Index >, greater1 > queue_
bool operator()(const Index &a, const Index &b) const
Index offsetDist(int dist_x, int dist_y, int nx, int ny)
Index(int index, float c, float d, float p)
bool isGoal(Index _p, const std::map< uint32_t, Index > &_goals, int32_t &segIdx)


tuw_multi_robot_router
Author(s): Benjamin Binder
autogenerated on Mon Jun 10 2019 15:42:49