Created
November 7, 2017 16:23
-
-
Save VictorSouzas/5712870f213237cf47341e33b6434bd6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ProcessSchedule; | |
import DataStructure.Queue; | |
import Process.Process; | |
public class RobinRound { | |
public static void main(String[] args) { | |
int quantum = 2; | |
int count = 0; | |
Process executionProcess = null; | |
boolean flag = false; | |
Queue waitingQueue = Generate.process(Integer.parseInt(args[0])); | |
Queue processQueue = new Queue(); | |
int time = 0; | |
do { | |
if(executionProcess == null){ | |
executionProcess = (Process) processQueue.remove(); | |
} | |
if(count == quantum){ | |
Event.remove(executionProcess, quantum, time); | |
flag = true; | |
} | |
if(checkIO(executionProcess)){ | |
Event.remove(executionProcess, -1, time); | |
flag = true; | |
} | |
Queue income = Event.arrive(waitingQueue, time); | |
if(flag){ | |
processQueue.add(executionProcess); | |
executionProcess = null; | |
count = 0; | |
} | |
} while(!waitingQueue.isEmpty() && !processQueue.isEmpty()); | |
} | |
public static void integrate(Queue income, Queue processQueue, int time){ | |
for (Process i = (Process) income.remove(); income.getSize() >= 0;){ | |
i.getInput().add(time); | |
processQueue.add(i); | |
} | |
} | |
public static boolean checkIO(Process process){ | |
for (int i = 0; i <= process.getIO().length-1; i++) | |
if(process.getDuration() == process.getIO()[i]) | |
return true; | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment