more useful options | |
PerlMonks |
Convex Hull Problemby code-ninja (Scribe) |
on Aug 26, 2013 at 18:34 UTC ( [id://1050990]=perlquestion: print w/replies, xml ) | Need Help?? |
code-ninja has asked for the wisdom of the Perl Monks concerning the following question:
I searched the Monastery for this problem and the solution that came up used the Math::ConvexHull module.
That being said, I have problem that I'll elucidate and I know that Convex Hull algorithm will best fit the need. I coded my rendition of the Jarvis' algorithm. Problem statement (updated): Suppose there are n events and each event is represented by a 3-tuple (x, y, z) where x is the start time, y is the end time and z is the cost of the event. for example:
Suppose that this represents all those possible events that I can attempt to earn money but clearly, I cannot attempt them all because for some events, start time overlaps with some other events, creating a deadlock. The best solution is I schedule the events in such a way that I "handpick" certain event that do not clash while not decreasing my profit (not necessarily maximize but I should not also face a loss). For example:
Why I think Convex Hull best fits the solution? Well, what I did was, instead of using the 3-tuple, I calculate how much time each event will actually take (by subtracting x from y) so this way I get a set of pair of points on a Cartesian plane. Now, applying the Jarvis algorithm, I'll get one convex quadrilateral that covers all the points exactly once and returns to the original point (The Traveling Salesman Problem). This way, I'll get all those points I can schedule without getting deadlocked and my profits will be maximized. I implemented the Jarvis algorithm from the wiki link above.
the code is going into an infinite loop and I'm finding it difficult to grasp why is it doing so? Any pointers? I'm unwilling to use any external module(s). Even if convex hull algorithm does not qualify as the best solution, I'd ask respected monks to comment on the code at least. :) PS: The problem statement may sound familiar to some. It was a problem in the ACM-ICPC 2011 final round. I'm not recalling the exact words of the problem. I was in the pre-final year of college and this was the only problem my team couldn't crack and we lost to this other team. It has been bugging me since then!UPDATE:The exact problem statement can be found here. Thanks to hdb. problem F.
Back to
Seekers of Perl Wisdom
|
|