Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.79 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Collections;
  3.  
  4. public class Main{
  5.  
  6.  
  7. public static boolean isEveryProcessExecuted(ArrayList<Process> proc) {
  8. for(Process p : proc) {
  9. if(p.getBurstTime() != 0) return false;
  10. }
  11. return true;
  12. }
  13.  
  14. // Rounds the number
  15. public static double round(double number, int precision) {
  16. return (double) Math.round(number * Math.pow(10d, precision)) / Math.pow(10d, precision);
  17. }
  18.  
  19. public static void printTimes(ArrayList<Process> proc) {
  20. for(Process p : proc) {
  21. System.out.print(p.getBurstTime() + " ");
  22. }
  23. System.out.println();
  24. for(Process p : proc) {
  25. System.out.print(p.getWaitingTime() + " ");
  26. }
  27. System.out.println();
  28. }
  29.  
  30. public static void generateProcesses(ArrayList<Process> proc, ArrayList<Process> proc1, ArrayList<Process> proc2, ArrayList<Process> proc3)
  31. {
  32. for (int i=0; i<100; i++)
  33. {
  34. int random1 = (int)(Math.random() * 10 + 1);
  35. int random2 = (int)(Math.random() * 10);
  36. proc.add(new Process(random1,random2));
  37. proc1.add(new Process(random1,random2));
  38. proc2.add(new Process(random1,random2));
  39. proc3.add(new Process(random1,random2));
  40. }
  41. Collections.sort(proc);
  42. Collections.sort(proc1);
  43. Collections.sort(proc2);
  44. Collections.sort(proc3);
  45. }
  46.  
  47. public static void sort(ArrayList<Process> proc, int globalTime)
  48. {
  49. int n = proc.size();
  50. int k;
  51. for (int m = n; m >= 0; m--)
  52. {
  53. for (int i = 0; i < n - 1; i++)
  54. {
  55. k = i + 1;
  56. if (proc.get(i).getBurstTime() > proc.get(k).getBurstTime())
  57. {
  58. swap(i, k, proc);
  59. }
  60. }
  61. }
  62.  
  63. for(int i = proc.size()-1; i >= 0; i--)
  64. {
  65. if(proc.get(i).getArrivalTime() > globalTime && proc.get(i).getBurstTime() != 0)
  66. {
  67. Process tmp = proc.get(i);
  68. proc.remove(i);
  69. proc.add(tmp);
  70. }
  71. }
  72.  
  73. for(int i = proc.size()-1; i >= 0; i--)
  74. {
  75. if(proc.get(i).getBurstTime() == 0)
  76. {
  77. Process tmp = proc.get(i);
  78. proc.remove(i);
  79. proc.add(tmp);
  80. }
  81. }
  82. }
  83.  
  84. public static void swap(int index1, int index2, ArrayList<Process> proc)
  85. {
  86. Process tmp = proc.get(index1);
  87. proc.set(index1, proc.get(index2));
  88. proc.set(index2, tmp);
  89. }
  90.  
  91. // Algorithm FCFS
  92. public static void algFCFS(ArrayList<Process> proc)
  93. {
  94. int globalTime = 0; // timeline
  95. double waitingTimeSum = 0;
  96. int longestWaitingTime = 0;
  97. int current = 0; // index of process currently in execution
  98.  
  99.  
  100. //System.out.println("Global time | Remaining times | Waiting times"); // Debug
  101. //System.out.print(globalTime + " TU\t|\t"); // Debug
  102. //printTimes(proc); // Debug
  103.  
  104.  
  105. // Iterate through the queue until every process is fully executed
  106. while(!isEveryProcessExecuted(proc))
  107. {
  108. // Iterate through every process
  109. for(int i = 0; i < proc.size(); i++)
  110. {
  111. // Consider only processes that have already arrived
  112. if(globalTime >= proc.get(i).getArrivalTime())
  113. {
  114. // Check if the process is currently in execution
  115. if(i == current)
  116. {
  117. // Check if the process was waiting
  118. if(proc.get(i).getWaitingTime() != 0)
  119. {
  120. proc.get(i).setStarted(); // In FCFS algorithm the process will be fully executed after it starts, so there doesn't have to be any check if the process has been partly executed before
  121. waitingTimeSum += proc.get(i).getWaitingTime();
  122. longestWaitingTime = proc.get(i).getWaitingTime(); // Because it's FCFS algorithm, every process will have longer waiting time than the previous one (except for the first)
  123. proc.get(i).resetWaitingTime();
  124. }
  125. // Execute the process for 1 TU
  126. proc.get(i).execute(1);
  127. // If the process isn't currently in execution, then add 1 TU to its waiting time
  128. }
  129. else if(proc.get(i).getBurstTime() != 0)
  130. { // but only if it hasn't been fully executed yet
  131. proc.get(i).addToWaitingTime(1);
  132. }
  133. }
  134. }
  135.  
  136. // If the currently executed process has been fully executed in current time unit, next process in queue is set to execution
  137. if(proc.get(current).getBurstTime() == 0)
  138. {
  139. current++;
  140. }
  141.  
  142. // Move timeline by 1 TU
  143. globalTime++;
  144.  
  145.  
  146. //System.out.print(globalTime + " TU\t|\t"); // Debug
  147. //printTimes(proc); // Debug
  148.  
  149.  
  150. }
  151.  
  152. System.out.println("Algorithm FCFS");
  153. System.out.println("Total execution time: " + globalTime + " TU");
  154. System.out.println("Average waiting time: " + round(waitingTimeSum / proc.size(), 2) + " TU");
  155. System.out.println("Longest waiting time: " + longestWaitingTime + " TU");
  156. }
  157.  
  158. // Algorithm SJF (non-preemptive)
  159. // sortTime - amount of time units needed to sort the queue
  160. public static void algSJF(ArrayList<Process> proc, int sortTime) {
  161. int globalTime = 0; // timeline
  162. double waitingTimeSum = 0;
  163. int longestWaitingTime = 0;
  164. int current = 0; // index of process currently in execution
  165. int earliestArrivalTime = 0; // variable needed to check if the queue needs sorting
  166.  
  167.  
  168. //System.out.println("Global time | Remaining times | Waiting times"); // Debug
  169. //System.out.print(globalTime + " TU\t|\t"); // Debug
  170. //printTimes(proc); // Debug
  171.  
  172.  
  173. // Initial sorting of processes
  174. sort(proc, globalTime);
  175. // Adding sortTime to waitingTime of every non-executed process
  176. for(Process p : proc) {
  177. if(p.getBurstTime() != 0 && p.getArrivalTime() <= globalTime) {
  178. p.addToWaitingTime(sortTime);
  179. }
  180. }
  181. // Moving timeline by sortTime
  182. globalTime += sortTime;
  183.  
  184.  
  185. //System.out.println("Sorting..."); // Debug
  186. //System.out.print(globalTime + " TU\t|\t"); // Debug
  187. //printTimes(proc); // Debug
  188.  
  189.  
  190. // Iterate through the queue until every process is fully executed
  191. while(!isEveryProcessExecuted(proc))
  192. {
  193. // Iterate through every process
  194. for(int i = 0; i < proc.size(); i++)
  195. {
  196. // Consider only processes that have already arrived
  197. if(globalTime >= proc.get(i).getArrivalTime())
  198. {
  199. // Check if the process is currently in execution
  200. if(i == current)
  201. {
  202. // Check if the process was waiting
  203. if(proc.get(i).getWaitingTime() != 0)
  204. {
  205. proc.get(i).setStarted(); // In non-preemptive SJF algorithm the process will be fully executed after it starts, so there doesn't have to be any check if the process has been partly executed before
  206. waitingTimeSum += proc.get(i).getWaitingTime();
  207. // Check if process's waiting time was the longest
  208. if(proc.get(i).getWaitingTime() > longestWaitingTime)
  209. {
  210. longestWaitingTime = proc.get(i).getWaitingTime();
  211. }
  212. proc.get(i).resetWaitingTime();
  213. }
  214. // Execute the process for 1 TU
  215. proc.get(i).execute(1);
  216. // If the process isn't currently in execution, then add 1 TU to its waiting time
  217. }
  218. else if(proc.get(i).getBurstTime() != 0)
  219. { // but only if it hasn't been fully executed yet
  220. proc.get(i).addToWaitingTime(1);
  221. }
  222. }
  223. }
  224.  
  225. // Moving timeline by 1 TU
  226. globalTime++;
  227.  
  228.  
  229. //System.out.print(globalTime + " TU\t|\t"); // Debug
  230. //printTimes(proc); // Debug
  231.  
  232.  
  233. // If the currently executed process has been fully executed in current time unit, determine next process to be set to execution
  234. if(proc.get(current).getBurstTime() == 0)
  235. {
  236. boolean sorted = false; // variable needed for later
  237. // Iterate through every process
  238. for(Process p : proc)
  239. {
  240. // Check if 1. process has already arrived, 2. process isn't fully executed, 3. the youngest process is older than the process currently being iterated through
  241. if(p.getArrivalTime() <= globalTime && p.getBurstTime() != 0 && p.getArrivalTime() > earliestArrivalTime)
  242. {
  243. // If such a process has been found, the queue needs to be sorted
  244. sort(proc, globalTime);
  245. // Adding sortTime to waitingTime of every non-executed process
  246. for(Process r : proc)
  247. {
  248. if(r.getBurstTime() != 0 && r.getArrivalTime() <= globalTime)
  249. {
  250. r.addToWaitingTime(sortTime);
  251. }
  252. }
  253. // Moving timeline by sortTime
  254. globalTime += sortTime;
  255. earliestArrivalTime = globalTime;
  256. current = 0; // Because the queue is sorted by remaining time ascending, next process to execute is the first one in the queue
  257. sorted = true;
  258.  
  259.  
  260. //System.out.println("Sorting..."); // Debug
  261. //System.out.print(globalTime + " TU\t|\t"); // Debug
  262. //printTimes(proc); // Debug
  263.  
  264.  
  265. // Since the queue has been sorted, there is no need to iterate through rest of the queue
  266. break;
  267. }
  268. }
  269. // If no new processes arrived, move to the next process in queue
  270. if(!sorted)
  271. {
  272. current++;
  273. }
  274. }
  275.  
  276. }
  277.  
  278. System.out.println("Algorithm SJF (non-preemptive)");
  279. System.out.println("Total execution time: " + globalTime + " TU");
  280. System.out.println("Average waiting time: " + round(waitingTimeSum / proc.size(), 2) + " TU");
  281. System.out.println("Longest waiting time: " + longestWaitingTime + " TU");
  282. }
  283.  
  284. // Algorithm SJF (preemptive)
  285. // sortTime - amount of time units needed to sort the queue
  286. public static void algPSJF(ArrayList<Process> proc, int sortTime) {
  287. int globalTime = 0; // timeline
  288. double waitingTimeSum = 0; // sum of every waiting time in the queue
  289. int longestWaitingTime = 0; // longest waiting time in general
  290. int executeStarts = 0; // variable counting the amount of changes of process executing
  291. int current = 0; // index of process currently in execution
  292. int earliestArrivalTime = 0; // variable needed to check if the queue needs sorting
  293.  
  294.  
  295. //System.out.println("Global time | Remaining times | Waiting times"); // Debug
  296. //System.out.print(globalTime + " TU\t|\t"); // Debug
  297. //printTimes(proc); // Debug
  298.  
  299.  
  300. // Initial sorting of processes
  301. sort(proc, globalTime);
  302. // Adding sortTime to waitingTime of every non-executed process
  303. for(Process p : proc) {
  304. if(p.getBurstTime() != 0 && p.getArrivalTime() <= globalTime) {
  305. p.addToWaitingTime(sortTime);
  306. }
  307. }
  308. // Moving timeline by sortTime
  309. globalTime += sortTime;
  310.  
  311.  
  312. //System.out.println("Sorting..."); // Debug
  313. //System.out.print(globalTime + " TU\t|\t"); // Debug
  314. //printTimes(proc); // Debug
  315.  
  316.  
  317. // Iterate through the queue until every process is fully executed
  318. while(!isEveryProcessExecuted(proc))
  319. {
  320. // Iterate through every process
  321. for(int i = 0; i < proc.size(); i++)
  322. {
  323. // Consider only processes that have already arrived
  324. if(globalTime >= proc.get(i).getArrivalTime())
  325. {
  326. // Check if the process is currently in execution
  327. if(i == current)
  328. {
  329. // Check if the process was waiting
  330. if(proc.get(i).getWaitingTime() != 0)
  331. {
  332. // Check if the process will start being executed in general
  333. if(!proc.get(i).wasStarted())
  334. {
  335. proc.get(i).setStarted();
  336. // Check if process's waiting-for-start time was the longest
  337. }
  338. waitingTimeSum += proc.get(i).getWaitingTime();
  339. // Check if process's waiting time was the longest
  340. if(proc.get(i).getWaitingTime() > longestWaitingTime)
  341. {
  342. longestWaitingTime = proc.get(i).getWaitingTime();
  343. }
  344. proc.get(i).resetWaitingTime();
  345. executeStarts++;
  346. }
  347. // Execute the process for 1 TU
  348. proc.get(i).execute(1);
  349. // If the process isn't currently in execution, then add 1 TU to its waiting time
  350. }
  351. else if(proc.get(i).getBurstTime() != 0)
  352. { // but only if it hasn't been fully executed yet
  353. proc.get(i).addToWaitingTime(1);
  354. }
  355. }
  356. }
  357.  
  358. // Moving timeline by 1 TU
  359. globalTime++;
  360.  
  361.  
  362. //System.out.print(globalTime + " TU\t|\t"); // Debug
  363. //printTimes(proc); // Debug
  364.  
  365.  
  366. // In preemptive SJF, the queue has to be checked if it needs sorting in every time unit
  367. boolean sorted = false; // variable needed for later
  368. // Iterate through every process
  369. for(Process p : proc)
  370. {
  371. // Check if 1. process has already arrived, 2. process isn't fully executed, 3. the youngest process is older than the process currently being iterated through
  372. if(p.getArrivalTime() <= globalTime && p.getBurstTime() != 0 && p.getArrivalTime() > earliestArrivalTime)
  373. {
  374. // If such a process has been found, the queue needs to be sorted
  375. sort(proc, globalTime);
  376. // Adding sortTime to waitingTime of every non-executed process
  377. for(Process r : proc)
  378. {
  379. if(r.getBurstTime() != 0 && r.getArrivalTime() <= globalTime)
  380. {
  381. r.addToWaitingTime(sortTime);
  382. }
  383. }
  384. // Moving timeline by sortTime
  385. earliestArrivalTime = globalTime;
  386. current = 0; // Because the queue is sorted by remaining time ascending, next process to execute is the first one in the queue
  387. sorted = true;
  388.  
  389.  
  390. //System.out.println("Sorting..."); // Debug
  391. //System.out.print(globalTime + " TU\t|\t"); // Debug
  392. //printTimes(proc); // Debug
  393.  
  394.  
  395. // Since the queue has been sorted, there is no need to iterate through rest of the queue
  396. break;
  397. }
  398. }
  399. // If no new processes arrived and current process has been fully executed, move to the next process in queue
  400. if(!sorted && proc.get(current).getBurstTime() == 0)
  401. {
  402. current++;
  403. }
  404.  
  405. }
  406.  
  407. System.out.println("Algorithm SJF (preemptive)");
  408. System.out.println("Total execution time: " + globalTime + " TU");
  409. System.out.println("Average waiting time: " + round(waitingTimeSum / executeStarts, 2) + " TU");
  410. System.out.println("Longest waiting time: " + longestWaitingTime + " TU");
  411. }
  412.  
  413. // Algorithm ROT
  414. // quant - length of the quant of time, which is the amount of time given to every process for execution in every queue iteration
  415. public static void algROT(ArrayList<Process> proc, int quant) {
  416. int globalTime = 0; // timeline
  417. double waitingTimeSum = 0; // sum of every waiting time in the queue
  418. int longestWaitingTime = 0; // longest waiting time in general
  419. int executeStarts = 0; // variable counting the amount of changes of process executing
  420. int current = 0; // index of process currently in execution
  421. int timeToAdd = 0; // variable stating how much time passed executing current process, since remaining time of the process can be less than the quant of time
  422.  
  423.  
  424. //System.out.println("Global time | Remaining times | Waiting times"); // Debug
  425. //System.out.print(globalTime + " TU\t|\t"); // Debug
  426. // printTimes(proc); // Debug
  427.  
  428.  
  429. // Iterate through the queue until every process is fully executed
  430. while(!isEveryProcessExecuted(proc)) {
  431. // Iterate through every process
  432. for(int i = 0; i < proc.size(); i++) {
  433. // Consider only processes that have already arrived
  434. if(globalTime >= proc.get(i).getArrivalTime()) {
  435. // Check if the process is currently in execution
  436. if(i == current) {
  437. // Check if the process was waiting
  438. if(proc.get(i).getWaitingTime() != 0) {
  439. // Check if the process will start being executed in general
  440. if(!proc.get(i).wasStarted()) {
  441. proc.get(i).setStarted();
  442. }
  443. waitingTimeSum += proc.get(i).getWaitingTime();
  444. // Check if process's waiting time was the longest
  445. if(proc.get(i).getWaitingTime() > longestWaitingTime) {
  446. longestWaitingTime = proc.get(i).getWaitingTime();
  447. }
  448. proc.get(i).resetWaitingTime();
  449. executeStarts++;
  450. }
  451. // Execute the process for the quant of time
  452. timeToAdd = proc.get(i).execute(quant); // Since execute() method returns time of process execution, its value is assigned to variable timeToAdd
  453. // Since the process executed may not be first in the queue,
  454. // and time of process execution has to be known in advance before adding it to waitingTime of every process,
  455. // a separate for loop will iterate through every process to modify waitingTimes.
  456. // Therefore, current loop has to be broken
  457. break;
  458. }
  459. }
  460. }
  461.  
  462. // Check if current process has been executed for at least 1 TU
  463. if(timeToAdd != 0) {
  464. // Adding timeToAdd to waitingTime of every process, except for the one which was being executed
  465. for(int i = 0; i < proc.size(); i++) {
  466. // Consider only processes which aren't yet fully executed and have already arrived
  467. if(i != current && proc.get(i).getBurstTime() != 0 && proc.get(i).getArrivalTime() <= globalTime) {
  468. proc.get(i).addToWaitingTime(timeToAdd);
  469. }
  470. }
  471.  
  472. // Moving timeline by timeToAdd
  473. globalTime += timeToAdd;
  474. timeToAdd = 0;
  475. // If the process hasn't been executed, this means that no processes are currently in the queue,
  476. // therefore no waitingTimes will be increased, and instead timeline has to be moved by 1 TU
  477. } else {
  478. globalTime++;
  479. }
  480.  
  481.  
  482. //System.out.print(globalTime + " TU\t|\t"); // Debug
  483. //printTimes(proc); // Debug
  484.  
  485.  
  486. // If every process has been fully executed, finish the algorithm
  487. // (without this line, the while loop a few lines lower will be infinite when every process has been fully executed)
  488. if(isEveryProcessExecuted(proc)) break;
  489.  
  490. int tmp = current;
  491. // Move to the next process in the queue
  492. current++;
  493. // Check if index of current process isn't outside the queue
  494. if(current >= proc.size()) {
  495. // If it is, move to the beginning of the queue
  496. current = 0;
  497. }
  498. // This loop cycles through the queue to assure correctness of the algorithm
  499. while((proc.get(current).getBurstTime() == 0 || proc.get(current).getArrivalTime() > globalTime) && current != tmp) {
  500. current = (current + 1) % proc.size();
  501. }
  502. }
  503.  
  504. System.out.println("Algorithm ROT");
  505. System.out.println("Total execution time: " + globalTime + " TU");
  506. System.out.println("Average waiting time: " + round(waitingTimeSum / executeStarts, 2) + " TU");
  507. System.out.println("Longest waiting time: " + longestWaitingTime + " TU");
  508. }
  509.  
  510. public static void main(String[] args) {
  511.  
  512. ArrayList<Process> proc = new ArrayList<Process>();
  513. ArrayList<Process> proc1 = new ArrayList<Process>();
  514. ArrayList<Process> proc2 = new ArrayList<Process>();
  515. ArrayList<Process> proc3 = new ArrayList<Process>();
  516.  
  517. generateProcesses(proc, proc1, proc2, proc3);
  518.  
  519.  
  520. algFCFS(proc);
  521. System.out.println();
  522. algSJF(proc1,0);
  523. System.out.println();
  524. algPSJF(proc2,0);
  525. System.out.println();
  526. algROT(proc3,2);
  527.  
  528. /*
  529. ArrayList<Process> proc = new ArrayList<Process>();
  530. proc.add(new Process(4,0));
  531. proc.add(new Process(2,0));
  532. proc.add(new Process(11,0));
  533. proc.add(new Process(3,0));
  534. proc.add(new Process(8,0));
  535. proc.add(new Process(2,11));
  536. proc.add(new Process(5,11));
  537. proc.add(new Process(3,11));
  538. proc.add(new Process(15,27));
  539. proc.add(new Process(2,30));
  540. ArrayList<Process> proc1 = new ArrayList<Process>();
  541. proc1.add(new Process(4,0));
  542. proc1.add(new Process(2,0));
  543. proc1.add(new Process(11,0));
  544. proc1.add(new Process(3,0));
  545. proc1.add(new Process(8,0));
  546. proc1.add(new Process(2,11));
  547. proc1.add(new Process(5,11));
  548. proc1.add(new Process(3,11));
  549. proc1.add(new Process(15,27));
  550. proc1.add(new Process(2,30));
  551. ArrayList<Process> proc2 = new ArrayList<Process>();
  552. proc2.add(new Process(4,0));
  553. proc2.add(new Process(2,0));
  554. proc2.add(new Process(11,0));
  555. proc2.add(new Process(3,0));
  556. proc2.add(new Process(8,0));
  557. proc2.add(new Process(2,11));
  558. proc2.add(new Process(5,11));
  559. proc2.add(new Process(3,11));
  560. proc2.add(new Process(15,27));
  561. proc2.add(new Process(2,30));
  562. ArrayList<Process> proc3 = new ArrayList<Process>();
  563. proc3.add(new Process(4,0));
  564. proc3.add(new Process(2,0));
  565. proc3.add(new Process(11,0));
  566. proc3.add(new Process(3,0));
  567. proc3.add(new Process(8,0));
  568. proc3.add(new Process(2,11));
  569. proc3.add(new Process(5,11));
  570. proc3.add(new Process(3,11));
  571. proc3.add(new Process(15,27));
  572. proc3.add(new Process(2,30));
  573.  
  574.  
  575. printTimes(proc);
  576. algFCFS(proc);
  577. System.out.println();
  578. algSJF(proc1,0);
  579. System.out.println();
  580. algPSJF(proc2,0);
  581. System.out.println();
  582. algROT(proc3,2);
  583. */
  584.  
  585. /*
  586. System.out.println(proc.get(0).getArrivalTime());
  587. System.out.println(proc.get(1).getArrivalTime());
  588.  
  589. System.out.println(proc1.get(0).getArrivalTime());
  590. System.out.println(proc1.get(1).getArrivalTime());
  591. //System.out.println(proc.get(2).getArrivalTime());
  592. //System.out.println(proc.get(3).getArrivalTime());
  593. //System.out.println(proc.get(4).getArrivalTime());
  594. System.out.println(proc.get(0).getBurstTime());
  595. System.out.println(proc.get(1).getBurstTime());
  596.  
  597. System.out.println(proc1.get(0).getBurstTime());
  598. System.out.println(proc1.get(1).getBurstTime());
  599. //System.out.println(proc.get(2).getBurstTime());
  600. //System.out.println(proc.get(3).getBurstTime());
  601. //System.out.println(proc.get(4).getBurstTime());
  602. */
  603.  
  604. /* ArrayList<Process> proc1 = new ArrayList<Process>();
  605. proc1.add(new Process(5, 0));
  606. proc1.add(new Process(2, 0));
  607. proc1.add(new Process(7, 0));
  608. proc1.add(new Process(3, 0));
  609. proc1.add(new Process(10, 0));
  610. proc1.add(new Process(6, 11));
  611. proc1.add(new Process(5, 11));
  612. proc1.add(new Process(8, 11));
  613. proc1.add(new Process(4, 27));
  614. proc1.add(new Process(4, 27));
  615.  
  616. ArrayList<Process> proc2 = new ArrayList<Process>();
  617. proc2.add(new Process(6, 11));
  618. proc2.add(new Process(4, 27));
  619. proc2.add(new Process(5, 0));
  620. proc2.add(new Process(2, 0));
  621. proc2.add(new Process(7, 0));
  622. proc2.add(new Process(5, 11));
  623. proc2.add(new Process(3, 0));
  624. proc2.add(new Process(8, 11));
  625. proc2.add(new Process(10, 0));
  626. proc2.add(new Process(4, 27));
  627.  
  628. ArrayList<Process> proc3 = new ArrayList<Process>();
  629. proc3.add(new Process(6, 11));
  630. proc3.add(new Process(4, 27));
  631. proc3.add(new Process(5, 0));
  632. proc3.add(new Process(2, 0));
  633. proc3.add(new Process(7, 0));
  634. proc3.add(new Process(5, 11));
  635. proc3.add(new Process(3, 0));
  636. proc3.add(new Process(8, 11));
  637. proc3.add(new Process(10, 0));
  638. proc3.add(new Process(4, 27));
  639.  
  640. ArrayList<Process> proc4 = new ArrayList<Process>();
  641. proc4.add(new Process(5, 0));
  642. proc4.add(new Process(2, 0));
  643. proc4.add(new Process(7, 0));
  644. proc4.add(new Process(3, 0));
  645. proc4.add(new Process(10, 0));
  646. proc4.add(new Process(6, 11));
  647. proc4.add(new Process(5, 11));
  648. proc4.add(new Process(8, 11));
  649. proc4.add(new Process(4, 27));
  650. proc4.add(new Process(4, 27));
  651.  
  652.  
  653. algFCFS(proc1);
  654. System.out.println();
  655. algSJF(proc2, 0);
  656. System.out.println();
  657. algPSJF(proc3, 0);
  658. System.out.println();
  659. algROT(proc4, 2);
  660. */
  661. /*
  662. for (int i=0; i<proc.size(); i++)
  663. {
  664. System.out.println(proc.get(i).getArrivalTime());
  665. }
  666. System.out.println();
  667. for (int i=0; i<proc.size(); i++)
  668. {
  669. System.out.println(proc.get(i).getBurstTime());
  670. }
  671. System.out.println();
  672. for (int i=0; i<proc1.size(); i++)
  673. {
  674. System.out.println(proc1.get(i).getArrivalTime());
  675. System.out.println(proc1.get(i).getBurstTime());
  676. }
  677. System.out.println();
  678. for (int i=0; i<proc2.size(); i++)
  679. {
  680. System.out.println(proc2.get(i).getArrivalTime());
  681. System.out.println(proc2.get(i).getBurstTime());
  682. }
  683. System.out.println();
  684. for (int i=0; i<proc3.size(); i++)
  685. {
  686. System.out.println(proc3.get(i).getArrivalTime());
  687. System.out.println(proc3.get(i).getBurstTime());
  688. }
  689.  
  690. algFCFS(proc);
  691. System.out.println();
  692. algSJF(proc1,0);
  693. System.out.println();
  694. algPSJF(proc2,0);
  695. System.out.println();
  696. algROT(proc3,2);
  697. */
  698. /*
  699. ArrayList<Process> proc = new ArrayList<Process>();
  700. proc.add(new Process(9,8));
  701. proc.add(new Process(8,16));
  702. proc.add(new Process(10,11));
  703. proc.add(new Process(3,2));
  704. proc.add(new Process(7,11));
  705. ArrayList<Process> proc1 = new ArrayList<Process>();
  706. proc1.add(new Process(9,8));
  707. proc1.add(new Process(8,16));
  708. proc1.add(new Process(10,11));
  709. proc1.add(new Process(3,2));
  710. proc1.add(new Process(7,11));
  711. ArrayList<Process> proc2 = new ArrayList<Process>();
  712. proc2.add(new Process(9,8));
  713. proc2.add(new Process(8,16));
  714. proc2.add(new Process(10,11));
  715. proc2.add(new Process(3,2));
  716. proc2.add(new Process(7,11));
  717. ArrayList<Process> proc3 = new ArrayList<Process>();
  718. proc3.add(new Process(9,8));
  719. proc3.add(new Process(8,16));
  720. proc3.add(new Process(10,11));
  721. proc3.add(new Process(3,2));
  722. proc3.add(new Process(7,11));
  723.  
  724. algFCFS(proc);
  725. System.out.println();
  726. algSJF(proc1,0);
  727. System.out.println();
  728. algPSJF(proc2,0);
  729. System.out.println();
  730. algROT(proc3,2);
  731. */
  732. }
  733.  
  734. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement