| | |
Round-Robin Scheduling Algorithm
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2005
Posts: 2
Reputation:
Solved Threads: 0
Hi,
would someone please help me with the following:
I would like to implement the Round-Robin scheduling algorith for the below code. I am really facing a problem whenever i try to implement Round-Robin scheduling algorith in this code. Your prompt action and support is highly appreciated and I am certain that one of you would do his/her best to help me by sharing his great knowledge with others.
The given Hint by someone is, I need to change the Run() method in Scheduling Algorith.java
=================================================
would someone please help me with the following:
I would like to implement the Round-Robin scheduling algorith for the below code. I am really facing a problem whenever i try to implement Round-Robin scheduling algorith in this code. Your prompt action and support is highly appreciated and I am certain that one of you would do his/her best to help me by sharing his great knowledge with others.
The given Hint by someone is, I need to change the Run() method in Scheduling Algorith.java
Java Syntax (Toggle Plain Text)
// Run() is called from Scheduling.main() and is where // the scheduling algorithm written by the user resides. // User modification should occur within the Run() function. import java.util.Vector; import java.io.*; public class SchedulingAlgorithm { public static Results Run(int runtime, Vector processVector, Results result) { int i = 0; int comptime = 0; int currentProcess = 0; int previousProcess = 0; int size = processVector.size(); int completed = 0; String resultsFile = "Summary-Processes"; result.schedulingType = "Batch (Nonpreemptive)"; result.schedulingName = "First-Come First-Served"; try { //BufferedWriter out = new BufferedWriter(new FileWriter(resultsFile)); //OutputStream out = new FileOutputStream(resultsFile); PrintStream out = new PrintStream(new FileOutputStream(resultsFile)); sProcess process = (sProcess) processVector.elementAt(currentProcess); out.println("Process: " + currentProcess + " registered... (" + process.cputime + " " + process.ioblocking + " " + process.cpudone + " " + process.cpudone + ")"); while (comptime < runtime) { if (process.cpudone == process.cputime) { completed++; out.println("Process: " + currentProcess + " completed... (" + process.cputime + " " + process.ioblocking + " " + process.cpudone + " " + process.cpudone + ")"); if (completed == size) { result.compuTime = comptime; out.close(); return result; } for (i = size - 1; i >= 0; i--) { process = (sProcess) processVector.elementAt(i); if (process.cpudone < process.cputime) { currentProcess = i; } } process = (sProcess) processVector.elementAt(currentProcess); out.println("Process: " + currentProcess + " registered... (" + process.cputime + " " + process.ioblocking + " " + process.cpudone + " " + process.cpudone + ")"); } if (process.ioblocking == process.ionext) { out.println("Process: " + currentProcess + " I/O blocked... (" + process.cputime + " " + process.ioblocking + " " + process.cpudone + " " + process.cpudone + ")"); process.numblocked++; process.ionext = 0; previousProcess = currentProcess; for (i = size - 1; i >= 0; i--) { process = (sProcess) processVector.elementAt(i); if (process.cpudone < process.cputime && previousProcess != i) { currentProcess = i; } } process = (sProcess) processVector.elementAt(currentProcess); out.println("Process: " + currentProcess + " registered... (" + process.cputime + " " + process.ioblocking + " " + process.cpudone + " " + process.cpudone + ")"); } process.cpudone++; if (process.ioblocking > 0) { process.ionext++; } comptime++; } out.close(); } catch (IOException e) { /* Handle exceptions */ } result.compuTime = comptime; return result; } }
Java Syntax (Toggle Plain Text)
// This file contains the main() function for the Scheduling // simulation. Init() initializes most of the variables by // reading from a provided file. SchedulingAlgorithm.Run() is // called from main() to run the simulation. Summary-Results // is where the summary results are written, and Summary-Processes // is where the process scheduling summary is written. // Created by Alexander Reeder, 2001 January 06 import java.io.*; import java.util.*; import sProcess; import Common; import Results; import SchedulingAlgorithm; public class Scheduling { private static int processnum = 5; private static int meanDev = 1000; private static int standardDev = 100; private static int runtime = 1000; private static Vector processVector = new Vector(); private static Results result = new Results("null","null",0); private static String resultsFile = "Summary-Results"; private static void Init(String file) { File f = new File(file); String line; String tmp; int cputime = 0; int ioblocking = 0; double X = 0.0; try { //BufferedReader in = new BufferedReader(new FileReader(f)); DataInputStream in = new DataInputStream(new FileInputStream(f)); while ((line = in.readLine()) != null) { if (line.startsWith("numprocess")) { StringTokenizer st = new StringTokenizer(line); st.nextToken(); processnum = Common.s2i(st.nextToken()); } if (line.startsWith("meandev")) { StringTokenizer st = new StringTokenizer(line); st.nextToken(); meanDev = Common.s2i(st.nextToken()); } if (line.startsWith("standdev")) { StringTokenizer st = new StringTokenizer(line); st.nextToken(); standardDev = Common.s2i(st.nextToken()); } if (line.startsWith("process")) { StringTokenizer st = new StringTokenizer(line); st.nextToken(); ioblocking = Common.s2i(st.nextToken()); X = Common.R1(); while (X == -1.0) { X = Common.R1(); } X = X * standardDev; cputime = (int) X + meanDev; processVector.addElement(new sProcess(cputime, ioblocking, 0, 0, 0)); } if (line.startsWith("runtime")) { StringTokenizer st = new StringTokenizer(line); st.nextToken(); runtime = Common.s2i(st.nextToken()); } } in.close(); } catch (IOException e) { /* Handle exceptions */ } } private static void debug() { int i = 0; System.out.println("processnum " + processnum); System.out.println("meandevm " + meanDev); System.out.println("standdev " + standardDev); int size = processVector.size(); for (i = 0; i < size; i++) { sProcess process = (sProcess) processVector.elementAt(i); System.out.println("process " + i + " " + process.cputime + " " + process.ioblocking + " " + process.cpudone + " " + process.numblocked); } System.out.println("runtime " + runtime); } public static void main(String[] args) { int i = 0; if (args.length != 1) { System.out.println("Usage: 'java Scheduling <INIT FILE>'"); System.exit(-1); } File f = new File(args[0]); if (!(f.exists())) { System.out.println("Scheduling: error, file '" + f.getName() + "' does not exist."); System.exit(-1); } if (!(f.canRead())) { System.out.println("Scheduling: error, read of " + f.getName() + " failed."); System.exit(-1); } System.out.println("Working..."); Init(args[0]); if (processVector.size() < processnum) { i = 0; while (processVector.size() < processnum) { double X = Common.R1(); while (X == -1.0) { X = Common.R1(); } X = X * standardDev; int cputime = (int) X + meanDev; processVector.addElement(new sProcess(cputime,i*100,0,0,0)); i++; } } result = SchedulingAlgorithm.Run(runtime, processVector, result); try { //BufferedWriter out = new BufferedWriter(new FileWriter(resultsFile)); PrintStream out = new PrintStream(new FileOutputStream(resultsFile)); out.println("Scheduling Type: " + result.schedulingType); out.println("Scheduling Name: " + result.schedulingName); out.println("Simulation Run Time: " + result.compuTime); out.println("Mean: " + meanDev); out.println("Standard Deviation: " + standardDev); out.println("Process #\tCPU Time\tIO Blocking\tCPU Completed\tCPU Blocked"); for (i = 0; i < processVector.size(); i++) { sProcess process = (sProcess) processVector.elementAt(i); out.print(Integer.toString(i)); if (i < 100) { out.print("\t\t"); } else { out.print("\t"); } out.print(Integer.toString(process.cputime)); if (process.cputime < 100) { out.print(" (ms)\t\t"); } else { out.print(" (ms)\t"); } out.print(Integer.toString(process.ioblocking)); if (process.ioblocking < 100) { out.print(" (ms)\t\t"); } else { out.print(" (ms)\t"); } out.print(Integer.toString(process.cpudone)); if (process.cpudone < 100) { out.print(" (ms)\t\t"); } else { out.print(" (ms)\t"); } out.println(process.numblocked + " times"); } out.close(); } catch (IOException e) { /* Handle exceptions */ } System.out.println("Completed."); } }
Last edited by Ancient Dragon; May 10th, 2009 at 5:04 pm. Reason: add code tags
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 8
Hi everyone,
You can try and see the below example and see where you have gone wrong
http://www.utdallas.edu/~ilyen/anima...am/manual.html
I hoped this helped you
Yours Sincerely
Richard West
You can try and see the below example and see where you have gone wrong
http://www.utdallas.edu/~ilyen/anima...am/manual.html
I hoped this helped you
Yours Sincerely
Richard West
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
•
•
Join Date: May 2009
Posts: 4
Reputation:
Solved Threads: 0
Hi,
would someone please help me with the following quotions
(the required is to implement a simulator for processes scheduling that
takes a file contains N of processes each with required details,and then
after reading these information from the input file ,the scheduler should
schedule the processes for execution.
input:N processes ,each with ID,cpu required time ,arrival time .
(Quantum for "Round Robin"algorithm),(Priority for "High Priority first algorithm)
(firs come first served(FCFS);
Output:for each process,start time,finish time ,and waiting time ,and average waiting
time for all processes
note:
in c++(object oriented programming language.
(please help me)
would someone please help me with the following quotions
(the required is to implement a simulator for processes scheduling that
takes a file contains N of processes each with required details,and then
after reading these information from the input file ,the scheduler should
schedule the processes for execution.
input:N processes ,each with ID,cpu required time ,arrival time .
(Quantum for "Round Robin"algorithm),(Priority for "High Priority first algorithm)
(firs come first served(FCFS);
Output:for each process,start time,finish time ,and waiting time ,and average waiting
time for all processes
note:
in c++(object oriented programming language.
(please help me)
![]() |
Similar Threads
- round robin algorithm (Computer Science)
- Round-Robin Scheduling using threads, having some trouble (VB.NET)
- round robin scheduling (C)
- Need some help with Round Robin scheduling (Java)
- round robin scheduling (Java)
- round robin scheduling (C)
Other Threads in the Java Forum
- Previous Thread: Help please, thanks
- Next Thread: perfect numbers . . !
| Thread Tools | Search this Thread |
Tag cloud for Java
@param android api appinventor apple applet application arguments array arrays automation binary bluetooth bold c++ chat chatprogramusingobjects class classes client code codesnippet compare compiler component coordinates database doctype draw eclipse editor error event exception fractal freeze game givemetehcodez graphics gui guidancer health html ide image input int integer j2me java javac javaprojects jmf jni jpanel jtable julia linux list login loop map method methods mobile netbeans newbie nonstatic number oracle page pattern plazmic print problem program programming project recursion scanner screen sell server set sharepoint size sms socket sort sourcelabs sql string swing system test testautomation threads time tree windows





