• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ drand48函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中drand48函数的典型用法代码示例。如果您正苦于以下问题:C++ drand48函数的具体用法?C++ drand48怎么用?C++ drand48使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了drand48函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: gen_SSCA2_graph_MPI

void gen_SSCA2_graph_MPI(graph_t* g)
{
    uint32_t local_TotVertices, TotVertices;
	uint32_t* clusterSizes;
	uint32_t* firstVsInCluster;
	uint32_t estTotClusters, local_totClusters;
	
	uint32_t *startVertex, *endVertex;
	uint32_t local_numEdges;
	weight_t* weights;
    weight_t MinWeight,MaxWeight;
    vertex_id_t u, v; 
    edge_id_t offset;
    uint32_t MaxCliqueSize;
    uint32_t MaxParallelEdges = 1;
    double ProbUnidirectional = 1.0;
    double ProbIntercliqueEdges = 0.1;
	uint32_t i_cluster, currCluster;
	uint32_t *startV, *endV, *d;
	uint32_t estNumEdges, edgeNum;

	uint32_t i, j, k, t, t1, t2, dsize;
	double p;
    int seed;
	uint32_t* permV;
    int size, rank, lgsize;
    

    g->directed = false;
    g->min_weight = 0;
    g->max_weight = 1;
    g->filename[0] = '\0';
    g->n = (vertex_id_t)1 << g->scale;
    if (strlen(g->filename) == 0) sprintf(g->filename, "ssca2-%d", g->scale);

    /*----------------------------------------------*/
	/*		initialize RNG 		*/
	/*----------------------------------------------*/
    seed = 2387;   
    srand48(seed);
   
    MinWeight = g->min_weight;
    MaxWeight = g->max_weight;
    TotVertices = g->n;
    size = g->nproc;
    g->local_n = g->n/size;
    local_TotVertices = g->local_n;
    rank = g->rank;
    for (lgsize = 0; lgsize < size; ++lgsize) {
        if ((1 << lgsize) == size) break;
    }
    
    MPI_Datatype MPI_VERTEX_ID_T;                                        
    MPI_Type_contiguous(sizeof(vertex_id_t), MPI_BYTE, &MPI_VERTEX_ID_T);
    MPI_Type_commit(&MPI_VERTEX_ID_T);                                   


	/*----------------------------------------------*/
	/*		generate local clusters		*/
	/*----------------------------------------------*/
    MaxCliqueSize = 49;

  	/* Estimate number of clusters required to make up 
	 * TotVertices and pad by 25% */
	estTotClusters = 1.25 * TotVertices / (size * MaxCliqueSize/2);
	
	/* Allocate a block of memory for this cluster-size array */
	clusterSizes = (uint32_t *) malloc(estTotClusters*sizeof(uint32_t));

	/* Generate random cluster sizes. */
    
	for(i = 0; i < estTotClusters; i++) {
		clusterSizes[i] = 1 + ( drand48() * MaxCliqueSize);
	}

	local_totClusters = 0;
  
	/* Allocate memory for storing the first vertex in each cluster */
	firstVsInCluster = (uint32_t *) malloc(estTotClusters*sizeof(uint32_t));

	/* Compute the first vertex in each cluster */
	firstVsInCluster[0] = 0;
	for (i=1; i<estTotClusters; i++) {
		firstVsInCluster[i] = firstVsInCluster[i-1] + clusterSizes[i-1];
		if (firstVsInCluster[i] > local_TotVertices-1)
			break;
	}

	local_totClusters = i;

	/* Fix the size of the last cluster */
	clusterSizes[local_totClusters-1] = local_TotVertices -\
		firstVsInCluster[local_totClusters-1];

	/*------------------------------------------------------*/
	/*		generate intra-cluster edges		*/
	/*------------------------------------------------------*/
 
	/* Roughly estimate the total number of edges */
	estNumEdges = (uint32_t) ((local_TotVertices * (double) MaxCliqueSize * (2-ProbUnidirectional)/2) +\
//.........这里部分代码省略.........
开发者ID:DISLab,项目名称:xcharm,代码行数:101,代码来源:gen_SSCA2_mpi.cpp


示例2: main

int main(int argc, char* argv[]) {
  if (argc != 4 ) {
    fprintf( stderr, "need csr-filename N reps!\n" );
    exit(-1);
  }

  char* l_csr_file;
  REALTYPE* l_a_sp; 
  unsigned int* l_rowptr;
  unsigned int* l_colidx;
  unsigned int l_rowcount, l_colcount, l_elements;
  
  REALTYPE* l_a_dense;
  REALTYPE* l_b;
  REALTYPE* l_c;
  REALTYPE* l_c_gold;
  REALTYPE* l_c_dense;
  REALTYPE l_max_error = 0.0;
  unsigned int l_m;
  unsigned int l_n;
  unsigned int l_k;

  unsigned int l_i;
  unsigned int l_j;
  unsigned int l_z;
  unsigned int l_elems;
  unsigned int l_reps;

  struct timeval l_start, l_end;
  double l_total;

  /* read sparse A */
  l_csr_file = argv[1];
  l_n = atoi(argv[2]);
  l_reps = atoi(argv[3]);
  if (my_csr_reader(  l_csr_file,
                 &l_rowptr,
                 &l_colidx,
                 &l_a_sp,
                 &l_rowcount, &l_colcount, &l_elements ) != 0 ) 
  {
    exit(-1);
  }
  l_m = l_rowcount;
  l_k = l_colcount;
  printf("CSR matrix data structure we just read:\n");
  printf("rows: %u, columns: %u, elements: %u\n", l_rowcount, l_colcount, l_elements);

  /* allocate dense matrices */
  l_a_dense = (REALTYPE*)_mm_malloc(l_k * l_m * sizeof(REALTYPE), 64);
  l_b = (REALTYPE*)_mm_malloc(l_k * l_n * sizeof(REALTYPE), 64);
  l_c = (REALTYPE*)_mm_malloc(l_m * l_n * sizeof(REALTYPE), 64);
  l_c_gold = (REALTYPE*)_mm_malloc(l_m * l_n * sizeof(REALTYPE), 64);
  l_c_dense = (REALTYPE*)_mm_malloc(l_m * l_n * sizeof(REALTYPE), 64);

  /* touch B */
  for ( l_i = 0; l_i < l_k*l_n; l_i++) {
    l_b[l_i] = (REALTYPE)drand48();
  }
  
  /* touch dense A */
  for ( l_i = 0; l_i < l_k*l_m; l_i++) {
    l_a_dense[l_i] = (REALTYPE)0.0;
  }
  /* init dense A using sparse A */
  for ( l_i = 0; l_i < l_m; l_i++ ) {
    l_elems = l_rowptr[l_i+1] - l_rowptr[l_i];
    for ( l_z = 0; l_z < l_elems; l_z++ ) {
      l_a_dense[(l_i*l_k)+l_colidx[l_rowptr[l_i]+l_z]] = l_a_sp[l_rowptr[l_i]+l_z];
    }
  }

  /* touch C */
  for ( l_i = 0; l_i < l_m*l_n; l_i++) {
    l_c[l_i] = (REALTYPE)0.0;
    l_c_gold[l_i] = (REALTYPE)0.0;
    l_c_dense[l_i] = (REALTYPE)0.0;
  }
  
  /* compute golden results */
  printf("computing golden solution...\n");
  for ( l_j = 0; l_j < l_n; l_j++ ) {
    for (l_i = 0; l_i < l_m; l_i++ ) {
      l_elems = l_rowptr[l_i+1] - l_rowptr[l_i];
      for (l_z = 0; l_z < l_elems; l_z++) {
        l_c_gold[(l_n*l_i) + l_j] +=  l_a_sp[l_rowptr[l_i]+l_z] * l_b[(l_n*l_colidx[l_rowptr[l_i]+l_z])+l_j];
      }
    }
  }
  printf("...done!\n");

  /* libxsmm generated code */
  printf("computing libxsmm (A sparse) solution...\n");
  libxsmm_code(l_b, l_c);
  printf("...done!\n");

  /* BLAS code */
  printf("computing BLAS (A dense) solution...\n");
  double alpha = 1.0;
  double beta = 1.0;
//.........这里部分代码省略.........
开发者ID:danielpeter,项目名称:libxsmm,代码行数:101,代码来源:pyfr_driver_asp_reg.c


示例3: prob_ok

/*determines if star with prob p should be separrated into stream*/
int prob_ok(int n, double* p)
{
    int ok;
    double r;
    double step1, step2, step3;

    r = drand48();

    switch (n)
    {
    case 1:
        if ( r > p[0] )
        {
            ok = 0;
        }
        else
        {
            ok = 1;
        }
        break;
    case 2:
        step1 = p[0] + p[1];
        if ( r > step1 )
        {
            ok = 0;
        }
        else if ( (r < p[0]) )
        {
            ok = 1;
        }
        else if ( (r > p[0]) && (r <= step1) )
        {
            ok = 2;
        }
        break;
    case 3:
        step1 = p[0] + p[1];
        step2 = p[0] + p[1] + p[2];
        if ( r > step2 )
        {
            ok = 0;
        }
        else if ( (r < p[0]) )
        {
            ok = 1;
        }
        else if ( (r > p[0]) && (r <= step1) )
        {
            ok = 2;
        }
        else if ( (r > step1) && (r <= step2) )
        {
            ok = 3;
        }
        break;
    case 4:
        step1 = p[0] + p[1];
        step2 = p[0] + p[1] + p[2];
        step3 = p[0] + p[1] + p[2] + p[3];
        if ( r > step3 )
        {
            ok = 0;
        }
        else if ( (r <= p[0]) )
        {
            ok = 1;
        }
        else if ( (r > p[0]) && (r <= step1) )
        {
            ok = 2;
        }
        else if ( (r > step1) && (r <= step2) )
        {
            ok = 3;
        }
        else if ( (r > step2) && (r <= step3) )
        {
            ok = 4;
        }
        break;
    default:
        fprintf(stderr,
                "ERROR:  Too many streams to separate using current code; "
                "please update the switch statement in probability.c->prob_ok to handle %d streams", n);
        exit(EXIT_SUCCESS);
    }
    return ok;
}
开发者ID:willeb,项目名称:milkywayathome_client,代码行数:89,代码来源:probability.c


示例4: fail_prone_malloc

void *
fail_prone_malloc(size_t size)
{
   return drand48() < ALLOC_ERR_PROB ? NULL : __libc_malloc(size);
}
开发者ID:emmaggie,项目名称:starcode,代码行数:5,代码来源:unittest.c


示例5: fail_prone_calloc

void *
fail_prone_calloc(size_t nitems, size_t size)
{
   return drand48() < ALLOC_ERR_PROB ? NULL : __libc_calloc(nitems, size);
}
开发者ID:emmaggie,项目名称:starcode,代码行数:5,代码来源:unittest.c


示例6: main

int main()
{
  int i, j, k, d = 10,d2=5;
  float * a = fvec_new (d * d);
  float * b = fvec_new (d * d);
  float * b0 = fvec_new (d * d);
#define B0(i,j) b0[(i)+(j)*d]
#define A(i,j) a[(i)+(j)*d]
#define B(i,j) b[(i)+(j)*d] 
  float * lambda = fvec_new (d);
  float * v = fvec_new (d * d);
  float *v_part=fvec_new (d * d2);

  for (i = 0 ; i < d ; i++)
    for (j = 0 ; j  <= i ; j++) {
      A(i,j) = A(j,i) = drand48(); 
      B0(i,j)=drand48();
      B0(j,i)=drand48();
      
/*      B(i,j) = B(j,i) = drand48(); */
    }
  /* make a positive definite b (with b=b0*b0') */
  for (i = 0 ; i < d ; i++)
    for (j = 0 ; j  < d ; j++) {
      double accu=0;
      for(k=0;k<d;k++) 
        accu+=B0(i,k)*B0(j,k);
      B(i,j)=accu;
    }

  printf ("a = ");
  fmat_print(a,d,d);

  printf ("\nb = "); 
  fmat_print(b,d,d);

  printf ("Solution of the eigenproblem Av=lambda v\n");
  
  printf ("\n");
  int ret=eigs_sym (d, a, lambda, v);
  assert(ret==0);
  printf ("\n");


  printf("Eigenvectors:\n");
  fmat_print(v,d,d);

  fprintf(stdout, "lambda = ");
  fvec_print (lambda, d);
  printf ("\n");

  printf("Partial eigenvalues/vectors:\n");

  printf ("\n");
  ret=eigs_sym_part (d, a, d2, lambda, v_part);
  assert(ret>0);
  if(ret<d2) 
    printf("!!! only %d / %d eigenvalues converged\n",ret,d2);

  printf ("\n");

  printf("Eigenvectors:\n");
  fmat_print(v_part,d,d2);
  
  fprintf(stdout, "lambda = ");
  fvec_print (lambda, d2);
  printf ("\n");

   
  printf ("Solution of the generalized eigenproblem Av=lambda B v\n");

  printf ("\n");
  ret=geigs_sym (d, a, b, lambda, v);
  assert(ret==0);
  printf ("\n");

  fmat_print(v,d,d);

  fprintf(stdout, "lambda = ");
  fvec_print (lambda, d);
  printf ("\n");

  free (a);
  free (lambda);
  free (v);

  return 0;
}
开发者ID:antran89,项目名称:BoW_frameworks,代码行数:88,代码来源:test_eigs.c


示例7: doAllFeatures

int doAllFeatures()
{
	/* Initial biases */
	{
		int u,m,f;
		
		for(u=0;u<NUSERS;u++) {
			for(f=0;f<NFEATURES;f++)
			    bU[u][f]=drand48()*0.01-0.005;
		}
		for(m=0;m<NMOVIES;m++) {
			for(f=0;f<NFEATURES;f++)
			    bV[m][f]=drand48()*0.01-0.005;
		}
	}
	
	
	/* Initial estimation for current feature */
	{
		int u,m,f;
		
		for(u=0;u<NUSERS;u++) {
			for(f=0;f<NFEATURES;f++)
			    sU[u][f]=drand48()*0.1-0.04;
		}
		for(m=0;m<NMOVIES;m++) {
			for(f=0;f<NFEATURES;f++) {
			    sV[m][f]=drand48()*0.05-0.025;
			    sY[m][f]=drand48()*0.02-0.01;
			}
		}
	}
	
	/* Optimize current feature */
	double nrmse=2., last_rmse=10.;
	double thr=sqrt(1.-E);
	int loopcount=0;
	    //thr=sqrt(1.-E2);
	double Gamma2 = G2;
	double Gamma0 = G0;
	while( ( nrmse < (last_rmse-E) ) || loopcount++ < 20) {
		last_rmse=nrmse;
		clock_t t0=clock();

		int u,m, f;
		for(u=0;u<NUSERS;u++) {

			// Calculate sumY and NuSY for each factor
			double sumY[NFEATURES];
			ZERO(sumY);
			double lNuSY[NFEATURES];
			ZERO(lNuSY);
			int base0=useridx[u][0];
			int d0=UNTRAIN(u);
			int j;
			int f;
			int dall=UNALL(u);
			double NuS = 1.0/sqrt(dall);
			for(j=0;j<d0;j++) {
				int mm=userent[base0+j]&USER_MOVIEMASK;
				for(f=0;f<NFEATURES;f++)
					sumY[f]+=sY[mm][f];
			}
//if ( loopcount > 1 ) {
//printf("sumY: %f\n", sumY);
//fflush(stdout);
//}
			for(j=0;j<d0;j++) {
				int mm=userent[base0+j]&USER_MOVIEMASK;
				for(f=0;f<NFEATURES;f++) {
					lNuSY[f] = NuS * sumY[f]; 
//if ( loopcount > 1 ) {
//printf("lNuSY: %f\n", lNuSY[f]);
//fflush(stdout);
//}
				}
			}

			double ycontrib[NFEATURES];
			ZERO(ycontrib);

			// For all rated movies
			double bdampen = d0/1.1;
			for(j=0;j<d0;j++) {
				int m=userent[base0+j]&USER_MOVIEMASK;

				// Figure out the current error
				double ee=err[base0+j];
				double e2 = ee;
				for (f=0; f<NFEATURES; f++) {
				    e2 -= (bU[u][f] + bV[m][f]);
					e2 -= ((sU[u][f]+lNuSY[f])*sV[m][f]);
				}


				// update U V and slope component of Y
				//double yfactor = NuS/sqrt(moviecount[m]); 
				//double yfactor = NuS;
				double yfactor = NuS/d0;
				for (f=0; f<NFEATURES; f++) {
//.........这里部分代码省略.........
开发者ID:Algozjb,项目名称:nprizeadditions,代码行数:101,代码来源:usvdspp3.c


示例8: gsl_rng_env_setup

void *elCamino(float *x_obs, float *x_aComparar,float *y_ayudaAx, float *xDelMomento,float *xCandidato, float *a, float *b, float *c, float *d,float *l,float paso, int t, int iteraciones, int burn)
{
  int i;
  float aPrima;
  float bPrima;
  float cPrima;
  float dPrima;
  float lPresente;
  float lCandidato;
  float gamma;
  float beta;
  float alpha;
  float x_0 = 15 ;
  float y_0 = 13; 

  const gsl_rng_type * T;
  gsl_rng * r;
  gsl_rng_env_setup();
  T = gsl_rng_default;
  r = gsl_rng_alloc (T);

  for(i=0; i < (iteraciones-1) ; i++)
    {
      aPrima = gsl_ran_gaussian(r, 0.1)+a[i];
      //bPrima = gsl_ran_gaussian(r, 0.1)+b[i];
      //cPrima = gsl_ran_gaussian(r, 0.1)+c[i];
      //dPrima = gsl_ran_gaussian(r, 0.1)+d[i];

      xDelMomento = RungeKutta(x_aComparar, y_ayudaAx, x_0, y_0, a[i], b[i], c[i], d[i], t, paso);
      xCandidato = RungeKutta(x_aComparar, y_ayudaAx, x_0, y_0, aPrima, b[i], c[i], d[i], t, paso);

      lPresente = likelyhood(x_obs, xDelMomento, t);
      lCandidato = likelyhood(x_obs, xCandidato , t);
 
      gamma = (lCandidato - lPresente);
      if(gamma>=0.00)
	{
	  a[i+1]=aPrima;
	}
      else
	{
	  beta = drand48();
	  alpha = exp(gamma);
	  if(beta<=alpha)
	    {
	      a[i+1]=aPrima;
	    }
	  else
	    {
	      a[i+1]=a[i];
	    }
	}
      //aPrima = gsl_ran_gaussian(r, 0.1)+a[i];
      bPrima = gsl_ran_gaussian(r, 0.1)+b[i];
      //cPrima = gsl_ran_gaussian(r, 0.1)+c[i];
      //dPrima = gsl_ran_gaussian(r, 0.1)+d[i];

      xDelMomento = RungeKutta(x_aComparar, y_ayudaAx, x_0, y_0, a[i], b[i], c[i], d[i], t, paso);
      xCandidato = RungeKutta(x_aComparar, y_ayudaAx, x_0, y_0, a[i], bPrima, c[i], d[i], t, paso);

      lPresente = likelyhood(x_obs, xDelMomento, t);
      lCandidato = likelyhood(x_obs, xCandidato , t);

      gamma = (lCandidato - lPresente);
      if(gamma>=0.00)
	{
	  b[i+1]=bPrima;
	}
      else
	{
	  beta = drand48();
	  alpha = exp(gamma);
	  if(beta<=alpha)
	    {
	      b[i+1]=bPrima;
	    }
	  else
	    {
	      b[i+1]=b[i];
	    }
	}

      //aPrima = gsl_ran_gaussian(r, 0.1)+a[i];
      //bPrima = gsl_ran_gaussian(r, 0.1)+b[i];
      cPrima = gsl_ran_gaussian(r, 0.1)+c[i];
      //dPrima = gsl_ran_gaussian(r, 0.1)+d[i];


      xDelMomento = RungeKutta(x_aComparar, y_ayudaAx, x_0, y_0, a[i], b[i], c[i], d[i], t, paso);
      xCandidato = RungeKutta(x_aComparar, y_ayudaAx, x_0, y_0, a[i], b[i], cPrima, d[i], t, paso);

      lPresente = likelyhood(x_obs, xDelMomento, t);
      lCandidato = likelyhood(x_obs, xCandidato , t);

      gamma = (lCandidato - lPresente);
      if(gamma>=0.00)
	{
	  c[i+1]=cPrima;
	}
      else
//.........这里部分代码省略.........
开发者ID:YvanDavidHerChar,项目名称:Tarea7,代码行数:101,代码来源:diferencial.c


示例9: main


//.........这里部分代码省略.........
		g_latest = g;
		g_size_latest = gsize;
		g_count_latest = count;
		fflush(stdout);
	}

	while(gsize < 206)
	{
		/*
		 * if we have a counter example
		 */
		if(count == 0)
		{
			printf("Eureka!  Counter-example found!\n");
			PrintGraph(g,gsize);
			fflush(stdout);
			/*
			 * make a new graph one size bigger
			 */
			new_g = (int *)malloc((gsize+1)*(gsize+1)*sizeof(int));
			if(new_g == NULL)
				exit(1);
			/*
			 * copy the old graph into the new graph leaving the
			 * last row and last column alone
			 */
			CopyGraph(g,gsize,new_g,gsize+1);

			/*
			 * zero out the last column and last row
			 */
			for(i=0; i < (gsize+1); i++)
			{
				if(drand48() > 0.5) {
					new_g[i*(gsize+1) + gsize] = 0; // last column
					new_g[gsize*(gsize+1) + i] = 0; // last row
				}
				else
				{
					new_g[i*(gsize+1) + gsize] = 1; // last column
					new_g[gsize*(gsize+1) + i] = 1; // last row
				}
			}

			/*
			 * throw away the old graph and make new one the
			 * graph
			 */
			free(g);
			g = new_g;
			gsize = gsize+1;

			/*
			 * reset the taboo list for the new graph
			 */
			taboo_list = FIFOResetEdge(taboo_list);

			/*
			 * keep going
			 */
			//continue;
			break; //Go to first while loop
		}

		/*
		 * otherwise, we need to consider flipping an edge
开发者ID:rathodsachin20,项目名称:ramsey_search,代码行数:67,代码来源:ramsey_proj_basic.c


示例10: SortNodeData

// Test node data sorting
void SortNodeData() {
  int NNodes = 10000;
  int NEdges = 100000;

  TPt <TNodeEDatNet<TInt, TInt> > Net;
  TPt <TNodeEDatNet<TInt, TInt> > Net1;
  TPt <TNodeEDatNet<TInt, TInt> > Net2;
  int i;
  int n;
  int NCount;
  int x,y;
  bool t;
  int NodeId;
  int NodeDat;
  bool ok;
  bool Sorted;
  int Min;
  int Value;

  Net = TNodeEDatNet<TInt, TInt>::New();
  t = Net->Empty();

  // create the nodes
  for (i = 0; i < NNodes; i++) {
    Net->AddNode((i*13) % NNodes);
  }
  t = Net->Empty();
  n = Net->GetNodes();

  // create random edges
  NCount = NEdges;
  while (NCount > 0) {
    x = (long) (drand48() * NNodes);
    y = (long) (drand48() * NNodes);
    // Net->GetEdges() is not correct for the loops (x == y),
    // skip the loops in this test
    if (x != y  &&  !Net->IsEdge(x,y)) {
      n = Net->AddEdge(x, y);
      NCount--;
    }
  }
  PrintNStats("SortNodeData:Net", Net);

  // add data to nodes, square of node ID % NNodes
  for (TNodeEDatNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
    NodeId = NI.GetId();
    NodeDat = (NI.GetId()*NI.GetId()) % NNodes;
    Net->SetNDat(NodeId, NodeDat);
  }

  // test node data
  ok = true;
  for (TNodeEDatNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
    NodeDat = Net->GetNDat(NI.GetId());
    Value = (NI.GetId()*NI.GetId()) % NNodes;
    if (NodeDat != Value) {
      ok = false;
    }
  }
  printf("network SortNodeData:Net, status1 %s\n", (ok == true) ? "ok" : "ERROR");

  // test sorting of node IDs (unsorted)
  Min = -1;
  Sorted = true;
  for (TNodeEDatNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
    Value = NI.GetId();
    if (Min > Value) {
      Sorted = false;
    }
    Min = Value;
  }
  printf("network SortNodeData:Net, status2 %s\n", (Sorted == false) ? "ok" : "ERROR");

  // sort the nodes by node IDs (sorted)
  Net->SortNIdById();

  // test sorting of node IDs
  Min = -1;
  Sorted = true;
  for (TNodeEDatNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
    Value = NI.GetId();
    if (Min > Value) {
      Sorted = false;
    }
    Min = Value;
  }
  printf("network SortNodeData:Net, status3 %s\n", (Sorted == true) ? "ok" : "ERROR");

  // test sorting of node data (unsorted)
  Min = -1;
  Sorted = true;
  for (TNodeEDatNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
    Value = Net->GetNDat(NI.GetId());
    if (Min > Value) {
      Sorted = false;
    }
    Min = Value;
  }
  printf("network SortNodeData:Net, status4 %s\n", (Sorted == false) ? "ok" : "ERROR");
//.........这里部分代码省略.........
开发者ID:Accio,项目名称:snap,代码行数:101,代码来源:demo-TNodeEDatNet.cpp


示例11: main

int main(void)
{
    // seed pseudorandom number generator
    srand48(time(NULL));

    // instantiate window
    GWindow window = newGWindow(WIDTH, HEIGHT);

    // instantiate bricks
    initBricks(window);

    // instantiate ball, centered in middle of window
    GOval ball = initBall(window);

    // instantiate paddle, centered at bottom of window
    GRect paddle = initPaddle(window);

    // instantiate scoreboard, centered in middle of window, just above ball
    GLabel label = initScoreboard(window);

    // number of bricks initially
    int bricks = COLS * ROWS;

    // number of lives initially
    int lives = LIVES;

    // number of points initially
    int points = 0;
    
    // velocity of ball
    // TODO use drand for velocityX
    double velocityX = drand48() * 3.0;
    double velocityY = 3.0;

    // keep playing until game over
    waitForClick();    
    while (lives > 0 && bricks > 0)
    {
        // check for mouse event
        GEvent event = getNextEvent(MOUSE_EVENT);


        updateScoreboard(window, label, points);
        // set velocity of ball
        move(ball, velocityX, velocityY);

        // detect collision
        GObject collision = detectCollision(window, ball);

        if (getX(ball) + getWidth(ball) >= getWidth(window))
        {
            velocityX = -velocityX;
        }
        // bounce off left edge of window
        else if (getX(ball) <= 0)
        {
            velocityX = -velocityX;
        }
        else if (getY(ball) + getHeight(ball) >= getHeight(window))
        {
            lives -= 1;
            waitForClick();
            setLocation(ball, 190, 290);
            move(ball, velocityX, -velocityY);
        }
        else if (getY(ball) <= 0)
        {
            velocityY = -velocityY;
        }
        else if (collision != NULL)
        {
            if (collision == paddle)
            {
                velocityY = -velocityY;
            }
            else if (strcmp(getType(collision), "GRect") == 0)
            {
                // TODO
                velocityY = -velocityY;
                removeGWindow(window, collision);
                points += 1;
                bricks -= 1;
            }
        }
        pause(10);
        


        if (event != NULL)
        {
                if (getEventType(event) == MOUSE_MOVED)
                {
                    // ensure circle follows top cursor
                    double x = getX(event) - getWidth(paddle) / 2;
                    double y = 525;
                    setLocation(paddle, x, y);
                }
        }

    }
//.........这里部分代码省略.........
开发者ID:stevenr024,项目名称:CS50,代码行数:101,代码来源:breakout.c


示例12: UpdateEdgeData

// Test update edge data
void UpdateEdgeData() {
  int NNodes = 10000;
  int NEdges = 100000;

  TPt <TNodeEDatNet<TInt, TInt> > Net;
  TPt <TNodeEDatNet<TInt, TInt> > Net1;
  TPt <TNodeEDatNet<TInt, TInt> > Net2;
  int i;
  int n;
  int NCount;
  int x,y;
  bool t;
  int SrcNId;
  int DstNId;
  int EdgeDat;
  int Value;
  bool ok;

  Net = TNodeEDatNet<TInt, TInt>::New();
  t = Net->Empty();

  // create the nodes
  for (i = 0; i < NNodes; i++) {
    Net->AddNode(i);
  }
  t = Net->Empty();
  n = Net->GetNodes();

  // create random edges and edge data x+y+10
  NCount = NEdges;
  while (NCount > 0) {
    x = (long) (drand48() * NNodes);
    y = (long) (drand48() * NNodes);
    // Net->GetEdges() is not correct for the loops (x == y),
    // skip the loops in this test
    if (x != y  &&  !Net->IsEdge(x,y)) {
      n = Net->AddEdge(x, y, x+y+10);
      NCount--;
    }
  }
  PrintNStats("UpdateEdgeData:Net", Net);

  // verify edge data, x+y+10
  ok = true;
  for (TNodeEDatNet<TInt, TInt>::TEdgeI EI = Net->BegEI(); EI < Net->EndEI(); EI++) {
    SrcNId = EI.GetSrcNId();
    DstNId = EI.GetDstNId();
    EdgeDat = Net->GetEDat(SrcNId, DstNId);
    Value = SrcNId+DstNId+10;
    if (EdgeDat != Value) {
      ok = false;
    }
  }
  printf("network UpdateEdgeData:Net, status1 %s\n", (ok == true) ? "ok" : "ERROR");

  // update edge data, x+y+5
  for (TNodeEDatNet<TInt, TInt>::TEdgeI EI = Net->BegEI(); EI < Net->EndEI(); EI++) {
    Net->SetEDat(EI.GetSrcNId(),EI.GetDstNId(),EI.GetSrcNId()+EI.GetDstNId()+5);
  }

  // verify edge data, x+y+5
  ok = true;
  for (TNodeEDatNet<TInt, TInt>::TEdgeI EI = Net->BegEI(); EI < Net->EndEI(); EI++) {
    SrcNId = EI.GetSrcNId();
    DstNId = EI.GetDstNId();
    EdgeDat = Net->GetEDat(SrcNId, DstNId);
    Value = SrcNId+DstNId+5;
    if (EdgeDat != Value) {
      ok = false;
    }
  }
  printf("network UpdateEdgeData:Net, status2 %s\n", (ok == true) ? "ok" : "ERROR");
}
开发者ID:Accio,项目名称:snap,代码行数:74,代码来源:demo-TNodeEDatNet.cpp


示例13: ManipulateNodesEdges

// Test node, edge creation
void ManipulateNodesEdges() {
  int NNodes = 10000;
  int NEdges = 100000;
  const char *FName = "demo.net.dat";

  TPt <TNodeEDatNet<TInt, TInt> > Net;
  TPt <TNodeEDatNet<TInt, TInt> > Net1;
  TPt <TNodeEDatNet<TInt, TInt> > Net2;
  int i;
  int n;
  int NCount;
  int ECount1;
  int ECount2;
  int x,y;
  bool t;

  Net = TNodeEDatNet<TInt, TInt>::New();
  t = Net->Empty();

  // create the nodes
  for (i = 0; i < NNodes; i++) {
    Net->AddNode(i);
  }
  t = Net->Empty();
  n = Net->GetNodes();

  // create random edges
  NCount = NEdges;
  while (NCount > 0) {
    x = (long) (drand48() * NNodes);
    y = (long) (drand48() * NNodes);
    // Net->GetEdges() is not correct for the loops (x == y),
    // skip the loops in this test
    if (x != y  &&  !Net->IsEdge(x,y)) {
      n = Net->AddEdge(x, y);
      NCount--;
    }
  }
  PrintNStats("ManipulateNodesEdges:Net", Net);

  // get all the nodes
  NCount = 0;
  for (TNodeEDatNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
    NCount++;
  }

  // get all the edges for all the nodes
  ECount1 = 0;
  for (TNodeEDatNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
    for (int e = 0; e < NI.GetOutDeg(); e++) {
      ECount1++;
    }
  }

  // get all the edges directly
  ECount2 = 0;
  for (TNodeEDatNet<TInt, TInt>::TEdgeI EI = Net->BegEI(); EI < Net->EndEI(); EI++) {
    ECount2++;
  }
  printf("network ManipulateNodesEdges:Net, nodes %d, edges1 %d, edges2 %d\n",
      NCount, ECount1, ECount2);

  // assignment
  Net1 = TNodeEDatNet<TInt, TInt>::New();
  *Net1 = *Net;
  PrintNStats("ManipulateNodesEdges:Net1",Net1);

  // save the network
  {
    TFOut FOut(FName);
    Net->Save(FOut);
    FOut.Flush();
  }

  // load the network
  {
    TFIn FIn(FName);
    Net2 = TNodeEDatNet<TInt, TInt>::Load(FIn);
  }
  PrintNStats("ManipulateNodesEdges:Net2",Net2);

  // remove all the nodes and edges
  for (i = 0; i < NNodes; i++) {
    n = Net->GetRndNId();
    Net->DelNode(n);
  }
  PrintNStats("ManipulateNodesEdges:Net",Net);

  Net1->Clr();
  PrintNStats("ManipulateNodesEdges:Net1",Net1);
}
开发者ID:Accio,项目名称:snap,代码行数:92,代码来源:demo-TNodeEDatNet.cpp


示例14: UpdateNodeData

// Test update node data
void UpdateNodeData() {
  int NNodes = 10000;
  int NEdges = 100000;

  TPt <TNodeEDatNet<TInt, TInt> > Net;
  TPt <TNodeEDatNet<TInt, TInt> > Net1;
  TPt <TNodeEDatNet<TInt, TInt> > Net2;
  int i;
  int n;
  int NCount;
  int x,y;
  bool t;
  int NodeDat;
  int Value;
  bool ok;

  Net = TNodeEDatNet<TInt, TInt>::New();
  t = Net->Empty();

  // create the nodes
  for (i = 0; i < NNodes; i++) {
    Net->AddNode(i,i+5);
  }
  t = Net->Empty();
  n = Net->GetNodes();

  // create random edges
  NCount = NEdges;
  while (NCount > 0) {
    x = (long) (drand48() * NNodes);
    y = (long) (drand48() * NNodes);
    // Net->GetEdges() is not correct for the loops (x == y),
    // skip the loops in this test
    if (x != y  &&  !Net->IsEdge(x,y)) {
      n = Net->AddEdge(x, y);
      NCount--;
    }
  }
  PrintNStats("UpdateNodeData:Net", Net);

  // read and test node data
  ok = true;
  for (TNodeEDatNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
    NodeDat = Net->GetNDat(NI.GetId());
    Value = NI.GetId()+5;
    if (NodeDat != Value) {
      ok = false;
    }
  }
  printf("network UpdateNodeData:Net, status1 %s\n", (ok == true) ? "ok" : "ERROR");

  // update node data, node ID + 10
  for (TNodeEDatNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
    Net->SetNDat(NI.GetId(), NI.GetId()+10);
  }

  // read and test node data
  ok = true;
  for (TNodeEDatNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
    NodeDat = Net->GetNDat(NI.GetId());
    Value = NI.GetId()+10;
    if (NodeDat != Value) {
      ok = false;
    }
  }
  printf("network UpdateNodeData:Net, status2 %s\n", (ok == true) ? "ok" : "ERROR");
}
开发者ID:Accio,项目名称:snap,代码行数:68,代码来源:demo-TNodeEDatNet.cpp


示例15: drand48

float Lowpass::main_body_quality(
  Streamline *st,
  float radius,
  int nsamples,
  float dist,
  Window2d *win,
  int &which_side
)
{
  int i;
  float rad;
  float delta;
  float x,y;
  float sum = 0;
  int count = 0;
  VectorField *vf = st->vf;

  /* kluge to work around problems at the image borders */

  float xmin = 2.0 / xsize;
  float ymin = 2.0 / ysize;
  float xmax = 1 - 2.0 / xsize;
  float ymax = image->getaspect() - 2.0 / ysize;

  /* measure the quality at several random positions along the streamline */

  for (i = 0; i < nsamples; i++) {

    int index = (int) (st->samples * drand48());
    SamplePoint *sample = &st->pts[index];

    x = sample->x;
    y = sample->y;

    /* don't measure near the borders */
    if (x < xmin || x > xmax || y < ymin || y > ymax)
      continue;

    rad = radius * rad_image->get_value(x,y) / xsize;
    delta = 0.3 * rad / nsamples;

    /* find out how to move perpendicular to the vector field */
    float dx = - delta * vf->yval(x,y);
    float dy =   delta * vf->xval(x,y);

    /* sample along either side of the streamline */
    float x1 = x + dx;
    float y1 = y + dy;
    float x2 = x - dx;
    float y2 = y - dy;

    /* measure the quality at the two points */
    float value1 = image->get_value(x1,y1);
    float value2 = image->get_value(x2,y2);
   // printf("value1: %f, value2: %f\n",value1,value2);

    sum += value1 - value2;

    count++;

  }

  /* return quality */

  if (count == 0)
    return (0.0);
  else {

    if (sum > 0)
      which_side = LEFT;
    else
      which_side = RIGHT;

    return (fabs (sum / count));
  }
}
开发者ID:haolly,项目名称:fluid3dsjtu,代码行数:76,代码来源:lowpass.cpp


示例16: main

int main(int argc, char *argv[], char *envp[])
{
	double 			*A, *B, *C;
	double 			elapsed = 0, totalElapsed = 0;
	double 			gflops = 0;
	int 			i, j, k;
	unsigned int	start = 1, end = 1, skip = 1, count = 1;
	unsigned int	size = 1, algorithm = 1, debug = 0;
	char 			c;

	struct timespec 	startTime, endTime;
	struct rusage 		ruStart, ruEnd;

	while((c = getopt(argc, argv, "c:s:e:j:a:d:")) != -1)
		switch(c) {
			case 's': 
				start = atoll(optarg);
				break;
			case 'e': 
				end = atoll(optarg);
				break;
			case 'j': 
				skip = atoll(optarg);
				break;
			case 'c':
				count = atoll(optarg);
				break;
			case 'a':
				algorithm = atoll(optarg);
				break;
			case 'd':
				debug = atoll(optarg);
				break;
			default:
				goto error0;
		}
	if(debug > 0) fprintf(stderr, "start = %d, end = %d, skip = %d, count = %d\n",
		start, end, skip, count);
	for(size=start; size<=end; size+=skip) {
		if(debug > 0) fprintf(stderr, "Starting size = %d\n", size);
		totalElapsed = 0;
		for(j=0; j<count; j++) {
			if(debug > 0) fprintf(stderr, "Computing matrix count = %d\n", j);
			A = calloc(size * size, sizeof(double));
			B = calloc(size * size, sizeof(double));
			C = calloc(size * size, sizeof(double));
			for(k=0; k<size * size; k++) {
				A[k] = drand48();
				B[k] = drand48();
			}
#ifdef HAVE_CLOCK_GETTIME
			clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &startTime);
#else
			getrusage(RUSAGE_SELF, &ruStart);
			startTime.tv_sec = ruStart.ru_utime.tv_sec + ruStart.ru_stime.tv_sec;
			startTime.tv_nsec = (ruStart.ru_utime.tv_usec + ruStart.ru_stime.tv_usec)*1000;
#endif
			switch(algorithm) {
				case 1:
					dMM(A, B, C, size, size, size);
					break;
				case 2:
					dMMT(A, B, C, size, size, size);
					break;
				case 3:
					dMMT2(A, B, C, size, size, size);
					break;
				case 4:
					dMMT2r(A, B, C, size, size, size);
					break;
				case 5:
					strassenMM(A, B, C, size, size, size);
					break;
				default:
					goto error1;
			}

#ifdef HAVE_CLOCK_GETTIME
			clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &endTime);
#else
			getrusage(RUSAGE_SELF, &ruEnd);
			endTime.tv_sec = ruEnd.ru_utime.tv_sec + ruEnd.ru_stime.tv_sec;
			endTime.tv_nsec = (ruEnd.ru_utime.tv_usec + ruEnd.ru_stime.tv_usec) * 1000;
#endif
			elapsed =  endTime.tv_sec;
			elapsed += (double)endTime.tv_nsec / 10e9;
			elapsed -= startTime.tv_sec;
			elapsed -= (double)startTime.tv_nsec / 10e9;
			totalElapsed += elapsed;
			if(debug > 0) {
				fprintf(stderr, "size = %d, alg = %d, start = %f, end = %f, elapsed = %f, Gops = %f\n",
					size, algorithm, 
					startTime.tv_sec + (double)(startTime.tv_nsec)/1e9,
					endTime.tv_sec + (double)(endTime.tv_nsec)/1e9,
					elapsed, ((double)2.0*size*size*size-size*size)/10e9
				);
			}
			free(A);
			free(B);
			free(C);		
//.........这里部分代码省略.........
开发者ID:meconlen,项目名称:matrixComp,代码行数:101,代码来源:measure.c


示例17: EvalClassExpression


//.........这里部分代码省略.........

/* If we get here, anything remaining on the RHS must be a clist */

    if (cp->rval.type != RVAL_TYPE_LIST)
    {
        Log(LOG_LEVEL_ERR, "RHS of promise body attribute '%s' is not a list", cp->lval);
        PromiseRef(LOG_LEVEL_ERR, pp);
        return true;
    }

// Class distributions

    if (strcmp(cp->lval, "dist") == 0)
    {
        for (rp = (Rlist *) cp->rval.item; rp != NULL; rp = rp->next)
        {
            result = IntFromString(rp->item);

            if (result < 0)
            {
                Log(LOG_LEVEL_ERR, "Non-positive integer in class distribution");
                PromiseRef(LOG_LEVEL_ERR, pp);
                return false;
            }

            total += result;
        }

        if (total == 0)
        {
            Log(LOG_LEVEL_ERR, "An empty distribution was specified on RHS");
            PromiseRef(LOG_LEVEL_ERR, pp);
            return false;
        }

        double fluct = drand48();
        double cum = 0.0;

        for (rp = (Rlist *) cp->rval.item; rp != NULL; rp = rp->next)
        {
            double prob = ((double) IntFromString(rp->item)) / ((double) total);
            cum += prob;

            if (fluct < cum)
            {
                break;
            }
        }

        snprintf(buffer, CF_MAXVARSIZE - 1, "%s_%s", pp->promiser, (char *) rp->item);
        /* FIXME: figure why explicit mark and get rid of it */
        EvalContextMarkPromiseDone(ctx, pp);

        if (strcmp(PromiseGetBundle(pp)->type, "common") == 0)
        {
            EvalContextHeapAddSoft(ctx, buffer, PromiseGetNamespace(pp));
        }
        else
        {
            EvalContextStackFrameAddSoft(ctx, buffer);
        }

        return true;
    }

    /* and/or/xor expressions */

    for (rp = (Rlist *) cp->rval.item; rp != NULL; rp = rp->next)
    {
        if (rp->type != RVAL_TYPE_SCALAR)
        {
            return false;
        }

        result = IsDefinedClass(ctx, (char *) (rp->item), PromiseGetNamespace(pp));

        result_and = result_and && result;
        result_or = result_or || result;
        result_xor ^= result;
    }

// Class combinations

    if (strcmp(cp->lval, "or") == 0)
    {
        return result_or;
    }

    if (strcmp(cp->lval, "xor") == 0)
    {
        return (result_xor == 1) ? true : false;
    }

    if (strcmp(cp->lval, "and") == 0)
    {
        return result_and;
    }

    return false;
}
开发者ID:JarleB,项目名称:core,代码行数:101,代码来源:verify_classes.c


示例18: ManipulateNodesEdges

// Test node, edge creation
void ManipulateNodesEdges() {
  int NNodes = 10000;
  int NEdges = 100000;
  const char *FName = "demo.graph.dat";

  PNGraph Graph;
  PNGraph Graph1;
  PNGraph Graph2;
  int i;
  int n;
  int NCount;
  int ECount1;
  int ECount2;
  int x,y;
  bool t;

  Graph = TNGraph::New();
  t = Graph->Empty();

  // create the nodes
  for (i = 0; i < NNodes; i++) {
    Graph->AddNode(i);
  }
  t = Graph->Empty();
  n = Graph->GetNodes();

  // create random edges
  NCount = NEdges;
  while (NCount > 0) {
    x = (long) (drand48() * NNodes);
    y = (long) (drand48() * NNodes);
    // Graph->GetEdges() is not correct for the loops (x == y),
    // skip the loops in this test
    if (x != y  &&  !Graph->IsEdge(x,y)) {
      n = Graph->AddEdge(x, y);
      NCount--;
    }
  }
  PrintGStats("ManipulateNodesEdges:Graph",Graph);

  // get all the nodes
  NCount = 0;
  for (TNGraph::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
    NCount++;
  }

  // get all the edges for all the nodes
  ECount1 = 0;
  for (TNGraph::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
    for (int e = 0; e < NI.GetOutDeg(); e++) {
      ECount1++;
    }
  }

  // get all the edges directly
  ECount2 = 0;
  for (TNGraph::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
    ECount2++;
  }
  printf("ManipulateNodesEdges:Graph, nodes %d, edges1 %d, edges2 %d\n",
      NCount, ECount1, ECount2);

  // assignment
  Graph1 = TNGraph::New();
  *Graph1 = *Graph;
  PrintGStats("ManipulateNodesEdges:Graph1",Graph1);

  // save the graph
  {
    TFOut FOut(FName);
    Graph->Save(FOut);
    FOut.Flush();
  }

  // load the graph
  {
    TFIn FIn(FName);
    Graph2 = TNGraph::Load(FIn);
  }
  PrintGStats("ManipulateNodesEdges:Graph2",Graph2);

  // remove all the nodes and edges
  for (i = 0; i < NNodes; i++) {
    n = Graph->GetRndNId();
    Graph->DelNode(n);
  }

  PrintGStats("ManipulateNodesEdges:Graph",Graph);

  Graph1->Clr();
  PrintGStats("ManipulateNodesEdges:Graph1",Graph1);
}
开发者ID:Accio,项目名称:snap,代码行数:93,代码来源:demo-TNGraph.cpp


示例19: bwa_aln2seq_core

void bwa_aln2seq_core(int n_aln, const bwt_aln1_t *aln, bwa_seq_t *s, int set_main, int n_multi)
{
	int i, 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ drawAxes函数代码示例发布时间:2022-05-30
下一篇:
C++ drand函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap