Coder Social home page Coder Social logo

box_packer's Introduction

BoxPacker

First fit heuristic algorithm for 3D bin-packing with weight limit.

Version 2

For version 2 this entire solution has been rewritten with an emphasis on making a much simpler and easier to understand implementation. However, I haven't gone to the trouble of reproducing all the previous functionality, so if you still need that, it can be found here: 1.2.4

Installation

Add to gemfile:

gem  'box_packer'

Usage

require 'box_packer'

packings = BoxPacker.pack(
  container: { dimensions: [15, 20, 13], weight_limit: 50 },
  items: [
    { dimensions: [2, 3, 5], weight: 47 },
    { dimensions: [2, 3, 5], weight: 47 },
    { dimensions: [3, 3, 1], weight: 24 },
    { dimensions: [1, 1, 4], weight: 7 },
  ]
)

packings.length # 3
packings[0][:weight] # 47
packings[0][:placements].length # 1
packings[0][:placements][0][:dimensions] # [5, 3, 2]
packings[0][:placements][0][:position] # [0, 0, 0]
packings[1][:weight] # 47
packings[1][:placements].length # 1
packings[1][:placements][0][:dimensions] # [5, 3, 2]
packings[1][:placements][0][:position] # [0, 0, 0]
packings[2][:weight] # 31
packings[2][:placements].length # 2
packings[2][:placements][0][:dimensions] # [3, 3, 1]
packings[2][:placements][0][:position] # [0, 0, 0]
packings[2][:placements][1][:dimensions] # [4, 1, 1]
packings[2][:placements][1][:position] # [3, 0, 0]

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.