Skip to main content

Python number partition algorithm library

Project description

madge

Last version Build Status Python Version Coverage Downloads

partition

```partiton` is a Python algorithm library which provides efficient algorithms for the number partition problem. You can also use it from shell command. These algorithms have many applications. One typical one is for parallel software testing. Currently, the following three algorithms are supported:

  • greedy algorithm, which is a benchmark algorithm with simple login
  • differencing algorithm, a.k.a. Karmarkar–Karp(KK) algorithm
  • dynamic programming(DP) algorithm, which is optimal for scenarios where the size of integers is not too large

Install

Use pip:

pip install partition

From source code:

python setup.py develop

How to use

command line usage

Get help:

partition -h

Query version:

partition --version

Available options:

usage: partition [-h] [--numbers NUMBERS] [--grouplen GROUPLEN]
                 [--algorithm {greedy,kk,dp}] [--version]

optional arguments:
  -h, --help            show this help message and exit
  --numbers NUMBERS     integer numbers to be partitioned, seperated by comma
  --grouplen GROUPLEN   length of groups to hold the partitioned integer
                        numbers, default is 2
  --algorithm {greedy,kk,dp}
                        select partition algorithms, available options are
                        greedy, kk and dp
  --version             print version

For example:

root@foo:~# partition --numbers 1,2,3,4,5 --grouplen 2 --algorithm greedy
Partition 1,2,3,4,5 into 2 groups, using algorithm: greedy
Group: 0, numbers: [5, 2, 1]
Group: 1, numbers: [4, 3]
Min group sum: 7, Max group sum: 8, difference: 1
Group(s) with min sum: [4, 3]
Group(s) with max sum: [5, 2, 1]
([[5, 2, 1], [4, 3]], 1)

python library usage

In [1]: import partition

In [2]: partition.partition.__version__
Out[2]: '0.1.0'

In [3]: partition.greedy.greedy([1,2,3,4,5], 2)
Out[3]: [[5, 2, 1], [4, 3]]

In [4]: partition.kk.kk([1,2,3,4,5], 2)
Out[5]: [[5, 3], [1, 2, 4]]

Lisense

MIT

Maintenance

This tool is developed by slxiao. You are welcome to raise any issues about the tool.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for partition, version 0.1.2
Filename, size File type Python version Upload date Hashes
Filename, size partition-0.1.2-py2-none-any.whl (5.4 kB) File type Wheel Python version py2 Upload date Hashes View hashes
Filename, size partition-0.1.2.tar.gz (4.3 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page