void GraphicsScene::actualiserScene() { vitesseTemps += 1.0; vitesseVx = round( vitesseTemps / 500.0 ); vitesseVy = round( vitesseTemps / 500.0 ); if( !dispersion && !ball->isStop() && ball->getEndPoint()->x() > width()/4 && ball->collidesWithItem( prismeForme ) ) { decomposition(); dispersion = true; } foreach(Ball* newBall, ballCollection) { if(newBall != ballDefault && !newBall->isStop() ) { collisionManager->testCollision( newBall ); newBall->updatePosition(); verifyVitesse( newBall ); } } iaManager->actualizeBarIADirection( ballCollection ); barIA->updatePosition(); barPlayer->testInitStop(); }
void decomposition(int num, int level = 0) { static int sum[40]; if (num == 1) // 1 { sum[level] = 1; printArr(sum, level+1); return; } /* if (num == 2) // 1+1 { sum[level] = 1; sum[level+1] = 1; printArr(sum, level+2); return; } */ for (int i = num - 1; i > 0; i--) { if (i > sum[level-1] && level != 0) //не даем повторение сумм i = sum[level-1]; sum[level] = i; int difference = num - i; if ( i >= difference && difference > 1) { sum[level+1] = difference; printArr(sum, level+2); } decomposition(difference, level+1); } }
std::vector<shortcut> operator()() const { std::vector<shortcut> shortcuts; monotone_decomposition decomposition; auto monotone_lines = decomposition(line); auto line_points = get_line_points(monotone_lines, line.coordinates); for (auto i = 0u; i < monotone_lines.size(); ++i) { const auto& m = monotone_lines[i]; PointFilterT filter(line.coordinates.begin() + m.begin_idx, line.coordinates.begin() + m.end_idx, i); auto filtered_points = filter(line_points); filtered_points.insert(filtered_points.end(), points.begin(), points.end()); auto transformed_points = transform_points(m.mono, filtered_points); auto monotone_shortcuts = simplify_monotone_line(m.line, transformed_points); // fix up indices for (auto& s : monotone_shortcuts) { s.first += m.begin_idx; s.last += m.begin_idx; BOOST_ASSERT(s.first < m.end_idx); BOOST_ASSERT(s.last < m.end_idx); } shortcuts.insert(shortcuts.end(), monotone_shortcuts.begin(), monotone_shortcuts.end()); } return shortcuts; }
/** A utility function to compute the barycentric coordinates of the origin wrt. to a given k-simplex. The simplex vertices' coordinates are given in the canonical basis of Z^d, and we assume k <= d. \param simplex the k+1 vertices of a k-simplex embedded in Z^d \return the barycentric coordinates of the origin wrt. simplex */ GJKnD::Vector GJKnD::barycentricCoordinatesOrigin(const std::vector<Point> & simplex) { assert(simplex.size() > 1); const size_t dim = simplex.size() - 1; // we compute some "basis vectors" wrt. simplex std::vector<Vector> basisVectors; for (size_t i = 0; i < dim; ++i) basisVectors.push_back(simplex[i] - simplex[dim]); // we project each vertex of the simplex onto each basis vector Matrix A(dim + 1, dim + 1); for (size_t j = 0; j < dim; ++j) for (size_t i = 0; i < dim + 1; ++i) A(j,i) = simplex[i].dot(basisVectors[j]); for (size_t i = 0; i < dim + 1; ++i) A(dim,i) = 1; Vector origin(dim + 1); for (size_t i = 0; i < dim + 1; ++i) origin(i) = 0.0; origin(dim) = 1; // we solve the linear system Eigen::ColPivHouseholderQR<Matrix> decomposition(A); if (!decomposition.isInvertible()) throw SingularSystem(); return decomposition.solve(origin); }
/** *\fn main (int argc, char * argv[]){ *\brief si on prend en argumen le chemin d'un fichier et un nom, on renome le fichier avec le nom et on retourne o, sinon on retournt -1; **/ int main (int argc, char * argv[]){ if(argc==3){ iter iter=decomposition(strdup(argv[1])); if(strcmp(iter->name, "FILE:")==0){ if(iter->next!=NULL){ iter=iter->next; if(strcmp(iter->name,"HOST")==0){ return 1; }else{ if(iter->next!=NULL){ iter=iter->next; disk_id *id=malloc(sizeof(disk_id)); error err = start_disk(iter->name, id); if(err.errnb!=-1){ if(tfs_rename(argv[1], argv[2])!=-1){ return 0; } } } } } } } return -1; }
int _tmain(int argc, _TCHAR* argv[]) { printf("Input N: \n"); int N = 0; scanf("%d", &N); decomposition(N); scanf("%d", &N); return 0; }
int main ( int argc, char *argv[] ) /******************************************************************************/ /* Purpose: MAIN is the main program for the star discrepancy bound computation. Modified: 30 September 2003 Reference: Eric Thiemard, An Algorithm to Compute Bounds for the Star Discrepancy, Journal of Complexity, Volume 17, pages 850-880, 2001. */ { int i; int j; double *oalpha; double *obeta; initparameters(argc,argv); readfile(argv[4]); printf("x={\n"); for (i=0;i<taille;i++) { printf(" ("); for (j=0;j<s;j++) printf(" %f",points[i][j]); printf(" )\n"); } printf("}\n\n"); supertree(); initlex(); oalpha = (double *) calloc((unsigned) s,sizeof(double)); obeta = (double *) calloc((unsigned) s,sizeof(double)); for (i=0;i<s;i++) obeta[i] = 1.0; decomposition(oalpha,obeta,0,1.0); printf("s=%d, epsilon=%f, n=%d\n",s,p,taille); printf("D_n^*(x) between %.10f and %.10f\n",borneinf,borne); return 0; }
complex det(const matrix& A) { matrix decomposition = LU(A); int N = A.nRows(); // Multiplies the diagonal entries to get the determinant up to a sign complex determinant(1., 0.); for(int i=0; i<N; i++) determinant *= decomposition(i,i); return determinant; }
boost::shared_ptr<DynamicGlyphMatcherT> operator()(boost::shared_ptr<const TFontImage> font, const std::map<std::string, std::string>& options) const { size_t nfeatures = 10; if (options.count("nf")) { try { nfeatures = boost::lexical_cast<size_t>(options.find("nf")->second); } catch (boost::bad_lexical_cast&) { } } boost::shared_ptr<EigendecompositionT> decomposition(new EigendecompositionT(font)); if (options.count("cache") && !options.find("cache")->second.empty()) { decomposition->loadFromCache(options.find("cache")->second); } else { decomposition->analyze(); } if (options.count("makecache") && !options.find("makecache")->second.empty()) { decomposition->saveToCache(options.find("makecache")->second); } boost::shared_ptr<PrincipalComponentsT> components(new PrincipalComponentsT(decomposition, nfeatures)); boost::shared_ptr<PcaGlyphMatcherT> matcher(new PcaGlyphMatcherT(components)); boost::shared_ptr<DynamicGlyphMatcherT> dynamic_matcher(new DynamicGlyphMatcherT(matcher)); return dynamic_matcher; }
Ref decomposition_call(ref_list args){ if (args->length != 1){ set_err(ETYPE, "too many arguments"); return NULL; } if (arg_isMatrix(args->list[0]) == false) return NULL; Matrix M = CAST_REF2MATRIX(args->list[0]); Matrix LUP[3] = {NULL, NULL, NULL}; decomposition(M,&LUP[0],&LUP[1],&LUP[2]); int i; for ( i = 0; i < 3; i++){ if (LUP[i] != NULL){ displayMatrix(LUP[i]); dropMatrix(LUP[i]); } } return NO_REF; }
/*! Decomposes a character into its parts. Returns an empty string if no decomposition exists. */ QString QChar::decomposition() const { return decomposition(ucs); }
int transient_simulation(LIST* list, gsl_matrix *matrix , gsl_matrix *c_matrix , gsl_vector *vector , gsl_vector *x, gsl_permutation* permutation) { LIST* v_i_list; double fin_time = list->fin_time; double curr_time = 0; double time_step = list->time_step; time_step = 0.1; int flag; gsl_vector *prev_vector; gsl_vector *temp_vector; gsl_vector *e_t; gsl_vector *e_t_minus_one; gsl_vector *prev_x; gsl_matrix *right_matrix; gsl_matrix *tmp_matrix; gsl_matrix *curr_matrix; int i; // sparse simulation int vector_size; char method; int sign; sparse_matrix* sp_matrix; sparse_vector* sp_vector; sparse_vector* sp_x; gsl_vector* x_sparse; gsl_vector* vector_sparse; gsl_vector* vector_gsl; if(!list->sparse ) { flag = create_mna(list, &matrix, &vector, 1 ,&c_matrix); //print_matrix_gsl(matrix); if(!flag ) { printf("Error creating mna system\n"); return -1; } v_i_list = create_source_list(list); tmp_matrix = gsl_matrix_calloc(matrix->size1 , matrix->size1); curr_matrix = gsl_matrix_calloc(matrix->size1 , matrix->size1); right_matrix = gsl_matrix_calloc(matrix->size1,matrix->size2); if( !tmp_matrix || !right_matrix) return 0; gsl_matrix_memcpy(right_matrix,matrix); gsl_matrix_memcpy(tmp_matrix,matrix); gsl_matrix_memcpy(curr_matrix,matrix); x = gsl_vector_calloc(matrix->size1); if( !x ) { printf("X vector : no memory\n"); exit(1); } if(list->transient_sim == METHOD_TR) { gsl_matrix_scale(c_matrix, (2/time_step)); gsl_matrix_add(tmp_matrix,c_matrix); gsl_matrix_sub(right_matrix,c_matrix); } else { gsl_matrix_scale (c_matrix, 1/time_step); gsl_matrix_add(tmp_matrix,c_matrix); gsl_matrix_memcpy(right_matrix , c_matrix); } x = gsl_vector_calloc(matrix->size1); if( !x ) { printf("X vector : no memory\n"); exit(1); } } else { method = list->solving_method; sp_matrix = (sparse_matrix*)create_mna_sparse( list , &sp_vector , &vector_size); if( !sp_matrix ) { fprintf(stderr, "Error creating MNA matrix \n"); exit(1); } /* conversion of a double into a gsl */ x_sparse = gsl_vector_calloc(sp_matrix->n); vector_sparse = gsl_vector_calloc(sp_matrix->n); double_vector_to_gsl_vector(vector_sparse,sp_vector,vector_size); sp_x = (sparse_vector*) malloc( vector_size * sizeof(sparse_vector)); } /* printf("matrix:\n"); print_matrix_gsl(matrix); printf("Tmp Matrix:\n"); print_matrix_gsl(tmp_matrix); printf("right_matrix:\n"); print_matrix_gsl(right_matrix); printf("c_matrix:\n"); print_matrix_gsl(c_matrix); */ prev_vector = gsl_vector_calloc(vector->size); temp_vector = gsl_vector_calloc(vector->size); if( !prev_vector || !temp_vector) { printf("Couldn't allocate memory for prev_vector & temp_vector"); return 0; } prev_x = gsl_vector_calloc(x->size); if( !prev_x ) { printf("Couldn't allocate memory for prev_x"); return 0; } e_t_minus_one = gsl_vector_calloc(vector->size); e_t = gsl_vector_calloc(vector->size); if( !e_t || !e_t_minus_one) { printf("Couldn't allocate memory for e(t) & e(t-1)"); return 0; } printf("TRANSIENT: Solving Method = %d\n",list->solving_method); printf("fin_time: %lf\n",fin_time); for(curr_time = (-1)*time_step; curr_time <= 3; curr_time += time_step) { if(curr_time == 0) { gsl_vector_memcpy(e_t_minus_one,vector); //dc initialize gsl_matrix_memcpy(matrix,tmp_matrix); } if(curr_time >= 0) { // x(t-1) gsl_vector_memcpy(prev_x,x); //print_vector_gsl(temp_vector); // right_matrix * x(t-1) lh_matrix_vector_mul( prev_x, right_matrix , temp_vector , NON_TRANSP); //print_vector_gsl(temp_vector); // calculate e(t) e_t = calc_right_hand_vect(v_i_list , e_t_minus_one ,curr_time); /*gsl_vector_memcpy(prev_vector,e_t); gsl_vector_add(prev_vector,e_t_minus_one); printf("e(t) + e(t-1) = \n"); print_vector_gsl(prev_vector); */ // get ready for next math operations gsl_vector_memcpy(prev_vector,e_t_minus_one); gsl_vector_memcpy(vector,e_t); if(list->transient_sim == METHOD_TR) { // e(t-1) - right_matrix*x(t-1) gsl_vector_sub(prev_vector, temp_vector); // e(t) + e(t-1) - right_matrix*x(t-1) gsl_vector_add(vector,prev_vector); printf("b = \n"); print_vector_gsl(vector); // e_t_minus_one = e_t for the next iteration gsl_vector_memcpy(e_t_minus_one,e_t); } LIST_NODE* curr; } for(i = 0; i < x->size; i++) gsl_vector_set(x,i,0); if ( !list->sparse ) { /* Cholesky or LU */ if( list->solving_method == METHOD_LU || list->solving_method == METHOD_CHOLESKY ) { gsl_matrix_memcpy(curr_matrix , matrix); decomposition(matrix,&permutation,&sign,list->solving_method); if(list->dc_sweep.node != NULL) { dc_sweep(*list,matrix,vector,x,permutation,list->solving_method); } else { int array_size = 1; solve(matrix,vector,x,permutation,list->solving_method); print_vector_gsl(x); if(list->plot == PLOT_ON) { gsl_vector ** plot_array; plot_array = plot_create_vector( array_size , x->size); if(plot_array == NULL) { perror("Error while allocating the ploting array\n"); exit(0); } plot_set_vector_index(plot_array ,x ,0); if ( list->solving_method == METHOD_LU ) plot_to_file(list->hashtable,plot_array,array_size,"results_plot_file_lu.txt"); else plot_to_file(list->hashtable,plot_array,array_size,"results_plot_file_chol.txt"); } } gsl_matrix_memcpy(matrix , curr_matrix); } else if ( list->solving_method == METHOD_CG ) { if( list->dc_sweep.node != NULL ) { dc_sweep(*list,matrix,vector,x,permutation,list->solving_method); } else { iter_solve_cg( matrix , vector , x); gsl_vector ** plot_array; plot_array = plot_create_vector( 1 , x->size); if(plot_array == NULL) { perror("Error while allocating the ploting array\n"); exit(0); } plot_set_vector_index(plot_array ,x ,0); plot_to_file(list->hashtable,plot_array,1 ,"results_plot_file_cg.txt"); } } else if( list->solving_method == METHOD_BICG) { if( list->dc_sweep.node != NULL ) { dc_sweep(*list,matrix,vector,x,permutation,list->solving_method); } else { iter_solve_bicg( matrix , vector , x); gsl_vector ** plot_array; plot_array = plot_create_vector( 1 , x->size); if(plot_array == NULL) { perror("Error while allocating the ploting array\n"); exit(0); } plot_set_vector_index(plot_array ,x ,0); plot_to_file(list->hashtable,plot_array,1 ,"results_plot_file_bicg.txt"); } } } else { if( method == METHOD_LU_SPARSE ) { if( !sparse_solve_LU( sp_matrix,sp_vector,sp_x,vector_size) ) { fprintf(stderr, "Solving Method Sparse LU failed\n" ); } gsl_vector ** plot_array; plot_array = plot_create_vector( 1 , vector_size); if(plot_array == NULL) { perror("Error while allocating the ploting array\n"); exit(0); } vector_gsl = gsl_vector_calloc(vector_size); double_vector_to_gsl_vector(vector_gsl,sp_x,vector_size); plot_set_vector_index(plot_array ,vector_gsl ,0); plot_to_file(list->hashtable,plot_array,1 ,"results_plot_file_lu_sparse.txt"); } else if( method == METHOD_CHOLESKY_SPARSE ) { if( !sparse_solve_cholesky( sp_matrix,sp_vector,sp_x,vector_size) ) { fprintf(stderr, "Solving Method Sparse Cholesky failed\n" ); } } else if ( method == METHOD_CG_SPARSE ) { if( !sparse_solve_cg( sp_matrix,vector_sparse,x_sparse) ) { fprintf(stderr, "Solving Method Sparse CG failed\n" ); } gsl_vector ** plot_array; plot_array = plot_create_vector( 1 , x_sparse->size); if(plot_array == NULL) { perror("Error while allocating the ploting array\n"); exit(0); } plot_set_vector_index(plot_array ,x_sparse ,0); plot_to_file(list->hashtable,plot_array,1 ,"results_plot_file_sparse_cg.txt"); } else if( method == METHOD_BICG_SPARSE ) { if( !sparse_solve_bicg( sp_matrix, vector_sparse, x_sparse) ) { fprintf(stderr, "Solving Method Sparse BiCG failed\n" ); } gsl_vector ** plot_array; plot_array = plot_create_vector( 1 , x_sparse->size); if(plot_array == NULL) { perror("Error while allocating the ploting array\n"); exit(0); } plot_set_vector_index(plot_array ,x_sparse ,0); plot_to_file(list->hashtable,plot_array,1 ,"results_plot_file_sparse_bicg.txt"); } else { fprintf(stderr, "Solving method not specified\n"); } } } /* clean up before exit */ if(list->sparse) cs_spfree(sp_matrix); free(vector); free(x); return 1; }
void Decomposition(FunctionCall fc) { int i, j, indexL, indexU, existL = 0, existU = 0; Matrix a, l, u; char nameA[MAXSIZE_NAME] = {0}; char nameL[MAXSIZE_NAME] = {0}; char nameU[MAXSIZE_NAME] = {0}; for (i = 0; i < MAXSIZE_NAME; i++) { nameL[i] = fc->name[i]; nameU[i] = fc->name[i]; if (fc->name[i] == '\0') { if (i<MAXSIZE_NAME-2) { nameL[i] = '_'; nameU[i] = '_'; nameL[i+1] = 'L'; nameU[i+1] = 'U'; nameL[i+2] = '\0'; nameU[i+2] = '\0'; } break; } } indexL = IndexMatrix(nameL); if (indexL==-1) { indexL = cur_mat; mats[indexL] = (StrMatObject*)malloc(sizeof(StrMatObject)); if (mats[indexL] == NULL) { printf("NewMatrix(): Could not allocate the new matrix\n"); return; } for (i = 0; i < MAXSIZE_NAME; i++) { mats[indexL]->name[i] = nameL[i]; if (nameL[i]=='\0') break; } } else existL = 1; indexU = IndexMatrix(nameU); if (indexU==-1) { indexU = cur_mat+1; mats[indexU] = (StrMatObject*)malloc(sizeof(StrMatObject)); if (mats[indexU] == NULL) { printf("NewMatrix(): Could not allocate the new matrix\n"); return; } for (i = 0; i < MAXSIZE_NAME; i++) { mats[indexU]->name[i] = nameU[i]; if (nameU[i]=='\0') break; } } else existU = 1; j = 0; // searching for matrix name for (i = 0; i < MAXSIZE_NAME; i++) { nameA[j] = fc->args[i]; if (nameA[j] == ',') { nameA[j] = '\0'; break; } j++; } a = GetMatrix(nameA); if (a==NULL) { printf("\tMatrix %s Not Found\n", nameA); if (!existL) free(mats[indexL]); if (!existU) free(mats[indexU]); return; } l = identityMatrix(a->rows); u = newMatrix(a->rows, a->cols); if (l!=NULL && u!=NULL) { decomposition(a, l, u); } if (existL) deleteMatrix(mats[indexL]->mat); mats[indexL]->mat = l; if (existU) deleteMatrix(mats[indexU]->mat); mats[indexU]->mat = u; // test: display the result displayMatrix(mats[indexL]->mat); displayMatrix(mats[indexU]->mat); if (!existL) cur_mat++; if (!existU) cur_mat++; }
void SpeedTest(FunctionCall fc) { int i, min, max, step, sec=0; int sizeTimeArray, fct; char fnc[MAXSIZE_FCT]; char foutput[256]; struct sigaction action; action.sa_handler = handler; sigemptyset(&action.sa_mask); struct timeval start, end, result; double maxtime = 0; double time; double usec; double* timeArray; Matrix a=NULL, b=NULL, tmp=NULL; E s; int n; TokenizeSpeedTest(fc, fnc, &min, &max, &step, &sec); if (min>0 && max>0 && step>0) { sizeTimeArray = ((max-min)/step)+1; timeArray = (double*)malloc(sizeTimeArray*sizeof(double)); for (i=0; i<sizeTimeArray; i++) timeArray[i] = 0; } usec = (double)sec * 1000000; sprintf(foutput, "speedtest_%s_%d_%d_%d_%d", fnc, min, max, step, sec); fct = GetFunction(fnc); switch (fct) { case NMX : { printf("\t You must specify another function\n"); return; } case ADD : { sigaction(SIGINT, &action, NULL); for (i=min; i<=max; i+=step) { a = randomMatrix(i, i, MIN_E, MAX_E); b = randomMatrix(i, i, MIN_E, MAX_E); gettimeofday(&start, NULL); tmp = addMatricis(a, b); gettimeofday(&end, NULL); timersub(&end, &start, &result); time = (result.tv_sec*1000000)+result.tv_usec; if (maxtime < time) maxtime = time; timeArray[(i-min)/step] = time; printf("\t* %s Size:%5d ;\tTime:%8.0f µs ;\n", fnc, i, time); deleteMatrix(a); deleteMatrix(b); deleteMatrix(tmp); if (usec >= 1000000) { if (time >= usec) { i++; break; } } if (CTRLC) { i++; break; } } CreateGNUPLOTFile(min, i-step, step, timeArray, maxtime, foutput); break; } case SUB : { sigaction(SIGINT, &action, NULL); for (i=min; i<=max; i+=step) { a = randomMatrix(i, i, MIN_E, MAX_E); b = randomMatrix(i, i, MIN_E, MAX_E); gettimeofday(&start, NULL); tmp = substractMatricis(a, b); gettimeofday(&end, NULL); timersub(&end, &start, &result); time = (result.tv_sec*1000000)+result.tv_usec; if (maxtime < time) maxtime = time; timeArray[(i-min)/step] = time; printf("\t* %s Size:%5d ;\tTime:%8.0f µs ;\n", fnc, i, time); deleteMatrix(a); deleteMatrix(b); deleteMatrix(tmp); if (usec >= 1000000) { if (time >= usec) { i++; break; } } if (CTRLC) { i++; break; } } CreateGNUPLOTFile(min, i-step, step, timeArray, maxtime, foutput); break; } case MUL : { sigaction(SIGINT, &action, NULL); for (i=min; i<=max; i+=step) { a = randomMatrix(i, i, MIN_E, MAX_E); b = randomMatrix(i, i, MIN_E, MAX_E); gettimeofday(&start, NULL); tmp = mulMatricis(a, b); gettimeofday(&end, NULL); timersub(&end, &start, &result); time = (result.tv_sec*1000000)+result.tv_usec; if (maxtime < time) maxtime = time; timeArray[(i-min)/step] = time; printf("\t* %s Size:%5d ;\tTime:%8.0f µs ;\n", fnc, i, time); deleteMatrix(a); deleteMatrix(b); deleteMatrix(tmp); if (usec >= 1000000) { if (time >= usec) { i++; break; } } if (CTRLC) { i++; break; } } CreateGNUPLOTFile(min, i-step, step, timeArray, maxtime, foutput); break; } case MSC : { sigaction(SIGINT, &action, NULL); for (i=min; i<=max; i+=step) { a = randomMatrix(i, i, MIN_E, MAX_E); s = mRand(MIN_SCA, MAX_SCA); gettimeofday(&start, NULL); tmp = mult_scal(a, s); gettimeofday(&end, NULL); timersub(&end, &start, &result); time = (result.tv_sec*1000000)+result.tv_usec; if (maxtime < time) maxtime = time; timeArray[(i-min)/step] = time; printf("\t* %s Size:%5d ;\tTime:%8.0f µs ;\n", fnc, i, time); deleteMatrix(a); deleteMatrix(tmp); if (usec >= 1000000) { if (time >= usec) { i++; break; } } if (CTRLC) { i++; break; } } CreateGNUPLOTFile(min, i-step, step, timeArray, maxtime, foutput); break; } case EXP : { sigaction(SIGINT, &action, NULL); for (i=min; i<=max; i+=step) { a = randomMatrix(i, i, MIN_E, MAX_E); n = (int)mRand(MIN_EXP, MAX_EXP); gettimeofday(&start, NULL); tmp = expo(a, n); gettimeofday(&end, NULL); timersub(&end, &start, &result); time = (result.tv_sec*1000000)+result.tv_usec; if (maxtime < time) maxtime = time; timeArray[(i-min)/step] = time; printf("\t* %s Size:%5d ;\tTime:%8.0f µs ;\n", fnc, i, time); deleteMatrix(a); deleteMatrix(tmp); if (usec >= 1000000) { if (time >= usec) { i++; break; } } if (CTRLC) { i++; break; } } CreateGNUPLOTFile(min, i-step, step, timeArray, maxtime, foutput); break; } case TRA : { sigaction(SIGINT, &action, NULL); for (i=min; i<=max; i+=step) { a = randomMatrix(i, i, MIN_E, MAX_E); gettimeofday(&start, NULL); tmp = transposeMatrix(a); gettimeofday(&end, NULL); timersub(&end, &start, &result); time = (result.tv_sec*1000000)+result.tv_usec; if (maxtime < time) maxtime = time; timeArray[(i-min)/step] = time; printf("\t* %s Size:%5d ;\tTime:%8.0f µs ;\n", fnc, i, time); deleteMatrix(a); deleteMatrix(tmp); if (usec >= 1000000) { if (time >= usec) { i++; break; } } if (CTRLC) { i++; break; } } CreateGNUPLOTFile(min, i-step, step, timeArray, maxtime, foutput); break; } case DET : { sigaction(SIGINT, &action, NULL); for (i=min; i<=max; i+=step) { a = randomMatrix(i, i, MIN_E, MAX_E); gettimeofday(&start, NULL); s = determinant(a); gettimeofday(&end, NULL); timersub(&end, &start, &result); time = (result.tv_sec*1000000)+result.tv_usec; if (maxtime < time) maxtime = time; timeArray[(i-min)/step] = time; printf("\t* %s Size:%5d ;\tTime:%8.0f µs ;\n", fnc, i, time); deleteMatrix(a); if (usec >= 1000000) { if (time >= usec) { i++; break; } } if (CTRLC) { i++; break; } } CreateGNUPLOTFile(min, i-step, step, timeArray, maxtime, foutput); break; } case DLU : { sigaction(SIGINT, &action, NULL); for (i=min; i<=max; i+=step) { a = randomMatrix(i, i, MIN_E, MAX_E); b = newMatrix(i, i); tmp = identityMatrix(i); gettimeofday(&start, NULL); decomposition(a, b, tmp); gettimeofday(&end, NULL); timersub(&end, &start, &result); time = (result.tv_sec*1000000)+result.tv_usec; if (maxtime < time) maxtime = time; timeArray[(i-min)/step] = time; printf("\t* %s Size:%5d ;\tTime:%8.0f µs ;\n", fnc, i, time); deleteMatrix(a); deleteMatrix(b); deleteMatrix(tmp); if (usec >= 1000000) { if (time >= usec) { i++; break; } } if (CTRLC) { i++; break; } } CreateGNUPLOTFile(min, i-step, step, timeArray, maxtime, foutput); break; } case SOL : { sigaction(SIGINT, &action, NULL); for (i=min; i<=max; i+=step) { a = randomMatrix(i, i, MIN_E, MAX_E); b = randomMatrix(i, 1, MIN_E, MAX_E); gettimeofday(&start, NULL); tmp = gauss(a, b); gettimeofday(&end, NULL); timersub(&end, &start, &result); time = (result.tv_sec*1000000)+result.tv_usec; if (maxtime < time) maxtime = time; timeArray[(i-min)/step] = time; printf("\t* %s Size:%5d ;\tTime:%8.0f µs ;\n", fnc, i, time); deleteMatrix(a); deleteMatrix(b); deleteMatrix(tmp); if (usec >= 1000000) { if (time >= usec) { i++; break; } } if (CTRLC) { i++; break; } } CreateGNUPLOTFile(min, i-step, step, timeArray, maxtime, foutput); break; } case INV : { sigaction(SIGINT, &action, NULL); for (i=min; i<=max; i+=step) { a = randomMatrix(i, i, MIN_E, MAX_E); gettimeofday(&start, NULL); tmp = invert(a); gettimeofday(&end, NULL); timersub(&end, &start, &result); time = (result.tv_sec*1000000)+result.tv_usec; if (maxtime < time) maxtime = time; timeArray[(i-min)/step] = time; printf("\t* %s Size:%5d ;\tTime:%8.0f µs ;\n", fnc, i, time); deleteMatrix(a); deleteMatrix(tmp); if (usec >= 1000000) { if (time >= usec) { i++; break; } } if (CTRLC) { i++; break; } } CreateGNUPLOTFile(min, i-step, step, timeArray, maxtime, foutput); break; } case RNK : { sigaction(SIGINT, &action, NULL); for (i=min; i<=max; i+=step) { a = randomMatrix(i, i, MIN_E, MAX_E); gettimeofday(&start, NULL); n = rank(a); gettimeofday(&end, NULL); timersub(&end, &start, &result); time = (result.tv_sec*1000000)+result.tv_usec; if (maxtime < time) maxtime = time; timeArray[(i-min)/step] = time; printf("\t* %s Size:%5d ;\tTime:%8.0f µs ;\n", fnc, i, time); deleteMatrix(a); if (usec >= 1000000) { if (time >= usec) { i++; break; } } if (CTRLC) { i++; break; } } CreateGNUPLOTFile(min, i-step, step, timeArray, maxtime, foutput); break; } case VAR : // default case NOF : // default default : { printf("\t%s : Function Not Implemented\n", fnc); fni++; break; } } if (fct!=NOF && fct !=VAR) fni = 0; free(timeArray); CTRLC = 0; sigemptyset(&action.sa_mask); }
void decomposition ( double *alpha, double *beta, int min, double value ) /******************************************************************************/ /* Purpose: DECOMPOSITION carries out the decomposition of a subinterval. Reference: Eric Thiemard, An Algorithm to Compute Bounds for the Star Discrepancy, Journal of Complexity, Volume 17, pages 850-880, 2001. */ { int i; double pbetaminp = 1.0; double palpha = 1.0; double pbeta; double delta; double *subalpha; double *subbeta; double *gamma; subalpha = (double *) calloc((unsigned) s,sizeof(double)); subbeta = (double *) calloc((unsigned) s+1,sizeof(double)); gamma = (double *) calloc((unsigned) s+1,sizeof(double)); for (i=min;i<s;i++) pbetaminp *= beta[i]; pbeta = pbetaminp; for (i=0;i<min;i++) { pbetaminp *= beta[i]; palpha *= alpha[i]; } pbetaminp -= p; delta = pow(pbetaminp/(pbeta*palpha),1.0/(s-min)); for (i=0;i<min;i++) { gamma[i] = alpha[i]; subalpha[i] = gamma[i]; subbeta[i] = beta[i]; } for (i=min;i<s;i++) { gamma[i] = delta*beta[i]; subalpha[i] = alpha[i]; subbeta[i] = beta[i]; } subbeta[min] = gamma[min]; value *= delta; if (value>p) for (i=min;i<s;i++) { decomposition(subalpha,subbeta,i,value); subalpha[i] = gamma[i]; subbeta[i] = beta[i]; subbeta[i+1] = gamma[i+1]; } else for (i=min;i<s;i++) { traiter(subalpha,subbeta,(i==0)?0:i-1); subalpha[i] = gamma[i]; subbeta[i] = beta[i]; subbeta[i+1] = gamma[i+1]; } traiter(gamma,beta,smin); free(gamma); free(subalpha); free(subbeta); return; }