dijkstra.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #ifndef _DIJKSTRA_H
  2. #define _DIJKSTRA_H
  3. #define PRIORITYBUFSIZE 10000
  4. #include <math.h>
  5. #include <stdint.h>
  6. #include <string.h>
  7. #include <stdio.h>
  8. #include <global_planner/planner_core.h>
  9. #include <global_planner/expander.h>
  10. // inserting onto the priority blocks
  11. #define push_cur(n) { if (n>=0 && n<ns_ && !pending_[n] && getCost(costs, n)<lethal_cost_ && currentBufferCount_<PRIORITYBUFSIZE){ currentBuffer_[currentBufferCount_++]=n; pending_[n]=true; }}
  12. #define push_next(n) { if (n>=0 && n<ns_ && !pending_[n] && getCost(costs, n)<lethal_cost_ && nextBufferCount_<PRIORITYBUFSIZE){ nextBuffer_[ nextBufferCount_++]=n; pending_[n]=true; }}
  13. #define push_over(n) { if (n>=0 && n<ns_ && !pending_[n] && getCost(costs, n)<lethal_cost_ && overBufferCount_<PRIORITYBUFSIZE){ overBuffer_[ overBufferCount_++]=n; pending_[n]=true; }}
  14. namespace global_planner {
  15. class DijkstraExpansion : public Expander {
  16. public:
  17. DijkstraExpansion(PotentialCalculator* p_calc, int nx, int ny);
  18. ~DijkstraExpansion();
  19. bool calculatePotentials(unsigned char* costs, double start_x, double start_y, double end_x, double end_y, int cycles, float* potential);
  20. /**
  21. * @brief Sets or resets the size of the map
  22. * @param nx The x size of the map
  23. * @param ny The y size of the map
  24. */
  25. void setSize(int nx, int ny); /**< sets or resets the size of the map */
  26. void setNeutralCost(unsigned char neutral_cost)
  27. {
  28. neutral_cost_ = neutral_cost;
  29. priorityIncrement_ = 2 * neutral_cost_;
  30. }
  31. void setPreciseStart(bool precise){ precise_ = precise; }
  32. private:
  33. /**
  34. * @brief Updates the cell at index n
  35. * @param costs The costmap
  36. * @param potential The potential array in which we are calculating
  37. * @param n The index to update
  38. */
  39. void updateCell(unsigned char* costs, float* potential, int n); /** updates the cell at index n */
  40. float getCost(unsigned char* costs, int n)
  41. {
  42. float c = costs[n];
  43. if (c < lethal_cost_ - 1 )
  44. {
  45. c = c * factor_ + neutral_cost_;
  46. if (c >= lethal_cost_)
  47. c = lethal_cost_ - 1;
  48. return c;
  49. }
  50. return lethal_cost_;
  51. }
  52. /** block priority buffers */
  53. int *buffer1_, *buffer2_, *buffer3_; /**< storage buffers for priority blocks */
  54. int *currentBuffer_, *nextBuffer_, *overBuffer_; /**< priority buffer block ptrs */
  55. int currentBufferCount_, nextBufferCount_,overBufferCount_;//nextEnd_, overEnd_; /**< end points of arrays */
  56. bool *pending_; /**< pending_ cells during propagation */
  57. bool precise_;
  58. int tick_count_; // counter for selecting cell push_back ordering
  59. /** block priority thresholds */
  60. float threshold_; /**< current threshold */
  61. float priorityIncrement_; /**< priority threshold increment */
  62. };
  63. } //end namespace global_planner
  64. #endif