Click here to Skip to main content
15,898,945 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: "Best Fit" Algorithm Request && Teach A Man To Fish Pin
Michael Fritzius18-Apr-10 9:40
professionalMichael Fritzius18-Apr-10 9:40 
GeneralRe: "Best Fit" Algorithm Request && Teach A Man To Fish Pin
Luc Pattyn18-Apr-10 10:02
sitebuilderLuc Pattyn18-Apr-10 10:02 
GeneralRe: "Best Fit" Algorithm Request && Teach A Man To Fish Pin
Luc Pattyn18-Apr-10 10:07
sitebuilderLuc Pattyn18-Apr-10 10:07 
GeneralRe: "Best Fit" Algorithm Request && Teach A Man To Fish Pin
harold aptroot18-Apr-10 11:39
harold aptroot18-Apr-10 11:39 
GeneralRe: "Best Fit" Algorithm Request && Teach A Man To Fish Pin
Michael Fritzius19-Apr-10 11:59
professionalMichael Fritzius19-Apr-10 11:59 
GeneralRe: "Best Fit" Algorithm Request && Teach A Man To Fish Pin
Luc Pattyn19-Apr-10 12:45
sitebuilderLuc Pattyn19-Apr-10 12:45 
GeneralRe: "Best Fit" Algorithm Request && Teach A Man To Fish Pin
Tim Craig19-Apr-10 12:48
Tim Craig19-Apr-10 12:48 
GeneralRe: "Best Fit" Algorithm Request && Teach A Man To Fish [modified] Pin
harold aptroot19-Apr-10 12:56
harold aptroot19-Apr-10 12:56 
Ok with the code I gave earlier that would take more than a million years Smile | :)
With a larger number of jobs, the greedy algorithm comes closer to the optimal solution, and there is a semi-greedy algorithm that is always* at least as good as the simple greedy algorithm but usually better:

1) Let s be the sum of all job-lengths and let bound be (s+m-1)/m (where m is the number of machines)
2) For each job in descending order (by length), assign it to the first machine where it wouldn't cause the sum of the lengths of the jobs assigned to that machine so far to exceed bound, if there is no such machine mark the job as "non scheduled".
3) If there are no jobs marked "non scheduled", return the schedule.
4) Otherwise, take the length (mlength) of the schedule of the machine with the shortest schedule, and take the length (jlength) of the smallest job.
5) Change the bound to bound+(jlength-(bound-mlength)) (IOW, make it so that you could add the smallest job to the smallest schedule without exceeding the bound)
6) Make all jobs non-marked and go back to step 2.

It is, of course, slower than the usual greedy approach, but (usually, at least) very fast compared to the optimal approach.

It always terminates, because jlength-(bound-mlength) can not be zero. If it were, that job would have been scheduled in step 2, so it wouldn't be the smallest "non scheduled" job. So the bound will grow until everything fits (potentially in a sub-optimal way).

* I have no proof, but after a large number of random tests I still had no disproof. But you could always run the usual greedy algorithm as well and take the best result, it takes essentially no time anyway.

edit: I didn't make this up myself, btw.
modified on Monday, April 19, 2010 7:26 PM

GeneralRe: "Best Fit" Algorithm Request && Teach A Man To Fish Pin
Tadeusz Westawic23-Apr-10 2:24
Tadeusz Westawic23-Apr-10 2:24 
AnswerRe: "Best Fit" Algorithm Request && Teach A Man To Fish Pin
Tadeusz Westawic23-Apr-10 3:57
Tadeusz Westawic23-Apr-10 3:57 
QuestionCSMA / CA Pin
hairy_hats14-Apr-10 4:59
hairy_hats14-Apr-10 4:59 
AnswerRe: CSMA / CA Pin
Anshul R9-Jun-10 4:14
Anshul R9-Jun-10 4:14 
QuestionBeating LabView's "Spreadsheet String To Array" function Pin
PaulowniaK7-Apr-10 20:21
PaulowniaK7-Apr-10 20:21 
AnswerRe: Beating LabView's "Spreadsheet String To Array" function Pin
Phil Martin7-Apr-10 20:29
professionalPhil Martin7-Apr-10 20:29 
AnswerRe: Beating LabView's "Spreadsheet String To Array" function Pin
J. Dunlap7-Apr-10 20:53
J. Dunlap7-Apr-10 20:53 
AnswerRe: Beating LabView's "Spreadsheet String To Array" function Pin
AspDotNetDev7-Apr-10 23:06
protectorAspDotNetDev7-Apr-10 23:06 
AnswerRe: Beating LabView's "Spreadsheet String To Array" function Pin
CPallini15-Apr-10 23:23
mveCPallini15-Apr-10 23:23 
Question15 puzzle solution in C or C++ Pin
123lucy457-Apr-10 5:25
123lucy457-Apr-10 5:25 
AnswerRe: 15 puzzle solution in C or C++ Pin
Luc Pattyn7-Apr-10 5:56
sitebuilderLuc Pattyn7-Apr-10 5:56 
GeneralRe: 15 puzzle solution in C or C++ Pin
Paul Conrad7-Apr-10 6:35
professionalPaul Conrad7-Apr-10 6:35 
AnswerRe: 15 puzzle solution in C or C++ Pin
Dave Kreskowiak7-Apr-10 7:03
mveDave Kreskowiak7-Apr-10 7:03 
GeneralRe: 15 puzzle algorithm in C or C++ Pin
123lucy457-Apr-10 16:11
123lucy457-Apr-10 16:11 
GeneralRe: 15 puzzle algorithm in C or C++ Pin
Luc Pattyn7-Apr-10 17:07
sitebuilderLuc Pattyn7-Apr-10 17:07 
GeneralRe: 15 puzzle algorithm in C or C++ Pin
Dave Kreskowiak7-Apr-10 17:42
mveDave Kreskowiak7-Apr-10 17:42 
GeneralRe: 15 puzzle algorithm in C or C++ Pin
Alan Balkany9-Apr-10 4:28
Alan Balkany9-Apr-10 4:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.