Ejemplo n.º 1
0
int resudial_itegral_r(const gsl_vector *in, void * p, gsl_vector *out){
    struct mu_data_fit * mu = (struct mu_data_fit *)p;
    struct fit_params fp = {in->data[0], in->data[1], in->data[2], \
                            in->data[3], in->data[4], in->data[5]} ;
    gsl_vector_set_zero(out);

    /*
    for (int i =0; i< in->size; i++){
        printf("%14.5f", gsl_vector_get (in, i)) ;
    }
    printf("\n") ;
*/

    
    size_t vsize= mu->k->size;
    gsl_vector *fftR_abs  = gsl_vector_alloc(vsize/2);
    


    compute_itegral_r(mu, fp, fftR_abs);

    size_t irmin=search_min(mu->r, mu->rmin - 0.5*mu->dwr);
    size_t irmax=search_min(mu->r, mu->rmax + 0.5*mu->dwr);

    int j=0, istep = (irmax-irmin)/MAX_FIT_POINTS;
    for (int i =0; i< out->size; i+=istep){
        double df = gsl_vector_get(fftR_abs, i+irmin) - gsl_vector_get(mu->mu_ft, i+irmin);
        gsl_vector_set(out, j, df);
        //printf("%10.5f", gsl_vector_get (out, i)) ;
        j++;
    }
    gsl_vector_free(fftR_abs);

    return GSL_SUCCESS;}
Ejemplo n.º 2
0
static bool
delete_node(const void *key, bnode_t *bnode, piojo_btree_t *tree)
{
        bool found_p, deleted_p=FALSE;
        size_t i;
        bnode_t *next;
        iter_t iter;

        while (bnode != NULL){
                i = bin_search(key, tree, bnode, &found_p);
                if (found_p){
                        /* Key in leaf, shrink the leaf and finish. */
                        if (bnode->leaf_p){
                                free_entry(&bnode->kvs[i], tree, &deleted_p);
                                --bnode->ecnt;
                                for (; i < bnode->ecnt; ++i){
                                        copy_bentry(i + 1, bnode, i, bnode, tree);
                                }
                                return TRUE;
                        }

                        /* Key in internal node, move prev/next key up and delete it. */
                        iter.bnode = bnode;
                        if (bnode->children[i]->ecnt >= tree->cmin){
                                free_entry(&bnode->kvs[i], tree, &deleted_p);
                                iter.eidx = i;
                                search_max(&iter);
                                copy_bentry(iter.eidx, iter.bnode, i, bnode, tree);
                                key = entry_key(i, bnode, tree);
                                bnode = bnode->children[i];
                        }else if (bnode->children[i + 1]->ecnt >= tree->cmin){
                                free_entry(&bnode->kvs[i], tree, &deleted_p);
                                iter.eidx = i + 1;
                                search_min(&iter);
                                copy_bentry(iter.eidx, iter.bnode, i, bnode, tree);
                                key = entry_key(i, bnode, tree);
                                bnode = bnode->children[i + 1];
                        }else{
                                /* Both node children are key deficient, merge and try again. */
                                PIOJO_ASSERT(bnode->children[i]->ecnt == tree->cmin - 1);
                                PIOJO_ASSERT(bnode->children[i + 1]->ecnt == tree->cmin - 1);
                                next = bnode->children[i];
                                merge_bnodes(tree, i, next, bnode->children[i + 1], bnode);
                                bnode = next;
                        }
                }else if (! bnode->leaf_p){
                        /* Key not in internal node, rebalance and try again. */
                        next = bnode->children[i];
                        if (next->ecnt < tree->cmin){
                                PIOJO_ASSERT(next->ecnt == tree->cmin - 1);
                                next = rebalance_bnode(tree, i, next, bnode);
                        }
                        bnode = next;
                }else{
                        /* Key not in leaf. */
                        bnode = NULL;
                }
        }
        return FALSE;
}
Ejemplo n.º 3
0
/**
 * Reads the next key (order given by @a keycmp function).
 * @param[in] key
 * @param[in] tree
 * @param[out] data Entry value, can be @b NULL.
 * @return next key or @b NULL if @a key is the last one.
 */
const void*
piojo_btree_next(const void *key, const piojo_btree_t *tree, void **data)
{
        iter_t iter;
        PIOJO_ASSERT(tree);
        PIOJO_ASSERT(key);

        iter = search_node(key, tree);
        PIOJO_ASSERT(iter.bnode != NULL);

        if (! iter.bnode->leaf_p && iter.eidx < iter.bnode->ecnt){
                iter.bnode = iter.bnode->children[iter.eidx + 1];
                iter.eidx = 0;
                search_min(&iter);
        }else if (iter.eidx + 1 < iter.bnode->ecnt){
                ++iter.eidx;
        }else{
                while (iter.bnode->parent != NULL){
                        iter.eidx = iter.bnode->pidx;
                        iter.bnode = iter.bnode->parent;
                        if (iter.eidx < iter.bnode->ecnt){
                                if (data != NULL){
                                        *data = entry_val(iter.eidx, iter.bnode, tree);
                                }
                                return entry_key(iter.eidx, iter.bnode, tree);
                        }
                }
                return NULL;
        }
        if (data != NULL){
                *data = entry_val(iter.eidx, iter.bnode, tree);
        }
        return entry_key(iter.eidx, iter.bnode, tree);
}
Ejemplo n.º 4
0
Archivo: 714.cpp Proyecto: waiwai444/oj
void solve()
{
	long long tot = 0;
	for(int i = 0; i < m; i++)
		tot += book[i];
	long long min = search_min(tot);
	get_partition(min);
	print_result();
}
Ejemplo n.º 5
0
void		find_path(t_info *s, t_graph *g, t_nodes *list)
{
  t_nodes	*elem;

  elem = s->elem_ent;
  while (elem->status != 2)
    if ((elem = search_min(s, g, list, elem)) == NULL)
      error("Exit");
  look_path(g, -1);
  go_ants(s, g, list);
}
Ejemplo n.º 6
0
int compute_itegral_r(const mu_data_fit *mu, const fit_params fp, gsl_vector *fftR_abs){
    size_t vsize= mu->k->size; 
    gsl_vector *mu_tmp=gsl_vector_alloc(vsize);
    gsl_vector_set_zero(mu_tmp);
    size_t ikmin=search_min(mu->k, mu->kmin - 0.5*mu->dwk);
    size_t ikmax=search_min(mu->k, mu->kmax + 0.5*mu->dwk);
    gsl_vector_view kw  = gsl_vector_subvector(mu->k, ikmin-1, ikmax-ikmin-1);
    gsl_vector_view muw = gsl_vector_subvector(mu_tmp, ikmin-1, ikmax-ikmin-1);


    gsl_vector *ktmp=gsl_vector_alloc((&kw.vector)->size);
    
    gsl_vector_memcpy(ktmp, &kw.vector);
    gsl_vector_add_constant(ktmp, fp.kshift);
    compute_itegral(ktmp, &fp, &muw.vector);
    hanning(mu_tmp, mu->k, mu->kmin, mu->kmax, mu->dwk);

    //FFT transform
    double *data = (double *) malloc(vsize*sizeof(double)); 
    memcpy(data, mu_tmp->data, vsize*sizeof(double));
    gsl_fft_real_radix2_transform(data, 1, vsize);

    //Unpack complex vector
    gsl_vector_complex *fourier_data = gsl_vector_complex_alloc (vsize);
    gsl_fft_halfcomplex_radix2_unpack(data, fourier_data->data, 1, vsize);
    gsl_vector *fftR_real = gsl_vector_alloc(vsize/2);
    gsl_vector *fftR_imag = gsl_vector_alloc(vsize/2);
    //gsl_vector *fftR_abs  = gsl_vector_alloc(vsize/2);
    complex_vector_parts(fourier_data, fftR_real, fftR_imag);
    complex_vector_abs(fftR_abs, fftR_real, fftR_imag);
    hanning(fftR_abs, mu->r, mu->rmin, mu->rmax, mu->dwr); 
    gsl_vector_free(fftR_real); gsl_vector_free(fftR_imag);
    gsl_vector_complex_free(fourier_data); gsl_vector_free(mu_tmp);  
    free(data);

}
Ejemplo n.º 7
0
void make_working(int wt[][NUM], int h, int w, const char *str1, const char *str2) {
  int i, j;

  for ( i = 0; i < h; i++ ) {
    wt[i][0] = i;
  }
  for ( j = 0; j < w; j++ ) {
    wt[0][j] = j;
  }

  for ( i = 1; i < h; i++ ) {
    for ( j = 1; j < w; j++ ) {
      wt[i][j] = search_min(wt, i, j);
      if ( str1[i-1] == str2[j-1] && wt[i][j] == wt[i-1][j-1] ) { continue; }
      wt[i][j]++;
    }
  }
}
Ejemplo n.º 8
0
/**
 * Reads the first key in @a tree (order given by @a keycmp function).
 * @param[in] tree
 * @param[out] data Entry value, can be @b NULL.
 * @return first key or @b NULL if @a tree is empty.
 */
const void*
piojo_btree_first(const piojo_btree_t *tree, void **data)
{
        iter_t iter;
        PIOJO_ASSERT(tree);

        if (tree->ecount > 0){
                iter.tree = tree;
                iter.eidx = 0;
                iter.bnode = tree->root;
                search_min(&iter);
                if (data != NULL){
                        *data = entry_val(iter.eidx, iter.bnode, tree);
                }
                return entry_key(iter.eidx, iter.bnode, tree);
        }
        return NULL;
}
Ejemplo n.º 9
0
void	push_swap_calc(t_e *e)
{
	t_list_cir *tmp;

	if (test_small_list(e))
		return ;
	while (e->size_l > 0)
	{
		search_min(e);
		pb(e);
		e->size_l--;
		ft_putendl("pb");
		if_display(e, 1);
	}
	tmp = e->l_b->next;
	while (tmp != e->l_b)
	{
		pa(e);
		ft_putendl("pa");
		if_display(e, 1);
		tmp = e->l_b->next;
	}
}
Ejemplo n.º 10
0
//Program Begin
int main(void)
{
	//Seed Random Generator
	srand(time(NULL));

	//Local Variables
	int mainSize, mainOption;
	int userRow, userColumn;
	int countMatchResult;
	int main2Darray[MAX][MAX];
	int main1Darray[MAX];

	//Receive and check user-selected size
	printf("\nEnter the size: ");
	scanf("%d", &mainSize);
	while(check_size(mainSize) == 0)
	{
		printf("Invalid input enter the size of the array again: ");
		scanf("%d", &mainSize);
	}

	do //Perform functions until user selects 6 (exit)
	{
		//Display menu, take and check user option
		display_menu();
		scanf("%d", &mainOption);
		while(check_option(mainOption) == 0)
		{
			printf("Invalid input: Enter the operation you want to perform: ");
			scanf("%d", &mainOption);
		}

		//Perform function based on user choice
		switch(mainOption)
		{
			case 1:
				// Perform Search Min Function
				initialize_2Darray(main2Darray, mainSize);

				//Display Arrays
				printf("\nSearch Min Operation\n\n");
				printf("2D array\n");
				print_2Darray(main2Darray, mainSize);

				//Get user row and column choice
				printf("\nEnter the row: ");
				scanf("%d", &userRow);
				printf("Enter the col: ");
				scanf("%d", &userColumn);

				//Perform function and display result
				printf( "\n\nThe smallest number present in the "
						"row %d and col %d is ", userRow, userColumn);
				printf("%d", search_min(main2Darray, userRow, userColumn, mainSize));

				break;

			case 2:
				// Perform Count Matches Function
				initialize_2Darray(main2Darray, mainSize);
				initialize_1Darray(main1Darray, mainSize);

				//Display initialized arrays
				printf("\nCount Match Operation\n\n");
				printf("2D array\n");
				print_2Darray(main2Darray, mainSize);
				printf("\n1D array\n");
				print_1Darray(main1Darray, mainSize);

				//Get user row choice
				printf("\n\nEnter the row: ");
				scanf("%d", &userRow);

				//Perform function and display result
				countMatchResult = count_match(main2Darray, main1Darray, mainSize, userRow);
				if(countMatchResult == 0)
					printf("\nThere are no numbers from 1D array present in the 2D array");
				else
				{
					printf( "\nThere are %d numbers from the 1D array present in the 2D array",
							countMatchResult);
				}

				break;

			case 3:
				// Perform Closest Row Function
				initialize_2Darray(main2Darray, mainSize);
				initialize_1Darray(main1Darray, mainSize);

				//Display initialized arrays
				printf("\nClosest Row Operation\n\n");
				printf("2D array\n");
				print_2Darray(main2Darray, mainSize);
				printf("\n1D array\n");
				print_1Darray(main1Darray, mainSize);

				//Perform function and display result
				printf( "\n\nRow closest to the 1D array is row %d",
						closest_row(main2Darray, main1Darray, mainSize));
				break;

			case 4:
				// Perform Sort 1D Array Function
				initialize_1Darray(main1Darray, mainSize);

				//Display initialized array
				printf("\nSort 1D Array Operation\n\n");
				printf("1D Array before sorting\n");
				print_1Darray(main1Darray, mainSize);

				//Display sorted array
				printf("\n1D Array after sorting\n");
				sort_1Darray(main1Darray, mainSize);
				print_1Darray(main1Darray, mainSize);

				break;

			case 5:
				// Perform Sort 2D Array Function
				initialize_2Darray(main2Darray, mainSize);

				//Display initialized array
				printf("\nSort 2D Array Operation\n\n");
				printf("2D Array before sorting\n");
				print_2Darray(main2Darray, mainSize);

				//Display sorted array
				printf("\n2D Array after sorting\n");
				sort_2Darray(main2Darray, mainSize);
				print_2Darray(main2Darray, mainSize);

				break;

			case 6:
				// Exit Program

				break;

			default:
				// Invalid input - Error
				printf( "\n"
						"*********************************\n\n"
						" Error: Invalid Switch Condition \n\n"
						"*********************************\n");
		}

	} while(mainOption != 6);

	return 0;
}