Group boxes together as close as possible without overlap

Hey, I need help finding a solution for grouping boxes together as can be seen underneath. Atm the solution uses Wallacei for GA, giving the fitness of the distance between all boxes, calculated as in picture 2. For collision the script runs a check to see any of the boxes overlap, and then gives the fitness function a penalty. The solution is capable of producing a working result with anything from 4 boxes and down, however, when the boxes increase the solution either dosent care about collision or dosen’t move them together. Do any of you have an idea on how improve any of the parts so that it will be able to handle more boxes?

Any help would be appreciated!

BR
Anders


are those 3D boxes or 2D rectangles?
could you please upload your current GH script with internalized geometries?

These are 2D rectangles. The script is attached.
grassyevol2.gh (430.5 KB)

Is there maybe a way to first start with two rectangles, put them together, then try to fit a third on the two, and so on, so the GA only focuses on one rectangle at a time?

You could adapt this script by @DanielPiker…

I already added a Rigid Point Set component and interconnected the area centroids.

Something doesn’t seem right yet unfortunately.

PS: seems like my file didn’t upload and was a bit too complicated…

1 Like

Here’s one way:
rect_pack.gh (10.5 KB)

rectpack

8 Likes

Thanks a lot! this helps me in the right direction:)

1 Like

Here’s an alternative. It’s by no means as neat as Daniels, but still pretty convenient and scalable.

I found that with more than 20 rectangles it would take a very long time to get a good solution, even with the zombie solver.

This script uses OpenNest, which has the side effect of placing large pieces first, which means you’ll get a left to right gradient of sizes
packing_count_2

rect_pack_opennest.gh (13.8 KB)

3 Likes

I just discovered the PackBox component from OpenNest
image
which does a similar thing but very quickly!

packing_count_22
rect_pack_opennest_boxes.gh (13.3 KB)

Can’t imagine this could be much use for an urban design exercise (i’m assuming the @Anders3 was doing?), because you can’t control at all where pieces will be placed

1 Like

Yee, we need to be able to pick the location for the boxes, which till now have been done by a ga, so the main issue is the complexity of the solution space when the boxes increase