Skip to main content

A thin QPBO wrapper for Python

Project description

Thin wrapper for QPBO

Thin Python wrapper for a modified version of the quadratic pseudo-Boolean optimization (QPBO) algorithm by 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.

QPBO vs. Maxflow

While the QPBO algorithm performs a s-t graph cut similar to Maxflow, it allows for non-submodular energy terms, which Maxflow doesn't. Amongst other things, this allows QPBO to solve optimization problems with exclusions terms, which can be very usefull. The graph constructed by the QPBO implementation is twice the size of a Maxflow graph for an equivalent problem. Thus, QPBO uses more memory and is slightly slower than Maxflow.

Installation

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

Graph types

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

Advanced features (QPBO-P and QPBO-I)

The QPBO implementation has a few advanced extensions known as QPBO-P and QPBO-I. Currently, not all advanced functions have been wrapped. If you need to use features of the QPBO C++ library that are not wrapped by thinqpbo, please let me know by creating an issue on GitHub.

Tiny example

import thinqpbo as tq

# Create graph object.
graph = tq.QPBOInt()

# 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_unary_term(0, 0, 5) # E1(0) = 5, s     --5->   n(0)
graph.add_unary_term(0, 1, 0) # E0(0) = 1, n(0)  --1->   t
graph.add_unary_term(1, 5, 0) # E0(1) = 5, n(1)  --5->   t
graph.add_pairwise_term(0, 1, 0, 7, 0, 4)   # E01(0,1) = 7, n(0)  --7->   n(1)
                                            # E11(0,1) = 4, Not possible with standard Maxflow


# Find maxflow/cut graph.
graph.solve()
graph.compute_weak_persistencies()
twice_energy = graph.compute_twice_energy()

for n in range(nodes_to_add):
    segment = graph.get_label(n)
    print('Node %d has label %d.' % (n, segment))
# Node 0 has label 0.
# Node 1 has label 0.

print('Twice energy/flow: %s' % twice_energy)
# Twice energy/flow: 12

License

As the QPBO 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

thinqpbo-0.1.4.tar.gz (112.9 kB view details)

Uploaded Source

Built Distributions

thinqpbo-0.1.4-cp39-cp39-win_amd64.whl (75.4 kB view details)

Uploaded CPython 3.9 Windows x86-64

thinqpbo-0.1.4-cp39-cp39-macosx_10_14_x86_64.whl (100.1 kB view details)

Uploaded CPython 3.9 macOS 10.14+ x86-64

thinqpbo-0.1.4-cp38-cp38-win_amd64.whl (75.4 kB view details)

Uploaded CPython 3.8 Windows x86-64

thinqpbo-0.1.4-cp38-cp38-macosx_10_14_x86_64.whl (99.9 kB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

thinqpbo-0.1.4-cp37-cp37m-win_amd64.whl (74.9 kB view details)

Uploaded CPython 3.7m Windows x86-64

thinqpbo-0.1.4-cp37-cp37m-macosx_10_14_x86_64.whl (102.7 kB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

thinqpbo-0.1.4-cp36-cp36m-win_amd64.whl (75.0 kB view details)

Uploaded CPython 3.6m Windows x86-64

thinqpbo-0.1.4-cp36-cp36m-macosx_10_14_x86_64.whl (102.8 kB view details)

Uploaded CPython 3.6m macOS 10.14+ x86-64

thinqpbo-0.1.4-cp27-cp27m-macosx_10_14_x86_64.whl (99.1 kB view details)

Uploaded CPython 2.7m macOS 10.14+ x86-64

File details

Details for the file thinqpbo-0.1.4.tar.gz.

File metadata

  • Download URL: thinqpbo-0.1.4.tar.gz
  • Upload date:
  • Size: 112.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for thinqpbo-0.1.4.tar.gz
Algorithm Hash digest
SHA256 bc0475bb93fa37e0af64efbd3a8c487941b5aa671e668028d144e28453887846
MD5 fdbdbff71077a8e8ceacfc8c2911c97e
BLAKE2b-256 e982f80001cb54d3d6d7203943565a766c2e85b67b75084c458d8568b555c92d

See more details on using hashes here.

File details

Details for the file thinqpbo-0.1.4-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: thinqpbo-0.1.4-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 75.4 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for thinqpbo-0.1.4-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 a41b30458f98e84c7c451a3564abddf6bed655f3bb0751ace89f56bd7996f664
MD5 8cb9fa61e786988b396fc330105163ff
BLAKE2b-256 c4870c28ace1026fd099b6267299ab5c940f18be30763d52cdc03fbafc37101d

See more details on using hashes here.

File details

Details for the file thinqpbo-0.1.4-cp39-cp39-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: thinqpbo-0.1.4-cp39-cp39-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 100.1 kB
  • Tags: CPython 3.9, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for thinqpbo-0.1.4-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 85590bbdd4dfbe5d09008278a0aa9423639576c81e84fb074b50e6eff6bbcb8f
MD5 ad36113702d1145310bb8dad1639f250
BLAKE2b-256 c2931b456df8218e9e014e321927d38b1f43fb5d594937ff219e7a03443c8e8e

See more details on using hashes here.

File details

Details for the file thinqpbo-0.1.4-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: thinqpbo-0.1.4-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 75.4 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for thinqpbo-0.1.4-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 16c28700cfbed7211555886e8fac4a3b56774361312fcb4b7df4898d023ad0f0
MD5 bff4d63e80f9f424b0b016b2e194ac10
BLAKE2b-256 0ee13816237ed1a7468b8f1204e11c5eff9b12de8146c1a053c028fccd1bd76c

See more details on using hashes here.

File details

Details for the file thinqpbo-0.1.4-cp38-cp38-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: thinqpbo-0.1.4-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 99.9 kB
  • Tags: CPython 3.8, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for thinqpbo-0.1.4-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 19ec9e7e1378037445846c7c97de92c319b691ae2695fda45f821d7ed97016cf
MD5 5ee217e51530e1b290226e272b4bb351
BLAKE2b-256 15f4c851497da906f53d85c10e9be192fecb2001896cd7d1ea937df46d0c3dad

See more details on using hashes here.

File details

Details for the file thinqpbo-0.1.4-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: thinqpbo-0.1.4-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 74.9 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for thinqpbo-0.1.4-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 8e7a9b217022e934a26260acd85a23e351911fbe2bfd823b78e030dcb5776fe3
MD5 d3033288d1deba757f469641cdd22f67
BLAKE2b-256 ab99965714525cbbfb1b64fe327fb30d11557220cfc58170315770d8693c6bfb

See more details on using hashes here.

File details

Details for the file thinqpbo-0.1.4-cp37-cp37m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: thinqpbo-0.1.4-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 102.7 kB
  • Tags: CPython 3.7m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for thinqpbo-0.1.4-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 c415922b4c3eddd6ce2422cf8538057428dc0cf0fc3e1d20fa201e8a4078f84e
MD5 8c334e37a34fba328ef96c159f830862
BLAKE2b-256 a0a0b63183c603c7ded17efc345dd8fad6aa3dc23b89b6cd09ddd481707e65d3

See more details on using hashes here.

File details

Details for the file thinqpbo-0.1.4-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: thinqpbo-0.1.4-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 75.0 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for thinqpbo-0.1.4-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 700c82f78b5a1b88fec2e226e1c19529ef95224fec060b86a2af5a38d72c9142
MD5 5b6da3e38eb436cfcdcd3b746534091e
BLAKE2b-256 0eff88430eab91ef38e20934f38fb21126698bf34b7718f1b639eca77253ffc8

See more details on using hashes here.

File details

Details for the file thinqpbo-0.1.4-cp36-cp36m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: thinqpbo-0.1.4-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 102.8 kB
  • Tags: CPython 3.6m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for thinqpbo-0.1.4-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 64f679fa873fa05bb9e9f81bc15376be8baedf49df32de7846afb6cf11753c8f
MD5 6ef0c82831c73af5d089b22e9bde701a
BLAKE2b-256 07750d181bcefe03b70fea3cd42d0247c4032bfc2f3f636535ed86dfdc5090a4

See more details on using hashes here.

File details

Details for the file thinqpbo-0.1.4-cp27-cp27m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: thinqpbo-0.1.4-cp27-cp27m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 99.1 kB
  • Tags: CPython 2.7m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for thinqpbo-0.1.4-cp27-cp27m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 41f3ba1cc4b27a95fdd8a60f56ad874f112d4e124c44e82114b0b34dd95c43fd
MD5 4654685bee74f225e43a364f211bf4dc
BLAKE2b-256 b475c5d18931f6633f3b633912764e4ccabbbc3a90ed491afb00011c689f87bb

See more details on using hashes here.

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