Git Product home page Git Product logo

bin-packing's People

Contributors

jakesgordon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bin-packing's Issues

Could you build and offer an arbitrary-size rects-in-rect-calculator ?

I was trying to get an answer to a real world packing problem:
How many plastic boxes of which available size(s) can fit into what cardboard enclosure of available size(s) with wasting as little space as possible?
For illustration, these were my commercially available candidates:
http://www.amazon.de/dp/B00NEFDGYU/
http://www.ebay.at/itm/350846130746
http://www.amazon.de/dp/B00P81VBKO/

Found out that this is a practical application with this scientific name:
https://en.wikipedia.org/wiki/Packing_problems#Identical_rectangles_in_a_rectangle

Then I was trying to find a free online calculator for this.
Your's was the closest one I found.
But these of its limitations did not allow it for me to be used for my purposes:

  • The enclosing rectangle's size is fixed, cannot be manually defined (to my cardboard dimensions, I would assume mm as pixels, doesn't matter as long as the ratio is correct)
  • Block definitions: I'd like N to be able to take * as input, meaning "as many as possible" (theoretical unlimited supply) -- or maybe allow one N per blockset to take a "maximize" or "minimize" argument -- and for any of this parametrizations the goal is to fill the space as good as possible with the available blocks, which are available in unlimited supply.
  • Color option: Same color for same sized blocks.

Would it be much work to adapt your demo, so that it would allow this?

Need Help!

Hey thanks for this wonderful piece of work,
I am using 2d bin package as dashboard, i want to make it drill down, would you please help me out, how could i add click event on every boxes?

Thanks.

Bug with simple packer

Hello, I am facing a problem when trying to use the simplest version of the lib, the packer.js (even though the filename refers to the other one)

It turns out that the following code:

     /**
     * Handle main data generation. This method generate only raw data, used by another API (INSERT LATE) to generate real used data.
     * @param {*} req
     * @param {*} res
     * @return {void}
     */
    getOffsets: (req, res) => {
        // Necessary data
        const mdfData = {
            height: 1000,
            width: 800
        }

        // Import optimizer library and instantiate it
        const growingPacker = require('../vendor/packer.growing.js');
        const packer        = new growingPacker(800, 1000);

        // This will take data to generate offsets
        let pieces = [
            { h: 21100, w: 2220},
            { h: 1000, w: 22000 },
            { h: 1000, w: 22000 },
            { h: 1000, w: 22000 },
            { h: 1000, w: 22000 },
            { h: 1000, w: 22000 },
            { h: 1000, w: 22000 },
            { h: 2000, w: 22000 },
            { h: 1000, w: 22000 },
        ];

        // Sort pieces by height
        pieces.sort((a, b) => { return(b.h < a.h) });
        
        // Generate offsets
        packer.fit(pieces);
        console.log(pieces); 
        

        res.send(pieces)
    }

It is generating this output:

[
    { "h": 21100, "w": 2220 },
    { "h": 1000, "w": 22000 },
    { "h": 1000, "w": 22000 },
    { "h": 1000, "w": 22000 },
    { "h": 1000, "w": 22000 },
    { "h": 1000, "w": 22000 },
    { "h": 1000, "w": 22000 },
    { "h": 2000, "w": 22000 },
    { "h": 1000, "w": 22000 }
]

My packer.growing.js looks like this:

Packer = function(w, h) {
  this.init(w, h);
};

Packer.prototype = {

  init: function(w, h) {
    this.root = { x: 0, y: 0, w: w, h: h };
  },

  fit: function(blocks) {
    var n, node, block;
    for (n = 0; n < blocks.length; n++) {
      block = blocks[n];
      if (node = this.findNode(this.root, block.w, block.h))
        block.fit = this.splitNode(node, block.w, block.h);
    }
  },

  findNode: function(root, w, h) {
    if (root.used)
      return this.findNode(root.right, w, h) || this.findNode(root.down, w, h);
    else if ((w <= root.w) && (h <= root.h))
      return root;
    else
      return null;
  },

  splitNode: function(node, w, h) {
    node.used = true;
    node.down  = { x: node.x,     y: node.y + h, w: node.w,     h: node.h - h };
    node.right = { x: node.x + w, y: node.y,     w: node.w - w, h: h          };
    return node;
  }

}

module.exports = Packer;

I am using Node + ExpressJS for development.

I was using Growing at first, which was generating the expected data output, but the feature I am developing requires me to enter a width/height limit.

If you can help me, I would be very grateful.
Thanks in advance, and sorry for the bad English

problem with fixed size

Hello there is a problem with fixed size.

Container size is : 800x600
I am trying on demo
If i give this params. It can not fit the rectangle.

100x600
700x100

Is there any option to rotate objects?

I didn't see an option to enable rotating objects
Sometimes objects need to be rotated to look their best.
If this option exists and I haven't seen it, please advise and if it doesn't exist, add it as soon as possible.
Thank you.

Can you help me please ?!!!

Thank you for your wonderfull work here.
I wonder if its available to add a new sheet if there is no room for parts instead of error message.

fails randomly

I'm having issues with calling .fit method consistenlty. I'm trying to fit a bunch of squares in a rectangle area.
I'm using GrowingPacker as per the readme example.
What I get in return is a random number of blocks that have fit equal to null.
Ideally I'd like to grow the container to fit all blocks.

Also, even if it happens that all blocks have fit - there's often enough room in the container so the blocks could be packed much tighter.

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.