Skip to content

Commit 9065501

Browse files
committed
Apply min scale if necessary.
Closes #75
1 parent 05a0bbd commit 9065501

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

polygon_coverage_solvers/include/polygon_coverage_solvers/impl/graph_base_impl.h

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -344,34 +344,31 @@ GraphBase<NodeProperty, EdgeProperty>::getAdjacencyMatrix() const {
344344
auto min_diff = std::numeric_limits<double>::max();
345345
for (size_t i = 0; i < sorted_cost.size() - 2; i++) {
346346
auto diff = std::fabs(sorted_cost[i + 1] - sorted_cost[i]);
347-
if (diff > std::numeric_limits<double>::epsilon() && diff < min_diff)
347+
const double equality = 0.000001; // Min. considered cost difference.
348+
if (diff > equality && diff < min_diff)
348349
min_diff = diff;
349350
}
350351

351352
// Only scale with min_diff if this does not blow up the cost.
353+
// Maximum expected cost is number of clusters times max. cost per cluster.
352354
// TODO(rikba): Find a tighter upper bound.
353355
double total_cost_upper_bound = sorted_cost.back() * graph_.size();
356+
// Add 0.1 to make sure that min_diff * max_scale > 1.0 to avoid rounding
357+
// errors.
354358
double max_scale = 1.1 / min_diff;
355359
double min_scale =
356360
std::numeric_limits<int>::max() / (total_cost_upper_bound + 1.0);
357361
double scale = 1.0;
358362
if (max_scale * total_cost_upper_bound < std::numeric_limits<int>::max()) {
359-
ROS_DEBUG("Optimal scale applied.");
363+
ROS_DEBUG("Optimal scale %.9f applied.", max_scale);
360364
scale = max_scale;
361-
} else if (min_scale * total_cost_upper_bound + 1 >
362-
std::numeric_limits<int>::max()) {
363-
// Recursive search for largest scale between min_scale and max_scale.
364-
ROS_WARN(
365-
"The adjacency matrix is ill conditioned. Adjacency matrix "
366-
"coefficients are reduced to guarantee upper cost bound. Consider "
367-
"removing small details in the polygon to have even decomposition "
368-
"size.");
369-
ROS_WARN("Recursively searching for best scale.");
370-
scale = searchLargestFeasibleScale(
371-
min_scale, max_scale,
372-
std::numeric_limits<int>::max() / total_cost_upper_bound + 1);
373-
374-
ROS_WARN_COND(min_diff < 1.0, "Loss of optimality.");
365+
} else {
366+
ROS_DEBUG("Minimum scale %.9f applied.", min_scale);
367+
scale = min_scale;
368+
ROS_WARN_COND(
369+
min_diff < 1.0,
370+
"The adjacency matrix is ill conditioned. Consider removing small "
371+
"details in the polygon to have even decomposition sizes.");
375372
}
376373

377374
ROS_DEBUG("The minimum cost difference is: %.9f", min_diff);

0 commit comments

Comments
 (0)