Code Monkey home page Code Monkey logo

packer's Introduction

Packer

3D Bin Packing with multiple wrappers (boxes).

Red Printing

Red-Printing is a brand name of printing service supported by Betterway-systems.

레드 프린팅은 베러웨이시스템즈에서 실시하는 인쇄 서비스의 브랜드 명입니다. 많은 이용 바랍니다.

Packer를 이용하시는 여러분, 인쇄 주문은 꼭 레드프린팅에서 해 주세요.

http://redprinting.co.kr/

Author

References

Demo

Packer Demo GIF

Programming
Algorithm from Airforce Bin Packing

Installation

Node.JS
npm install -g 3d-bin-packing
tsd install 3d-bin-packing
TypeScript (JavaScript) only

If you want the TypeScript (JavaScript) only mode, any installation procedure is not required.

Build Cloud Server

However, if you want to install the C++ mode, you've to install Visual C++ Redistributable for Visual Studio 2015. After the installation, execute release/cpp/Packer.exe. Then a cloud server deducting packer solution will be opened. After running the cloud server, open release/browser/index.html.

You also can separate cloud server(C++) and clients(Web), let users to connect remote Packer server, by editing ip address in release/browser/server.xml

Implementation

Design

alt text

Languages
  • C++
    • Server solving packing problem.
    • Deduct the best optimization result with genetic algorithm
  • TypeScript
    1. Act a role of client connecting to C++ server.
    2. Do packing itself without C++ server and do not use genetic algorithm.
    • The optimization result can be inferior than C++
Dependency

Usage

TypeScript (Node.JS)
import packer = require("3d-bin-packing");
import samchon = require("samchon-framework");

function main(): void
{
    ///////////////////////////
    // CONSTRUCT OBJECTS
    ///////////////////////////
    let wrapperArray: packer.WrapperArray = new packer.WrapperArray();
    let instanceArray: packer.InstanceArray = new packer.InstanceArray();

    // Wrappers
    wrapperArray.push
    (
        new packer.Wrapper("Large", 1000, 40, 40, 15, 0),
        new packer.Wrapper("Medium", 700, 20, 20, 10, 0),
        new packer.Wrapper("Small", 500, 15, 15, 8, 0)
    );

    ///////
    // Each Instance is repeated #15
    ///////
    instanceArray.insert(instanceArray.end(), 15, new packer.Product("Eraser", 1, 2, 5));
    instanceArray.insert(instanceArray.end(), 15, new packer.Product("Book", 15, 30, 3));
    instanceArray.insert(instanceArray.end(), 15, new packer.Product("Drink", 3, 3, 10));
    instanceArray.insert(instanceArray.end(), 15, new packer.Product("Umbrella", 5, 5, 20));

    // Wrappers also can be packed into another Wrapper.
    instanceArray.insert(instanceArray.end(), 15, new packer.Wrapper("Notebook-Box", 2000, 30, 40, 4, 2));
    instanceArray.insert(instanceArray.end(), 15, new packer.Wrapper("Tablet-Box", 2500, 20, 28, 2, 0));

    ///////////////////////////
    // BEGINS PACKING
    ///////////////////////////
    // CONSTRUCT PACKER
    let my_packer: packer.Packer = new packer.Packer(wrapperArray, instanceArray);

    ///////
    // PACK (OPTIMIZE)
    let result: packer.WrapperArray = my_packer.optimize();
    ///////

    ///////////////////////////
    // TRACE PACKING RESULT
    ///////////////////////////
    let xml: samchon.library.XML = result.toXML();
    console.log(xml.toString());
}

main();
C++
#include <iostream>
#include <bws/packer/Packer.hpp>

#include <bws/packer/WrapperArray.hpp>
#include <bws/packer/InstanceArray.hpp>
# include <bws/packer/Product.hpp>
# include <bws/packer/Wrapper.hpp>

using namespace std;
using namespace samchon::library;
using namespace bws::packer;

int main()
{
	///////////////////////////
	// CONSTRUCT OBJECTS
	///////////////////////////
	shared_ptr<WrapperArray> wrapperArray(new WrapperArray());
	shared_ptr<InstanceArray> instanceArray(new InstanceArray());
	
	// Wrappers
	wrapperArray->emplace_back(new bws.packer.Wrapper("Large", 1000, 40, 40, 15, 0));
	wrapperArray->emplace_back(new Wrapper("Medium", 700, 20, 20, 10, 0));
	wrapperArray->emplace_back(new Wrapper("Small", 500, 15, 15, 8, 0));
	
	///////
	// Each Instance is repeated #15
	///////
	instanceArray->insert(instanceArray->end(), 15, make_shared<Product>("Eraser", 1, 2, 5));
	instanceArray->insert(instanceArray->end(), 15, make_shared<Product>("Book", 15, 30, 3));
	instanceArray->insert(instanceArray->end(), 15, make_shared<Product>("Drink", 3, 3, 10));
	instanceArray->insert(instanceArray->end(), 15, make_shared<Product>("Umbrella", 5, 5, 20));
	
	// Wrappers also can be packed into another Wrapper.
	instanceArray->insert(instanceArray->end(), 15, make_shared<Wrapper>("Notebook-Box", 2000, 30, 40, 4, 2));
	instanceArray->insert(instanceArray->end(), 15, make_shared<Wrapper>("Tablet-Box", 2500, 20, 28, 2, 0));
	
	///////////////////////////
	// BEGINS PACKING
	///////////////////////////
	// CONSTRUCT PACKER
	Packer packer(wrapperArray, instanceArray);
	GAParameters gaParams = {500, 100, 50, 0.2};
	
	///////
	// PACK (OPTIMIZE)
	///////
	shared_ptr<WrapperArray> &result = packer.optimize(gaParams);
	
	///////////////////////////
	// TRACE PACKING RESULT
	///////////////////////////
	shared_ptr<XML> xml = result->toXML();
	cout << xml->toString() << endl;
	
	return 0;
}

License

BSD v3.

Copyright (c) 2016, betterwaysystems All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  • Neither the name of packer nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

packer's People

Contributors

betterway-tinyman 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

packer's Issues

Strange Result for same Data

Hello,

I just tried your BoxPacker, but unfortunately I can't understand the result for following two XML files:

<packerForm> <instanceFormArray> <instanceForm count="24"> <instance name="Item1" width="9.5" height="9.5" length="10" type="product" /> </instanceForm> <instanceForm count="12"> <instance name="Item2" width="17.5" height="17.5" length="21.5" type="product" /> </instanceForm> <instanceForm count="2"> <instance name="Item3" width="10.25" height="10.83" length="16.3" type="product" /> </instanceForm> <instanceForm count="6"> <instance name="Item" width="9.5" height="18" length="6.08" type="product" /> </instanceForm> </instanceFormArray> <wrapperArray> <instance name="Large" price="102" width="59" height="59" length="40.5" thickness="0" type="wrapper" /> <instance name="Middle" price="101" width="58" height="29" length="40.5" thickness="0" type="wrapper" /> <instance name="Small" price="100" width="40.5" height="29" length="29" thickness="0" type="wrapper" /> </wrapperArray> </packerForm>

And the same file here, only the position of the Items has changed:

<packerForm><instanceFormArray> <instanceForm count="12"><instance name=„Item2" width="1750" height="1750" length="2150" type="product" /></instanceForm><instanceForm count="2"><instance name=„Item3" width="1025" height="1630" length="1083" type="product" /></instanceForm><instanceForm count="24"><instance name=„Item1" width="950" height="1500" length="1500" type="product" /></instanceForm><instanceForm count="6"><instance name=„Item4" width="950" height="1800" length="608" type="product" /></instanceForm> <wrapperArray><instance name=„Large" width="5900" price="102" height="5900" length="4050" thickness="0" type="wrapper" /><instance name=„Small" width="4050" price="100" height="2900" length="2900" thickness="0" type="wrapper" /><instance name=„Middle" width="5800" price="101" height="2900" length="4050" thickness="0" type="wrapper" /></wrapperArray></packerForm>

The result is a different:

With the first XML the Items fits into one large Box.
With the second XML the system suggest a big one and 2 small boxes

Why is this?

Compile TS- / JS Part

Hello,
the cpp part works fine!
The files in release folder of the browser-project works fine too, but I can't compile the TS - code of the web project to release.
Maybe I can support you by some donation?

Can we add weight parameter?

wrappers have a weight limitation, we cannot add product more than this limit otherwise wrappers will be not able to handle the products init. so can we add this parameter to the existing code?

it.equal_to is not a function - NodeJS

I was successfully using this package for a few days, but when I installed all of my npm dependencies on a different system I started getting errors. Nothing changed in package.json and my first copy was still working fine until I cleared /node_modules and npm install, which gave me the same errors afterward. Has something changed with one of this projects dependencies that could have broken it? I even created a blank project and followed the example in this repos readme, but I get the same error.

Node - tested on 4.2.2 and 6.5.0

Error:

Warning: Invalid argument supplied to oneOf, expected an instance of array.
/Users/{user}/Projects/{project}/node_modules/3d-bin-packing/release/node/packer.js:318
                for (var it = this.layer_map.begin(); !it.equal_to(this.layer_map.end()); it = it.next()) {
                                                          ^

TypeError: it.equal_to is not a function
    at Boxologic.iterate_orientations (/Users/{user}/Projects/{project}/node_modules/3d-bin-packing/release/node/packer.js:318:59)
    at Boxologic.pack (/Users/{user}/Projects/{project}/node_modules/3d-bin-packing/release/node/packer.js:302:18)
    at WrapperGroup.pack (/Users/{user}/Projects/{project}/node_modules/3d-bin-packing/release/node/packer.js:3553:39)
    at WrapperGroup.optimize (/Users/{user}/Projects/{project}/node_modules/3d-bin-packing/release/node/packer.js:3537:42)
    at Packer.initGenes (/Users/{user}/Projects/{project}/node_modules/3d-bin-packing/release/node/packer.js:1952:34)
    at Packer.optimize (/Users/{user}/Projects/{project}/node_modules/3d-bin-packing/release/node/packer.js:1859:42)
    at main (/Users/{user}/Projects/{project}/index.js:29:28)
    at Object.<anonymous> (/Users/{user}/Projects/{project}/index.js:37:1)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)

Can't get it to work

Hi @samchon
I am trying to implement for an test application but iam unable to get your example to work.

iam not a ts or c++ dev. perhaps you could help me in understanding how your application is working.
if i get it work i want to create a linux shell application wich will read a file with the data and output it to a file.

thank you.

Packer crashes if an instance is larger than the largest wrapper

Steps to reproduce:

  1. Go to the packer demo website
  2. Add an instance with WxHxL = 1x1x2
  3. Add a wrapper with WxHxL = 1x1x1
  4. Press 'Pack'

Expected result: an error or warning informing you that one of the instances does not fit in any wrappers

Actual result: the website becomes kind of 'greyed out' and does not respond to any mouse clicks. No errors. The only way to continue is press F5 and start over again.

Standalone Boxologic project using Cmake

Hi,

I'm really interested by your rewrite of Boxologic.
I would like to use it from ruby (which doesn't have any box packing lib).
I tried building your project with CLion but I can't create a valid CMakeList.txt file.

Could you create a standalone Boxologic project using Cmake ?

Can we add a "KeepFlat" parameter to items?

There's a way to control on a per-item level whether the item can be turned onto it’s side or not. Like a "ship this way up" parameter?

Or a way to "not rotate" the item.

Your API Have Bug

Please Try Input Below
apibug

<instanceFormArray>
	<instanceForm count="1">
		<instance name="KSE0000010847" width="38" height="19.5" length="18.5" type="product" />
	</instanceForm>
	<instanceForm count="1">
		<instance name="KSE0000009437" width="38" height="19.5" length="18.5" type="product" />
	</instanceForm>
	<instanceForm count="1">
		<instance name="KSE0000003726" width="32.9" height="12.2" length="11.5" type="product" />
	</instanceForm>
	<instanceForm count="1">
		<instance name="KSE0000003109" width="32.9" height="12.2" length="11.5" type="product" />
	</instanceForm>
	<instanceForm count="1">
		<instance name="KSE0000032032" width="38" height="19.5" length="18.5" type="product" />
	</instanceForm>
	<instanceForm count="1">
		<instance name="KSE0000016348" width="38" height="19.5" length="18.5" type="product" />
	</instanceForm>
	<instanceForm count="1">
		<instance name="KSE0000007726" width="32.9" height="12.2" length="11.5" type="product" />
	</instanceForm>
	<instanceForm count="1">
		<instance name="KSE0000024689" width="32.9" height="12.2" length="11.5" type="product" />
	</instanceForm>
</instanceFormArray>
<wrapperArray>
	<instance name="S" price="1" width="38.1" height="40.64" length="29.21" thickness="0" type="wrapper" />
	<instance name="M" price="2" width="38.1" height="55.7" length="39.1" thickness="0" type="wrapper" />
	<instance name="L" price="3" width="40.1" height="86.6" length="49.6" thickness="0" type="wrapper" />
</wrapperArray>

I love your api. Please help me. Thank

Cant get it to work

How can I run the javascript version of your code?
I saw the hosted code and its simply awesome.
Also tell how can I donate some bucks to you/the organization?

Get wrapper products in JSON format

I am not able to find any method for getting products from a given wrapper. I see that the demo has the ability to do this. Is there any way to accomplish this in JSON format? Thanks.

Weight consideration of each box

Hi Sir,

Do you have any idea how to consider the weight of each box? In such a way that heavier boxes should be on the bottom and the lighter would be on the top.

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.