85 num_robots_{num_robots},
87 exploration_map_{env.GetSystemExplorationMap()},
88 explored_idf_map_{env.GetSystemExploredIDFMap()} {
89 voronoi_cells_.resize(num_robots_);
92 actions_.resize(num_robots_);
93 goals_ = robot_global_positions_;
96 exploit_threshold_ = 0.2 * local_win_ * local_win_;
98 robot_status_.resize(num_robots_, 0);
99 random_goal_counter_.resize(num_robots_, 10);
108 std::uniform_real_distribution<>(-time_step_dist_, time_step_dist_);
123 for (
size_t iRobot = 0; iRobot < num_robots_; ++iRobot) {
124 robot_status_[iRobot] = 0;
128 robot_global_positions_[iRobot], local_win_,
141 if (unexplored < exploit_threshold_ and idf_value > exploit_threshold_) {
142 robot_status_[iRobot] = 1;
143 for (
size_t jRobot = 0; jRobot < iRobot; ++jRobot) {
144 double goal_dist = (goals_[iRobot] - goals_[jRobot]).norm();
145 if (goal_dist < too_close_factor_ * params_.
pSensorSize *
148 robot_status_[jRobot] = 0;
157 double best_bcr = 0, best_benefit = 0;
158 double pos_x_lim = std::min(pos[0] + time_step_dist_,
160 double pos_y_lim = std::min(pos[1] + time_step_dist_,
162 for (
double pos_x = std::max(pos[0] - time_step_dist_, eps);
163 pos_x < pos_x_lim; pos_x += 1 * params_.
pResolution) {
164 for (
double pos_y = std::max(pos[1] - time_step_dist_, eps);
165 pos_y < pos_y_lim; pos_y += 1 * params_.
pResolution) {
166 Point2 qpos{pos_x, pos_y};
167 double dist = (qpos - pos).norm();
169 dist = std::max(dist, time_step_dist_);
178 double benefit = unexplored;
179 if (unexplored > 0.1 * sensor_area_) {
185 benefit += 2 * idf_value;
188 double bcr = benefit / dist;
189 double bcr_diff = bcr - best_bcr;
191 if (bcr_diff < -
kEps) {
194 if (std::abs(bcr_diff) <
kEps) {
195 Point2 unit_best_goal = best_goal.normalized();
196 Point2 unit_qpos = qpos.normalized();
197 Point2 unit_curr_pos = pos.normalized();
198 if (unit_best_goal.dot(unit_curr_pos) >
199 unit_qpos.dot(unit_curr_pos)) {
204 if (bcr_diff >
kEps or update ==
true) {
207 best_benefit = benefit;
218 double best_angle = 0;
219 double best_bcr = 0, best_benefit = 0, best_idf_benefit = 0;
220 for (
double rad = time_step_dist_; rad <= 20 * time_step_dist_;
221 rad += time_step_dist_) {
222 for (
double angle = 0; angle < 2 * M_PI; angle += M_PI / 180) {
223 Point2 qpos = pos + rad *
Point2{std::cos(angle), std::sin(angle)};
224 std::cout <<
"rad: " << rad <<
" " << angle << std::endl;
225 qpos[0] = std::min(qpos[0],
static_cast<double>(params_.
pWorldMapSize));
226 qpos[1] = std::min(qpos[1],
static_cast<double>(params_.
pWorldMapSize));
227 qpos[0] = std::max(qpos[0], eps);
228 qpos[1] = std::max(qpos[1], eps);
229 std::cout <<
"qpos: " << qpos[0] <<
" " << qpos[1] << std::endl;
230 double dist = (qpos - pos).norm();
241 double unexplored_benefit = unexplored;
242 double idf_benefit = 0;
248 if (unexplored > 0.1 * sensor_area_) {
249 idf_benefit = 2.5 * idf_value;
251 double benefit = unexplored_benefit + idf_benefit;
252 double bcr = benefit / dist;
253 double bcr_diff = bcr - best_bcr;
255 if (bcr_diff < -better_threshold_) {
258 if (std::abs(bcr_diff) < better_threshold_) {
259 if (best_angle > angle) {
263 if (bcr_diff > better_threshold_ or update ==
true) {
266 best_benefit = benefit;
268 best_idf_benefit = idf_benefit;
272 if (best_benefit > better_threshold_) {
275 if (best_idf_benefit > 0.1) {
289#pragma omp parallel for num_threads(num_robots_)
290 for (
size_t iRobot = 0; iRobot < num_robots_; ++iRobot) {
291 if (robot_status_[iRobot] == 0) {
292 double best_benefit =
294 if (best_benefit < better_threshold_) {
295 robot_status_[iRobot] = 1;
305 std::vector<int> exploit_robots;
306 for (
size_t iRobot = 0; iRobot < num_robots_; ++iRobot) {
307 if (robot_status_[iRobot] != 0) {
308 exploit_robots_pos.push_back(robot_global_positions_[iRobot]);
309 exploit_robots.push_back(iRobot);
314 exploit_robots_pos, explored_idf_map_,
319 for (
size_t iCell = 0; iCell < exploit_robots.size(); ++iCell) {
320 size_t iRobot = exploit_robots[iCell];
321 auto goal = exploit_voronoi_cells[iCell].centroid();
322 goals_[iRobot] = goal;
325 int num_exploring_robots = num_robots_ - exploit_robots.size();
326 std::cout <<
"Number of exploring_robots: " << num_exploring_robots
342 if (first_step_ ==
true) {
345 for (
size_t iRobot = 0; iRobot < num_robots_; ++iRobot) {
346 goals_[iRobot] = robot_global_positions_[iRobot] +
347 Point2{rand_dist_(gen_), rand_dist_(gen_)};
350 }
else if (trigger_exploit_ ==
false) {
354 is_converged_ =
true;
355 for (
size_t iRobot = 0; iRobot < num_robots_; ++iRobot) {
356 actions_[iRobot] =
Point2(0, 0);
357 Point2 diff = goals_[iRobot] - robot_global_positions_[iRobot];
358 double dist = diff.norm();
362 direction.normalize();
363 actions_[iRobot] = speed * direction;
367 if (actions_[iRobot].norm() > eps) {
368 is_converged_ =
false;