项目作者: dgisolfi

项目描述 :
The multidimensional 0–1 knapsack problem solved using a greedy algorithm.
高级语言: Python
项目地址: git://github.com/dgisolfi/mkp.git
创建时间: 2020-03-22T22:47:30Z
项目社区:https://github.com/dgisolfi/mkp

开源协议:MIT License

下载


mkp

The multidimensional 0–1 knapsack problem solved using a greedy algorithm.

About

This tool was born from nessecity and can be used to determine any combination of balanced knapsacks based on an object’s value.

Problem Statement

note: Although the following is not the only use for this tool, this was the original use case.

You are holding a Beer Olympics, the goal is to create teams that are equally matched(or as close as possible) to ensure each team has a fair chance. Each player has a rating for each event, the ratings add up to the player’s overall value. Implement a greedy algorithm to solve the multidimensional 0–1 knapsack problem.

Details:

  • Each team has 3 players
  • there are 5 teams
  • Each player has a total value that is calculated by the given file inputs

File input:

Below are the details about each player. The rating for each player is separated by a semi-colon, all ratings should be summed to find a player’s value.

  1. -- Name; Case Race; Beer Ball; Flip 50;
  2. Nicole;1;2;2;
  3. Jenna;2;2;5;
  4. Krendan;4;3;3;
  5. Dylan;4;3;3;
  6. Luke;5;5;3;
  7. Jason;5;4;3;
  8. Brendan;5;4;3;
  9. James E;3;3;3;
  10. Aidan;3;4;5;
  11. Daniel;4;5;4;
  12. Maya;3;3;5;
  13. James C;3;3;3;
  14. Kayvan;3;2;2;
  15. Steph;3;2;4;
  16. Kevin;3;3;3;

Installation

For installation just run the make target

make

Usage

CLI

  1. mkp -h
  2. Usage: __main__.py [OPTIONS]
  3. Options:
  4. -h, --help Show this message and exit.
  5. --version Show the version and exit.
  6. -e, --examples Generate example files
  7. -k, --knapsacks INTEGER The total number of knapsacks to fill [required]
  8. -c, --capacity INTEGER The capacity of each knapsack [required]
  9. -f, --file PATH Path to objects for knapsacking [required]

Input

the object input is provided via a file, the format for which is defined below.

Comment Deliminator: --

  1. -- Object Title; Event 1 Rating; Event 2 Rating; ... Event N Rating;

Development

To get all necessary dependencies run:

  1. make init

Then enter a new pipenv shell via:

  1. pipenv shell

Now to run the cli from source run

  1. python3 -m mkp