Пример #1
0
int main(int argc, char *argv[]) {
    FILE *fp;
    int blocklist[MAX_JOBS];
    int number;
    int i = 0;
    if (argc == 2){
        fp = fopen(argv[1], "r");
    }
     else { 
         fp = stdin;
     }
    while( fscanf(fp, "%d", &number) > 0)
    {
      blocklist[i] = number;
      
        i++;
        
    }
    
    printf("Assignment 6: Block Access Algorithm");
    printf("\nBy: Nikki Talley, Chad Rasmussen and Josh Chevrier");
    printf("\n");
    fcfs(blocklist, i);
    sstf(blocklist, i);
    look(blocklist, i);
    cLook(blocklist, i);
     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 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;
}
Пример #4
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;
}
Пример #5
0
void Simulation::update_elevators()
{
	for (int i = 0; i < elevators.size(); i++)
	{
		Elevator curr = elevators[i];
		
		//this elevator has no requests and hasnt started
		if (!curr.requests.empty())
		{
			elevators[i].active = true;
			sstf(i);
		}
		else if (curr.currRequest.pickupFloor == -1 && curr.requests.empty())
		{
			elevators[i].active = false;
		}

		move_elevators(i);
	}
}
Пример #6
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);

}
Пример #7
0
void get_next(int *in,int size)
{
	int min ,max,temp;
	min = get_min();max = get_max();

	switch(mode)
	{
		case 0: if(findex == -1)
				findex+=1;
			else{
				head=in[findex];
				findex++;
			}
			break;	
		case 1: if(findex == -1);
			else
				sstf(in,size);
			findex++;
			break;
		case 2: if(findex == -1);
			else
				scan_look();
			findex++;
			break;
		case 3: if(findex == -1);
			else
				scan_look();
			findex++;
			break;
		case 4: if(findex == -1);
			else
				c_scan_c_look();
			findex++;
			break;
		case 5: if(findex == -1);
			else
				c_scan_c_look();
			findex++;
	}
}