All squares are visited using a random start location and random order of directions to expand the rectangle. However, a solution is only found in the 3rd try.
To solve this, every possible expanded rectangle should be found. Instead of randomly choosing cells and the direction for expansion, the selection should be more carefully chosen. I think that every possible expanded rectangle could be found with only having to test every cell that is in a corner (or diagonal from it for inverse corners), and all orderings of expansion should be tested. Then the number of tests is still reasonably small.
Even then, as shown by the last test case, you really need to try different orientations.
Edit: also, if there is a hole in the dead centre, it wouldn't make it any less the best position if no suction cups are actually in the centre of the gripper, but it would be missed
Another slight improvement I've thought of: When initialising the set of unvisited points, calculate the maximum sized circle centered at that point. Pretty simple calculation: Find the minimum distance from that point to every line segment of the target shape.
Now consider unvisited points in order of circle size (a HashSet no longer works here but whatever) instead of randomly, and instead of starting with an infinitely small rectangle you can now start with the largest square that fits in the point's bounding circle (just some math).
Admittedly this won't work in any of your example test cases, but I imagine realistically shapes will be larger than just enough to fit exactly one suction cup on (not that your example is invalid). The heuristic should avoid marking large areas for gripping completely with small rectangles extending from other obscure features, as those would now only be marked later.
Another use case that'll break my algorithm is very small, very frequent holes: Since the gripper has multiple suction cups with some empty space between them, it would technically be possible to place the gripper such that the space between suction cups is positioned between gaps. My algorithm assumes we need a continuously flat surface.
Some more points on actual input shapes: The exact use case for this (kinda avoided it for anonymity but whatever) is stone cutting, like marble and such for fancy tables and kitchen tops. Holes are for sinks, taps, stovetops, cutouts for those little walls that seperate kitchen and dining room and so on. These are not super mass-produced, but they're extremely heavy, so these guys have a robotic solution to automatically load them from the output conveyor onto a palette.
Can these stone cutting machines produce really small holes? Are these stones ever cut to any bizarrely exotic shapes that don't resemble the rectangle they start as? I honestly don't know. If I got the job I'd probably be able to get more details on the actual manufacturing constraints which would help with figuring out what kind of cases the algorithm would actually need to cover.
Would be nice to have a mathematically optimal solution to any truly arbitrary shape though xD
View all comments
Show parent comment
2
u/BrandonJohns Jan 12 '22 edited Jan 12 '22
Thanks for sharing~
I'm impressed you came up with that on the spot.
With respect, if I understand correctly, the result is not necessarily optimal and could in some cases fail to find a solution.
Here are my example test cases: https://imgur.com/TYmt0xh
All squares are visited using a random start location and random order of directions to expand the rectangle. However, a solution is only found in the 3rd try.
To solve this, every possible expanded rectangle should be found. Instead of randomly choosing cells and the direction for expansion, the selection should be more carefully chosen. I think that every possible expanded rectangle could be found with only having to test every cell that is in a corner (or diagonal from it for inverse corners), and all orderings of expansion should be tested. Then the number of tests is still reasonably small.
Even then, as shown by the last test case, you really need to try different orientations.
Edit: also, if there is a hole in the dead centre, it wouldn't make it any less the best position if no suction cups are actually in the centre of the gripper, but it would be missed