diff --git a/Apollonius_graph_2/changes.txt b/Apollonius_graph_2/changes.txt index 16251fa015a..4e0aea0bd43 100644 --- a/Apollonius_graph_2/changes.txt +++ b/Apollonius_graph_2/changes.txt @@ -1,3 +1,6 @@ +21 July 2006: Menelaos Karavelas +- added various site generators and example programs + 20 July 2006: Menelaos Karavelas - fixes in #includes: correct files are now included - added mixed traits classes, filtered and non-filtered diff --git a/Apollonius_graph_2/generators/README.txt b/Apollonius_graph_2/generators/README.txt index 844d94a033e..a5b3bb618e7 100644 --- a/Apollonius_graph_2/generators/README.txt +++ b/Apollonius_graph_2/generators/README.txt @@ -4,23 +4,67 @@ include/CGAL directory: make_degenerate.h ================= PROVIDES: make_degenerate (function) -INPUT: A input range of sites, an output iterator, and a traits class +INPUT: A input range of sites, an output iterator, and a traits class. OUTPUT: Computes the Apollonius graph of the input range, then writes the Voronoi circles of the Apollonius diagram of the input sites to the output iterator. The output is a set of sites for - the Apollonius diagram + the Apollonius diagram. +EXAMPLE: mk_degen.cpp USAGE: Can be used to generate a set of sites in almost degenerate or - degenerate configuration using the input set of sites + degenerate configuration using the input set of sites. random_sites_in_0x1_box.h ========================= PROVIDES: Random_sites_in_0x1_box (functor) -INPUT: at construction time the max radius and a seed need to be passed +INPUT: at construction time the max radius and a seed need to be passed. OUTPUT: using operator*(), the user can get one random site with its center in the box [0,1]x[0,1] and its radius between 0 and the max radius passed at construction time; the random number - generator used is CGAL::Random + generator used is CGAL::Random. +EXAMPLE: gen_sites_in_0x1_box.cpp USAGE: Can be used to generate random sites within the [0,1]x[0,1] box with a prespecified max radius and seed for the random number generator. There is no guarantee as to whether the site returned is hidden or not by previously generated sites. + +random_integral_sites_in_square_2.h +=================================== +PROVIDES: Random_integral_sites_in_square_2 (functor) +INPUT: at construction two unsigned integers b and B and a seed need + to be passed. +OUTPUT: using operator*(), the user can get one random site with its + center in [-M,M]x[-M,M], where M = 2^b-1, and its weight in + [0,R], where R = 2^B-1; the random number generator used is + CGAL::Random. Zero bit size means that the corresponding + number is zero. +EXAMPLE: gen_integral_sites_in_square.cpp +USAGE: Can be used to generate sites with integer coordinates and + weight; the bit size of the coordinates and the weight can be + prescribed; allowed values of bit sizes are between 0 and 52, + inclusive. There is no guarantee as to whether the site + returned is hidden or not by previously generated sites. + +random_integral_sites_on_parabola_2.h +===================================== +PROVIDES: Random_integral_sites_on_parabola_2 (functor) +INPUT: at construction an unsigned integer b, an unsigned integer p + and a seed need to be passed. By default p is set to 0. +OUTPUT: using operator*(), the user can get one random site of the + form {(t, t^2), w}, where t is in [-M, M], M = 2^b-1; the + weight w is equal to t^2 unless p is not equal to zero, + in which case w is equal t^2 + e, where e is an integer of bit + size at most p; the random number generator used is + CGAL::Random. Zero bit size means that the corresponding + number is zero. +EXAMPLE: gen_integral_sites_on_parabola.cpp +USAGE: Can be used to generate sites with integer coordinates and + weight with prescribed bit size; allowed values of bit sizes + are between 0 and 26, inclusive. There is no guarantee as to + whether the site returned is hidden or not by previously + generated sites. If p is equal to 0, the Apollonius diagram + created has a vertex of degree n-2, where n is the number of + sites created; all sites are tangent to the x-axis and all lie + above it. If p is non-zero, but small with respect to b, then + the centers of the sites still lie on the parabola y = x^2, but + the weights are perturbed by just a fe bits, thus providing a + set of input sites that are in almost degenerate configuration. diff --git a/Apollonius_graph_2/generators/gen_integral_sites_in_square.cpp b/Apollonius_graph_2/generators/gen_integral_sites_in_square.cpp new file mode 100644 index 00000000000..0e48f685eb7 --- /dev/null +++ b/Apollonius_graph_2/generators/gen_integral_sites_in_square.cpp @@ -0,0 +1,62 @@ +#include +#include +#include + +#include +#include +#include + +#include +#include + +typedef CGAL::Simple_cartesian K; +typedef CGAL::Apollonius_site_2 Site_2; +typedef CGAL::Random Random; + +int usage (int argc, char *argv[]) +{ + std::cerr << "usage: " << argv[0] + << " " + << "[bit size of weights] [seed]" << std::endl; + return 2; +} + +int main(int argc, char *argv[]) +{ + int num, seed = 17; + unsigned int b, B; + + if ( argc < 3 ) { + return usage(argc, argv); + } + + { + std::istringstream is(argv[1]); + if ( !(is >> num) ) { return usage(argc, argv); } + } + + { + std::istringstream is(argv[2]); + if ( !(is >> b) ) { return usage(argc, argv); } + B = b; + } + + if ( argc > 3 ) { + std::istringstream is(argv[3]); + if ( !(is >> B) ) { return usage(argc, argv); } + } + + if ( argc > 4 ) { + std::istringstream is(argv[4]); + if ( !(is >> seed) ) { return usage(argc, argv); } + } + + CGAL::Random_integral_sites_in_square_2 g(b, B, seed); + + std::cout << std::setprecision(17); + for (int i = 0; i < num; ++i) { + std::cout << *g << std::endl; + } + + return 0; +} diff --git a/Apollonius_graph_2/generators/gen_integral_sites_on_parabola.cpp b/Apollonius_graph_2/generators/gen_integral_sites_on_parabola.cpp new file mode 100644 index 00000000000..648d403d9ee --- /dev/null +++ b/Apollonius_graph_2/generators/gen_integral_sites_on_parabola.cpp @@ -0,0 +1,61 @@ +#include +#include +#include + +#include +#include +#include + +#include +#include + +typedef CGAL::Simple_cartesian K; +typedef CGAL::Apollonius_site_2 Site_2; +typedef CGAL::Random Random; + +int usage (int argc, char *argv[]) +{ + std::cerr << "usage: " << argv[0] + << " " + << "[bit size of perturbation] [seed]" << std::endl; + return 2; +} + +int main(int argc, char *argv[]) +{ + int num, seed = 17; + unsigned int b, p = 0; + + if ( argc < 3 ) { + return usage(argc, argv); + } + + { + std::istringstream is(argv[1]); + if ( !(is >> num) ) { return usage(argc, argv); } + } + + { + std::istringstream is(argv[2]); + if ( !(is >> b) ) { return usage(argc, argv); } + } + + if ( argc > 3 ) { + std::istringstream is(argv[3]); + if ( !(is >> p) ) { return usage(argc, argv); } + } + + if ( argc > 4 ) { + std::istringstream is(argv[4]); + if ( !(is >> seed) ) { return usage(argc, argv); } + } + + CGAL::Random_integral_sites_on_parabola_2 g(b, p, seed); + + std::cout << std::setprecision(17); + for (int i = 0; i < num; ++i) { + std::cout << *g << std::endl; + } + + return 0; +} diff --git a/Apollonius_graph_2/generators/gen_sites_in_0x1_box.cpp b/Apollonius_graph_2/generators/gen_sites_in_0x1_box.cpp index ec8268b8f0b..2d3c01c5b42 100644 --- a/Apollonius_graph_2/generators/gen_sites_in_0x1_box.cpp +++ b/Apollonius_graph_2/generators/gen_sites_in_0x1_box.cpp @@ -24,20 +24,20 @@ int main (int argc, char **argv) int num, seed = 42; double rmax; - if (argc < 2) + if (argc < 3) return usage (argc, argv); { - std::istringstream is (argv[1]); - if (! (is >> num)) return usage (argc, argv); + std::istringstream is(argv[1]); + if ( !(is >> num) ) { return usage(argc, argv); } } { - std::istringstream is (argv[2]); - if (! (is >> rmax)) return usage (argc, argv); + std::istringstream is(argv[2]); + if ( !(is >> rmax) ) { return usage(argc, argv); } } if (argc > 3) { - std::istringstream is (argv[3]); - if (! (is >> seed)) return usage (argc, argv); + std::istringstream is(argv[3]); + if ( !(is >> seed) ) { return usage(argc, argv); } } CGAL::Random_sites_in_0x1_box g(rmax, seed); diff --git a/Apollonius_graph_2/generators/include/CGAL/Apollonius_graph_2/random_integral_sites_in_square_2.h b/Apollonius_graph_2/generators/include/CGAL/Apollonius_graph_2/random_integral_sites_in_square_2.h new file mode 100644 index 00000000000..75abed3670f --- /dev/null +++ b/Apollonius_graph_2/generators/include/CGAL/Apollonius_graph_2/random_integral_sites_in_square_2.h @@ -0,0 +1,49 @@ +#ifndef CGAL_APOLLONIUS_GRAPH_2_RANDOM_INTEGRAL_SITES_IN_SQUARE_2_H +#define CGAL_APOLLONIUS_GRAPH_2_RANDOM_INTEGRAL_SITES_IN_SQUARE_2_H 1 + +#include +#include + +CGAL_BEGIN_NAMESPACE + +// creates a random site with x, y in [-M,M]x[-M,M] +// where M = 2^b - 1 and r in [0,R], R = 2^B - 1 + +template +class Random_integral_sites_in_square_2 +{ +public: + typedef Site Site_2; + typedef R Random; + +public: + Random_integral_sites_in_square_2(unsigned int b, int seed) + : b_(b), B_(b), r_(seed) { + CGAL_precondition( b >= 0 && b <= 52 ); + } + + Random_integral_sites_in_square_2(unsigned int b, unsigned int B, int seed) + : b_(b), B_(B), r_(seed) { + CGAL_precondition( b >= 0 && b <= 52 ); + CGAL_precondition( B >= 0 && B <= 52 ); + } + + Site_2 operator*() + { + double x = random_integer(r_, b_, true); + double y = random_integer(r_, b_, true); + double w = random_integer(r_, B_, false); + assert( w >= 0 ); + + typename Site_2::Point_2 p(x, y); + return Site_2(p, w); + } + +private: + unsigned int b_, B_; + Random r_; +}; + +CGAL_END_NAMESPACE + +#endif // CGAL_APOLLONIUS_GRAPH_2_RANDOM_INTEGRAL_SITES_IN_SQUARE_2_H diff --git a/Apollonius_graph_2/generators/include/CGAL/Apollonius_graph_2/random_integral_sites_on_parabola_2.h b/Apollonius_graph_2/generators/include/CGAL/Apollonius_graph_2/random_integral_sites_on_parabola_2.h new file mode 100644 index 00000000000..8699229fcff --- /dev/null +++ b/Apollonius_graph_2/generators/include/CGAL/Apollonius_graph_2/random_integral_sites_on_parabola_2.h @@ -0,0 +1,49 @@ +#ifndef CGAL_APOLLONIUS_GRAPH_2_RANDOM_INTEGRAL_SITES_ON_PARABOLA_2_H +#define CGAL_APOLLONIUS_GRAPH_2_RANDOM_INTEGRAL_SITES_ON_PARABOLA_2_H 1 + +#include +#include + +CGAL_BEGIN_NAMESPACE + +// creates a random site of the form {(t, t^2), t^2}, where t is in +// the range [-M, M], M = 2^b - 1 + +template +class Random_integral_sites_on_parabola_2 +{ +public: + typedef Site Site_2; + typedef R Random; + +public: + Random_integral_sites_on_parabola_2(unsigned int b, int seed) + : b_(b), p_(0), r_(seed) { + CGAL_precondition( b >= 0 && b <= 26 ); + } + + Random_integral_sites_on_parabola_2(unsigned int b, unsigned int p, + int seed) + : b_(b), p_(p), r_(seed) { + CGAL_precondition( b >= 0 && b <= 26 ); + CGAL_precondition( p >= 0 && p <= 26 ); + } + + Site_2 operator*() + { + double t = random_integer(r_, b_, true); + double t2 = t * t; + double perb = random_integer(r_, p_, true); + + typename Site_2::Point_2 p(t, t2); + return Site_2(p, t2 + perb); + } + +private: + unsigned int b_, p_; + Random r_; +}; + +CGAL_END_NAMESPACE + +#endif // CGAL_APOLLONIUS_GRAPH_2_RANDOM_INTEGRAL_SITES_ON_PARABOLA_2_H diff --git a/Apollonius_graph_2/generators/include/CGAL/random_integer.h b/Apollonius_graph_2/generators/include/CGAL/random_integer.h index e8afc5f8a92..3f5ef12edc1 100644 --- a/Apollonius_graph_2/generators/include/CGAL/random_integer.h +++ b/Apollonius_graph_2/generators/include/CGAL/random_integer.h @@ -55,13 +55,15 @@ double random_integer(int b, bool allow_negative = true) } template -double random_integer(Random& r, int b, bool allow_negative = true) +double random_integer(Random& r, unsigned int b, bool allow_negative = true) { // returns random integers in the range [0, 2^b - 1). // b is required to be at least 1 and at most 52 // and if allow_negative is true then the range includes negative // numbers as well and becomes: [-2^b + 1, 2^b - 1). - assert( b >= 1 && b <= 52 ); + CGAL_precondition( b >= 0 && b <= 52 ); + + if ( b == 0 ) { return 0; } double M = pow(2.0,b); CGAL::Gmpz z; @@ -76,13 +78,16 @@ double random_integer(Random& r, int b, bool allow_negative = true) template -double random_even_integer(Random& r, int b, bool allow_negative = true) +double random_even_integer(Random& r, unsigned int b, + bool allow_negative = true) { // returns random even integers in the range [0, 2^b - 1). // b is required to be at least 1 and at most 52 // and if allow_negative is true then the range includes negative // numbers as well and becomes: [-2^b + 1, 2^b - 1). - assert( b >= 1 && b <= 52 ); + assert( b >= 0 && b <= 52 ); + + if ( b == 0 ) { return 0; } double M = pow(2.0,b); CGAL::Gmpz z;