473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

modify a Round Robin algorithm to a Best-Fit

kirara
19
Hi all,
I am trying to develop a mechanism to know which machine can handle a user job (by providing his Requirements) for now I wrote this method but it is a Round robin, I am trying to modify it to a best-fit algorithm can anybody give me tips about how should I begin?

Expand|Select|Wrap|Line Numbers
  1.   public static String canDo(Resources userReq,Hashtable hash){
  2.                 //getResourceInfo() is a method that store the machine name 
  3.                //and thier resources(cpu,memory,disk) in a hashtable
  4.         Hashtable resourceInfo = connectData.getResourcesInfo();
  5.         Enumeration en = resourceInfo.keys();
  6.         String status ="";
  7.         String machineName;
  8.         Resources machineRec;
  9.         while(en.hasMoreElements()) {
  10.                  machineName = (String)en.nextElement();
  11.                  status = "the following machine has been allocated to you: "+machineName;
  12.                  //resourc
  13.                  machineRec = (Resources)resourceInfo.get(machineName);
  14.                  if(machineRec.getCpu().getCpuIdle()>=userReq.getCpu().getCpuIdle())
  15.                  if(machineRec.getMemory().getFreeMemory()>=userReq.getMemory().getFreeMemory())
  16.                  if(machineRec.getDisk().getFreeSpace()>=userReq.getDisk().getFreeSpace()){
  17.                      break;
  18.  
  19.          }
  20.     }
  21.  
  22.         return status;
  23.     }
Dec 27 '06 #1
3 6525
r035198x
13,262 8TB
Hi all,
I am trying to develop a mechanism to know which machine can handle a user job (by providing his Requirements) for now I wrote this method but it is a Round robin, I am trying to modify it to a best-fit algorithm can anybody give me tips about how should I begin?

Expand|Select|Wrap|Line Numbers
  1.   public static String canDo(Resources userReq,Hashtable hash){
  2.                 //getResourceInfo() is a method that store the machine name 
  3.                //and thier resources(cpu,memory,disk) in a hashtable
  4.         Hashtable resourceInfo = connectData.getResourcesInfo();
  5.         Enumeration en = resourceInfo.keys();
  6.         String status ="";
  7.         String machineName;
  8.         Resources machineRec;
  9.         while(en.hasMoreElements()) {
  10.                  machineName = (String)en.nextElement();
  11.                  status = "the following machine has been allocated to you: "+machineName;
  12.                  //resourc
  13.                  machineRec = (Resources)resourceInfo.get(machineName);
  14.                  if(machineRec.getCpu().getCpuIdle()>=userReq.getCpu().getCpuIdle())
  15.                  if(machineRec.getMemory().getFreeMemory()>=userReq.getMemory().getFreeMemory())
  16.                  if(machineRec.getDisk().getFreeSpace()>=userReq.getDisk().getFreeSpace()){
  17.                      break;
  18.  
  19.          }
  20.     }
  21.  
  22.         return status;
  23.     }
Maybe if you can point me to a best-fit algorithm tutorial or better still to just give it here I think your problem should be quite easy to solve. Just from intuition though:

You are simply getting the next value from enumeration.
To get the best fit you would need to go through the values first, selecting the best fit and removing it from the collection. I would therefore suggest that you load the data items into an ArrayList first(for easier traversal) then you can apply the algorithm to the arraylist.
Dec 28 '06 #2
kirara
19
You are simply getting the next value from enumeration.
To get the best fit you would need to go through the values first, selecting the best fit and removing it from the collection...
that's exactly my question how to select the best fit and remove it from the collection(shorten the orginal list), can you please be more specific I don't need codes just how the algorithm can be implemented
thanks in advance

note: when you said point me to a tutorial you meant I should read a tutorial or I should give you one?? (I didn't understand) :)
Dec 28 '06 #3
r035198x
13,262 8TB
that's exactly my question how to select the best fit and remove it from the collection(shorten the orginal list), can you please be more specific I don't need codes just how the algorithm can be implemented
thanks in advance

note: when you said point me to a tutorial you meant I should read a tutorial or I should give you one?? (I didn't understand) :)
I meant me. I don't know the algorithm very well.


Your elements obviously have a property(eg, size, length ) that you are comparing with a value you want to fit the elements at. eg Say your list contains objects with memory values that are integers and you want to select the best fit say for size 10.

The brute force approach would be to go through the list as follows

best = firstElement;
for(each object ob in the list) {
if(ob is a better fit than best) {
best = ob;
}
}
then call list.remove(best);

And use best
Dec 28 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jerry Khoo | last post by:
i am currently working c++ project about executing a round robin algorrithm, how do i control when the algorithm should stop, what is the condition for the loop to stop, what is the condition to...
7
by: William Stacey [MVP] | last post by:
I can think of a couple ways to do this, but was wonder what the fastest way you can think of. Want to take any arraylist of > 1 element and make the first element the last, and all the rest of...
1
by: Ioannis Vranos | last post by:
I was checking .NET multithreading lately, and my book mentions that the thread scheduler provides quantoms of a time to each thread in "round robin" fashion. Is there any on line reference...
1
by: Scott | last post by:
Hi All. I have a web site that is currently using DNS round robin as a poor man's load balancer. Some users are receiving an 'Unable to Validate Data' error when posting back to the server. ...
5
by: Marc | last post by:
Hi, I cannot get the round function to work on vb.net. I get the message that round is not declared? Has round function changed or something? MsgBox(round(3, 3))
6
by: rhitx | last post by:
Can somebody please give like an overview how to do a round robin scheduler.. I know that we're suppose to use a quantum/quanta? Is this going to be like an int, then assign with with a value? ...
2
by: =?Utf-8?B?aGVyYmVydA==?= | last post by:
how do I code generic functions to return the next item in an enumeration a) sorted by name, b) sorted by value c) sorted by declaration in a round-robin style ? for example the enum is Enum...
6
by: Zeng | last post by:
Math.Round has good behavior as following: Math.Round(3.45, 1); //Returns 3.4. The last '5' is thrown away because 4 is even Math.Round(3.75, 1); //Returns 3.8. The last '5' is used because '7'...
4
by: lilmax88 | last post by:
I have a program in which I need to take a numeric value for dollars. There is a "set" function that must screen the value for the following 3 conditions with the indicated handling functionality:...
5
by: 08butoryr | last post by:
Hi everyone! this should be pretty simple for programmers on this forum... I need to design a java program which interacts with a MS Access DB in order to simulate the progression of a soccer round...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.