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
Built Distributions
File details
Details for the file thinmaxflow-0.1.5.tar.gz
.
File metadata
- Download URL: thinmaxflow-0.1.5.tar.gz
- Upload date:
- Size: 151.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a90bc2c47177ba510d561581ee45b51a21da9e051c6b099e82bb022e3b7746b |
|
MD5 | 7b4a319705426b43719fa936094b6cfc |
|
BLAKE2b-256 | bb158d73e7faf40fc45ca1ecc5d4212b6e70aae9e049645ab9f005d21ee28f62 |
File details
Details for the file thinmaxflow-0.1.5-cp312-cp312-win_amd64.whl
.
File metadata
- Download URL: thinmaxflow-0.1.5-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 79.3 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05ddf3744553280b4f07984fe2b1cccd32a5c07316a82631a53338c23784e8b6 |
|
MD5 | b1967f1bca3bee2676bf2869359c9270 |
|
BLAKE2b-256 | 1d674348464c7ae7d5739572f0f7499df9629b6325c349aa7caf65883ab7d31a |
File details
Details for the file thinmaxflow-0.1.5-cp312-cp312-macosx_10_9_universal2.whl
.
File metadata
- Download URL: thinmaxflow-0.1.5-cp312-cp312-macosx_10_9_universal2.whl
- Upload date:
- Size: 175.3 kB
- Tags: CPython 3.12, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 929d31c94af1a87cfc76fe2c3d3ba9654297f3f8e1f2e84683a8ee160c4a0fec |
|
MD5 | 5404a26fe91691d1aa3b955081d4714e |
|
BLAKE2b-256 | a597cb0f386d99014bd7d81b1dd58afa53fc80fe4c72d2f08136ad7c822763f0 |
File details
Details for the file thinmaxflow-0.1.5-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: thinmaxflow-0.1.5-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 77.8 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 425e15bd511c3a12f625f61cba087b59d9dcf33f306bf88d8d368887312a24a6 |
|
MD5 | 9e5783b768eee371f4aacf5657c5ec79 |
|
BLAKE2b-256 | efabd92672ca67f78b5ffe96df8094a3ad564bab7410c54dd8cf5624feccc3c3 |
File details
Details for the file thinmaxflow-0.1.5-cp311-cp311-macosx_10_9_universal2.whl
.
File metadata
- Download URL: thinmaxflow-0.1.5-cp311-cp311-macosx_10_9_universal2.whl
- Upload date:
- Size: 175.2 kB
- Tags: CPython 3.11, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5279fdbdc393425ce645855986a49e39b82ec556a2b1b63f55b599a90a2a6f1e |
|
MD5 | 6588cb342f616d09444520dfe468bad2 |
|
BLAKE2b-256 | 45c3325c192dbb2ca8d4b1791869705bcac65d64ca005003ebb9407a522be043 |
File details
Details for the file thinmaxflow-0.1.5-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: thinmaxflow-0.1.5-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 77.5 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86ed217ee69e065759de9452c47e83ea9b7382308ecb06bad49fc29f7c29ad3e |
|
MD5 | 16efe5226c917404b7923a52758ebb37 |
|
BLAKE2b-256 | cc7d08aedbedfbf49da729ec2c1e1ea0f5d2e2042ab7f7c749e45634284c83a1 |
File details
Details for the file thinmaxflow-0.1.5-cp310-cp310-macosx_12_0_x86_64.whl
.
File metadata
- Download URL: thinmaxflow-0.1.5-cp310-cp310-macosx_12_0_x86_64.whl
- Upload date:
- Size: 94.7 kB
- Tags: CPython 3.10, macOS 12.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad1af5d877a0f12d7c2eb637da8caf37a31c87d608921f0aabd1029b02eb6795 |
|
MD5 | 1903c18dd63e0ae1fc2ecc64366d76a0 |
|
BLAKE2b-256 | 778506e6db79ae788abe1d993f0fb3256995a3a9f4f40eda7d7072d372eba77c |
File details
Details for the file thinmaxflow-0.1.5-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: thinmaxflow-0.1.5-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 78.1 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 011e39f09656d15dbba55941a4a6a461a40c6683595a9021ed38c5859ab68b33 |
|
MD5 | 13c488e4a36a745834b1d727b671bc98 |
|
BLAKE2b-256 | b6e979468e91b3b2a4cd1679268cb0829f8b217736fe23a9d086bc71c8a365c4 |
File details
Details for the file thinmaxflow-0.1.5-cp39-cp39-macosx_12_0_x86_64.whl
.
File metadata
- Download URL: thinmaxflow-0.1.5-cp39-cp39-macosx_12_0_x86_64.whl
- Upload date:
- Size: 95.4 kB
- Tags: CPython 3.9, macOS 12.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97b0483ce00f0730b6ba3b8f1908a9a0e251a327271d00cdc30d046c4642783d |
|
MD5 | e25dc175dc165e309355f9f1c6e26288 |
|
BLAKE2b-256 | 48462e0240f38e9dcdf6dda1ead7a1f3fe216d81c0d2e8e9dcd89c9649b25af2 |