views:

142

answers:

1

Anybody know of an efficient algorithm for moving rectangles in a square which contains obstacles?

Rectangles:

  • can rotate
  • can move/teleport
  • must not collide with obstacles (black squares)

Obstacles:

  • can't be moved
  • can be added anywhere

Goal: when obstacle is added, try to move rectangles so that they don't collide with any of obstacles.

State 1

State 2

State 3

State 4

State 5

+1  A: 

Take a look at this: http://stackoverflow.com/questions/1726632/dynamic-programming-largest-square-block/1726667#1726667
Basically, given the rectangles, you add an obstacle, and remove the square that the obstacle interferes with.
Then, run the linked algorithm(with the "limiters" being the obstacles and existing squares), and if a place was found that can fit a square of NxN size (N is the large part of the rectangle), and add the rectangle).
This can be optimized a bit further, and I entrust you with doing so. (Basically - the rectangles won't always be put in the most optimal place. This can be remedied, at least to some degree)
This solution will give you O(n) time and space for each obstacle added.
Possible modification you should also look into: Don't rebuild the array for each obstacle, but build it for the void-of-obstacles array, and modify it as you go along. This will save going through the entire array for every single obstacle.

Rubys