GithubHelp home page GithubHelp logo

albert-espin / knapsack-packing Goto Github PK

View Code? Open in Web Editor NEW
51.0 3.0 17.0 212.04 MB

Evolutionary Algorithm for the 2D Packing Problem combined with the 0/1 Knapsack Problem (Master Thesis)

License: Other

Python 67.70% TeX 32.30%
knapsack-problem evolutionary-algorithm knapsack-packing algorithm algorithms packing packing-algorithm knapsack knapsack01 irregular-packing

knapsack-packing's Introduction

An Evolutionary Algorithm for Solving the Two-Dimensional Packing Problem Combined with the 0/1 Knapsack Problem

Introduction

This project contains the code to solve a combination of the Packing Problem and the Knapsack Problem in 2D: different items with value, weight and shape can be placed in a container (of a certain shape), and the goal is to maximize the value of items placed in the container, without geometric intersections nor exceeding a maximum weight limit (capacity) of the container. Check the report for a more detailed explanation of the problem, the developed algorithms (present in the "KnapsackPacking") and the performed experiments (whose results, including many plots, can be found in the "Output" folder).

Performing experiments

To run the code, Python 3.x is required, with the following packages:

  • matplotlib
  • numpy
  • pandas
  • pickle
  • shapely

The file to run is "problem_experiments.py". An IDE is recommended, but running from terminal should be possible too. By default, the problems created in functions invoked by "create_problems()" are used, but you can replace them with your own problem definitions, following the same syntax scheme.

This repository includes files that summarize experiments. You can set whether the saved experiments should be loaded (or otherwise run new ones) in the following line:

load_experiments = True

You can set how many times to run each algorithm on each problem, and whether multiple process (how many) should be used:

execution_num = 10
process_num = 10

When performing experiments, you can select which data should be saved or plotted:

show_problem_stats = False
save_problem_stats = False
show_manual_solution_plots = False
save_manual_solution_plots = False
show_algorithm_solution_plots = False
save_algorithm_solution_plots = False
show_value_evolution_plots = False
save_value_evolution_plots = False
show_time_division_plots = False
save_time_division_plots = False
show_algorithm_comparison = False
save_algorithm_comparison = False
show_aggregated_result_tables = True
save_aggregated_result_tables = False

You can change the implementation or default parameters of the developed algorithms in their respective files:

  • Evolutionary algorithm in "evolutionary.py".
  • Greedy algorithm in "greedy.py".
  • Reversible algorithm in "reversible.py"

The supported shapes for items are:

  • Polygons (supported by Shapely).
  • Compound polygons with holes, a.k.a. multi-polygons (supported by Shapely).
  • Circles (added in "circle.py").
  • Ellipses (added in "ellipse.py").

You can add new shapes if you want, by first checking how circles and ellipses were defined (and their intersection checks with the rest of items).

Solution examples

The solutions obtained by the evolutionary algorithm for some of the tested problems are shown below. In these 7 problems, the result is optimal, i.e. the maximum possible value is obtained. In the Joint (Knapsack + Packing) Problem, a solution can be optimal even if some items are left outside of the container (even if there is enough geometrical space available), namely in cases where the weight limit would be exceeded and no other combination of placed items would have yielded higher value. More details about these and other problems can be found in the report.

Problem 1

Problem 2

Problem 3

Problem 4

Problem 6

Problem 7

Problem 8

Research context

This work was submitted as Master Thesis for Master in Artificial Intelligence of Universitat Politècnica de Catalunya (UPC), in January 2020. The official publication in the repository of the University can be found here.

knapsack-packing's People

Contributors

albert-espin 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

Watchers

 avatar  avatar  avatar

knapsack-packing's Issues

# Circles in square; Can't be the same with the Wolfram Alpha query:

Hi Albert-espin
The knapsack-packing algorithm is really nice. I love it so much.
But when i try the example as follow, i encount problem. Can you help me? Maybe it can be solve by adjusting the parameters of the three algorithms. The problem is followed. and I try the isosceles_triangle +Rectangle, isosceles_triangle + circle case.

The result is different from the Wolfram Alpha query: "pack 70 circles of radius 17 in a square of side 300"; full link https://www.wolframalpha.com/input?i=pack+70+circles+of+radius+17+in+a+square+of+side+300

WF
Problem1
image
image

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.