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

C++ random_seed函数代码示例

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

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



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

示例1: vector_random_area

Vector vector_random_area(Seed * seed, Vector const corners[2][2])
{
    float u = random_seed(seed);
    float v = random_seed(seed);

    return vector_interpolate_bilinear(corners, u, v);
}
开发者ID:clyde7,项目名称:iv,代码行数:7,代码来源:vector.c


示例2: main

int
main ()
{
    random_t* random1Ptr;
    random_t* random2Ptr;
    random_t* random3Ptr;
    long i;

    puts("Starting...");

    random1Ptr = random_alloc();
    random2Ptr = random_alloc();
    random3Ptr = random_alloc();

    random_seed(random2Ptr, (RANDOM_DEFAULT_SEED + 1));
    random_seed(random3Ptr, (RANDOM_DEFAULT_SEED + 1));

    for (i = 0; i < NUM_ITERATIONS; i++) {
        unsigned long rand1 = random_generate(random1Ptr);
        unsigned long rand2 = random_generate(random2Ptr);
        unsigned long rand3 = random_generate(random3Ptr);
        printf("i = %2li, rand1 = %12lu, rand2 = %12lu, rand2 = %12lu\n",
                i, rand1, rand2, rand3);
        assert(rand1 != rand2);
        assert(rand2 == rand3);
    }

    random_free(random1Ptr);
    random_free(random2Ptr);

    puts("Done.");

    return 0;
}
开发者ID:amohtasham,项目名称:rstm,代码行数:34,代码来源:random.c


示例3: tester

static void
tester (long geneLength, long segmentLength, long minNumSegment, bool_t doPrint)
{
    gene_t* genePtr;
    segments_t* segmentsPtr;
    random_t* randomPtr;
    bitmap_t* startBitmapPtr;
    long i;
    long j;

    genePtr = gene_alloc(geneLength);
    segmentsPtr = segments_alloc(segmentLength, minNumSegment);
    randomPtr = random_alloc();
    startBitmapPtr = bitmap_alloc(geneLength);

    random_seed(randomPtr, 0);
    gene_create(genePtr, randomPtr);
    random_seed(randomPtr, 0);
    segments_create(segmentsPtr, genePtr, randomPtr);

    assert(segmentsPtr->minNum == minNumSegment);
    assert(vector_getSize(segmentsPtr->contentsPtr) >= minNumSegment);

    if (doPrint) {
        printf("Gene = %s\n", genePtr->contents);
    }

    /* Check that each segment occurs in gene */
    for (i = 0; i < vector_getSize(segmentsPtr->contentsPtr); i++) {
        char *charPtr = strstr(genePtr->contents,
                               (char*)vector_at(segmentsPtr->contentsPtr, i));
        assert(charPtr != NULL);
        j = charPtr - genePtr->contents;
        bitmap_set(startBitmapPtr, j);
        if (doPrint) {
            printf("Segment %li (@%li) = %s\n",
                   i, j, (char*)vector_at(segmentsPtr->contentsPtr, i));
        }
    }

    /* Check that there is complete overlap */
    assert(bitmap_isSet(startBitmapPtr, 0));
    for (i = 0, j = 0; i < geneLength; i++ ) {
        if (bitmap_isSet(startBitmapPtr, i)) {
           assert((i-j-1) < segmentLength);
           j = i;
        }
    }

    gene_free(genePtr);
    segments_free(segmentsPtr);
    random_free(randomPtr);
    bitmap_free(startBitmapPtr);
}
开发者ID:takayuki,项目名称:al,代码行数:54,代码来源:segments.c


示例4: rgb_timing

void rgb_timing(Test **test, Rgb_Timing *timing)
{

 double total_time,avg_time;
 int i,j;
 unsigned int *rand_uint;

 MYDEBUG(D_RGB_TIMING){
   printf("# Entering rgb_timing(): ps = %u  ts = %u\n",test[0]->psamples,test[0]->tsamples);
 }

 seed = random_seed();
 gsl_rng_set(rng,seed);

 rand_uint = (uint *)malloc((size_t)test[0]->tsamples*sizeof(uint));

 total_time = 0.0;
 for(i=0;i<test[0]->psamples;i++){
   start_timing();
   for(j=0;j<test[0]->tsamples;j++){
     rand_uint[j] = gsl_rng_get(rng);
   }
   stop_timing();
   total_time += delta_timing();
 }
 avg_time = total_time/(test[0]->psamples*test[0]->tsamples);

 timing->avg_time_nsec = avg_time*1.0e+9;
 timing->rands_per_sec = 1.0/avg_time;

 free(rand_uint);
 
}
开发者ID:goodwordalchemy,项目名称:ThinkComplexity,代码行数:33,代码来源:rgb_timing.c


示例5: EventLoop

/**********************************************************************
 * Function: EventLoop
 * Description: this is the main event loop for the program. It 
 * listens for events for .5 seconds, if none come in, it checks 
 * wheter it should timeout and lock the program. If the unit
 * is scheduled to sleep within the next five seconds, it locks
 * the display. 
 * Note: timeout does not work properly if you overclock you 
 * palm's processor.
 * ********************************************************************/ 
static void 
EventLoop (void) 
{
	EventType event;
	UInt16 error;
	
	do
		
	{
		
			// wait a bit for an event
			EvtGetEvent (&event, 50);

				/* Dont seed with empty events!*/
			if(event.eType != nilEvent)
				random_seed((byte *) &event, sizeof(event)); 
	
			// first the system gets the event, then the Menu event handler, then the application
			// event handler, then finally the form event handler
			if (!SysHandleEvent (&event))
			if (!MenuHandleEvent (0, &event, &error))
				if (!ApplicationHandleEvent (&event))
					FrmDispatchEvent (&event);
	}
	while (event.eType != appStopEvent);
}
开发者ID:sjlombardo,项目名称:strip-palm,代码行数:36,代码来源:StripCS.c


示例6: gsl_rng_env_setup

void cHamiltonianMatrix::randomPotential(gsl_vector* randV){

	const gsl_rng_type * T;
	  gsl_rng * r;

	  gsl_rng_env_setup();

	  T = gsl_rng_default;
	  r = gsl_rng_alloc (T);
	  // gsl_rng_env_setup() is getting a generator type and seed from environment variables.
	  // http://stackoverflow.com/questions/9768519/gsl-uniform-random-number-generator
	  // dev/random solution is very time consuming compared to the gettimeofday(),
	  // the gettimeofday() solution, might be better its level of accuracy is enough:
	  unsigned long int seed_number;
	  if (rank == 0) {
//		  seed_number = 0; // debug purpose.
		  seed_number = random_seed();
//		  cout << "Before broadcasting, seed number is " << seed_number << endl;
	  }
	  MPI_Bcast(&seed_number, 1, MPI_UNSIGNED_LONG, 0, MPI_COMM_WORLD); //replace MPI_INT by MPI_UNSIGNED_LONG if int is not long enough.
//	  cout << "After broadcasting, rank " << rank << " has seed number " << seed_number << endl;
	    gsl_rng_set(r,seed_number);
//	    gsl_rng_set(r,random_seed_devrandom());

	  for (int i = 0; i < L; i++)
	    {
	      gsl_vector_set(randV, i, -W/2+W*gsl_rng_uniform (r));
	      // gsl_vector_set(randV,i,1+i-double(L)/2.0);// non-disordered potential for benchmark
	    }

	  gsl_rng_free (r);
}
开发者ID:franklin5,项目名称:manyBodyLocalization,代码行数:32,代码来源:polaron.cpp


示例7: random_init

void random_init(void) {
    // Initialize the memory of the random variables
    memset(&random_vars, 0, sizeof(random_vars_t));

    // Initialize the shift register
    random_vars.shift_reg = random_seed();
}
开发者ID:Joan93,项目名称:MasterThesis,代码行数:7,代码来源:random.c


示例8: init

int init(int nprt,int ndim,double *box,
         double **pxyz,double **pvel,double **pacc)
{
  /* allocate & initialize particles */
  int     i,k;
  double  x;
  double *xyz=NULL;
  double *vel=NULL;
  double *acc=NULL;

  /* allocate */
  xyz=(double*)malloc(ndim*nprt*sizeof(double));
  vel=(double*)malloc(ndim*nprt*sizeof(double));
  acc=(double*)malloc(ndim*nprt*sizeof(double));
  if( !xyz || !vel || !acc ) return 1;

  /* init */
  random_seed(1);
  for(i=0; i<nprt; i++) {
    for(k=0; k<ndim; k++) {
       x=random_number();
       xyz[i*ndim+k]=x * (box[2*k+1]-box[2*k]) + box[2*k]; 
    }
  }

  /* update pointers */
  *(pxyz)=xyz;
  *(pvel)=vel;
  *(pacc)=acc;
  return 0;
}
开发者ID:fooeybartoni,项目名称:CSI702,代码行数:31,代码来源:pp.c


示例9: main

void main() {
	video_mode = 9;
	max_entities = 30000;
	terrain_chunk = 0;
	level_load(NULL);
	random_seed(0);
	mouse_mode = 4;
	vec_set(camera.x, vector(-1101, -97, 800));
	vec_set(camera.pan, vector(4,-29,0));
	
	// Terrain
	BMAP* bmapHeightMap = generate_random_heightmap_noise(256, 256, 64);
	BMAP* bmapColorMap = heightmap_to_colormap(bmapHeightMap);
	ENTITY* entTerrain = terrain_from_heightmap(vector(0,0,-300), bmapHeightMap, 65, 65, 30, 0.4);
	ent_setskin(entTerrain, bmapColorMap, 2);
	entTerrain.material = mat_terrain_multi_texture;
	
	// Roads
	proc_city_create_skins();	
	List *points = roadnetwork_from_rectlangle(entTerrain.min_x + 100, entTerrain.min_y + 100, entTerrain.max_x - 50, entTerrain.max_y - 50, 200, 6);
	//List *points = roadnetwork_from_voronoi(30, entTerrain.min_x + 100, entTerrain.min_y + 100, entTerrain.max_x - 50, entTerrain.max_y - 50);
	List *intersections = roadnetwork_calculate(points);
	roadnetwork_join_near_intersections(intersections, 100); // Delete intersections which are too near to each other
	List *roadNetwork = roadnetwork_build(intersections, 300, true);
	
	// Parcels
	create_parcels(roadNetwork);
}
开发者ID:Acknex,项目名称:TUST,代码行数:28,代码来源:test_procedural_world.c


示例10: main

int main(int argc,char *argv[]) {
  double x,y,pi;
  int n_trials,i_trial,n_hits;

  if (argc != 3) {
    fprintf(stderr,"%s <N trials> <seed>\n",argv[0]);
    exit(1);
  }
  n_trials = atoi(argv[1]);
  random_seed(atoi(argv[2]));
  i_trial = 0;
  n_hits = 0;
  while (i_trial < n_trials) {
/*
   Add statements here to generate two random coordinates
   within the square in the double precision variables x and y,
   and increment the integer variable n_hits if x and y
   represent a point within the unit circle
   Hint: save computation time by NOT calling the sqrt() function!
*/
    x = 2.0*(random_gen() - 0.5);
    y = 2.0*(random_gen() - 0.5);
    if (x*x + y*y <= 1) n_hits++;
    i_trial++;
  }
  pi = 4.0 * ((double) n_hits) / ((double) n_trials);
  printf("%.8f\n",pi);
  exit(0);
}
开发者ID:picoriley,项目名称:Computational-Physics,代码行数:29,代码来源:pi.c


示例11: client_alloc

/* =============================================================================
 * client_alloc
 * -- Returns NULL on failure
 * =============================================================================
 */
client_t*
client_alloc (long id,
              manager_t* managerPtr,
              long numOperation,
              long numQueryPerTransaction,
              long queryRange,
              long percentUser)
{
    client_t* clientPtr;

    clientPtr = (client_t*)malloc(sizeof(client_t));
    if (clientPtr == NULL) {
        return NULL;
    }

    clientPtr->randomPtr = random_alloc();
    if (clientPtr->randomPtr == NULL) {
        return NULL;
    }

    clientPtr->id = id;
    clientPtr->managerPtr = managerPtr;
    random_seed(clientPtr->randomPtr, id);
    clientPtr->numOperation = numOperation;
    clientPtr->numQueryPerTransaction = numQueryPerTransaction;
    clientPtr->queryRange = queryRange;
    clientPtr->percentUser = percentUser;

    return clientPtr;
}
开发者ID:HPDCS,项目名称:stmEnergyOptimization,代码行数:35,代码来源:client.c


示例12: ebox_init

    void ebox_init(void)
    {
        get_system_clock(&cpu.clock);
        get_chip_info();
        cpu.company[0] = 'S';
        cpu.company[1] = 'T';
        cpu.company[2] = '\0';


        SysTick_Config(cpu.clock.core/1000);//  每隔 1ms产生一次中断
        SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);//systemticks clock;
        micro_para = cpu.clock.core/1000000;//减少micros函数计算量
        
        
        //统计cpu计算能力//////////////////
        cpu.ability = 0;
        millis_seconds = 0;
        do
        {
            cpu.ability++;//统计cpu计算能力
        }
        while(millis_seconds < 100);
        cpu.ability = cpu.ability * 10;
        ////////////////////////////////
        ADC1_init();

        NVIC_PriorityGroupConfig(NVIC_GROUP_CONFIG);

        //将pb4默认设置为IO口,禁用jtag
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
        GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
        set_systick_user_event_per_sec(1000);
        random_seed(AD_value[0]);//初始化随机数种子

    }
开发者ID:link271991396,项目名称:STM32_X,代码行数:35,代码来源:ebox_core.cpp


示例13: main

int
main ()
{
    gene_t* gene1Ptr;
    gene_t* gene2Ptr;
    gene_t* gene3Ptr;
    random_t* randomPtr;

    bool_t status = memory_init(1, 4, 2);
    assert(status);

    puts("Starting...");

    gene1Ptr = gene_alloc(10);
    gene2Ptr = gene_alloc(10);
    gene3Ptr = gene_alloc(9);
    randomPtr = random_alloc();

    random_seed(randomPtr, 0);
    gene_create(gene1Ptr, randomPtr);
    random_seed(randomPtr, 1);
    gene_create(gene2Ptr, randomPtr);
    random_seed(randomPtr, 0);
    gene_create(gene3Ptr, randomPtr);

    assert(gene1Ptr->length == strlen(gene1Ptr->contents));
    assert(gene2Ptr->length == strlen(gene2Ptr->contents));
    assert(gene3Ptr->length == strlen(gene3Ptr->contents));

    assert(gene1Ptr->length == gene2Ptr->length);
    assert(strcmp(gene1Ptr->contents, gene2Ptr->contents) != 0);

    assert(gene1Ptr->length == (gene3Ptr->length + 1));
    assert(strcmp(gene1Ptr->contents, gene3Ptr->contents) != 0);
    assert(strncmp(gene1Ptr->contents,
                   gene3Ptr->contents,
                   gene3Ptr->length) == 0);

    gene_free(gene1Ptr);
    gene_free(gene2Ptr);
    gene_free(gene3Ptr);
    random_free(randomPtr);

    puts("All tests passed.");

    return 0;
}
开发者ID:Ikulagin,项目名称:transmem,代码行数:47,代码来源:gene.c


示例14: main

int main(int argc, char **argv)
  {
  int		i;			/* Runs. */
  population	*pop=NULL;		/* Population of solutions. */
  char		*beststring=NULL;	/* Human readable form of best solution. */
  size_t	beststrlen=0;		/* Length of beststring. */

  for (i=0; i<50; i++)
    {
    if (pop) ga_extinction(pop);

    random_seed(424242*i);

    pop = ga_genesis_integer(
       50,			/* const int              population_size */
       1,			/* const int              num_chromo */
       25,			/* const int              len_chromo */
NULL, /*pingpong_ga_callback,*/	/* GAgeneration_hook      generation_hook */
       NULL,			/* GAiteration_hook       iteration_hook */
       NULL,			/* GAdata_destructor      data_destructor */
       NULL,			/* GAdata_ref_incrementor data_ref_incrementor */
       pingpong_score,		/* GAevaluate             evaluate */
       pingpong_seed,		/* GAseed                 seed */
       NULL,			/* GAadapt                adapt */
       ga_select_one_randomrank,	/* GAselect_one           select_one */
       ga_select_two_randomrank,	/* GAselect_two           select_two */
       pingpong_mutate,		/* GAmutate               mutate */
       pingpong_crossover,	/* GAcrossover            crossover */
       NULL,			/* GAreplace              replace */
       NULL			/* vpointer		User data */
            );

    ga_population_set_parameters(
       pop,			/* population      *pop */
       GA_SCHEME_DARWIN,	/* const ga_scheme_type     scheme */
       GA_ELITISM_PARENTS_SURVIVE,	/* const ga_elitism_type   elitism */
       0.5,			/* double  crossover */
       0.5,			/* double  mutation */
       0.0              	/* double  migration */
                              );

    ga_evolution(
       pop,			/* population              *pop */
       200			/* const int               max_generations */
              );

    pingpong_ga_callback(i, pop);
    }

  printf("The final solution found was:\n");
  beststring = ga_chromosome_integer_to_string(pop, ga_get_entity_from_rank(pop,0), beststring, &beststrlen);
  printf("%s\n", beststring);

  ga_extinction(pop);

  s_free(beststring);

  exit(EXIT_SUCCESS);
  }
开发者ID:versionzero,项目名称:gaul,代码行数:59,代码来源:pingpong.c


示例15: main

int main(int argc, char **argv)
  {
  population	*pop=NULL;		/* Population structure. */
  char		*beststring=NULL;	/* Human readable form of best solution. */
  size_t	beststrlen=0;		/* Length of beststring. */

  random_seed(23091975);

  pop = ga_genesis_char(
     120,				/* const int              population_size */
     1,					/* const int              num_chromo */
     (int) strlen(target_text),		/* const int              len_chromo */
     struggle_generation_hook, 		/* GAgeneration_hook      generation_hook */
     NULL,				/* GAiteration_hook       iteration_hook */
     NULL,				/* GAdata_destructor      data_destructor */
     NULL,				/* GAdata_ref_incrementor data_ref_incrementor */
     struggle_score,			/* GAevaluate             evaluate */
     ga_seed_printable_random,		/* GAseed                 seed */
     struggle_adaptation,		/* GAadapt                adapt */
     ga_select_one_sus,			/* GAselect_one		select_one */
     ga_select_two_sus,			/* GAselect_two		select_two */
     ga_mutate_printable_singlepoint_drift,	/* GAmutate	mutate */
     ga_crossover_char_allele_mixing,	/* GAcrossover		crossover */
     NULL,				/* GAreplace		replace */
     NULL				/* vpointer		User data */
            );

  ga_population_set_parameters(
     pop,				/* population		*pop */
     GA_SCHEME_LAMARCK_CHILDREN,	/* const ga_scheme_type	scheme */
     GA_ELITISM_PARENTS_DIE,		/* const ga_elitism_type	elitism */
     0.8,				/* const double		crossover */
     0.05,				/* const double		mutation */
     0.0				/* const double		migration */
                            );

  if ( ga_evolution( pop, 1000 )<1000 )
    {
    printf("The evolution was stopped because the termination criteria were met.\n" );
    }
  else
    {
    printf("The evolution was stopped because the maximum number of generations were performed.\n" );
    }

  printf( "The final solution with score %f was:\n",
          ga_get_entity_from_rank(pop,0)->fitness );
  beststring = ga_chromosome_char_to_string(pop, ga_get_entity_from_rank(pop,0), beststring, &beststrlen);
  printf("%s\n", beststring);
  printf( "Total number of fitness evaluations: %ld\n", evaluation_count );

  ga_extinction(pop);

  s_free(beststring);

  exit(EXIT_SUCCESS);
  }
开发者ID:versionzero,项目名称:gaul,代码行数:57,代码来源:struggle3.c


示例16: sort_rnd_data_fill

/* fill random length array with random data */
void sort_rnd_data_fill(int *data, int length, int min, int max)
{
	int i = 0;
	random_seed();
	while(i < length) {
		data[i]= random_int(min, max);
		i++;
	}
}
开发者ID:NeelPatel21,项目名称:C-Data-Structures,代码行数:10,代码来源:lib_test.c


示例17: vector_random_hemi_direction_2

Vector vector_random_hemi_direction_2(Seed * seed, Vector n)
{
    float u = 0; while (u < 0.001) u = random_seed(seed);
    float v = random_seed(seed);

    float r = sqrt(1 - u * u);
    float phi = 2 * M_PI * v;

    Vector w = vector_polar(phi, r);
    w.z = u;

    Vector x = vector_perpendicular(n);
    Vector y = cross(n, x);
    Vector z = n;
    
    //return vector_transform(x, y, z, w);
    return vector_normalize(vector_transform(x, y, z, w));
}
开发者ID:clyde7,项目名称:iv,代码行数:18,代码来源:vector.c


示例18: vector_random_hemi_direction_cos

Vector vector_random_hemi_direction_cos(Seed * seed, Vector n)
{
    float u = random_seed(seed);
    float v1 = random_seed(seed);

    float r = sqrt(u);
    float phi = 2 * M_PI * v1;

    Vector v = vector_polar(phi, r);
    Vector w = {v.x, v.y, sqrt(fmax(0, 1 - v.x * v.x - v.y * v.y))};

    Vector x = vector_perpendicular(n);
    Vector y = cross(n, x);
    Vector z = n;
    
    //return vector_transform(x, y, z, w);
    return vector_normalize(vector_transform(x, y, z, w));
}
开发者ID:clyde7,项目名称:iv,代码行数:18,代码来源:vector.c


示例19: main

int main(int argc, char **argv)
  {
  int		i;			/* Loop over runs. */
  population	*pop=NULL;		/* Population of solutions. */
  char		*beststring=NULL;	/* Human readable form of best solution. */
  size_t	beststrlen=0;		/* Length of beststring. */

  for (i=0; i<50; i++)
    {
    random_seed(i);

    pop = ga_genesis_char(
       120,			/* const int              population_size */
       1,			/* const int              num_chromo */
       (int) strlen(target_text),	/* const int              len_chromo */
       NULL,		 	/* GAgeneration_hook      generation_hook */
       NULL,			/* GAiteration_hook       iteration_hook */
       NULL,			/* GAdata_destructor      data_destructor */
       NULL,			/* GAdata_ref_incrementor data_ref_incrementor */
       struggle_score,		/* GAevaluate             evaluate */
       ga_seed_printable_random,	/* GAseed                 seed */
       NULL,			/* GAadapt                adapt */
       ga_select_one_sus,	/* GAselect_one           select_one */
       ga_select_two_sus,	/* GAselect_two           select_two */
       ga_mutate_printable_singlepoint_drift,	/* GAmutate               mutate */
       ga_crossover_char_allele_mixing,	/* GAcrossover            crossover */
       NULL,			/* GAreplace		replace */
       NULL			/* vpointer		User data */
            );

    ga_population_set_parameters(
       pop,			/* population      *pop */
       GA_SCHEME_DARWIN,	/* const ga_scheme_type     scheme */
       GA_ELITISM_PARENTS_DIE,	/* const ga_elitism_type   elitism */
       0.9,			/* double  crossover */
       0.2,			/* double  mutation */
       0.0              	/* double  migration */
                              );

    ga_evolution_threaded(
       pop,			/* population      *pop */
       500			/* const int       max_generations */
              );

    printf( "The final solution with seed = %d was:\n", i );
    beststring = ga_chromosome_char_to_string(pop, ga_get_entity_from_rank(pop,0), beststring, &beststrlen);
    printf("%s\n", beststring);
    printf( "With score = %f\n", ga_entity_get_fitness(ga_get_entity_from_rank(pop,0)) );

    ga_extinction(pop);
    }

  s_free(beststring);

  exit(EXIT_SUCCESS);
  }
开发者ID:versionzero,项目名称:gaul,代码行数:56,代码来源:struggle_threaded.c


示例20: main

int main(int argc, char **argv)
  {
  population	*pop=NULL;		/* Population of solutions. */
  char		*beststring=NULL;	/* Human readable form of best solution. */
  size_t	beststrlen=0;		/* Length of beststring. */

  random_seed(20092004);

  pop = ga_genesis_integer(
     200,			/* const int              population_size */
     1,				/* const int              num_chromo */
     100,			/* const int              len_chromo */
     NULL,			/* GAgeneration_hook      generation_hook */
     NULL,			/* GAiteration_hook       iteration_hook */
     NULL,			/* GAdata_destructor      data_destructor */
     NULL,			/* GAdata_ref_incrementor data_ref_incrementor */
     all5s_score,		/* GAevaluate             evaluate */
     ga_seed_integer_random,	/* GAseed                 seed */
     NULL,			/* GAadapt                adapt */
     ga_select_one_sus,		/* GAselect_one           select_one */
     ga_select_two_sus,		/* GAselect_two           select_two */
     ga_mutate_integer_singlepoint_drift,	/* GAmutate               mutate */
     ga_crossover_integer_singlepoints,		/* GAcrossover            crossover */
     NULL,			/* GAreplace		replace */
     NULL			/* vpointer		User data */
          );

  ga_population_set_allele_min_integer(pop, 0);
  ga_population_set_allele_max_integer(pop, 10);

  ga_population_set_parameters(
     pop,			/* population      *pop */
     GA_SCHEME_DARWIN,		/* const ga_scheme_type  scheme */
     GA_ELITISM_PARENTS_SURVIVE,	/* const ga_elitism_type   elitism */
     0.8,			/* double		 crossover */
     0.05,			/* double		 mutation */
     0.0              		/* double		 migration */
                            );

  ga_evolution(
     pop,			/* population              *pop */
     250			/* const int               max_generations */
            );

/* Display final solution. */
  printf("The final solution was:\n");
  beststring = ga_chromosome_integer_to_string(pop, ga_get_entity_from_rank(pop,0), beststring, &beststrlen);
  printf("%s\n", beststring);
  printf("With score = %f\n", ga_get_entity_from_rank(pop,0)->fitness);

/* Free memory. */
  ga_extinction(pop);
  s_free(beststring);

  exit(EXIT_SUCCESS);
  }
开发者ID:versionzero,项目名称:gaul,代码行数:56,代码来源:all5s_allele_ranges.c



注:本文中的random_seed函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ random_string函数代码示例发布时间:2022-05-30
下一篇:
C++ random_range函数代码示例发布时间: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