Пример #1
0
int Program::exec()
{
	std::vector<unsigned int> positions;
	Random rand;

	for (unsigned long r = ReadsCount_; r > 0; r--)
		positions.push_back(rand.next(1, Config_.getInt("Head", "MaxPos", 1) - 1));
	DS_.add(positions);

	Disk fcfs(Config_.getInt("Head", "InitPos", 1));
	Disk sstf(Config_.getInt("Head", "InitPos", 1));
	Disk scan(Config_.getInt("Head", "InitPos", 1));
	CSCANDisk cscan(Config_.getInt("Head", "InitPos", 1), Config_.getInt("Head", "MaxPos", 1));

	std::cout << "FCFS \t\t SSTF \t\t SCAN \t\t CSCAN" << std::endl;
	do
	{
		fcfs.setNextPosition(DS_.popFCFS());
		sstf.setNextPosition(DS_.popSSTF());
		scan.setNextPosition(DS_.popSCAN());
		cscan.setNextPosition(DS_.popCSCAN());

		std::string str = "";
		str += fcfs.toString() + " \t ";
		str += sstf.toString() + " \t ";
		str += scan.toString() + " \t ";
		str += cscan.toString();
		std::cout << str << std::endl;
		Log_.out(str);
	}
	while (!DS_.done());
	std::cin.get();
	return 0;
}
Пример #2
0
void choice()
{
	clrscr();
	i=nor;
	movt=0;
	int ch;
	cout<<"1.FCFS\n2.SSTF\n3.SCAN\n4.LOOK\n5.CSCAN\n6.CLOOK\n7.Exit\nEnter Choice : ";
	cin>>ch;
	switch(ch)
	{
		case 1:fcfs();
			break;
		case 2:sstf();
			break;
		case 3:scan();
			break;
		case 4:look();
			break;
		case 5:cscan();
			break;
		case 6:clook();
			break;
		default:exit(1);
	}
}
Пример #3
0
int main()
{
    input();
    printf("%d\n\n\n",clook());
    printf("%d\n\n\n",cscan());
    printf("%d\n\n\n",fcfs());
    printf("%d\n\n\n",look());
    printf("%d\n\n\n",scan());
    printf("%d\n\n\n",sstf());
    return 0;
}
Пример #4
0
void main()
{
	printf("Enter The no. of tasks per cylinder :");
	scanf("%d",&task);
	printf("Enter the current head position: ");
	scanf("%d",&hand);
	for(i=0;i<task;i++)
	{
		printf("Enter the track no. %d: ",(i+1));
		scanf("%d",&track[i][0]);
	}
	//fcfs();
	cscan();
}
Пример #5
0
IO_PAIR mmu_NRU::locate_event()
{
	IO_PAIR temp;
	if(mmutype=='f')
	{
		temp=*readylist.begin();
		readylist.erase(readylist.begin());
		return temp;
	}
	else if(mmutype=='s')
	{
		vector<IO_PAIR>::iterator it=readylist.begin();
		for (it = readylist.begin() ; it != readylist.end(); ++it)
		{
			it->priority=abs(it->track_number-current_position);
		}
		sort(readylist.begin(),readylist.end(),my_priority);

		temp=*readylist.begin();
		readylist.erase(readylist.begin());
		return temp;
	}
	else if(mmutype=='S')
	{
		if(direction==true)
		{
			temp=up();
			return temp;
		}
		else
		{
			temp=down();
			return temp;
		}
	}
	else if(mmutype=='C')
	{
		temp=cscan();
		return temp;
	}
	else
	{
		printf("prameter error! Please check the parameter for -s option\n");
		exit(0);
	}

}
Пример #6
0
int setup_scheduler(const char* input_file, const char* scheduler, int sec_to_sec_seek, int end_to_end_seek){
	char** tokens = read_input(input_file);
	int len = array_len(tokens);
	access_data* data[len];
	char* tok;
	char* line;

	int i = 0;
	while (i < len){
		line = tokens[i];
		tok = strtok(line," ");

		int arrival_time = atoi((const char*)tok);
    	tok = strtok(NULL," ");
    	int sector = atoi((const char*)tok);

		access_data* a = malloc(sizeof(access_data));
		new_data(a, arrival_time, sector);
		data[i] = a;

		i++;
	}

	//show_data(data, len);

	if (strcmp(scheduler, "FCFS") == 0){
		fcfs(data, len, sec_to_sec_seek);
	}
	else if (strcmp(scheduler, "SSTN") == 0){
		sstn(data, len, sec_to_sec_seek);
	}
	else if (strcmp(scheduler, "SCAN") == 0){
		scan(data, len, sec_to_sec_seek);
	}
	else if (strcmp(scheduler, "CSCAN") == 0){
		cscan(data, len, sec_to_sec_seek);
	}
	else{
		fprintf(stderr, "%s\n","Invalid scheduling algorithm.");
		exit(EXIT_FAILURE);
	}

	free_access_data(data, len);
	free(tokens);

	return 0;
}
Пример #7
0
/*
**policy_handler select the corresponding function to handle the request sequence
**@ncylinder is the total number of cylinders
**@ipolicy is the index if policy
**@ifile is the file pointer to the input_file
**@result is a pointer to dynamic array for store execute sequence and their travel_num
**@travel is the total travel number
*/
void policy_handler(int ncylinder, int ipolicy, FILE *ifile, int **result, int *travel)
{
	int *list = NULL;
	init_sequence(ncylinder, ifile, &list);
	init_result(result);
	item *sorted = NULL;
	int first = list[0];

	//sort the request according to there distance to the head of disk
	if (ipolicy == 2 || ipolicy == 3 || ipolicy == 4)
		 sorted = sort(ncylinder, list);
	if (ipolicy == 1)
		*travel = fcfs(ncylinder, list, *result);
	else if (ipolicy == 2)
		*travel = sstf(first, sorted, *result);
	else if (ipolicy == 3)
		*travel = cscan(ncylinder, first, sorted, *result);
	else if (ipolicy == 4)
		*travel = look(ncylinder, first, sorted, *result);

}