示例#1
0
int run_iterations(int run_index, parameters params) {
	FILE *stats = stats_open_file(run_index);
	stats_print_header(stats);

	int counter = 1;
	int *count;
	int max_infected = 0, time_of_max_infected;
	int day;
	
	igraph_t graph;
	
	for(int K = params.K_low; K < params.K_high; K += params.K_step) {
		for(double p = params.p_low; p < params.p_high; p += params.p_step) {
			for(int i = 0; i < REPITITIONS; i++) {
				printf("%i\n", counter);

				// Initialize the graph
				igraph_watts_strogatz_game(&graph, 1, NETWORK_SIZE, K, p);

				//
				// Initialize the variables that keep track of the state of 
				// each vertex.
				 
				// For each vertex, we track what state it is in (susceptible, latent, infectious, recovered)
				// and how long they have been in their current state.

				state_init(&graph);
				state_counter_init(&graph);

				count = state_counts(&graph);

				//
				// The main loop
				//
				max_infected = 0;
				time_of_max_infected = 1;
				for(day = 1; day <= SIMULATION_LENGTH; day++) {
					spread_infection(&graph);

					//char graph_file[100];
					//sprintf(&graph_file[0], "graph-data/graph%i-k-%i-p-%f.graphml", day, K, p);

					//graph_save(&graph, graph_file);

					count = state_counts(&graph);

					if(count[INFECTIOUS] > max_infected) {
						max_infected = count[INFECTIOUS];
						time_of_max_infected = day;
					}

					if(count[INFECTIOUS] == 0) {
						break;
					}
				}

				stats_save(&graph, stats, counter, K, p, max_infected, time_of_max_infected, count[SUSCEPTIBLE], count[LATENT], count[INFECTIOUS], count[RECOVERED], day);

				counter += 1;
				igraph_destroy(&graph);
			}
		}
	}
	

	stats_close_file(stats);
}
示例#2
0
文件: cardgame.c 项目: asqz/runner
int init(const platform_env_t* env)
{
    paused = 0;

    LOGI("Environment:\n  Platform: %d\n  Assets: %s\n  Shared: %s\n  Config: %s\n  Tmp: %s\n",
         env->platform,
         env->assets_dir,
         env->shared_dir,
         env->config_dir,
         env->tmp_dir);

    io_driver_t* assets = NULL;
    io_driver_t* config = NULL;
    io_driver_t* tmp = NULL;
    io_driver_t* shared = NULL;
    if (io_init(&io) != 0 ||
#ifdef ANDROID
            io_driver_apk_init(&assets, env->platform_specific) != 0 ||
#else
            io_driver_fs_init(&assets, env->assets_dir) != 0 ||
#endif
            io_driver_fs_init(&config, env->config_dir) != 0 ||
            io_driver_fs_init(&shared, env->shared_dir) != 0 ||
            io_driver_fs_init(&tmp, env->tmp_dir) != 0 ||
            io_bind(io, "/config", config) ||
            io_bind(io, "/tmp", tmp) ||
            io_bind(io, "/shared", shared) ||
            io_bind(io, "/assets", assets)
       )
    {
        LOGE("Error initializing I/O system");
        return -1;
    }
    io_set_working_dir(io, "/assets");
    io_set_default(io);

    if (gfx_init(&gfx) != 0)
    {
        LOGE("Error initializing GFX system");
        return -1;
    }

    font_info_t info =
    {
        .name = "fonts/default.ttf",
        .face_index = 0,
        .width = 0,
        .height = 14 * 64,
        .dpi_x = 0,
        .dpi_y = 72,
    };
    if (font_init(&font, &info, NULL) != 0)
    {
        LOGE("Error loading font");
        return -1;
    }

    info.height = 22 * 64;
    if (font_init(&big_font, &info, NULL) != 0)
    {
        LOGE("Error loading font");
        return -1;
    }

    if (atlases_load(&atlases, "atlases.dat") != 0)
    {
        LOGE("Error loading atlases metadata");
        return -1;
    }

    if (sprites_load(&sprites, "sprites.dat") != 0)
    {
        LOGE("Error loading sprites metadata");
        return -1;
    }

    stats_load(&global_stats, "/config/player.dat");

    if (am_init(&am, achievements_get_all(), achievements_get_count(), achievement_progress, achievement_unlocked))
    {
        LOGE("Unable to initialize achievements manager");
        return -1;
    }
    achievements_context.am = am;
    am_load(am, "/config/achievements.dat");

    timestamp_set(&timer);
    timestamp_set(&fps_timer);

    push_screen(SCREEN_MAIN_MENU);

    return 0;
}

void shutdown()
{
    LOGI("shutdown");
    atlases_free(atlases);
    sprites_free(sprites);
    font_free(font);
    font_free(big_font);
    gfx_free(gfx);

    stats_dump(&global_stats);
    stats_save(&global_stats, "/config/player.dat");
    stats_free(&global_stats);

    if (am != NULL)
    {
        am_save(am, "/config/achievements.dat");
        am_dump(am);
        am_free(am);
        am = NULL;
    }

    io_free(io);
    io = NULL;

    atlases = NULL;
    sprites = NULL;
    font = NULL;
    big_font = NULL;
    gfx = NULL;
}