44 Expander(p_calc, xs, ys) {
47 bool AStarExpansion::calculatePotentials(
unsigned char* costs,
double start_x,
double start_y,
double end_x,
double end_y,
48 int cycles,
float* potential) {
50 int start_i = toIndex(start_x, start_y);
51 queue_.push_back(
Index(start_i, 0));
53 std::fill(potential, potential + ns_,
POT_HIGH);
54 potential[start_i] = 0;
56 int goal_i = toIndex(end_x, end_y);
59 while (queue_.size() > 0 && cycle < cycles) {
60 Index top = queue_[0];
61 std::pop_heap(queue_.begin(), queue_.end(), greater1());
68 add(costs, potential, potential[i], i + 1, end_x, end_y);
69 add(costs, potential, potential[i], i - 1, end_x, end_y);
70 add(costs, potential, potential[i], i + nx_, end_x, end_y);
71 add(costs, potential, potential[i], i - nx_, end_x, end_y);
79 void AStarExpansion::add(
unsigned char* costs,
float* potential,
float prev_potential,
int next_i,
int end_x,
81 if (next_i < 0 || next_i >= ns_)
90 potential[next_i] = p_calc_->calculatePotential(potential, costs[next_i] + neutral_cost_, next_i, prev_potential);
91 int x = next_i % nx_, y = next_i / nx_;
92 float distance = abs(end_x - x) + abs(end_y - y);
94 queue_.push_back(
Index(next_i, potential[next_i] + distance * neutral_cost_));
95 std::push_heap(queue_.begin(), queue_.end(),
greater1());