A thin Python wrapper for the Hochbaum Pseudo Flow (HPF) fast s-t min-cut/max-flow algorithm
Project description
Thin wrapper for HPF
Thin Python wrapper for the non-parametric Hochbaum Pseudoflow (HPF) min-cut/max-flow algorithm. The original source code by Bala Chandran and Dorit S. Hochbaum is availbable here. The C++ code used in this wrapper has been refractored by Patrick M. Jensen and published here.
Installation
Install from repository (requires Cython
):
git clone https://github.com/Skielex/thinhpf
cd thinhpf
pip install .
Package will be made available on PyPI later.
Tiny example
import thinhpf
hpf = thinhpf.hpf()
# Add s and t.
next_node_id = hpf.add_node(2)
def offset(n):
return 2 + n
s = 0
t = 1
hpf.set_source(0)
hpf.set_sink(1)
# Number of nodes to add.
nodes_to_add = 2
# Add two nodes.
next_node_id = hpf.add_node(nodes_to_add)
# Add edges.
hpf.add_edge(s, offset(0), 5) # s --5-> n(0)
hpf.add_edge(offset(0), t, 1) # n(0) --1-> t
hpf.add_edge(offset(1), t, 3) # n(1) --3-> t
hpf.add_edge(offset(0), offset(1), 2) # n(0) --2-> n(1)
hpf.add_edge(offset(1), offset(0), 1) # n(1) --1-> n(0)
# Find maxflow/cut hpf.
hpf.mincut()
flow = hpf.compute_maxflow()
for n in range(nodes_to_add):
segment = hpf.what_label(n)
print('Node %d has label %d.' % (n, segment))
# Node 0 has label 0.
# Node 1 has label 1.
print('Flow: %s' % flow)
# Maximum flow: 3
Related repositories
- Hochbaum Group on GitHub
- Original source website
- slgbuilder Python package (CVPR 2020)
- shrdr Python package (ICCV 2021)
- thinqpbo Python package
- thinmaxflow Python package
- C++ implementations of max-flow/min-cut algorithms
License
The original C code by Bala Chandran and Dorit S. Hochbaum and thereby the content of hpf.h
(previously pseudo.c
) is published under an academic license (see LICENSE file). More information on the original website.
Project details
Release history Release notifications | RSS feed
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
Hashes for thinhpf-0.1.1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e3437b215f73df745ece7a847af928cce7614063d406f25d6ded0ea9ba1f4d3 |
|
MD5 | cff8bb0c6e460a086cd307b1a4def469 |
|
BLAKE2b-256 | 07c8d3051b75956c59c045fe491f53cfd7e21bba99fc161f6e986d7e575419ae |
Hashes for thinhpf-0.1.1-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d40532c958a5d28852adf26e61f72dac3c9dc00c033dedcd5530ec2b1f1c78e |
|
MD5 | b2de716592fb2be583cc507468654174 |
|
BLAKE2b-256 | ba558e36bedb452de32e17650755636c56b3446e62ba5faeefc271604b83b4c1 |
Hashes for thinhpf-0.1.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f7d9e14e0d79c2a52489512e1f48489636f15e7d9acba466cbd605a770a132e |
|
MD5 | 36090d8f1e0fb71b445603641c086ed8 |
|
BLAKE2b-256 | 4fadb37882616c315f561a7bcc1c3d9dee79a85e5e2372b38e6275658412ee12 |
Hashes for thinhpf-0.1.1-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e279ddd84c4720d45f8129ef492a1aadb8fadd2abad6eb4cd0ba89454913a82 |
|
MD5 | da9587824bf1f8bccd900143dcb8ca09 |
|
BLAKE2b-256 | c4cac3b54198a28a06aa824dea3e54dd542a821a6bc6ea897a1033f2fdaa5923 |
Hashes for thinhpf-0.1.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b71ee2b72e9509e0f8055b31026b1ae70097616003bd17be8840883c0fd0cabd |
|
MD5 | 3440eca68f6286667df13862a0b5a8d0 |
|
BLAKE2b-256 | 5a5b680e31e1a0e96ba99546ba996bebc807d11a5a739723a6266dc2d705c3a1 |
Hashes for thinhpf-0.1.1-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2e1be8eedd28cd4b85f04a1dfb90cf337fe85301ac038a9193666b1ac077c5f |
|
MD5 | cf18078ab2acfe7a65940efa9cdeb6bb |
|
BLAKE2b-256 | 8d91affa2b9cf52a56de1f78354794add366a71746a4a59103c59a0bb45735cf |
Hashes for thinhpf-0.1.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c8cb2a87ddad6e6e235030090d1a789b94a104da06cefee650d81e51e2cf7e7 |
|
MD5 | 68ae7198ef6b3178139f8485c4b6148e |
|
BLAKE2b-256 | b5ad36f8b1b82ce7a9614309cb65e3ce514fbac2dff0705ff13e143db3866c75 |
Hashes for thinhpf-0.1.1-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6284d702311e34d3eed26def71b9e5de602b561532174cbf9908e85f5af752f5 |
|
MD5 | d3815736f93ebd7fd9e00ccb01dcdd5f |
|
BLAKE2b-256 | 2ce67ac8a17759078171006d6322e4e1bd14c0d94b2a304942b62c43715176d7 |