58 int const max_iterations,
59 int const num_sites,
MapType const &map,
60 int const map_size,
double const res) {
64 std::srand(time(NULL));
67 std::vector<Voronoi> all_voronoi_cells;
70 all_voronoi_cells.resize(num_tries);
71 std::vector<double> obj_values;
72 obj_values.resize(num_tries, 0);
73 std::uniform_real_distribution<> distrib_pts(0.001, map_size * res - 0.001);
75#pragma omp parallel for
76 for (
int iter = 0; iter < num_tries; ++iter) {
78 sites.resize(num_sites);
79 for (
int iSite = 0; iSite < num_sites; ++iSite) {
80 sites[iSite] =
Point2(distrib_pts(gen_), distrib_pts(gen_));
82 bool cont_flag =
true;
88 for (iSteps = 0; iSteps < max_iterations and cont_flag ==
true; ++iSteps) {
91 for (
int iSite = 0; iSite < num_sites; ++iSite) {
93 voronoi_cells[iSite].centroid() - voronoi_cells[iSite].site;
94 if (diff.norm() < res) {
98 sites[iSite] = voronoi_cells[iSite].centroid();
103 all_voronoi_cells[iter] = voronoi;
106 int best_vornoi_idx = 0;
107 double min = obj_values[0];
108 for (
int iter = 1; iter < num_tries; ++iter) {
109 if (obj_values[iter] < min) {
110 min = obj_values[iter];
111 best_vornoi_idx = iter;
114 return all_voronoi_cells[best_vornoi_idx];
118 int const max_iterations,
119 int const num_sites,
MapType const &map,
120 int const map_size,
double const res,
126 std::vector<std::vector<double>> cost_matrix;
127 cost_matrix.resize(num_sites, std::vector<double>(num_sites));
128#pragma omp parallel for num_threads(num_sites)
129 for (
int iRobot = 0; iRobot < num_sites; ++iRobot) {
130 for (
int jCentroid = 0; jCentroid < num_sites; ++jCentroid) {
131 cost_matrix[iRobot][jCentroid] =
132 (positions[iRobot] - voronoi_cells[jCentroid].centroid()).norm();
135 HungarianAlgorithm HungAlgo;
136 std::vector<int> assignment;
137 HungAlgo.Solve(cost_matrix, assignment);
140 goals.resize(num_sites);
141 for (
int iRobot = 0; iRobot < num_sites; ++iRobot) {
142 goals[iRobot] = voronoi_cells[assignment[iRobot]].centroid();