Giter Site home page Giter Site logo

3d-bin-container-packing's Introduction

Build Status

3d-bin-container-packing

This library does 3D rectangular bin packing; it attempts to match a set of 3D items to one in a set of 3D containers. The result is the single container which can hold all the items; no attempt is made to subdivide the items into several containers.

Projects using this library will benefit from:

  • short and predictable calculation time,
  • fairly good use of container space, and
  • intuitive use for a human

So while the algorithm will not produce the theoretically optimal result (which is NP-hard), its reasonable simplicity means that in many cases it would be possible to stack the resulting container for a human without instructions.

In short, the library provides a service which is usually good enough, in time and reasonably user-friendly ;-)

Bugs, feature suggestions and help requests can be filed with the issue-tracker.

Obtain

The project is implemented in Java and built using Maven. The project is available on the central Maven repository.

Example dependency config:

<dependency>
    <groupId>com.github.skjolber</groupId>
    <artifactId>3d-bin-container-packing</artifactId>
    <version>1.0.5</version>
</dependency>

Usage

The units of measure is out-of-scope, be they cm, mm or inches.

Largest Area Fit First (LAFF) packager

Obtain a Packager instance:

// initialization
List<Dimension> containers = new ArrayList<Dimension>();
containers.add(Dimension.newInstance(10, 10, 3)); // your container dimensions here
Packager packager = new LargestAreaFitFirstPackager(containers);

The packager instance is thread-safe.

Packing

Then compose your item list and perform packing:

List<Box> products = new ArrayList<Box>();
products.add(new Box("Foot", 6, 10, 2));
products.add(new Box("Leg", 4, 10, 1));
products.add(new Box("Arm", 4, 10, 2));
	
// match to container
Container match = packager.pack(products);

The resulting match variable returning the resulting packaging details or null if no match.

The above example would return a match (Foot and Arm would be packaged at the height 0, Leg at height 2).

Rotation

By adding an additional argument to the constructor, 2D or 3D rotation of boxes can be toggled:

boolean rotate3d = ...;
Packager packager = new LargestAreaFitFirstPackager(containers, rotate3d, true, true);

Brute-force packager

For a low number of packages (like <= 6) the brute force packager might be a good fit.

Packager packager = new BruteForcePackager(containers);

Using a deadline is recommended whenever brute-forcing in a real-time application.

// limit search using 5 seconds deadline
long deadline = System.currentTimeMillis() + 5000;

Container match = packager.pack(products, deadline);

Details

Largest Area Fit First algorithm

The implementation is based on this paper, and is not a traditional Bin packing problem solver.

The box which covers the largest ground area of the container is placed first. Boxes which fill the full remaining height take priority. Subsequent boxes are stacked in the remaining space in at the same level, the boxes with the greatest volume first. Then level is increased and the process repeated. Boxes are rotated, containers not.

The algorithm runs reasonably fast, usually in milliseconds.

Brute-force algorithm

This algorithm places the boxes in the same way as the LAFF algorithm, but has no logic for selecting the best box or rotation; running through all permutations, for each permutation all rotations.

The maximum complexity this approach is exponential at n! * 6^n. The algorithm runs for under a second for small number of products (<= 6), to seconds or minutes (<= 8) or hours for larger numbers.

However accounting for container and box sizes might reduce this bound considerably, and the resulting complexity can be calculated using PermutationRotationIterator before packaging is attempted.

Contact

If you have any questions or comments, please email me at [email protected].

Feel free to connect with me on LinkedIn, see also my Github page.

License

Apache 2.0

History

  • 1.0.5: Binary search approach for packaging with deadline
  • 1.0.4: Add deadline and brute force packager.
  • 1.0.3: Fix for issue #5, minor cleanup.
  • 1.0.2: Fix for issue #4, minor improvements.
  • 1.0.1: Add option to toggle 2D and 3D rotation and box placement coordinates, compliments of NothinRandom.
  • 1.0.0: Initial release.

3d-bin-container-packing's People

Contributors

skjolber avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.