programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Round Robin Algorithm

Greenhorn
Posts: 12
Can somebody help me out?

I am trying to make a round robin algorithm in a JFrame, but I can't get the correct syntax and coding. Can you guys please help me out? Just the syntax please.

The image is posted here. Thanks for your help guys.

Piet Souris
Rancher
Posts: 1983
67
On this Wikipedia site:
http://en.wikipedia.org/wiki/Round-robin_tournament
you will find a complete algorithm description.

Doesn't look too complicated, and if you use a List, there is a
rotate method in the Collections class, that seems very suitable here.

What have you tried so far? Where do you get stuck?

Greenhorn
Posts: 12
I do not really know how to execute the codes sir.

My problem is that each every time a certain job process ends, I need to get their turn around time, each job. That's the main problem.

For example.

| A | B | C | A | C |
0---3--6---9--12-14

I need to get A = 12; B = 6; and C = 14;

and together with that I need to get the Total Turnaround Time.

Piet Souris
Rancher
Posts: 1983
67
I'm afraid you've lost me here.

What exactly is your problem? Is it the "Round Robin", i.e. how to determine a complete
schedule for some competition, or is it the retrieving of the "scores" of the teams?

I've had a look at the picture under the link you provided (reluctantly, you never know to what
sites you are getting sent), and there I see jobs A ... F, and something about CPU cycles
and Arrival Times.

"
For example.

| A | B | C | A | C |
0---3--6---9--12-14

I need to get A = 12; B = 6; and C = 14;

"

but I have no clue what you mean by this.

So, please be specific: what exactly is it that is going on here, and what exactly is the problem?

Maneesh Godbole
Bartender
Posts: 11445
18
Welcome to the Ranch.

Krad Despair wrote:I do not really know how to execute the codes sir.

What codes? You haven't posted any code.
We do not just hand out ready made solutions here at the Ranch.
Show us what you have tried. Tell us where you are stuck and we will help point you in the direction.

Greenhorn
Posts: 12
I'm sorry for not being clear.

By the way the first link I've posted is a safe link, it's a link to the screenshot of my JFrame.
I haven't posted the code since it is blank.

In my button action performed, I only have these codes.

After that I do not know how to implement the Round Robin process. I'm sorry for this kind of disturbance.

I need to get the Total turnaround time of the process.

and to clear out the thing I've posted about.

| A | B | C| etc.

Now I know how you call it.

I need to get the total CPU time of each job.

Does anyone know how to apply it?

Piet Souris
Rancher
Posts: 1983
67

the idea of a Round Robin schedule is as follows:

suppose we have four participants, 1, 2, 3, 4.
Now, we fix 1, and put the other 3 in a set.
We have thus: 1, {2, 3, 4}.

Now pair them, from left to right:

1-2 and 3-4.

For the next round, rotate the set, and it becomes {3, 4, 2}.
Pair these again, we get:

1-3 and 4-2.

Finally (with n participants we have n - 1 rounds), rotate again: 1, {4, 2, 3}
and so we get: 1-4 and 2-3.

So, keep the first participant apart, put the rest in an ArraList, say arr,
and for the rotation we have the method.

Collections.rotate(arr, 1)

This also works for six elements.

So in this way it is easy to find the pairings in your frame, just put the sequence in the left to right order to your participants labels.

Now, your picture mentions Arrival Times, so what you mean by "Total turnaround time" is unclear to me.

Maybe you need the maximum of the six "Arriaval Time" textfields?
In that case you need to take the value of the strings, like:

And take the max of all the doubles you get here.

Greetings,
Piet

Sresh Rangi
Ranch Hand
Posts: 54
5
Piet Souris wrote:On this Wikipedia site:
http://en.wikipedia.org/wiki/Round-robin_tournament
you will find a complete algorithm description.

Doesn't look too complicated, and if you use a List, there is a
rotate method in the Collections class, that seems very suitable here.

What have you tried so far? Where do you get stuck?

It sounds more like he's trying something like:
http://en.wikipedia.org/wiki/Round-robin_scheduling

Greenhorn
Posts: 12
He is right sir, I am talking about Round Robin Scheduling Algorithm.

Piet Souris
Rancher
Posts: 1983
67

Well, this website is about time slicing, probably the way operating systems apply such things.

I must confess I know nothing about the way a time slicing can be implemented. Nevertheless, apart from this ,
the idea seems rather simple.

Suppose that you have a supervisor object. It maintains a List of runnable tasks.
its List.

Furthermore, it has a variable "currentTask", that points to one of the task in the List and it starts this task,
while starting a timer. When the timer fires, the supervisor adds the time passed to the time that this currentTask has spent so far.
Then the supervisor appoints the next item in the List as the currentTask, and starts it (or continues it).
And so on. When the currentTask was the last one of the List, the supervisor simply goes on with the first task of the List.

removed from the List, et cetera.

In this way, there's this Round Robin working. Scheduling is thus very easy, and the TotalTurnaroundTime is also known.

This has nothing to do with the scheduling of, say, a chess tournament according to a Round Robin scheduling.

As said, I have no idea how to implement such a thing in Java, unless the RunnableTasks were of a special kind,
say Threads that would cooperate in running a given time, then go to sleep, to be woken up by the supervisor.

Anyway, if you must implement such a thing, true time slicing, and listing the tasks at hand like the TaskManager
in Windows, I hope someone else with knowledge in this area will jump in.

The example you gave (A | B | C | et cetera): if you have a list in this form, I would suggest you create a