Skip to main content

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

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


Download files

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

Source Distribution

thinhpf-0.1.1.tar.gz (187.1 kB view hashes)

Uploaded Source

Built Distributions

thinhpf-0.1.1-cp310-cp310-win_amd64.whl (125.0 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

thinhpf-0.1.1-cp310-cp310-macosx_10_15_x86_64.whl (170.5 kB view hashes)

Uploaded CPython 3.10 macOS 10.15+ x86-64

thinhpf-0.1.1-cp39-cp39-win_amd64.whl (125.6 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

thinhpf-0.1.1-cp39-cp39-macosx_10_15_x86_64.whl (171.1 kB view hashes)

Uploaded CPython 3.9 macOS 10.15+ x86-64

thinhpf-0.1.1-cp38-cp38-win_amd64.whl (125.8 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

thinhpf-0.1.1-cp38-cp38-macosx_10_14_x86_64.whl (170.6 kB view hashes)

Uploaded CPython 3.8 macOS 10.14+ x86-64

thinhpf-0.1.1-cp37-cp37m-win_amd64.whl (126.3 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

thinhpf-0.1.1-cp37-cp37m-macosx_10_14_x86_64.whl (170.2 kB view hashes)

Uploaded CPython 3.7m macOS 10.14+ x86-64

Supported by

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