写出以下程序各步骤的注释: cells_visited_ = 0; // priority buffers threshold_ = lethal_cost_; currentBuffer_ = buffer1_; currentEnd_ = 0; nextBuffer_ = buffer2_; nextEnd_ = 0; overBuffer_ = buffer3_; overEnd_ = 0; memset(pending_, 0, ns_ * sizeof(bool)); std::fill(potential, potential + ns_, POT_HIGH); // set goal int k = toIndex(start_x, start_y); if(precise_) { double dx = start_x - (int)start_x, dy = start_y - (int)start_y; dx = floorf(dx * 100 + 0.5) / 100; dy = floorf(dy * 100 + 0.5) / 100; potential[k] = neutral_cost_ * 2 * dx * dy; potential[k+1] = neutral_cost_ * 2 * (1-dx)*dy; potential[k+nx_] = neutral_cost_*2*dx*(1-dy); potential[k+nx_+1] = neutral_cost_*2*(1-dx)*(1-dy);//*/ push_cur(k+2); push_cur(k-1); push_cur(k+nx_-1); push_cur(k+nx_+2); push_cur(k-nx_); push_cur(k-nx_+1); push_cur(k+nx_*2); push_cur(k+nx_*2+1); }else{ potential[k] = 0; push_cur(k+1); push_cur(k-1); push_cur(k-nx_); push_cur(k+nx_); }
时间: 2024-03-31 08:36:26 浏览: 66
TSP.zip_lingo_tsp_tsp 旅行商
// Initialize cells_visited_ to 0
cells_visited_ = 0;
// Initialize priority buffers
threshold_ = lethal_cost_;
currentBuffer_ = buffer1_;
currentEnd_ = 0;
nextBuffer_ = buffer2_;
nextEnd_ = 0;
overBuffer_ = buffer3_;
overEnd_ = 0;
// Initialize pending_ to false for each cell
memset(pending_, 0, ns_ * sizeof(bool));
// Initialize potential to POT_HIGH for each cell
std::fill(potential, potential + ns_, POT_HIGH);
// Set goal cell
int k = toIndex(start_x, start_y);
if(precise_)
{
// If precise mode is on, calculate potential value for each corner of the goal cell
double dx = start_x - (int)start_x, dy = start_y - (int)start_y;
dx = floorf(dx * 100 + 0.5) / 100;
dy = floorf(dy * 100 + 0.5) / 100;
potential[k] = neutral_cost_ * 2 * dx * dy;
potential[k+1] = neutral_cost_ * 2 * (1-dx)*dy;
potential[k+nx_] = neutral_cost_*2*dx*(1-dy);
potential[k+nx_+1] = neutral_cost_*2*(1-dx)*(1-dy);
// Push the 8 surrounding cells to the current buffer
push_cur(k+2);
push_cur(k-1);
push_cur(k+nx_-1);
push_cur(k+nx_+2);
push_cur(k-nx_);
push_cur(k-nx_+1);
push_cur(k+nx_*2);
push_cur(k+nx_*2+1);
}
else
{
// If precise mode is off, set potential of goal cell to 0 and push the 4 surrounding cells to the current buffer
potential[k] = 0;
push_cur(k+1);
push_cur(k-1);
push_cur(k-nx_);
push_cur(k+nx_);
}
阅读全文