void _calculate_parameters(double h,my_point p[],double w[],int num) { double H,I,J,K,L,A0, A1; double x,y,d; if (num > MAX_POINTS_NUM) { fprintf(stderr,"Point number is larger than previous set!\n"); return; } is_set_ret = false; compute_Aj(h,w,num); H = compute_H(p,num); I = compute_I(p,num); J = compute_J(p,num); K = compute_K(p,num); L = compute_L(p,num); A0 = H -h*h*J*J-K+h*h*L*L; A1 = 2*(I-h*h*J*L); // printf("H=%.3lf I=%.3lf J=%.3lf K=%.3lf L=%.3lf A0=%.3lf A1=%.3lf\n", // H,I,J,K,L,A0,A1); // printf("Calculated as follows:\n"); if (0 == A0) { if (0 == A1) { // A0 A1 are0 // x,y could be any value #if 1 printf("The distribution of the given points is a circle.\n"); x = y = sqrt(2.0) / 2; d = -(h*h*(J*x+L*y)); compute_error(d,x,y,p,num); #else #endif } else { // A0 is 0 A1 is not 0,x2=1/2,x2+y2=1 double ar[2] = {sqrt(2.0)/2,-sqrt(2.0)/2};// possible values of x,y int i,j; for (i=0;i<2;i++) { x = ar[i]; for (j=0;j<2;j++) { y = ar[j]; d = -(h*h*(J*x+L*y)); compute_error(d,x,y,p,num); } } } } else if (0 == A1) { double x_ar[4] = {0,0,1,-1}; double y_ar[4] = {1,-1,0,0};//possible values of x,y int i; for (i=0;i<4;i++) { x = x_ar[i]; y = y_ar[i]; d = -(h*h*(J*x+L*y)); compute_error(d,x,y,p,num); } } else { // A0!=0 A1!=0 double t = A0 / sqrt (A1*A1+A0*A0); // 0 < t < 1 double x_ar[4] = {sqrt (0.5*(1+t)),sqrt (0.5*(1-t)), -sqrt (0.5*(1+t)),-sqrt (0.5*(1-t))}; // possible values of x , x2 ≠ 0 or 1 int i; for (i=0;i<4;i++) { x = x_ar[i]; y = (A1/A0)* (x - 0.5/x); d = -(h*h*(J*x+L*y)); compute_error(d,x,y,p,num); } } }
static void compute_csas(ConsensusSA *csa) { unsigned long i, sa_i, sa_i_size = 0, sa_prime, sa_prime_size; GtArray *splice_form; GtBittab **C, **left, **right, **L, **R, *U_i, *SA_i, *SA_prime; #ifndef NDEBUG unsigned long u_i_size, u_i_minus_1_size; gt_assert(csa && csa->set_of_sas); #endif /* init sets */ C = gt_malloc(sizeof (GtBittab*) * csa->number_of_sas); left = gt_malloc(sizeof (GtBittab*) * csa->number_of_sas); right = gt_malloc(sizeof (GtBittab*) * csa->number_of_sas); L = gt_malloc(sizeof (GtBittab*) * csa->number_of_sas); R = gt_malloc(sizeof (GtBittab*) * csa->number_of_sas); for (i = 0; i < csa->number_of_sas; i++) { C[i] = gt_bittab_new(csa->number_of_sas); left[i] = gt_bittab_new(csa->number_of_sas); right[i] = gt_bittab_new(csa->number_of_sas); L[i] = gt_bittab_new(csa->number_of_sas); R[i] = gt_bittab_new(csa->number_of_sas); } U_i = gt_bittab_new(csa->number_of_sas); SA_i = gt_bittab_new(csa->number_of_sas); SA_prime = gt_bittab_new(csa->number_of_sas); splice_form = gt_array_new(sizeof (unsigned long)); /* compute sets */ compute_C(C, csa); compute_left(left, csa); compute_right(right, csa); compute_L(L, C, left, csa->number_of_sas); compute_R(R, C, right, csa->number_of_sas); /* U_0 = SA */ for (i = 0; i < csa->number_of_sas; i++) gt_bittab_set_bit(U_i, i); #ifndef NDEBUG /* preparation for assertion below */ u_i_minus_1_size = gt_bittab_count_set_bits(U_i); #endif while (gt_bittab_is_true(U_i)) { sa_i = GT_UNDEF_ULONG; for (sa_prime = gt_bittab_get_first_bitnum(U_i); sa_prime != gt_bittab_get_last_bitnum(U_i); sa_prime = gt_bittab_get_next_bitnum(U_i, sa_prime)) { if (sa_i == GT_UNDEF_ULONG) { sa_i = sa_prime; gt_bittab_or(SA_i, L[sa_i], R[sa_i]); sa_i_size = gt_bittab_count_set_bits(SA_i); } else { gt_bittab_or(SA_prime, L[sa_prime], R[sa_prime]); sa_prime_size = gt_bittab_count_set_bits(SA_prime); if (sa_prime_size > sa_i_size) { sa_i = sa_prime; sa_i_size = sa_prime_size; gt_bittab_equal(SA_i, SA_prime); } } } /* make sure the computed splice form is maximal w.r.t. to compatibility */ gt_assert(splice_form_is_valid(SA_i, csa)); /* process splice form */ if (csa->process_splice_form) { gt_array_reset(splice_form); gt_bittab_get_all_bitnums(SA_i, splice_form); csa->process_splice_form(splice_form, csa->set_of_sas, csa->number_of_sas, csa->size_of_sa, csa->userdata); } /* U_i = U_i-1 \ SA_i */ gt_bittab_nand(U_i, U_i, SA_i); #ifndef NDEBUG /* ensure that |U_i| < |U_i-1| */ u_i_size = gt_bittab_count_set_bits(U_i); gt_assert(u_i_size < u_i_minus_1_size); u_i_minus_1_size = u_i_size; #endif } /* free sets */ for (i = 0; i < csa->number_of_sas; i++) { gt_bittab_delete(C[i]); gt_bittab_delete(left[i]); gt_bittab_delete(right[i]); gt_bittab_delete(L[i]); gt_bittab_delete(R[i]); } gt_free(C); gt_free(left); gt_free(right); gt_free(L); gt_free(R); gt_bittab_delete(U_i); gt_bittab_delete(SA_i); gt_bittab_delete(SA_prime); gt_array_delete(splice_form); }