필터 지우기
필터 지우기

FCFS code

조회 수: 11 (최근 30일)
Ayda
Ayda 2012년 4월 7일
답변: Sanjana 2024년 3월 5일
Good Morning\ Evening
I have number of processes and each process has its arrival time the question require to simulate processes using First Come First Serve.
I wrote this code for FCFS but did not return a correct values the result should display the order of FCFS
numOfJobs=input('Enter the number of jobs to run = ');
for i=1:numOfJobs
job(i)=i;
end
job1=job;
arrivalTime=input('Enter the arrival time of each job = ,[in vector form] ');
for i=1:numOfJobs-1
y=i+1;
for j=y:numOfJobs
if(arrivalTime(j)<arrivalTime(i))
firstcome=job(j);
job(j)=job(i);
job(i)=firstcome;
end
end
end
job;
out2=[out1 arrivalTime']
Also I have to figure out the starting time, the completion time and total waiting Time for each process

답변 (2개)

Walter Roberson
Walter Roberson 2012년 4월 7일
You can replace most of what you have written with
[sortedArrivalTimes, job] = sort(arrivalTime);
It is not possible to work out the starting and completion and waiting times without knowing how long each job takes. Other than that you can say that the starting time for the first job to arrive will be sortedArrivalTimes(1)
  댓글 수: 2
Ayda
Ayda 2012년 4월 7일
thank you very much
but if I want to use the for loop,, where is the mistake
Walter Roberson
Walter Roberson 2012년 4월 7일
Using bubble sort is a mistake more often than not...

댓글을 달려면 로그인하십시오.


Sanjana
Sanjana 2024년 3월 5일
numOfJobs=input('Enter the number of jobs to run = ');
for i=1:numOfJobs
job(i)=i;
end
job1=job;
arrivalTime=input('Enter the arrival time of each job = ,[in vector form] ');
for i=1:numOfJobs-1
y=i+1;
for j=y:numOfJobs
if(arrivalTime(j)<arrivalTime(i))
firstcome=job(j);
job(j)=job(i);
job(i)=firstcome;
end
end
end
job;
out2=[out1 arrivalTime']

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by