Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generator: replace <boost/random.hpp> with <random> #8207

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#include <CGAL/license/Apollonius_graph_2.h>


#include <random>

// class implementation
//---------------------
Expand Down Expand Up @@ -425,10 +425,9 @@ int
Apollonius_graph_hierarchy_2<Gt,Agds,LTag>::
random_level()
{
boost::geometric_distribution<> proba(1.0/ag_hierarchy_2__ratio);
boost::variate_generator<boost::rand48&, boost::geometric_distribution<> > die(random, proba);
std::geometric_distribution<> proba(1.0/ag_hierarchy_2__ratio);

return (std::min)(die(), (int)ag_hierarchy_2__maxlevel)-1;
return (std::min)(proba(random), (int)ag_hierarchy_2__maxlevel)-1;
}

template<class Gt, class Agds, class LTag>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@


#include <map>

#include <boost/random/linear_congruential.hpp>
#include <boost/random/geometric_distribution.hpp>
#include <boost/random/variate_generator.hpp>
#include <random>

#include <CGAL/Apollonius_graph_2.h>
#include <CGAL/Triangulation_data_structure_2.h>
Expand Down Expand Up @@ -210,7 +207,7 @@ class Apollonius_graph_hierarchy_2
// class variables
// here is the stack of graphs which form the hierarchy
Apollonius_graph_base* hierarchy[ag_hierarchy_2__maxlevel];
boost::rand48 random; // random generator
std::mt19937 random; // random generator

public:
template<class OutputItFaces, class OutputItBoundaryEdges,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <iostream>
#include <fstream>
#include <sstream>
#include <boost/random/linear_congruential.hpp>
#include <random>

namespace CGAL {

Expand Down Expand Up @@ -271,7 +271,7 @@ namespace CGAL {
bool adjust_bb;
double zoom;
std::string filename;
boost::rand48 rng;
std::mt19937 rng;

public: // construction and destruction:

Expand Down
7 changes: 3 additions & 4 deletions Bounding_volumes/include/CGAL/Min_sphere_of_spheres_d.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@

#include <CGAL/license/Bounding_volumes.h>


#include <CGAL/Min_sphere_of_spheres_d/Min_sphere_of_spheres_d_configure.h>
#include <boost/random/linear_congruential.hpp>
#include <cmath>
#include <vector>
#include <iostream>
#include <random>

#include <CGAL/Min_sphere_of_spheres_d/Min_sphere_of_spheres_d_configure.h>
#include <CGAL/Min_sphere_of_spheres_d/Min_sphere_of_spheres_d_pair.h>
#include <CGAL/Min_sphere_of_spheres_d/Min_sphere_of_spheres_d_support_set.h>

Expand Down Expand Up @@ -59,7 +58,7 @@ namespace CGAL_MINIBALL_NAMESPACE {
// ball has been respected in the miniball computation.
bool is_up_to_date;

boost::rand48 rng;
std::mt19937 rng;

public: // iterators:
typedef const Result *Cartesian_const_iterator; // coordinate iterator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
#include <CGAL/basic.h>
#include <CGAL/Box_intersection_d/box_limits.h>

#include <boost/random/linear_congruential.hpp>
#include <boost/random/uniform_int.hpp>
#include <boost/random/variate_generator.hpp>

#include <algorithm>
#include <iterator>
Expand All @@ -30,6 +28,7 @@
#include <cmath>
#include <climits>
#include <cstddef>
#include <random>

namespace CGAL {

Expand Down Expand Up @@ -242,9 +241,9 @@ RandomAccessIter
iterative_radon( RandomAccessIter begin, RandomAccessIter end,
Predicate_traits traits, int dim, int num_levels )
{
typedef typename boost::variate_generator<boost::rand48&, boost::uniform_int<std::ptrdiff_t> > Generator;
boost::rand48 rng;
Generator generator(rng, boost::uniform_int<std::ptrdiff_t>(0, (end-begin)-1));
std::mt19937 rng;
auto generator = std::bind( boost::uniform_int<std::ptrdiff_t>(0, (end-begin)-1), rng);
using Generator = decltype(generator);
Iterative_radon<RandomAccessIter, Predicate_traits, Generator> IR(begin, traits, dim, generator);
return IR(num_levels);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int_distribution.hpp>
#include <boost/random/uniform_01.hpp>
#include <boost/random/normal_distribution.hpp>
#if defined(CGAL_LINKED_WITH_BOOST_IOSTREAMS) && defined(CGAL_LINKED_WITH_BOOST_SERIALIZATION)
#include <boost/serialization/vector.hpp>
#endif
Expand All @@ -62,8 +61,8 @@ inline void init_feature_class_data(FeatureClassDataFloat& /*data*/, int /*n_cla
typedef std::unordered_set<int> FeatureSet;

typedef boost::random::uniform_int_distribution<> UniformIntDist;
typedef boost::random::normal_distribution<> NormalDist;
typedef boost::random::mt19937 RandomGen;
typedef std::normal_distribution<> NormalDist;
typedef std::mt19937 RandomGen;
typedef boost::random::uniform_01<> UnitDist;

struct ForestParams {
Expand Down
2 changes: 1 addition & 1 deletion Generator/doc/Generator/CGAL/Random.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ the same time, even if a fixed seed has been chosen.

\cgalHeading{Implementation}

We use the boost random library function `boost::rand48()` to generate the random
We use the standard library function `std::mt19937()` to generate the random
numbers.

\sa `CGAL::get_default_random()`
Expand Down
6 changes: 3 additions & 3 deletions Generator/doc/Generator/CGAL/random_convex_hull_in_disc_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ The generated polygon will have an average number of vertices \f$ n^\frac{1}{3}(

\cgalHeading{Requirements}

- `Generator` has to be a Boost random generator, such as `boost::random::mt19937`.
- `Generator` has to be a random generator, such as `std::mt19937`.

- `fast` is a Boolean , set to `true` for time efficiency and to `false` for memory efficiency.
- `fast` is a Boolean, set to `true` for time efficiency and to `false` for memory efficiency.

- `Traits` is a model of the concept `RandomConvexHullTraits_2`.

Expand All @@ -28,7 +28,7 @@ The generated polygon will have an average number of vertices \f$ n^\frac{1}{3}(

The implementation is based on an incremental construction of a convex hull. At each step, we choose a number of points to pick uniformly at random in the disc. Then, a subset of these points, that won't change the convex hull, is evaluated using a Binomial law.
As these points won't be generated, the time and size complexities are reduced \cgalCite{Devillers2014Generator}.
A tradeoff between time and memory is provided with the option `fast`, true by default. Using the `fast` option, both time and size expected complexities are \cgalBigOLarge{n^\frac{1}{3}\log^\frac{2}{3}n}.
A tradeoff between time and memory is provided with the option `fast`, `true` by default. Using the `fast` option, both time and size expected complexities are \cgalBigOLarge{n^\frac{1}{3}\log^\frac{2}{3}n}.
If this option is disabled, the expected size complexity becomes \cgalBigOLarge{n^\frac{1}{3}} but the expected time complexity becomes \cgalBigOLarge{n^\frac{1}{3}\log^2 n}.

\cgalHeading{Example}
Expand Down
4 changes: 2 additions & 2 deletions Generator/examples/Generator/random_convex_hull_2.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/random_convex_hull_in_disc_2.h>
#include <CGAL/Polygon_2_algorithms.h>
#include <boost/random.hpp>
#include <random>
#include <iostream>
#include <vector>
using namespace CGAL;
Expand All @@ -15,7 +15,7 @@ int main( )
{
int N=10000;
std::vector<Point> v;
boost::mt19937 gen;
std::mt19937 gen;
gen.seed(0u);

random_convex_hull_in_disc_2(N,RADIUS,gen,std::back_inserter(v),K());
Expand Down
27 changes: 10 additions & 17 deletions Generator/include/CGAL/random_convex_hull_in_disc_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

#ifndef CGAL_RANDOM_CONVEX_HULL_DISC_H
#define CGAL_RANDOM_CONVEX_HULL_DISC_H 1
#include <boost/random.hpp>
#include <random>
//#include <boost/random.hpp>
#include <CGAL/Polygon_2_algorithms.h>
#include <CGAL/function_objects.h>
#include <CGAL/copy_n.h>
Expand Down Expand Up @@ -57,28 +58,22 @@ void generate_points_annulus(long n, double a, double b, double small_radius,
double big_radius, std::list<P>& l,
GEN& gen) { // generate n points between a and b
if (n > 1) {
boost::binomial_distribution<long> bin_distribution(n, .5);
boost::variate_generator<GEN&, boost::binomial_distribution<long> >
g(gen, bin_distribution);
long nb = g();
std::binomial_distribution<long> bin_distribution(n, .5);
long nb = bin_distribution(gen);
generate_points_annulus(nb, a, (a + b) / 2.0, small_radius, big_radius, l,
gen);
generate_points_annulus(n - nb, (a + b) / 2.0, b, small_radius, big_radius,
l, gen);
}
if (n == 1) // generation of a point
{
boost::random::uniform_real_distribution<double> random_squared_radius_distribution(
std::uniform_real_distribution<double> random_squared_radius_distribution(
small_radius * small_radius / (big_radius * big_radius), 1);

boost::random::uniform_real_distribution<double> random_angle_distribution(a, b);
boost::random::variate_generator<
GEN&, boost::random::uniform_real_distribution<double> > random_angle(gen, random_angle_distribution);
boost::random::variate_generator<
GEN&, boost::random::uniform_real_distribution<double> > random_squared_radius(gen, random_squared_radius_distribution);
std::uniform_real_distribution<double> random_angle_distribution(a, b);

double alpha = random_angle();
double r = big_radius * std::sqrt(random_squared_radius());
double alpha = random_angle_distribution(gen);
double r = big_radius * std::sqrt(random_squared_radius_distribution(gen));
typedef Creator_uniform_2<double, P> Creator;
Creator creator;
typedef typename Creator::argument_type T;
Expand Down Expand Up @@ -217,12 +212,10 @@ void random_convex_hull_in_disc_2(std::size_t n, double radius, std::list<typena
} else {
nb = static_cast<long>((std::min)(T, n - simulated_points));
}
boost::binomial_distribution<long> dbin(nb, to_double(p_disc));
boost::variate_generator<
GEN&, boost::binomial_distribution<long> > bin(gen, dbin);
std::binomial_distribution<long> dbin(nb, to_double(p_disc));

// How many points are falling in the small disc and won't be generated:
long k_disc = bin();
long k_disc = dbin(gen);
simulated_points += k_disc;

std::list<P> m;
Expand Down
2 changes: 1 addition & 1 deletion Generator/test/Generator/random_hull_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ main( )

Polygon_2 p,q;
int n( 1000);
boost::mt19937 gen(0);
std::mt19937 gen(0);

// build random hull from n random points in a disc:
random_convex_hull_in_disc_2(n,1.0,gen,std::back_inserter(p),K(), true);
Expand Down
8 changes: 4 additions & 4 deletions GraphicsView/demo/Apollonius_graph_2/Apollonius_graph_2.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <fstream>
#include <random>

#include <boost/config.hpp>
#include <boost/version.hpp>
// CGAL headers
Expand All @@ -9,7 +11,6 @@
#include <CGAL/point_generators_2.h>
#include <CGAL/IO/WKT.h>

#include <boost/random/linear_congruential.hpp>
#include <boost/random/uniform_real.hpp>

// Qt headers
Expand Down Expand Up @@ -197,12 +198,11 @@ MainWindow::on_actionInsertRandomPoints_triggered()
QApplication::setOverrideCursor(Qt::WaitCursor);
std::vector<Apollonius_site_2> points;
points.reserve(number_of_points);
boost::rand48 rng;
std::mt19937 rng;
boost::uniform_real<> dist(0.005*width, 0.05*width);
boost::variate_generator<boost::rand48&, boost::uniform_real<> > radius(rng,dist);

for(int i = 0; i < number_of_points; ++i){
points.push_back(Apollonius_site_2(*pg++,radius()));
points.push_back(Apollonius_site_2(*pg++,dist(rng)));
}
ag.insert(points.begin(), points.end());
// default cursor
Expand Down
2 changes: 1 addition & 1 deletion GraphicsView/demo/Generator/Generator_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ MainWindow::on_actionGenerateSegmentFans_triggered()
void
MainWindow::on_actionGeneratePolytopeInDisc_triggered()
{
boost::mt19937 gen;
std::mt19937 gen;
gen.seed(time(nullptr));
std::vector<Point_2> points;
QRectF rect = CGAL::Qt::viewportsBbox(&scene);
Expand Down
6 changes: 3 additions & 3 deletions Hash_map/benchmark/Hash_map/hm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <fstream>
#include <map>
#include <algorithm>
#include <random>

#include <CGAL/Surface_mesh.h>
#include <CGAL/Simple_cartesian.h>
Expand All @@ -19,7 +20,6 @@
#include <unordered_map>

#include <boost/random/random_number_generator.hpp>
#include <boost/random/linear_congruential.hpp>

typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::Point_3 Point_3;
Expand All @@ -44,8 +44,8 @@ run(const G& g)
V2.push_back(vd);
}

boost::rand48 random;
boost::random_number_generator<boost::rand48> rng(random);
std::mt19937 random;
boost::random_number_generator<std::mt19937> rng(random);
std::random_shuffle(V.begin(), V.end(), rng);

Timer t;
Expand Down
3 changes: 0 additions & 3 deletions Hash_map/benchmark/Hash_map/polyhedron.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
#include <boost/unordered_map.hpp>
#include <unordered_map>

#include <boost/random/random_number_generator.hpp>
#include <boost/random/linear_congruential.hpp>

typedef CGAL::Simple_cartesian<int> Kernel;
struct Point_3 : Kernel::Point_3 {
using Kernel::Point_3::operator=;
Expand Down
3 changes: 0 additions & 3 deletions Hash_map/benchmark/Hash_map/surface_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
#include <boost/unordered_map.hpp>
#include <unordered_map>

#include <boost/random/random_number_generator.hpp>
#include <boost/random/linear_congruential.hpp>

typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::Point_3 Point_3;
typedef Kernel::Vector_3 Vector_3;
Expand Down
3 changes: 0 additions & 3 deletions Hash_map/benchmark/Hash_map/triangulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
#include <boost/unordered_map.hpp>
#include <unordered_map>

#include <boost/random/random_number_generator.hpp>
#include <boost/random/linear_congruential.hpp>

typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::Point_2 Point_2;
typedef Kernel::Vector_2 Vector_2;
Expand Down
15 changes: 4 additions & 11 deletions Interval_skip_list/include/CGAL/Interval_skip_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,10 @@

#include <CGAL/license/Interval_skip_list.h>


#include <CGAL/basic.h>
#include <list>
#include <iostream>

#include <boost/random/linear_congruential.hpp>
#include <boost/random/geometric_distribution.hpp>
#include <boost/random/variate_generator.hpp>

#include <random>

//#define CGAL_ISL_USE_CCC
#define CGAL_ISL_USE_LIST
Expand Down Expand Up @@ -125,7 +120,7 @@ class Interval_for_container : public Interval_
private:
typedef Interval_ Interval;
typedef typename Interval::Value Value;
boost::rand48 random;
std::mt19937 random;

#ifdef CGAL_ISL_USE_LIST
std::list<Interval> container;
Expand Down Expand Up @@ -1194,10 +1189,8 @@ template <class Interval>
int
Interval_skip_list<Interval>::randomLevel()
{
boost::geometric_distribution<> proba(0.5);
boost::variate_generator<boost::rand48&, boost::geometric_distribution<> > die(random, proba);

return (std::min)(die(), (int)maxLevel)+1;
std::geometric_distribution<> proba(0.5);
return (std::min)(proba(random), (int)maxLevel)+1;
}


Expand Down
Loading