示例#1
0
/**
 * ouput_algorith_result
 *
 * Esta función llama a los 3 algoritmos sobre un
 * PLANNER_INPUT e imprime el resultado en un buffer
 * de datos, que bien puede ser 'stdout' o un fichero
 */
void output_algorithm_result(PLANNER_INPUT* data_input, FILE* target)
{
	PLANNER_RESULT rtemp;

	fprintf(target, INFO_RESULT);
	fprintf(target, INFO_RESULT_SEPARATOR);
		fprintf(target, INFO_RESULT_FCFS);
	fprintf(target, INFO_RESULT_SEPARATOR);

	// fcfs
	rtemp = fcfs_algorithm(*data_input);

	print_planner_result(rtemp, target);

	fprintf(target, INFO_RESULT_SEPARATOR);
		fprintf(target, INFO_RESULT_SRT);
	fprintf(target, INFO_RESULT_SEPARATOR);

	// srt
	rtemp = srt_algorithm(*data_input);

	print_planner_result(rtemp, target);

	fprintf(target, INFO_RESULT_SEPARATOR);
		fprintf(target, INFO_RESULT_RR, data_input->quant);
	fprintf(target, INFO_RESULT_SEPARATOR);

	// rr
	rtemp = round_robin_algorithm(*data_input);

	print_planner_result(rtemp, target);
}
示例#2
0
// unit test
void test_srt()
{
	PLANNER_INPUT test;

	test.times[0].t_llegada = 0;
	test.times[0].t_servicio = 5;

	test.times[1].t_llegada = 1;
	test.times[1].t_servicio = 3;

	test.times[2].t_llegada = 2;
	test.times[2].t_servicio = 4;

	test.times[3].t_llegada = 3;
	test.times[3].t_servicio = 2;

	test.num = 4;

	PLANNER_RESULT test2 = srt_algorithm(test);

	print_planner_result(test2, stdout);
}
示例#3
0
文件: main.cpp 项目: thornb/pj3
//----------------------------------------------------------------------------------------------------------------------
void run_algorithm(std::string cpu_algo, std::string  mem_algo, std::vector<Process>  all_vec,
                   std::ofstream & output_file) {
    const int temp_t_cs = t_cs;
    int temp_t = t;

    if (cpu_algo == "SRT") {

        SRT srt_algorithm(mem_algo, memory_space_size);
        srt_algorithm.calc_totalBurstTime(all_vec);

        srt_algorithm.runSRTsim(all_vec, temp_t, temp_t_cs, n);

        output_file << "SRT Algorithm with " << mem_algo << " Algorithm \n";
        output_file << "-- average CPU burst time: " << std::setprecision(5) << srt_algorithm.avgCpuBurst << " ms \n";
        output_file << "-- average wait time: " << srt_algorithm.avgWaitTime << " ms \n";
        output_file << "-- average turnaround time: " << srt_algorithm.avgTurnTime << " ms \n";
        output_file << "-- total number of context switches: " << srt_algorithm.numSwitches << "\n\n\n";
    }

    else if (cpu_algo == "RR") {

        RR rr_algorithm(mem_algo, memory_space_size);
        rr_algorithm.calc_totalBurstTime(all_vec);

        rr_algorithm.runRRsim(all_vec, temp_t, temp_t_cs, n, t_slice);

        output_file << "RR Algorithm with " << mem_algo << " Algorithm \n";
        output_file << "-- average CPU burst time: " << std::setprecision(5) << rr_algorithm.avgCpuBurst << " ms \n";
        output_file << "-- average wait time: " << rr_algorithm.avgWaitTime << " ms \n";
        output_file << "-- average turnaround time: " << rr_algorithm.avgTurnTime << " ms \n";
        output_file << "-- total number of context switches: " << rr_algorithm.numSwitches << "\n\n\n";

    }

    else {
        std::cout << "Incorrect algorithm name provided.\n";
    }
}