Skip to main content

A thin Maxflow wrapper for Python

Project description

Thin wrapper for Maxflow

Thin Python wrapper for a modified version of the Maxflow algorithm by Yuri Boykov and Vladimir Kolmogorov. The original source code by Vladimir Kolmogorov availbable at http://pub.ist.ac.at/~vnk/software.html. This wrapper uses a modified version with support for larger graphs and slightly lower memory usage. See submodule repository for more details.

Maxflow vs. QPBO

A more advanced alternative to the Maxflow algorithm is (quadratic pseudo-Boolean optimization) QPBO, which also uses s-t graph cut. Unlike Maxflow, it allows for non-submodular energy terms, which Maxflow doesn't (unless you construct the graph in a specific way, which is what QPBO does). Amongst other things, this allows QPBO to solve optimization problems with exclusions terms, which can be very usefull. QPBO uses more memory and is slightly slower than Maxflow.

Installation

Install package using pip install thinmaxflow or clone this repository (including submodule). Building the package requires Cython.

Graph types

Currently, there are four different types of graphs: GraphInt, GraphShort, GraphFloat and GraphDouble. The only difference is the underlying datatypes used for the edge capacities in the graph. For stability, it is recommended to use GraphInt for integer capacities and GraphDouble for floating point capacities. However, in some cases, it maybe be favourable to use GraphShort or GraphFloat to reduce memory consumption.

Tiny example

import thinmaxflow as tf

# Create graph object.
graph = tf.GraphInt()

# Number of nodes to add.
nodes_to_add = 2

# Add two nodes.
first_node_id = graph.add_node(nodes_to_add)

# Add edges.
graph.add_tweights(0, 5, 0) # s     --5->   n(0)
graph.add_tweights(0, 0, 1) # n(0)  --1->   t
graph.add_tweights(1, 0, 3) # n(1)  --3->   t
graph.add_edge(0, 1, 2, 1)  # n(0)  --2->   n(1)
                            # n(1)  --1->   n(0)

# Find maxflow/cut graph.
flow = graph.maxflow()

for n in range(nodes_to_add):
    segment = graph.what_segment(n)
    print('Node %d belongs to segment %d.' % (n, segment))
# Node 0 belongs to segment 0.
# Node 1 belongs to segment 1.

print('Maximum flow: %s' % flow)
# Maximum flow: 3

License

As the Maxflow implementation is distributed under the GPLv3 license, so is this package.

Project details


Download files

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

Source Distribution

thinmaxflow-0.1.2.tar.gz (89.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

thinmaxflow-0.1.2-cp37-cp37m-win_amd64.whl (52.0 kB view details)

Uploaded CPython 3.7mWindows x86-64

thinmaxflow-0.1.2-cp37-cp37m-macosx_10_13_x86_64.whl (57.9 kB view details)

Uploaded CPython 3.7mmacOS 10.13+ x86-64

thinmaxflow-0.1.2-cp36-cp36m-win_amd64.whl (52.1 kB view details)

Uploaded CPython 3.6mWindows x86-64

thinmaxflow-0.1.2-cp36-cp36m-macosx_10_13_x86_64.whl (45.8 kB view details)

Uploaded CPython 3.6mmacOS 10.13+ x86-64

thinmaxflow-0.1.2-cp35-cp35m-win_amd64.whl (50.6 kB view details)

Uploaded CPython 3.5mWindows x86-64

thinmaxflow-0.1.2-cp35-cp35m-macosx_10_13_x86_64.whl (57.9 kB view details)

Uploaded CPython 3.5mmacOS 10.13+ x86-64

thinmaxflow-0.1.2-cp34-cp34m-macosx_10_13_x86_64.whl (57.5 kB view details)

Uploaded CPython 3.4mmacOS 10.13+ x86-64

thinmaxflow-0.1.2-cp27-cp27m-macosx_10_13_x86_64.whl (57.0 kB view details)

Uploaded CPython 2.7mmacOS 10.13+ x86-64

File details

Details for the file thinmaxflow-0.1.2.tar.gz.

File metadata

  • Download URL: thinmaxflow-0.1.2.tar.gz
  • Upload date:
  • Size: 89.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for thinmaxflow-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4736cd040e1078b96d79a28f6564d59f4c9d20738a18297f2cbf764f5b69759e
MD5 3eb73880b76a8b9b3d39c4ac7674d16f
BLAKE2b-256 ed6a5c67bbfd8430d3ecdfd719f4619f79269f355b1edff782ea94b141772f38

See more details on using hashes here.

File details

Details for the file thinmaxflow-0.1.2-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: thinmaxflow-0.1.2-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 52.0 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for thinmaxflow-0.1.2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 b0033409a1934531d4458b4954f0bfab7c24c86e8eda48b1045c7447906acf83
MD5 714621ccda5c5d3448f1632bee18524d
BLAKE2b-256 849616880e46c74b7eaa9a929c49fe6bdb27d4634e687b36ba277d49e2cea8f6

See more details on using hashes here.

File details

Details for the file thinmaxflow-0.1.2-cp37-cp37m-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: thinmaxflow-0.1.2-cp37-cp37m-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 57.9 kB
  • Tags: CPython 3.7m, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for thinmaxflow-0.1.2-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 619a806869f2f6fd6847462d03944d46ee246691aeb833cddb4de4b58f783ba5
MD5 b0d71254d05b20ffe87414d29335fca7
BLAKE2b-256 7717a867c1d18c61a118252a3bcbe8d0e676267f601a16ec824c0e554937ab27

See more details on using hashes here.

File details

Details for the file thinmaxflow-0.1.2-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: thinmaxflow-0.1.2-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 52.1 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for thinmaxflow-0.1.2-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 f83e1dcc18ccd5afb0531e65a9e5afafe8ef7e19ae7ab978bb2cd118026c9df9
MD5 8aa456384bdf4bd8bcbedbc80a8dc6d2
BLAKE2b-256 f6099aac0d09727d263b824fd10d7d94030fe938f687f847f2bc125aa23dd4d9

See more details on using hashes here.

File details

Details for the file thinmaxflow-0.1.2-cp36-cp36m-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: thinmaxflow-0.1.2-cp36-cp36m-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 45.8 kB
  • Tags: CPython 3.6m, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for thinmaxflow-0.1.2-cp36-cp36m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 1cb845658aa51dded7205817334eae48673d0759674e4b4c61fff208b35141fc
MD5 c9df5ead0b2d8846ce2a25a04f9036af
BLAKE2b-256 32d874e123cbb935d2d3862f505aaf88b8f86fbcc15c29d5122cb2c08108e57a

See more details on using hashes here.

File details

Details for the file thinmaxflow-0.1.2-cp35-cp35m-win_amd64.whl.

File metadata

  • Download URL: thinmaxflow-0.1.2-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 50.6 kB
  • Tags: CPython 3.5m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for thinmaxflow-0.1.2-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 3a1f8049eab3194c8a4d973df09a7ed9fab694205439e1cd73b3c0e8bbe305e7
MD5 80348f2218e50c1c19630745dedc302b
BLAKE2b-256 1e05516faa8a2b6ac8c22569c094e9c45c5bedad484b2e6722c91e6c2585fcbd

See more details on using hashes here.

File details

Details for the file thinmaxflow-0.1.2-cp35-cp35m-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: thinmaxflow-0.1.2-cp35-cp35m-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 57.9 kB
  • Tags: CPython 3.5m, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for thinmaxflow-0.1.2-cp35-cp35m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 aab032be0847476983f5f60c00afcd00f72a3137e33ff03fa3b2007a2a538515
MD5 3412240cf8f940173b8e5861090062a0
BLAKE2b-256 b7390efbf6dd643cb9b6183119ac2e34adf07da5040c86d6726d881345bb23dd

See more details on using hashes here.

File details

Details for the file thinmaxflow-0.1.2-cp34-cp34m-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: thinmaxflow-0.1.2-cp34-cp34m-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 57.5 kB
  • Tags: CPython 3.4m, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for thinmaxflow-0.1.2-cp34-cp34m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 cdd2f37e596fb909c2129d35825a776bf4ee75ce646a98f829c1123d863d6d83
MD5 437eda5df31fa70e585a96841184e1ba
BLAKE2b-256 9d61aad326a0db546fa644270d1e2ec3bd4fc30d66dd967a1e91929f3c1db478

See more details on using hashes here.

File details

Details for the file thinmaxflow-0.1.2-cp27-cp27m-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: thinmaxflow-0.1.2-cp27-cp27m-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 57.0 kB
  • Tags: CPython 2.7m, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for thinmaxflow-0.1.2-cp27-cp27m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 9abde6b943a18d2632828ea28b8d6cf779e178722deba55a108382a63aede487
MD5 294bb457592dfa31662f2d5758787aa2
BLAKE2b-256 9c4eabd0ab71ee6a67e7fc6547220859844a4034ecf27cdacdfebe74a093feb7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page