Giter VIP home page Giter VIP logo

2d-bin-packing-heuristic's Introduction

2D-bin-packing-heuristic

This repo contains a 2D bin packing strategy that is based on two greedy heuristics. This is my interpretation of Dahmani et. al. "Self-adaptive metaheuristics for solving a multi-objective 2-dimensional vector packing problem," Applied Soft Computing (2014). It can be used by itself or in conjunction with an optimization algorithm.

The included code was written for the bin packing problem of sorting ideal two-dimensional items into larger bins. Each small item has a unique weight and a height associated with it. The larger bins all have the same maximum weight and height allowance, as shown in the figure below.

2D Bin Packing Problem

My problem is a multi-objective problem where one of the objectives is to minimize the number of bins used. The number of bins used in each solution can vary as there are other objectives to satisfy. The binpacking.py script takes a list of small item indices, such as:

genes = [1, 2, ..., N]

and translates it into an x and y matrix, as shown in the figure below.

LoadingMatrices

Here, N is the total number of small items to be sorted, and M is the theoretical maximum number of larger bins needed. The i-indices relate to individual bins, and the j-indices relate to individual small items. The x-matrix shows where each item is located, and the y-matrix indicates which bins are in use. In the python script, it is assumed that each item was assigned a number from 1 to N. Also, to avoid changing the size of the matrices during the calculation, the x- and y-matrices are initialized with M = N, and the m variable in the script keeps of how many open bins there are.

For binpacking.py to work, you need an input file containing a list of items. The example included in the example folder contains 500 items. The first line indicates the max. weight and height of a bin, and then each line after that is a weight and height for a given item. The example file was generated using 2DCPackGen. The items.py file creates item objects from an Item class, and the constraints.py file checks to make sure a given packing does not violate the constraints.

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.