如何用nodejs打包2D盒子?

我正在开发一个节点js的web应用程序,我需要使用一个盒子打包algorithm来find最佳的解决scheme。 我可以尝试自己做一个algorithm( http://en.wikipedia.org/wiki/Packing_problems ),但我想知道这样的事情是否已经存在? 任何想法?

目前我有一个像这样的对象数组。

var box = [ {info: 'some info', width:200, height: 50}, {info: 'some info', width:200, height: 50} ]; 

我想要有(x,y)坐标,知道在哪里把每个盒子打包到一个2D空间中。

你有背包节点js模块 (我是开发者),可以做你所需要的。

只要已经定义了heightwidth属性,就可以传递任何对象列表。 这里是一个简短的例子:

 var BackPack = require("backpacking"); var boxes = []; for(var i = 0; i<20; i++){ var width = Math.floor(Math.random() * (20 - 5 + 1)) + 5; var height = Math.floor(Math.random() * (20 - 5 + 1)) + 5; boxes.push({info: 'box_'+i, 'width': width, 'height': height}); } // Define the width and the height of the container where you want to pack your boxes. backPack = new BackPack(40, 10000); // Here you have the packedBoxes with de x and y coordinates. packedBoxes = backPack.pack(boxes); 

放弃

解决scheme不是最佳的。 但这是一个快速的algorithm。 包装的质量应在下个月改进。

更多信息

有关更多详细信息, 请参阅github.com自述文件https://github.com/paulfournel/backpacking/