Skip to main content

An exact cover solver that returns all solutions for a given problem

Project description

DXZ

dxz is a Python package that implements the dxz algorithm that is described in the paper Dancing with Decision Diagrams: A Combined Approach to Exact Cover. The algorithms returns all solutions to a given exact cover problem.

Installation

Use the package manager pip to install dxz.

pip install dxz

The Algorithm

dxz is an algorithm for solving an exact cover problem. It build a zdd that represents all solutions for a given problem. This module converts the zdd to to a list of lists of ints. Each list in the list represents one solution.

For more details about dxz read the paper Dancing with Decision Diagrams: A Combined Approach to Exact Cover.

Usage

import dxz

rows = 8
columns = 5

# A flatten matrix of boolean values. Row 0 is 1,0,0,1,1 row 2 is 0,1,1,0,0 and so on.
matrix = [
    1,0,0,1,1, # 0
    0,1,1,0,0, # 1
    0,0,0,1,1, # 2
    0,1,0,1,0, # 3
    1,0,1,0,0, # 4
    0,0,0,0,1, # 5
    0,0,0,1,0, # 6
    1,0,0,0,0, # 7
]

# Get all solutions to the exact cover problem.
solutions = dxz.dxz_solve(rows, columns, matrix, 0)

print(solutions)
# [
#   [1,0],
#   [1,7,2],
#   [1,7,6,5],
#   [3,4,5]
# ]
# One solutions is row 1 and 2 another solution is row 1, 7 and 2.

# Get only the number of solutions
number_of_solutions = dxz.dxz_count(rows, columns, matrix)


# Get only 3 solutions.
solutions = dxz.dxz_solve(rows, columns, matrix, 3)

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

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

dxz-0.0.6.tar.gz (7.9 kB view details)

Uploaded Source

File details

Details for the file dxz-0.0.6.tar.gz.

File metadata

  • Download URL: dxz-0.0.6.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for dxz-0.0.6.tar.gz
Algorithm Hash digest
SHA256 32d2e957f537c24ee8df54e0fd8cd6e8d62ea37a59ebfbfebb61b4c4c7782091
MD5 f5861ccf2b49796e6d3751474b400c51
BLAKE2b-256 dcf5049f7af622aae07d1f6efd57b7f76834853de4a74266b061ec689f2b2c3e

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