private List <RealTimeRequest> FindRealtimeRequests(int currentTime) { List <RealTimeRequest> result = new List <RealTimeRequest>(); List <RealTimeRequest> missed = new List <RealTimeRequest>(); foreach (Request req in allRequests) { if (req.GetType() == typeof(RealTimeRequest) && req.CheckRequestState() == Request.requestState.QUEUED) { RealTimeRequest temp = (RealTimeRequest)req; if (temp.GetTimeToDeadline(currentTime) >= 0) { result.Add((RealTimeRequest)req); } else { missed.Add((RealTimeRequest)req); } } } foreach (RealTimeRequest req in missed) { missedDeadline++; allRequests.Remove(req); allRequests.Add(req.ToRequest()); } return(result); }
private List <RealTimeRequest> FindRequestsThatCanBeServed(List <RealTimeRequest> requests, int currentTime) { List <RealTimeRequest> realTimeRequestsThatCanBeServed = new List <RealTimeRequest>(); foreach (RealTimeRequest req in requests) { if (req.CheckRequestState() == Request.requestState.QUEUED) { if (drive.CalculateDistanceFromPoint(req.GetPosition()) < req.GetTimeToDeadline(currentTime)) { realTimeRequestsThatCanBeServed.Add(req); } } } if (realTimeRequestsThatCanBeServed.Count != 0) { int lowestIndex = requests.Count(); RealTimeRequest shortestDeadlineRequest = realTimeRequestsThatCanBeServed.First(); foreach (RealTimeRequest req in realTimeRequestsThatCanBeServed) //dumbest sorting EVUR xDDDD { if (allRequests.IndexOf(req) < lowestIndex) { lowestIndex = allRequests.IndexOf(req); shortestDeadlineRequest = req; } } realTimeRequestsThatCanBeServed.Remove(shortestDeadlineRequest); realTimeRequestsThatCanBeServed.Insert(0, shortestDeadlineRequest); } return(realTimeRequestsThatCanBeServed); }
public void WriteFile(List <Request> requests, String filename) { try { var writer = new StreamWriter(File.OpenWrite(ValidateFilename(filename))); foreach (Request req in requests) { if (req.GetType() == typeof(RealTimeRequest)) { RealTimeRequest temp = req as RealTimeRequest; String line = temp.GetPosition() + "," + temp.GetAppearTime() + "," + temp.GetDeadline(); writer.WriteLine(line); } else { writer.WriteLine(req.GetPosition() + "," + req.GetAppearTime()); } } writer.Close(); } catch (IOException) { } }
public RealTimeRequest FindShortestDeadlineRequest(int currentTime, List <RealTimeRequest> realTimeRequests) { if (FindRequestsThatCanBeServed(realTimeRequests, currentTime).Count() != 0) { RealTimeRequest shortestDeadlineRequest = FindRequestsThatCanBeServed(realTimeRequests, currentTime).First(); int shortest = Int32.MaxValue; foreach (RealTimeRequest req in realTimeRequests) { if ((req.GetTimeToDeadline(currentTime) < shortest) && (req.CheckRequestState() == Request.requestState.QUEUED)) { shortestDeadlineRequest = req; shortest = req.GetTimeToDeadline(currentTime); } } return(shortestDeadlineRequest); } else { return(null); } }
private bool CheckFDSCANDirection(List <RealTimeRequest> realTimeRequests, int currentTime, scanDirection currentDirection) { List <RealTimeRequest> realTimeRequestsThatCanBeServed = FindRequestsThatCanBeServed(realTimeRequests, currentTime); try { RealTimeRequest requestToBeServed = realTimeRequestsThatCanBeServed.First(); if (currentDirection == scanDirection.FORWARD) { if (requestToBeServed.GetPosition() > drive.GetPosition()) { return(false); } else { return(true); } } else if (currentDirection == scanDirection.BACKWARD) { if (requestToBeServed.GetPosition() > drive.GetPosition()) { return(true); } return(false); } else { return(false); } } catch (NullReferenceException exception) { return(false); } }