void canopy::initialize() { initialize_memory(); compute_haz(); compute_foliage_drag_area_index(); }
void initialize_system () { FILE *fconfig; fconfig = fopen ("config.sys", "r"); fscanf (fconfig, "%d\n", &Observe); fscanf (fconfig, "%d %d\n", &cpuQuantum, &idleQuantum); fscanf (fconfig, "%d %d %d %d\n", &pageSize, &memSize, &swapSize, &OSmemSize); fscanf (fconfig, "%d\n", &periodAgeScan); fscanf (fconfig, "%d\n", &spoolPsize); fclose (fconfig); OriginalPages= find_pages(memSize,pageSize); OriginalPages_swapspace = find_pages(swapSize,pageSize); rem_pages = OriginalPages; rem_pages_swapspace = OriginalPages_swapspace; #undef num_pages #define num_pages OriginalPages; OSpages= find_pages(OSmemSize,pageSize); printf("OS Size is %d , OS pages are %d\n", OSmemSize, OSpages); rem_pages= OriginalPages-OSpages; idlePages= find_pages(3, pageSize); /*printf("Idle Size is 256, Idle pages are %d, rem pages are %d \n", idlePages, rem_pages); rem_pages = rem_pages-idlePages;*/ printf("remaining pages are %d\n", rem_pages); #undef num_pages #define num_pages rem_pages; printf("Number of frames in Main memory is %d remaininng pages are %d\n", OriginalPages, rem_pages); initialize_cpu (); printf("initialized CPU \n"); initialize_swap_freelist(rem_pages_swapspace, OriginalPages_swapspace); printf("initialized Swap Space \n"); initialize_freelist(rem_pages, OriginalPages); printf("initialized Main Memory \n"); initialize_timer (); printf("initialized timer \n"); initialize_memory (); printf("initialized memory \n"); initialize_process (); printf("initialized process \n"); // initialize_memory (); // printf("initialized memory \n"); }
/** * Kernel state reset before syscall tests. */ void reset() { initialize_memory(); initialize_tasks(); initialize_scheduling(); initialize_messaging(); t0 = task_create(0, 0, MEDIUM); t1 = task_create(0, 0, MEDIUM); t2 = task_create(0, 1, MEDIUM); }
int main() { initialize_memory(); register_callbacks(); create_context(); load_program(); allocate_control_block(); run_kernel_loop(); free_memory(); return 0; }
// Main program: Initialize the cpu, and read the initial memory values // int main(int argc, char *argv[]) { printf("SDC Simulator pt 1 Devanshu Bharel: CS 350 Lab 6\n"); CPU cpu_value, *cpu = &cpu_value; printf("Initalizing CPU:\n"); initialize_CPU(cpu); printf("Initalizing MEM:\n"); initialize_memory(argc, argv, cpu); dump_CPU(cpu); dump_memory(cpu); dump_registers(cpu); // That's it for Lab 6 // return 0; }
// sudo apt-get install libncurses5-dev // http://stackoverflow.com/questions/4025891/create-a-function-to-check-for-key-press-in-unix-using-ncurses // https://viget.com/extend/game-programming-in-c-with-the-ncurses-library int main(int argc, char **argv) { char *debug_filename = NULL; char *input_filename = NULL; int c; opterr = 0; while ((c = getopt(argc, argv, "d:p:")) != -1) { switch (c) { case 'd': debug_filename = optarg; break; case 'p': input_filename = optarg; break; case '?': fprintf(stderr, "Unknown option: %c\n", optopt); print_usage(); return 1; default: print_usage(); return 1; } } if (optind < argc || input_filename == NULL || (ends_with(input_filename, required_input_ext, 0) != 1)) { print_usage(); return 1; } FILE *input_file = fopen(input_filename, "rb"); if (!input_file) { fprintf(stderr, "Fatal error when opening input file: '%s'\n", argv[1]); exit(1); } FILE *debug_file = NULL; if (debug_filename) { debug_file = fopen(debug_filename, "w"); } chip_8_cpu cpu = initialize_cpu(); initialize_memory(cpu, input_file); fclose(input_file); execute_loop(cpu, debug_file); free_cpu(cpu); return EXIT_SUCCESS; }
void initialize_kernel() { bwsetfifo(COM2, OFF); void (**syscall_handler)() = (void (**)())0x28; *syscall_handler = &kernel_enter; void (**irq_handler)() = (void (**)())0x38; *irq_handler = &irq_enter; initialize_cache(); initialize_memory(); initialize_fine_timer(); initialize_scheduling(); initialize_tasks(); initialize_messaging(); initialize_events(); initialize_waiting(); }
int main(int argc, char *argv[]) { printf("SDC Simulator pt 2: CS 350 Lab 7\n"); printf("Devanshu Bharel\n"); CPU cpu_value, *cpu = &cpu_value; initialize_CPU(cpu); initialize_memory(argc, argv, cpu); char *prompt = ">"; printf("\nBeginning execution; Hit [ENTER] to continue\n%s", prompt); int done = read_execute_command(cpu); while (!done) { done = read_execute_command(cpu); printf("%s", prompt); } return 0; }
// Main program: Initialize the cpu, read initial memory values, // and execute the read-in program starting at location 00. // int main(int argc, char *argv[]) { printf("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n"); printf("=-=-=-=-=-=-= SDC SIM lab06 CS350 Devanshu Bharel =-=-=-=-=-=-=\n"); printf("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n"); initialize_control_unit(reg, NREG); initialize_memory(argc, argv, mem, MEMLEN); char *prompt = "> "; printf("\nBeginning execution; type h for help\n%s", prompt); int done = read_execute_command(reg, NREG, mem, MEMLEN); while (!done) { printf("%s", prompt); done = read_execute_command(reg, NREG, mem, MEMLEN); } printf("At termination\n"); dump_control_unit(pc, ir, running, reg, NREG); dump_memory(mem, MEMLEN); return 0; }
int main(int argc, char *argv[]) { printf("SDC Simulator\n"); /* initialize everything */ initialize_control_unit(reg, NREG); initialize_memory(argc, argv, mem, MEMLEN); char *prompt = "> "; printf("\nBeginning execution; type h for help\n%s", prompt); int done = read_execute_command(reg, NREG, mem, MEMLEN); while (!done) { printf("%s", prompt); done = read_execute_command(reg, NREG, mem, MEMLEN); } /* Dump everything when done */ printf("Termination\n"); dump_control_unit(pc, ir, running, reg, NREG); printf("\n"); dump_memory(mem, MEMLEN); return 0; }
extern void game_update_and_render(Memory* memory, RenderState *renderer, float last_frame_time_seconds, const u8 *keys, SDL_Event e) { UNUSED(keys); UNUSED(e); ASSERT(sizeof(PermanentState) <= memory->permanent_size); PermanentState *permanent = (PermanentState *)memory->permanent; ASSERT(sizeof(ScratchState) <= memory->scratch_size); ScratchState *scratch = (ScratchState *)memory->scratch; ASSERT(sizeof(DebugState) <= memory->debug_size); DebugState *debug = (DebugState *)memory->debug; ASSERT(sizeof(Node16Arena) <= memory->node16_size); Node16Arena *node16 = (Node16Arena *)memory->node16; ASSERT(sizeof(Node16) == sizeof(Node16*)*2 + 16); ASSERT(sizeof(FoundPathNode) == sizeof(BarNode)); if (memory->is_initialized == false) { initialize_memory(permanent, node16, renderer, memory); } // dynamic blocks for (u32 i = 0; i < permanent->dynamic_block_count; i++) { if ( permanent->dynamic_blocks[i].total_frames > 1) { permanent->dynamic_blocks[i].frame_duration_left += last_frame_time_seconds; if (permanent->dynamic_blocks[i].frame_duration_left >= permanent->dynamic_blocks[i].duration_per_frame) { int frame_index = permanent->dynamic_blocks[i].current_frame; if (permanent->dynamic_blocks[i].plays_forward == 1) { frame_index +=1; if (frame_index > permanent->dynamic_blocks[i].last_frame) frame_index = permanent->dynamic_blocks[i].first_frame; } else { frame_index -= 1; if (frame_index < permanent->dynamic_blocks[i].first_frame) frame_index = permanent->dynamic_blocks[i].last_frame; } permanent->dynamic_blocks[i].current_frame = frame_index; permanent->dynamic_blocks[i].frame_duration_left = 0; SimpleFrame f = generated_frames[frame_index]; permanent->dynamic_blocks[i].frame.x_pos = f.frameX; permanent->dynamic_blocks[i].frame.y_pos = f.frameY; permanent->dynamic_blocks[i].frame.width = f.frameW; permanent->dynamic_blocks[i].frame.height = f.frameH; permanent->dynamic_blocks[i].frame.y_internal_off = f.ssH - (f.sssY + f.frameH); permanent->dynamic_blocks[i].frame.x_internal_off = f.ssW - (f.sssX + f.frameW); } } } permanent->colored_line_count = 0; #if 1 { permanent->colored_line_count = 0; for (u32 i = 0; i < permanent->actor_count; i++) { if (permanent->paths[i].Sentinel->Next != permanent->paths[i].Sentinel) { float distance = Vector3Distance(permanent->steer_data[i].location, permanent->paths[i].Sentinel->Next->path.node); if (distance < 5.f){ Node16 *First = permanent->paths[i].Sentinel->Next; permanent->paths[i].Sentinel->Next = First->Next; First->Next = node16->Free->Next; node16->Free->Next = First; First->Prev = node16->Free; } } BEGIN_PERFORMANCE_COUNTER(actors_steering); { Vector3 seek_force = seek_return(&permanent->steer_data[i], permanent->paths[i].Sentinel->Next->path.node); seek_force = Vector3MultiplyScalar(seek_force, 1); actor_apply_force(&permanent->steer_data[i], seek_force); permanent->steer_data[i].velocity = Vector3Add(permanent->steer_data[i].velocity, permanent->steer_data[i].acceleration); permanent->steer_data[i].velocity = Vector3Limit(permanent->steer_data[i].velocity, permanent->steer_data[i].max_speed); permanent->steer_data[i].location = Vector3Add(permanent->steer_data[i].location, Vector3MultiplyScalar(permanent->steer_data[i].velocity, last_frame_time_seconds)); permanent->steer_data[i].acceleration = Vector3MultiplyScalar(permanent->steer_data[i].acceleration, 0); // left = frame 0, down = frame 1 right = frame 2,up = frame 3 double angle = (180.0 / PI) * atan2(permanent->steer_data[i].velocity.x, permanent->steer_data[i].velocity.y); angle = angle + 180; if (angle > 315 || angle < 45) { permanent->anim_data[i].frame = 10; //11 } else if (angle >= 45 && angle <= 135) { permanent->anim_data[i].frame = 4;// 5 } else if (angle >=135 && angle <= 225) { permanent->anim_data[i].frame = 6; //7 } else if (angle > 225 && angle <= 315) { permanent->anim_data[i].frame = 8; //9 } permanent->anim_data[i].frame_duration_left += last_frame_time_seconds; if (permanent->anim_data[i].frame_duration_left > 0.1f) { permanent->anim_data[i].frame += 1; } if (permanent->anim_data[i].frame_duration_left > 0.2f) { permanent->anim_data[i].frame_duration_left = 0; } END_PERFORMANCE_COUNTER(actors_steering); } #if 1 if (permanent->paths[i].Sentinel->Next != permanent->paths[i].Sentinel) { Node16 * d= permanent->paths[i].Sentinel->Next; u32 c = permanent->colored_line_count; while (d->Next != permanent->paths[i].Sentinel){ //if (d->path.node.z != d->Next->path.node.z) { // printf("going from %f,%f,[%f] to %f,%f,[%f]\n", d->path.node.x, d->path.node.y, d->path.node.z, d->Next->path.node.x, d->Next->path.node.y, d->Next->path.node.z); //} permanent->colored_lines[c].x1 = getRotatedXFloat(d->path.node.x, d->path.node.y, facing_side, permanent->dims); permanent->colored_lines[c].y1 = getRotatedYFloat(d->path.node.x, d->path.node.y, facing_side, permanent->dims); permanent->colored_lines[c].z1 = d->path.node.z; permanent->colored_lines[c].x2 = getRotatedXFloat(d->Next->path.node.x, d->Next->path.node.y, facing_side, permanent->dims); permanent->colored_lines[c].y2 = getRotatedYFloat(d->Next->path.node.x, d->Next->path.node.y, facing_side, permanent->dims); permanent->colored_lines[c].z2 = d->Next->path.node.z; permanent->colored_lines[c].r = 0.0f; permanent->colored_lines[c].g = 0.0f; permanent->colored_lines[c].b = 0.0f; d = d->Next; c++; } permanent->colored_line_count = c; } #endif ASSERT( permanent->colored_line_count < LINE_BATCH_COUNT * MAX_IN_BUFFER) if (permanent->paths[i].Sentinel->Next != permanent->paths[i].Sentinel) { continue; } BEGIN_PERFORMANCE_COUNTER(mass_pathfinding); TempMemory temp_mem = begin_temporary_memory(&scratch->arena); grid_node * Start = get_node_at(permanent->grid, permanent->steer_data[i].location.x/permanent->block_size.x, permanent->steer_data[i].location.y/permanent->block_size.y, (permanent->steer_data[i].location.z + 10)/permanent->block_size.z_level); if (Start->walkable) { } else { Start = get_neighboring_walkable_node(permanent->grid, Start->X, Start->Y, Start->Z); if (!Start->walkable) { Start = get_random_walkable_node(permanent->grid); } } grid_node * End = get_random_walkable_node(permanent->grid); ASSERT(Start->walkable); ASSERT(End->walkable); path_list * PathRaw = find_path(Start, End, permanent->grid, &scratch->arena); path_list *Path = NULL; if (PathRaw) { //Path = smooth_path(PathRaw, &scratch->arena, permanent->grid); Path = PathRaw; if (Path) { path_node * done= Path->Sentinel->Prev; while (done != Path->Sentinel) { Node16 *N = NULL; if ( node16->Free->Next != node16->Free) { N = node16->Free->Next; node16->Free->Next = N->Next; node16->Free->Next->Prev = node16->Free; } else { N = PUSH_STRUCT(&node16->arena, Node16); } ActorPath * p = &(permanent->paths[i]); // TODO iam not sure about this, is this the right way to center all positions in the path nodes? // should it be done somewhere else instead? // TODO and why o why does it need something extra when facing Front and not under other circumstances. //float xMult = 0;//facing_side == Front ? 1 : facing_side == Left ? -0.5 : 0.5; //float yMult = 0;//facing_side == Front ? 0.5 : 1; N->path.node.x = (permanent->block_size.x/2) + done->X * permanent->block_size.x; N->path.node.y = (permanent->block_size.y/2) + done->Y * permanent->block_size.y; N->path.node.z = done->Z * permanent->block_size.z_level; /* if (done->Prev != Path->Sentinel) { */ /* // going up */ /* if (done->Z > done->Prev->Z) { */ /* printf("going up\n"); */ /* printf("%d,%d,%d %d,%d,%d\n", done->X,done->Y,done->Z, done->Prev->X, done->Prev->Y, done->Prev->Z); */ /* } */ /* if (done->Z < done->Prev->Z) { */ /* printf("going down 222\n"); */ /* printf("%d,%d,%d %d,%d,%d\n", done->X,done->Y,done->Z, done->Prev->X, done->Prev->Y, done->Prev->Z); */ /* } */ /* } */ /* if (done->Next != Path->Sentinel) { */ /* // going down */ /* if (done->Z < done->Next->Z) { */ /* printf("going down\n"); */ /* printf("%d,%d,%d %d,%d,%d\n", done->X,done->Y,done->Z, done->Next->X, done->Next->Y, done->Next->Z); */ /* } */ /* } */ // if this is part of a stair move going up east/west // TODO: this routine patches some issues which, IMO would better be solved at the root, dunno how wnad where though./ #if 0 // pathing movemenst going up on east/west stairs if (facing_side == Front) { if (done->Prev != Path->Sentinel) { // going up if (done->Z > done->Prev->Z) { if (done->X < done->Prev->X){ N->path.node.x += permanent->block_size.x; } else if (done->X > done->Prev->X){ N->path.node.x -= permanent->block_size.x; } } } if (done->Next != Path->Sentinel) { // going down if (done->Z < done->Next->Z) { if (done->X < done->Next->X){ N->path.node.x -= permanent->block_size.x; } else if (done->X > done->Next->X){ N->path.node.x += permanent->block_size.x; } } } } if (facing_side == Left) { if (done->Prev != Path->Sentinel) { // going up if (done->Z > done->Prev->Z) { if (done->Y < done->Prev->Y){ N->path.node.y += permanent->block_size.y; } else if (done->Y > done->Prev->Y){ N->path.node.y -= permanent->block_size.y; } } } if (done->Next != Path->Sentinel) { // going down if (done->Z < done->Next->Z) { if (done->Y < done->Next->Y){ N->path.node.y -= permanent->block_size.y; } else if (done->Y > done->Next->Y){ N->path.node.y += permanent->block_size.y; } } } } if (facing_side == Right) { if (done->Prev != Path->Sentinel) { // going up if (done->Z > done->Prev->Z) { if (done->Y < done->Prev->Y){ N->path.node.y += permanent->block_size.y; } else if (done->Y > done->Prev->Y){ N->path.node.y -= permanent->block_size.y; } } } if (done->Next != Path->Sentinel) { // going down if (done->Z < done->Next->Z) { if (done->Y < done->Next->Y){ N->path.node.y -= permanent->block_size.y; } else if (done->Y > done->Next->Y){ N->path.node.y += permanent->block_size.y; } } } } #endif DLIST_ADDFIRST(p, N); done = done->Prev; } } } END_PERFORMANCE_COUNTER(mass_pathfinding); //path_list * Path = ExpandPath(PathSmooth, &scratch->arena); BEGIN_PERFORMANCE_COUNTER(grid_cleaning); for (int i = 0; i < permanent->grid->width * permanent->grid->height * permanent->grid->depth;i++) { permanent->grid->nodes[i].f = 0; permanent->grid->nodes[i].g = 0; permanent->grid->nodes[i].opened = 0; permanent->grid->nodes[i].closed = 0; permanent->grid->nodes[i].Next = NULL; permanent->grid->nodes[i].parent = NULL; } END_PERFORMANCE_COUNTER(grid_cleaning); end_temporary_memory(temp_mem); } set_colored_line_batch_sizes(permanent, renderer); } #endif BEGIN_PERFORMANCE_COUNTER(actors_data_gathering); for (u32 i = 0; i < permanent->actor_count; i++) { permanent->actors[i]._location = getRotatedVec3( permanent->steer_data[i].location, facing_side, permanent->dims, permanent->block_size); permanent->actors[i]._palette_index = permanent->anim_data[i].palette_index; permanent->actors[i]._frame = permanent->anim_data[i].frame; permanent->actors[i].x_off = 0; permanent->actors[i].y_off = 0; if ( permanent->anim_data[i].frame == 4) { permanent->actors[i].complex = &generated_body_frames[BP_walking_west_body_000]; } else if (permanent->anim_data[i].frame == 5) { permanent->actors[i].complex = &generated_body_frames[BP_walking_west_body_001]; } else if (permanent->anim_data[i].frame == 6) { permanent->actors[i].complex = &generated_body_frames[BP_walking_south_body_000]; } else if (permanent->anim_data[i].frame == 7) { permanent->actors[i].complex = &generated_body_frames[BP_walking_south_body_001]; } else if (permanent->anim_data[i].frame == 8) { permanent->actors[i].complex = &generated_body_frames[BP_walking_east_body_000]; } else if (permanent->anim_data[i].frame == 9) { permanent->actors[i].complex = &generated_body_frames[BP_walking_east_body_001]; } else if (permanent->anim_data[i].frame == 10) { permanent->actors[i].complex = &generated_body_frames[BP_walking_north_body_000]; } else if (permanent->anim_data[i].frame == 11) { permanent->actors[i].complex = &generated_body_frames[BP_walking_north_body_001]; } /* if ( permanent->anim_data[i].frame % 2 == 0) { */ /* permanent->actors[i].complex = &generated_body_frames[BP_total_east_body_000]; */ /* } else { */ /* permanent->actors[i].complex = &generated_body_frames[BP_total_east_body_001]; */ /* } */ } for (u32 i = permanent->actor_count; i < permanent->actor_count*2; i++) { u32 j = i - permanent->actor_count; permanent->actors[i]._location = getRotatedVec3( permanent->steer_data[j].location, facing_side, permanent->dims, permanent->block_size); permanent->actors[i]._palette_index = (1.0f / 16.0f) * (j % 16);//permanent->anim_data[j].palette_index; permanent->actors[i]._frame = permanent->anim_data[j].frame; int deltaX = permanent->actors[j].complex->anchorX - permanent->actors[j].complex->pivotX; int deltaY = permanent->actors[j].complex->anchorY - permanent->actors[j].complex->pivotY; permanent->actors[i].x_off = deltaX; permanent->actors[i].y_off = -1 * deltaY; if ( permanent->anim_data[j].frame == 4) { permanent->actors[i].complex = &generated_body_frames[BP_facing_west_head_000]; } else if (permanent->anim_data[j].frame == 5) { permanent->actors[i].complex = &generated_body_frames[BP_facing_west_head_000]; } else if (permanent->anim_data[j].frame == 6) { permanent->actors[i].complex = &generated_body_frames[BP_facing_south_head_000]; } else if (permanent->anim_data[j].frame == 7) { permanent->actors[i].complex = &generated_body_frames[BP_facing_south_head_000]; } else if (permanent->anim_data[j].frame == 8) { permanent->actors[i].complex = &generated_body_frames[BP_facing_east_head_000]; } else if (permanent->anim_data[j].frame == 9) { permanent->actors[i].complex = &generated_body_frames[BP_facing_east_head_000]; } else if (permanent->anim_data[j].frame == 10) { permanent->actors[i].complex = &generated_body_frames[BP_facing_north_head_000]; } else if (permanent->anim_data[j].frame == 11) { permanent->actors[i].complex = &generated_body_frames[BP_facing_north_head_000]; } } END_PERFORMANCE_COUNTER(actors_data_gathering); BEGIN_PERFORMANCE_COUNTER(actors_sort); Actor_quick_sort(permanent->actors, permanent->actor_count*2); END_PERFORMANCE_COUNTER(actors_sort); }
int infogb_init(char *display) { initialize_memory(); initialize_rom(); return 1; }
IOFSTest() { // You can do set-up work for each test here. initialize_memory(); initialize_io(); }
// Construct an in-memory cache block cache_block::cache_block(cache_id_type cache_id, size_t max_capacity, fixed_size_cache_manager* owning_cache_manager) : cache_id(cache_id), owning_cache_manager(owning_cache_manager) { initialize_memory(max_capacity); }
/*Algoritmo Principal*/ int main(int argc, char *argv[]) { char name[20];// = "_kita_1"; char archiveName[20] = "archive"; char fitputName[20] = "fitput"; char varputName[20] = "varput"; char hvName[20]= "hv"; unsigned int i, j, t; unsigned int fun, gen; clock_t startTime, endTime; double duration, clocktime; FILE *fitfile,*varfile; /*Parametros iniciales*/ strcpy(name,argv[1]); fun = atoi(argv[2]); gen = atoi(argv[3]); printf("%s %d %d \n",name,fun,gen); initialize_data(fun,gen); /*Iniciar variables*/ initialize_memory(); /* sprintf(name,"kita_1_"); sprintf(archiveName,strcat(name,"archive.out")); sprintf(fitputName, strcat(name,"fitput.out")); sprintf(varputName, strcat(name,"varput.out")); sprintf(hvName,strcat(name,"hv.out")); */ //fitfile = fopen(strcat(strcat(fitputName,name),".out"),"w"); //varfile = fopen(strcat(strcat(varputName,name),".out"),"w"); //hv = fopen(strcat(strcat(hvName,name),".out"),"w"); /* Iniciar generador de aleatorios*/ initialize_rand(); startTime = clock(); /* Iniciar contador de generaciones*/ t = 0; /* Iniciar valores de la poblacion de manera aleatoria*/ initialize_pop(); /* Calcular velocidad inicial*/ initialize_vel(); /* Evaluar las particulas de la poblacion*/ evaluate(); /* Almacenar el pBest inicial (variables and valor de aptitud) de las particulas*/ store_pbests(); /* Insertar las particulas no domindas de la poblacion en el archivo*/ insert_nondom(); //printf("\n%d",nondomCtr); /*Ciclo Principal*/ while(t <= maxgen) { //clocktime = (clock() - startTime)/(double)CLOCKS_PER_SEC; /*if(verbose > 0 && t%printevery==0 || t == maxgen) { fprintf(stdout,"Generation %d Time: %.2f sec\n",t,clocktime); fflush(stdout); }*/ /*if(t%printevery==0 || t == maxgen) { fprintf(outfile,"Generation %d Time: %.2f sec\n",t,clocktime); }*/ /* Calcular la nueva velocidad de cada particula en la pooblacion*/ //printf("\n 1"); compute_velocity(); /* Calcular la nueva posicion de cada particula en la poblacion*/ //printf("\n 2"); compute_position(); /* Mantener las particulas en la poblacion de la poblacion en el espacio de busqueda*/ //printf("\n 3"); maintain_particles(); /* Pertubar las particulas en la poblacion*/ if(t < maxgen * pMut) mutate(t); /* Evaluar las particulas en la poblacion*/ //printf("\n 4"); evaluate(); /* Insertar nuevas particulas no domindas en el archivo*/ //printf("\n 5"); update_archive(); /* Actualizar el pBest de las particulas en la poblacion*/ //printf("\n 6"); update_pbests(); /* Escribir resultados del mejor hasta ahora*/ //verbose > 0 && t%printevery==0 || t == maxgen /*if(t%printevery==0 || t == maxgen) { //fprintf(outfile, "Size of Pareto Set: %d\n", nondomCtr); fprintf(fitfile, "%d\n",t); fprintf(varfile, "%d\n",t); for(i = 0; i < nondomCtr; i++) { for(j = 0; j < maxfun; j++) fprintf(fitfile, "%f ", archiveFit[i][j]); fprintf(fitfile, "\n"); } fprintf(fitfile, "\n\n"); fflush(fitfile); for(i = 0; i < nondomCtr; i++) { for(j = 0; j < maxfun; j++) fprintf(varfile, "%f ", archiveVar[i][j]); fprintf(varfile, "\n"); } fprintf(varfile, "\n\n"); fflush(varfile); }*/ /* Incrementar contador de generaciones*/ t++; //printf("%d\n",t); } /* Escribir resultados en el archivo */ save_results(strcat(strcat(archiveName,name),".out")); endTime = clock(); duration = ( endTime - startTime ) / (double)CLOCKS_PER_SEC; fprintf(stdout, "%lf sec\n", duration); //fclose(fitfile); //fclose(varfile); free_memory(); return EXIT_SUCCESS; }
int main(void) { srand(time(NULL)); /* * Creates a stream and checks to see if the Processes.txt file exists. * If it doesn't, the program returns an error and will exit. */ ifstream inputProcesses; inputProcesses.open("Processes.txt"); while(!inputProcesses.is_open()) { cout << "ERROR: file Process.txt can not be opened. Please check that Process.txt is in the correct folder." << endl; exit(0); } //Checks the Processes.txt file for any errors in formatting check_file(inputProcesses); initialize_console(); /* * Initially read in inputs and build processes * Run long term scheduler to put a few processes into NEW * Allocate memory for processes in NEW to put into READY * Run short term scheduler to bring a process from READY->RUNNING * Loop time cycles and process interrupts */ initialize_memory(); /* * Initial process arrival, the OS always starts with something running? * This potentially simplifies the main loop and makes the fetch-execute-interrupt * logic more apparent. */ new_process_arrival(retrieve_next_process(inputProcesses)); /* Fetch-execute-interrupt begins * Wait 0.1 seconds to simulate the cycle * Process in RUN executes for a 0.1 cycle * Check for interrupts or preemption * If process is EXIT then run short term scheduler */ /* * The main do while loop for the program, which exits when the user inputs * 'exit' as a string to end the program. The string input is the main string * for processing user input, and cycle_count is a counter for how many cycles * have been looped. */ string input = ""; int cycle_count = 0; /* * Do we want to initially run to completion? * NOTE: This position will change, we will want to * allow the user to change this at ANY POINT. */ /* cout << "Run OS to completion? (y or n):\n"; getline(cin, input); // Temporary Logic and Display, CHANGE LATER if (input == "y") run_to_completion = true; else if (input == "n") run_to_completion = false; else cout << "Wrong input: run_to_completion is false"; // User echo initially to make sure we are reading input correctly. cout << "You entered: " << input << endl << endl; cout << "BEGINNING SIMULATION" << endl; */ do { /* * Check if any new processes have arrived first. * If no processes have arrived, only passes a NULL reference. */ new_process_arrival(retrieve_next_process(inputProcesses));; hold_on_state_change(); /* * Long term FCFS scheduler * Simulates process arrival. */ long_term_scheduler(); hold_on_state_change(); /* * Short term preemptive scheduler. * Implemented as Round Robin with a 10 cycle time slice. */ short_term_scheduler(); hold_on_state_change(); // Increase cycle count of the fetch-execute-interrupt cycle cycle_count++; // Run the current process in the RUNNING state execute_running_process(); // Check for any interrupts check_io_interrupt(); hold_on_state_change(); // Check active IO devices process_io_devices(); hold_on_state_change(); // Debugging print for the new and ready queues debug_print(); // User interaction cout << "Type 'exit' to exit the program:\n"; cout << "Press enter to advance one clock cycle (this is temporary):\n>"; if(run_to_completion != true){ getline(cin, input); } else if(new_queue.empty() && blocked_queue.empty() && running_process.check_state("NULL") && ready_queue.empty()){ // Also check if simulation is finished. If file is empty, and all queues are empty. //Sleep for 2000 milliseconds cout << "Simulation has finished" << endl; input = "exit"; } else{ Sleep(2000); } // User echo initially to make sure we are reading input correctly. cout << "You entered: " << input << endl << endl; clear_console(); } while (input != "exit"); cout << "System exiting\n"; // User must press a key to exit getline(cin, input); return 0; }
void GCoptimization::commonInitialization() { m_needToFreeV = 0; m_random_label_order = 1; initialize_memory(); }