Kamor04
Kamor04

Reputation: 307

Allocate the item in container - 3D bin packing problem | Python

I am looking for advice or idea for positioning items in container in 3D Bin Packing Problem. I am checking if item fitting in container using [x, y, z] position. My goal is to place the item if possible. If it is not possible I am placing the item in unpacked list. Below is my piece of code:

        for item in self.items: 
            for itemInBin in binn.items:
                positionToPlace= [itemInBin.position[0] + itemInBin.getWidth(), itemInBin.getHeight() + itemInBin.position[1], itemInBin.getDepth() + itemInBin.position[2]]

                if positionToPlace[0] <= binn.getWidth() or positionToPlace[1] <= binn.getHeight() or positionToPlace[2] <= binn.getDepth(): # do not exceed the dimensions of the container
                    binn.putItem(item, positionToPlace)
                else:
                    unpacked.append(item)

For test data:

The first four items should be packed into Container and one item goes to the unpacked array. Using a position should look like [20, 20, 8], but for my case is [80, 80, 8]. I tried to assign the current position of the item, without its width, height or depth if it exceeds the container dimension, but it was the wrong idea.

I am thinking about "if statements" or function which precisely allocate items if possible. It means it will be available place on X, Y or Z axis. I know my solution is really bad at this time, but I wanted to show you something. In other function, I am rotating item to place it optimally, and it seems to works fine.

Please help me with positionToPlace - I don't want to add a position if it exceeds the container dimension for every instance.

Upvotes: 1

Views: 654

Answers (1)

Tristan Nguyen
Tristan Nguyen

Reputation: 41

Idea:

You need to chose only one dimension to be SUM up. Keep other as they are.

in this case:

itemInBin.getDepth() + itemInBin.position[2]

Upvotes: 1

Related Questions