Closed yg42 closed 3 years ago
Hello @yg42 ,
thank you for your report, and sorry for the late reply.
This issue comes from the fact that random_selection()
can collect twice (or more) the same vertex in dead_cells
. So the line cdt.remove(*it_cells);
is likely to fail at removing a vertex that has already been removed earlier in the same loop.
You can use a std::set
to store the "dead vertices" for example to make sure that your vertex set is unique.
Thank you very much for your time. I can thus propose to add in Generator/include/CGAL/random_selection.h the following code. I am really sorry I do not have time for proposing a pull request.
template <class RandomAccessIterator, class Size, class OutputIterator,
class Random>
OutputIterator unique_random_selection( RandomAccessIterator first,
RandomAccessIterator last,
Size n,
OutputIterator result,
Random& rnd)
// choose n random (unique) values from the range [`first',`last')
// and write it to `result'. Each item has an equal probability to
// be chosen. In case n is greater than range, this is silently ignored
{
std::ptrdiff_t m = last - first;
std::vector<int> numbers;
for (int i=0; i<m; i++) {
numbers.push_back(i);
}
std::iota(numbers.begin(), numbers.end(), 0);
// ignore in case to many items are requested
if (n > m)
n = m;
// random shuffle, then get only n first items.
CGAL::cpp98::random_shuffle(numbers.begin(), numbers.end(), rnd);
for ( Size i = 0; i < n; i++) {
*result++ = first[ numbers[i]];
}
return result;
}
template <class RandomAccessIterator, class Size, class OutputIterator>
OutputIterator unique_random_selection( RandomAccessIterator first,
RandomAccessIterator last,
Size n,
OutputIterator result)
{
return unique_random_selection( first, last, n, result, get_default_random());
}
Issue Details
Dear all, I submit my problem to your wisdom...
When running the next code, I get an assertion violation:
Is there a bug or is it a misunderstanding or misuse on my part? in this case, I am really sorry to bother. Thank you very much for your time.
Source Code
Here is the source code I tried to minimize.
Environment
To reproduce: