Creating movable rectangles with a restricted boundary (Updated)

Hello, I was able to make some progress with the script. But now I encounter a new problem! How can I ensure that the rectangles have a minimum distance between one another?


Here is the new Grasshopper file: Movable rectangles.gh (14.8 KB)

Hi, I was wondering how I could create copies of a square/rectangle (green ones) and move them in a restricted boundary (large red square) in such a way that they have atleast 1unit distance between the edges of one another (green ones). The idea is to create as many rectangles as possible in this manner (initial sizes of each green square/rectangle may vary) and finally use Galapagos to maximize on the sum total of their surface area.

Movable rectangles.gh (9.7 KB) movable rectangles.3dm (31.5 KB)