Comments on: Algorithm Challenge!
http://ask.metafilter.com/78807/Algorithm-Challenge/
Comments on Ask MetaFilter post Algorithm Challenge!Sun, 16 Dec 2007 19:03:04 -0800Sun, 16 Dec 2007 19:03:04 -0800en-ushttp://blogs.law.harvard.edu/tech/rss60Question: Algorithm Challenge!
http://ask.metafilter.com/78807/Algorithm-Challenge
Algorithmfilter: I have a set of tasks and a set of workers. Tasks vary in size. Each task can be done by only some of the workers. How can I find a mapping from tasks to workers that minimizes the load on the the heaviest-loaded worker, and assigns all the work? <br /><br /> Here's an example in case it's not totally clear:<br>
Tasks:<br>
Task A: 2 hours<br>
Task B: 5 hours<br>
Task C: 3 hours<br>
Task D: 2 hours<br>
Task E: 7 hours<br>
Task F: 7 hours<br>
Task G: 4 hours<br>
<br>
Worker 1 is able to do A, B, C<br>
Worker 2 is able to do B, C, D<br>
Worker 3 is able to do C, D, E<br>
Worker 4 is able to do D, E, F<br>
Worker 5 is able to do E, F, G<br>
Worker 6 is able to do F, G, A<br>
Worker 7 is able to do G, A, B<br>
<br>
Here's one mapping that this not optimal (because there are other obvious mappings that have the heaviest-loaded worker doing less than worker 2's 10 hours of work):<br>
<br>
1 -> (A)<br>
2 -> (B, C, D)<br>
3 -> (E)<br>
4 -> (F)<br>
5 -> (G)<br>
6 -> ()<br>
7 -> ()<br>
<br>
Can the optimal mapping be computed in polynomial time? How about an approximation?<br>
<br>
I feel like this must be analagous to a combinatorial optimization problem; it's similar to multi-commodity max flow, or the assignment problem, but neither is a good fit as far as I can tell. I'm pretty sure the objective function is non-linear, which is probably what's killing me. I'm thinking that simulated annealing may be the way to go (randomly swapping assignments on each iteration), but I'd rather not resort to that.post:ask.metafilter.com,2007:site.78807Sun, 16 Dec 2007 18:35:35 -0800jewzillaalgorithmscombinatorialoptimizationBy: hattifattener
http://ask.metafilter.com/78807/Algorithm-Challenge#1169797
Can you use a dynamic-programming approach? Even with a limited horizon you should get pretty good results unless your data set is somehow pathological. I think.<br>
<br>
It does seem like the kind of optimization / resource allocation / operations-research problem that was studied extensively in the 50s and 60s but doesn't show up in textbooks much any more. Have you checked Knuth?comment:ask.metafilter.com,2007:site.78807-1169797Sun, 16 Dec 2007 19:03:04 -0800hattifattenerBy: grimmelm
http://ask.metafilter.com/78807/Algorithm-Challenge#1169803
NP-complete. <br>
<br>
Here's a reduction from <a href="http://en.wikipedia.org/wiki/Partition_problem">PARTITION</a>. Given a partition problem, create an instance of your problem with two workers and one task of length n for each integer n in the multiset to be partitioned. Suppose your algorithm can find the optimal assignment in polynomial time. Then we can easily check whether that assignment divides the work exactly evenly. If so, then the multiset can be partitioned; if not, it can't. Thus, whatever poly-time algorithm can solve your problem can also provide a a poly-time solution to PARTITION. <br>
<br>
So the bad news is that you shouldn't go looking for a polynomial-time exact solution. The good news is that you might still be able to find a reasonable approximation algorithm.comment:ask.metafilter.com,2007:site.78807-1169803Sun, 16 Dec 2007 19:08:10 -0800grimmelmBy: miasma
http://ask.metafilter.com/78807/Algorithm-Challenge#1169868
This is a very classic problem in operations research called the job-shop schedule problem. It is NP-hard, and is a discrete, combinatorial optimization problem. Depending on how large a problem you want to throw it at, you can probably use a standard search via brute-force, a heuristic method, or a metaheuristic method such as hill-climbing, simulated annealing, or evolutionary algorithms.<br>
<br>
<a href="http://en.wikipedia.org/wiki/Job-shop_problem">http://en.wikipedia.org/wiki/Job-shop_problem</a><br>
<br>
In this situation, your Workers on the Machines, Your Tasks are the Jobscomment:ask.metafilter.com,2007:site.78807-1169868Sun, 16 Dec 2007 20:09:05 -0800miasmaBy: jewzilla
http://ask.metafilter.com/78807/Algorithm-Challenge#1169925
Looks like mine's actually the <i>flexible</i> job shop problem (because each job can be done only by a subset of machines). It's a little easier because there's only one operation per job, but my intuition is that it doesn't get me off the hook. Sounds like there's a lot of research on this to go through, but you pointed me in the right direction. Thanks!comment:ask.metafilter.com,2007:site.78807-1169925Sun, 16 Dec 2007 21:29:14 -0800jewzillaBy: breath
http://ask.metafilter.com/78807/Algorithm-Challenge#1169929
I've had decent success using the <a href="http://web.mit.edu/dimitrib/www/TheAuctionAP.pdf">auction algorithm</a> on similar problems. It has the benefit of being nearly as easy to code as an annealing algorithm but without the fudge factor of "did I run it for long enough and/or add enough randomness?"comment:ask.metafilter.com,2007:site.78807-1169929Sun, 16 Dec 2007 21:37:06 -0800breathBy: philomathoholic
http://ask.metafilter.com/78807/Algorithm-Challenge#1169965
Can you use the <a href="http://en.wikipedia.org/wiki/Simplex_algorithm">simplex</a> algorithm? I took a class in Linear Programming, and we had to solve problems like this and we used the simplex algorithm. <small>Or am I way off?</small>comment:ask.metafilter.com,2007:site.78807-1169965Sun, 16 Dec 2007 22:33:53 -0800philomathoholicBy: grumblebee
http://ask.metafilter.com/78807/Algorithm-Challenge#1170287
I've had this problem for years. I've tried and failed to find an app to help me with it, and I've thought about trying to build one. For me, the domain is scheduling actors for rehearsals. I have X number of actors. I'm not paying them, so I don't want to waste their time. On a given night, there are Y scenes I could rehearse. By the end of the rehearsal period, I need to have rehearsed them all, but I don't have to rehearse them in order.<br>
<br>
Not all actors are in all scenes. <br>
<br>
Many actors have conflicts on specific days. Actor 1 can never work Tuesday nights. Actor 2 is generally free except for two specific dates.<br>
<br>
I can't figure out a reasonable way to make sure all the scenes get rehearsed in the most efficient way possible. Sometimes I have an actor that I'm thinking about casting. He has a bunch of conflicts. I'm not sure whether or not I can fit him into the production. Will his conflicts, when added to someone else's, mean that there are certain scenes that I won't be able to rehearse at all?<br>
<br>
I'll be following this thread with interest.comment:ask.metafilter.com,2007:site.78807-1170287Mon, 17 Dec 2007 07:47:12 -0800grumblebeeBy: jewzilla
http://ask.metafilter.com/78807/Algorithm-Challenge#1170296
Breath: thanks, I'll check that out.<br>
philomathoholic: I don't think the objective function is linear, so simplex won't cut itcomment:ask.metafilter.com,2007:site.78807-1170296Mon, 17 Dec 2007 07:49:40 -0800jewzillaBy: mhum
http://ask.metafilter.com/78807/Algorithm-Challenge#1171532
The specific version of job-shop scheduling you're looking at is known as "<a href="http://www.google.com/search??num=100&hl=en&safe=off&btnG=Search&q=%22minimum%20makespan%22">minimum makespan"</a> scheduling. Classically, this problem comes in two flavours: 1) "identical machines", where each job takes the same amount of time on each machine and 2) "idependent machines", where they don't. Your restriction that only some jobs can be performed by some machines seems too place your version somewhere between these two versions but probably closer to the identical machines version.<br>
<br>
A brief Google search seems to suggest that the simple greedy heuristic (due to Graham) of assigning the longest remaining job to the least-loaded worker (aka "least processing time (LPT) scheduling") should provide a good starting point. In the independent machines case, this scheme provides a (4/3)-approximation, (i.e.: the solution it provides is guaranteed to be no worse than 4/3 times the optimal solution). See <a href="http://www.google.com/url?sa=t&ct=res&cd=6&url=http%3A%2F%2Falgo2.iti.uni-karlsruhe.de%2Fvanstee%2Fcourses%2Flpt.ps&ei=4CpnR7vJJo24eoijsUw&usg=AFQjCNH2yaz_l6AJ_1V7nhQl8bFYb9KAVA&sig2=91PR1f-dhJ_7cmPjhx9NnQ">this</a> (ps file), for a proof. I haven't checked to see what guarantees can be proved in your case where some jobs can't run on some machines.<br>
<br>
Also, note that while the problem is NP-complete, there exists a <a href="http://en.wikipedia.org/wiki/Polynomial-time_approximation_scheme">polynomial-time approximation scheme</a> for it, at least in the identical machines case. You can see a sketch of it <a href="http://www.cs.uiowa.edu/~sriram/253/fall02/lec4.pdf">here</a>. You'll have to go through it in more detail to see if it can be adapted to the restrictions in your case.comment:ask.metafilter.com,2007:site.78807-1171532Mon, 17 Dec 2007 18:26:57 -0800mhum