mirror of https://github.com/CGAL/cgal
Some adjustements to the RS interface.
This commit is contained in:
parent
517a7aceb7
commit
37694c45c4
|
|
@ -32,6 +32,12 @@ class GBRS_algebraic_kernel {
|
|||
|
||||
public:
|
||||
|
||||
// constructor: we must initialize RS just a time, so this is a good
|
||||
// time to do it
|
||||
GBRS_algebraic_kernel () {
|
||||
CGAL_assertion_msg (!(init_rs ()), "error initializing RS");
|
||||
};
|
||||
|
||||
typedef IntegralDomain_ Coefficient;
|
||||
typedef Rational_polynomial_1 Polynomial_1;
|
||||
typedef MpfiInterval Algebraic_real_1;
|
||||
|
|
|
|||
|
|
@ -42,8 +42,7 @@ class Construct_polynomial_1 {
|
|||
InputIterator it;
|
||||
for (it = first; it != last; ++it)
|
||||
++elements;
|
||||
CGAL_assertion_msg (elements != 0,
|
||||
"the container can't be empty");
|
||||
CGAL_assertion_msg (elements, "the container can't be empty");
|
||||
int degree = elements-1;
|
||||
Polynomial_1 p (degree);
|
||||
for (it = first; it != last; ++it)
|
||||
|
|
@ -51,7 +50,10 @@ class Construct_polynomial_1 {
|
|||
return p;
|
||||
};
|
||||
|
||||
// TODO: check this "functor" (is this a functor?)
|
||||
// TODO: check this "functor" (what is a functor in C++?)
|
||||
|
||||
// great! now I know what is that... now I hate C++ a lot more than
|
||||
// ten minutes ago... f_-_!
|
||||
template <class InputIterator1, class InputIterator2>
|
||||
Polynomial_1 operator()
|
||||
(InputIterator1 first_coeff, InputIterator1 last_coeff,
|
||||
|
|
@ -60,17 +62,13 @@ class Construct_polynomial_1 {
|
|||
unsigned int greater = 0;
|
||||
InputIterator1 c;
|
||||
InputIterator2 d = deg;
|
||||
for (c = first_coeff; c != last_coeff; ++c) {
|
||||
for (c = first_coeff; c != last_coeff; ++c)
|
||||
if (d > greater)
|
||||
greater = d;
|
||||
++d;
|
||||
}
|
||||
greater = d++;
|
||||
// now, construct the polynomial of degree d
|
||||
Polynomial_1 p (d);
|
||||
for (c = first_coeff; c != last_coeff; ++c) {
|
||||
p.set_coef (deg, *c);
|
||||
++deg;
|
||||
}
|
||||
for (c = first_coeff; c != last_coeff; ++c)
|
||||
p.set_coef (deg++, *c);
|
||||
return p;
|
||||
};
|
||||
}; // Construct_polynomial_1
|
||||
|
|
@ -87,13 +85,15 @@ class Solve_1 {
|
|||
if (known_to_be_square_free)
|
||||
return res;
|
||||
mpfi_t *x;
|
||||
int nr = solve_1 (x, p);
|
||||
if (nr > 0)
|
||||
int nr;
|
||||
CGAL_assertion_msg (((nr = solve_1 (x, p)) >= 0),
|
||||
"error in resolution");
|
||||
if (nr)
|
||||
for (int i=0; i<nr; ++i) {
|
||||
Algebraic a (x[i]);
|
||||
mpfi_clear (x[i]); // don't waste space
|
||||
*res = a;
|
||||
++res;
|
||||
// x[i] was mpfi_inited by RS? If so,
|
||||
mpfi_clear (x[i]);
|
||||
*(res++) = a;
|
||||
}
|
||||
free (x);
|
||||
return res;
|
||||
|
|
@ -107,14 +107,16 @@ class Solve_1 {
|
|||
OutputIteratorMult mult) const {
|
||||
CGAL_assertion_msg (false, "not implemented yet");
|
||||
mpfi_t *x;
|
||||
int nr = solve_1 (x, p);
|
||||
if (nr > 0)
|
||||
int nr;
|
||||
CGAL_assertion_msg (!((nr = solve_1 (x, p)) < 0),
|
||||
"error in resolution");
|
||||
if (nr)
|
||||
for (int i=0; i<nr; ++i) {
|
||||
Algebraic a (x[i]);
|
||||
*roots = a;
|
||||
*mult = 1; // FIXME
|
||||
++roots;
|
||||
++mult;
|
||||
// x[i] was mpfi_inited by RS? If so,
|
||||
mpfi_clear (x[i]);
|
||||
*(roots++) = a;
|
||||
*(mult++) = 1; // FIXME
|
||||
}
|
||||
return std::make_pair (roots, mult);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,7 +17,9 @@
|
|||
//
|
||||
// Author(s) : Luis Peñaranda <penarand@loria.fr>
|
||||
|
||||
// this file is based on the RS original example, rs_demo_mp.c
|
||||
// this file is based on the RS original example, rs_demo_mp.c (because we
|
||||
// don't know RS, this little funny suprising amazing fantastic candy-flavored
|
||||
// library)
|
||||
|
||||
#include <gmp.h>
|
||||
#include <mpfi.h>
|
||||
|
|
@ -32,6 +34,11 @@ CGAL_BEGIN_NAMESPACE
|
|||
#define DEF_PREC 23
|
||||
#endif
|
||||
|
||||
int init_rs () {
|
||||
rs_init_rs ();
|
||||
return 0;
|
||||
};
|
||||
|
||||
int affiche_vect_ibfr (mpfi_t *&x, int index, const int ident_vect) {
|
||||
int ident_elt;
|
||||
int nb = rs_export_dim_vect_ibfr (ident_vect);
|
||||
|
|
@ -42,8 +49,7 @@ int affiche_vect_ibfr (mpfi_t *&x, int index, const int ident_vect) {
|
|||
}
|
||||
|
||||
int affiche_sols_eqs (mpfi_t *&x) {
|
||||
int ident_sols_eqs, nb_elts, ident_node, ident_vect;
|
||||
int i;
|
||||
int ident_sols_eqs, nb_elts, ident_node, ident_vect, i;
|
||||
ident_sols_eqs = rs_get_default_sols_eqs ();
|
||||
// the number of solutions
|
||||
nb_elts = rs_export_list_vect_ibfr_nb (ident_sols_eqs);
|
||||
|
|
@ -60,28 +66,22 @@ int affiche_sols_eqs (mpfi_t *&x) {
|
|||
}
|
||||
|
||||
void create_rs_upoly(mpz_t *poly, const int deg, const int ident_pol) {
|
||||
int i;
|
||||
int /*ident_pol,*/ ident_mon, ident_coeff;
|
||||
rs_import_uppring ("T");
|
||||
int ident_mon, ident_coeff, i;
|
||||
rs_import_uppring ("T"); // what the heck is this?
|
||||
for (i=0; i<=deg; ++i)
|
||||
if (mpz_sgn (poly[/*deg-*/i]) != 0) { // don't add if == 0
|
||||
if (mpz_sgn (poly[i])) { // don't add if == 0
|
||||
// (this is one of the few things we know about RS)
|
||||
ident_mon = rs_export_new_mon_upp_bz ();
|
||||
ident_coeff = rs_export_new_gmp ();
|
||||
/*CGAL_assertion_msg
|
||||
(mpz_cmp_ui (mpq_denref (poly[deg-i]), 1) == 0,
|
||||
"by now, RS works only with integer coeffs");*/
|
||||
/*rs_import_bz_gmp
|
||||
(ident_coeff,
|
||||
TO_RSPTR_IN (mpq_numref (poly[deg-i])));*/
|
||||
rs_import_bz_gmp
|
||||
(ident_coeff, TO_RSPTR_IN (&(poly[/*deg-*/i])));
|
||||
(ident_coeff, TO_RSPTR_IN (&(poly[i])));
|
||||
rs_dset_mon_upp_bz (ident_mon, ident_coeff, i);
|
||||
rs_dappend_list_mon_upp_bz (ident_pol, ident_mon);
|
||||
}
|
||||
}
|
||||
|
||||
int solve_1 (mpfi_t *&x, const Rational_polynomial_1 &p1, unsigned int prec) {
|
||||
rs_init_rs ();
|
||||
// the solver must be initialized
|
||||
rs_reset_all ();
|
||||
create_rs_upoly
|
||||
(p1.get_coefs (), p1.get_degree (), rs_get_default_up ());
|
||||
|
|
@ -93,7 +93,7 @@ int solve_1 (mpfi_t *&x, const Rational_polynomial_1 &p1, unsigned int prec) {
|
|||
return affiche_sols_eqs (x); // return the number of solutions
|
||||
}
|
||||
|
||||
int solve_1 (mpfi_t *&x, const Rational_polynomial_1 &p1) {
|
||||
inline int solve_1 (mpfi_t *&x, const Rational_polynomial_1 &p1) {
|
||||
return solve_1 (x, p1, DEF_PREC);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,13 +24,17 @@
|
|||
#include <CGAL/Gbrs_polynomial_1.h>
|
||||
|
||||
CGAL_BEGIN_NAMESPACE
|
||||
// both functions return the number of roots
|
||||
|
||||
// initialize the RS solver, returns 0 if everything was OK
|
||||
int init_solver ();
|
||||
|
||||
// next functions return the number of roots:
|
||||
|
||||
// solve given the precision
|
||||
int solve_1 (mpfi_t *&, const Rational_polynomial_1 &, unsigned int);
|
||||
|
||||
// solve with the default precision
|
||||
int solve_1 (mpfi_t *&, const Rational_polynomial_1 &);
|
||||
inline int solve_1 (mpfi_t *&, const Rational_polynomial_1 &);
|
||||
|
||||
CGAL_END_NAMESPACE
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue