// The strategy we impose has two parameters: The maximun number of // allocations MAX_ALLOC and the maximum number of regions // NUM_REGIONS. We do more allocations when we have not reached 90% // of MAX_ALLOC and do most deallocations when we have allocated more // than 90% of MAX_ALLOC. We can never allocate more than MAX_ALLOC // and NUM_REGIONS. The region we allocate in is chosen as follows: // Pick a region r randomly. The we allocate in the region between r // and the top most region. This strategy is taken from Mads Toftes // region simulator, see the homepage for the ML Kit version 2. void sim_regs() { UInt32 rnd = tilf(0,99); if ((double)total_alloc < MAX_ALLOC*0.9) { // Do 95% allocations and 5% de-allocations. if (rnd < 5) sim_dealloc(0); else sim_alloc(); } else { // Do 60% de-allocations and 40% allocations. if (rnd < 60) sim_dealloc(1); else sim_alloc(); } }
static int Simulator_init(Simulator *self, PyObject *args, PyObject *kwds) { int ret = -1; int sim_ret; static char *kwlist[] = {"sample", "event_classes", "num_loci", "num_parents", "max_population_size", "max_occupancy", "dimension", "simulate_pedigree", "random_seed", "torus_diameter", "pixel_size", "recombination_probability", NULL}; PyObject *sample, *events; sim_t *sim = PyMem_Malloc(sizeof(sim_t)); self->sim = sim; if (self->sim == NULL) { goto out; } memset(self->sim, 0, sizeof(sim_t)); sim->num_loci = 1; sim->num_parents = 2; sim->torus_diameter = 1000; sim->pixel_size = 2; sim->recombination_probability = 0.5; sim->random_seed = 1; sim->max_population_size = 1000; sim->max_occupancy = 10; sim->dimension = 2; sim->simulate_pedigree = 0; sim->max_time = DBL_MAX; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O!|IIIIIIkddd", kwlist, &PyList_Type, &sample, &PyList_Type, &events, &sim->num_loci, &sim->num_parents, &sim->max_population_size, &sim->max_occupancy, &sim->dimension, &sim->simulate_pedigree, &sim->random_seed, &sim->torus_diameter, &sim->pixel_size, &sim->recombination_probability)) { goto out; } if (Simulator_parse_sample(self, sample) != 0) { goto out; } if (Simulator_parse_events(self, events) != 0) { goto out; } if (Simulator_check_input(self) != 0) { goto out; } sim_ret = sim_alloc(self->sim); if (sim_ret != 0) { handle_library_error(sim_ret); goto out; } sim_ret = sim_initialise(self->sim); if (sim_ret != 0) { handle_library_error(sim_ret); goto out; } ret = 0; out: return ret; }