PGROUTING  3.2
pgrouting::algorithms::Pgr_astar< G >::distance_heuristic Class Reference
Inheritance diagram for pgrouting::algorithms::Pgr_astar< G >::distance_heuristic:
Collaboration diagram for pgrouting::algorithms::Pgr_astar< G >::distance_heuristic:

Public Member Functions

 distance_heuristic (B_G &g, const std::vector< V > &goals, int heuristic, double factor)
 
 distance_heuristic (B_G &g, V goal, int heuristic, double factor)
 
double operator() (V u)
 

Private Attributes

double m_factor
 
B_Gm_g
 
std::set< Vm_goals
 
int m_heuristic
 

Detailed Description

template<class G>
class pgrouting::algorithms::Pgr_astar< G >::distance_heuristic

Definition at line 216 of file pgr_astar.hpp.

Constructor & Destructor Documentation

◆ distance_heuristic() [1/2]

template<class G >
pgrouting::algorithms::Pgr_astar< G >::distance_heuristic::distance_heuristic ( B_G g,
V  goal,
int  heuristic,
double  factor 
)
inline

Definition at line 218 of file pgr_astar.hpp.

219  : m_g(g),
220  m_factor(factor),
221  m_heuristic(heuristic) {
222  m_goals.insert(goal);
223  }

References pgrouting::algorithms::Pgr_astar< G >::distance_heuristic::m_goals.

◆ distance_heuristic() [2/2]

template<class G >
pgrouting::algorithms::Pgr_astar< G >::distance_heuristic::distance_heuristic ( B_G g,
const std::vector< V > &  goals,
int  heuristic,
double  factor 
)
inline

Definition at line 224 of file pgr_astar.hpp.

229  : m_g(g),
230  m_goals(goals.begin(), goals.end()),
231  m_factor(factor),
232  m_heuristic(heuristic) {}

Member Function Documentation

◆ operator()()

template<class G >
double pgrouting::algorithms::Pgr_astar< G >::distance_heuristic::operator() ( V  u)
inline

Definition at line 234 of file pgr_astar.hpp.

234  {
235  if (m_heuristic == 0) return 0;
236  if (m_goals.empty()) return 0;
237  double best_h((std::numeric_limits<double>::max)());
238  for (auto goal : m_goals) {
239  double current((std::numeric_limits<double>::max)());
240  double dx = m_g[goal].x() - m_g[u].x();
241  double dy = m_g[goal].y() - m_g[u].y();
242  switch (m_heuristic) {
243  case 0:
244  current = 0;
245  break;
246  case 1:
247  current = std::fabs((std::max)(dx, dy)) * m_factor;
248  break;
249  case 2:
250  current = std::fabs((std::min)(dx, dy)) * m_factor;
251  break;
252  case 3:
253  current = (dx * dx + dy * dy) * m_factor * m_factor;
254  break;
255  case 4:
256  current = std::sqrt(dx * dx + dy * dy) * m_factor;
257  break;
258  case 5:
259  current = (std::fabs(dx) + std::fabs(dy)) * m_factor;
260  break;
261  default:
262  current = 0;
263  }
264  if (current < best_h) {
265  best_h = current;
266  }
267  }
268  {
269  auto s_it = m_goals.find(u);
270  if (!(s_it == m_goals.end())) {
271  // found one more goal
272  m_goals.erase(s_it);
273  }
274  }
275  return best_h;
276  }

References pgrouting::algorithms::Pgr_astar< G >::distance_heuristic::m_factor, pgrouting::algorithms::Pgr_astar< G >::distance_heuristic::m_g, pgrouting::algorithms::Pgr_astar< G >::distance_heuristic::m_goals, and pgrouting::algorithms::Pgr_astar< G >::distance_heuristic::m_heuristic.

Member Data Documentation

◆ m_factor

template<class G >
double pgrouting::algorithms::Pgr_astar< G >::distance_heuristic::m_factor
private

◆ m_g

template<class G >
B_G& pgrouting::algorithms::Pgr_astar< G >::distance_heuristic::m_g
private

◆ m_goals

◆ m_heuristic

template<class G >
int pgrouting::algorithms::Pgr_astar< G >::distance_heuristic::m_heuristic
private

The documentation for this class was generated from the following file:
pgrouting::algorithms::Pgr_astar::distance_heuristic::m_goals
std::set< V > m_goals
Definition: pgr_astar.hpp:280
pgrouting::algorithms::Pgr_astar::distance_heuristic::m_heuristic
int m_heuristic
Definition: pgr_astar.hpp:282
pgrouting::algorithms::Pgr_astar::distance_heuristic::m_g
B_G & m_g
Definition: pgr_astar.hpp:279
pgrouting::algorithms::Pgr_astar::distance_heuristic::m_factor
double m_factor
Definition: pgr_astar.hpp:281