コード例 #1
0
ファイル: fitness.c プロジェクト: emkev/genetic
int main(int argc , char **argv)
{
  int i , j , t , targetlen , parent_a , parent_b ;
  int *numcorrect; 
  char **newpop , **oldpop , **swap;
  double *normfit;

  //srandom(seed);
  srand((unsigned)time(NULL));

  // whether to consider forcing the size to be even . 

  targetlen = 10;
  printf("hello! \n");
  newpop = malloc(sizeof(char *) * size);
  oldpop = malloc(sizeof(char *) * size);
  printf("hello 1-1 \n");
  numcorrect = malloc(sizeof(int) * size);
  normfit = malloc(sizeof(double) * size);
  printf("hello2 \n");
  for(i = 0 ; i < size ; i++)
  {
    newpop[i] = malloc(sizeof(char) * targetlen + 1);
    oldpop[i] = malloc(sizeof(char) * targetlen + 1);
    for(j = 0 ; j < targetlen ; j++)
    {
      oldpop[i][j] = random_letter_or_space();
    }
    newpop[i][targetlen] = 0;
    oldpop[i][targetlen] = 0;
  }

  for(t = 0 ; t < steps ; t++)
  {
    compute_fitness(oldpop , numcorrect , normfit);
    dump_stats(numcorrect , oldpop , t + 1 , targetlen);
    for(i = 0 ; i < size ; i += 2)
    {
      parent_a = select_one(normfit);
      parent_b = select_one(normfit);
      // whether to add parent_a can not be equal to parent_b .  
      //printf("p_a = %d , p_b = %d \n" , parent_a , parent_b);
      reproduce(oldpop , newpop , parent_a , parent_b , targetlen , i);
    }
    
    swap = oldpop;
    oldpop = newpop;
    newpop = swap; 
    /*
    swap = newpop;
    newpop = oldpop;
    oldpop = swap;
    */
  }
  exit(0);
}
コード例 #2
0
ファイル: gabump.c プロジェクト: Stray/CBofN
int main(int argc, char **argv)
{
  int i, j, t, parent_a, parent_b;
  char **swap, **newpop, **oldpop;
  double *fit, *normfit;
  
  get_options(argc, argv, options, help_string);

  srandom(seed);

  /* Force the size to be even. */
  size += (size / 2 * 2 != size);

  /* Initialize the population. */
  newpop = xmalloc(sizeof(char *) * size);
  oldpop = xmalloc(sizeof(char *) * size);
  fit = xmalloc(sizeof(double) * size);
  normfit = xmalloc(sizeof(double) * size);
  for(i = 0; i < size; i++) {
    newpop[i] = xmalloc(sizeof(char) * len + 1);
    oldpop[i] = xmalloc(sizeof(char) * len + 1);
    for(j = 0; j < len; j++)
      oldpop[i][j] = random() % 2 + '0';
    oldpop[i][len] = 0;
    newpop[i][len] = 0;
  }

  /* For each time step... */
  for(t = 0; t < gens; t++) {
    compute_fitness(oldpop, fit, normfit);
    dump_stats(t, oldpop, fit);

    /* Pick two parents by fitness and mate them until the
     * next generation has been made.
     */
    for(i = 0; i < size; i += 2) {
      parent_a = select_one(normfit);
      parent_b = select_one(normfit);
      reproduce(oldpop, newpop, parent_a, parent_b, i);
    }
    /* Make everything old new again. */
    swap = newpop; newpop = oldpop; oldpop = swap;
  }

  exit(0);
}
コード例 #3
0
int
QcOfflineCacheDatabase::has_tile(const QcTileSpec & tile_spec)
{
  QSqlRecord record = select_one(TILE, QStringList(OFFLINE_COUNT), tile_where_clause(tile_spec));
  if (record.isEmpty())
    return 0;
  else
    return record.value(0).toInt();
}
コード例 #4
0
ファイル: jitsymbol.c プロジェクト: crossbuild/oprofile
/*
 * Within the index range (into the array entries_address_ascending), find the
 * symbol with the maximal lifetime and split/truncate all symbols that overlap
 * with it (i.e. that there won't be any overlaps anymore).
 */
static int handle_overlap_region(int start_idx, int end_idx)
{
	int rc = OP_JIT_CONV_OK;
	int idx;
	struct jitentry * e;
	int cnt;
	char * name;
	int i, j;
	unsigned long long totaltime, pct;

	if (debug) {
		for (i = start_idx; i <= end_idx; i++) {
			e = entries_address_ascending[i];
			verbprintf(debug, "overlap idx=%i, name=%s, "
				   "start=%llx, end=%llx, life_start=%lli, "
				   "life_end=%lli, lifetime=%lli\n",
				   i, e->symbol_name, e->vma,
				   e->vma + e->code_size, e->life_start,
				   e->life_end, e->life_end - e->life_start);
		}
	}
	idx = select_one(start_idx, end_idx);
	// This can't happen, but we check anyway, just to silence Coverity
	if (idx == OP_JIT_CONV_FAIL) {
		rc = OP_JIT_CONV_FAIL;
		goto out;
	}
	totaltime = eliminate_overlaps(start_idx, end_idx, idx);
	if (totaltime == ULONG_MAX) {
		rc = OP_JIT_CONV_FAIL;
		goto out;
	}
	e = entries_address_ascending[idx];
	pct = (totaltime == 0) ? 100 : (e->life_end - e->life_start) * 100 / totaltime;

	cnt = 1;
	j = pct;
	while ((j = j/10))
		cnt++;

	// Mark symbol name with a %% to indicate the overlap.
	cnt += strlen(e->symbol_name) + 2 + 1;
	name = xmalloc(cnt);
	snprintf(name, cnt, "%s%%%llu", e->symbol_name, pct);
	if (e->sym_name_malloced)
		free(e->symbol_name);
	e->symbol_name = name;
	e->sym_name_malloced = 1;
	verbprintf(debug, "selected idx=%i, name=%s\n", idx, e->symbol_name);
out:
	return rc;
}
コード例 #5
0
void
QcOfflineCacheDatabase::delete_tile(const QcTileSpec & tile_spec)
{
  QString where = tile_where_clause(tile_spec);
  QSqlRecord record = select_one(TILE, QStringList(OFFLINE_COUNT), where);
  if (!record.isEmpty()) {
    int offline_count = record.value(0).toInt();
    if (offline_count > 1) {
      KeyValuePair kwargs;
      kwargs.insert(OFFLINE_COUNT, offline_count -1);
      update(TILE, kwargs, where);
    }
    else
      delete_row(TILE, where);
  }
}
コード例 #6
0
int
QcOfflineCacheDatabase::get_provider_id(const QString & provider)
{
  if (m_providers.contains(provider))
    return m_providers[provider];
  else {
    KeyValuePair kwargs;
    kwargs.insert(NAME, provider);
    insert(PROVIDER, kwargs);
    QString where = format_simple_where(kwargs);
    QSqlRecord record = select_one(PROVIDER, QStringList(PROVIDER_ID), where);
    int provider_id = record.value(0).toInt();
    m_providers.insert(provider, provider_id);
    return provider_id;
  }
}
コード例 #7
0
void
QcOfflineCacheDatabase::insert_tile(const QcTileSpec & tile_spec)
{
  QString where = tile_where_clause(tile_spec);
  QSqlRecord record = select_one(TILE, QStringList(OFFLINE_COUNT), where);
  if (record.isEmpty()) {
    int map_level_id = get_map_level_id(tile_spec);
    KeyValuePair kwargs;
    kwargs.insert(MAP_LEVEL_ID, map_level_id);
    kwargs.insert(ROW, tile_spec.x());
    kwargs.insert(COLUMN, tile_spec.y());
    kwargs.insert(OFFLINE_COUNT, 1);
    insert(TILE, kwargs);
  } else {
    int offline_count = record.value(0).toInt();
    KeyValuePair kwargs;
    kwargs.insert(OFFLINE_COUNT, offline_count +1);
    update(TILE, kwargs, where);
  }
}
コード例 #8
0
int
QcOfflineCacheDatabase::get_map_level_id(const QcTileSpec & tile_spec)
{
  int provider_id = get_provider_id(tile_spec.plugin()); // Fixme: provider
  unsigned int map_level_hash = hash_tile_spec(provider_id, tile_spec.map_id(), tile_spec.level());
  if (m_map_levels.contains(map_level_hash))
    return m_map_levels[map_level_hash];
  else {
    KeyValuePair kwargs;
    kwargs.insert(PROVIDER_ID, provider_id);
    kwargs.insert(MAP_ID, tile_spec.map_id());
    kwargs.insert(LEVEL, tile_spec.level());
    insert(MAP_LEVEL, kwargs);
    QString where = format_simple_where(kwargs);
    QSqlRecord record = select_one(MAP_LEVEL, QStringList(MAP_LEVEL_ID), where);
    int map_level_id = record.value(0).toInt();
    m_map_levels.insert(map_level_hash, map_level_id);
    return map_level_id;
  }
}
コード例 #9
0
ファイル: menu.c プロジェクト: max1325/uae-wii
int menu_select_sized(const char *title, const char **msgs, int *submenus, int sel,
		int x, int y, int x2, int y2,
		void (*select_next_cb)(menu_t *p, void *data),
		void *select_next_cb_data, int font_size)

{
	menu_t menu;
	int out;
	/*
	int info;

	if (!strcmp(title, "Folder") || !strcmp(title, "Single File") ||
			!strcmp(title, "C-64 Disc") || !strcmp(title, "C-64 Tape") || sel < 0)
		info = 0;
	else
		info = 1;
	*/
	if (FULL_DISPLAY_X == 640)
	{
	if (font_size == 16) menu_init_internal(&menu, title, menu_font16, msgs, x, y, x2, y2);
	else menu_init_internal(&menu, title, menu_font20, msgs, x, y, x2, y2);
	}
	else
	{
	if (font_size == 16) menu_init_internal(&menu, title, menu_font8, msgs, x, y, x2, y2);
	else menu_init_internal(&menu, title, menu_font10, msgs, x, y, x2, y2);
	}


	if (sel >= 0)
		select_one(&menu, sel);
	out = menu_select_internal(real_screen, &menu, submenus, sel,
			select_next_cb, select_next_cb_data, font_size);

	menu_fini(&menu);

	return out;
}
コード例 #10
0
ファイル: common_options.c プロジェクト: minadanesh/apsc496
void
select_debug(const struct debug_device *dev, unsigned size) {
	select_one(dev, size, 0);
	if(debug_opt[1] != NULL) select_one(dev, size, 1);
}