Skip to main content

Solver using Simulated Bifurcation

Project description

COSBr

Combinatorial Optimization Solver using discrete simulated Bifurcation in C++ with Python bindings.

Description

COSBr is a Python package that provides fast C++ implementations of Discrete Simulated Bifurcation (DSB) algorithms for solving combinatorial optimization problems.

Installation

pip install cosbr

Usage

Basic Usage

import numpy as np
from cosbr import gcp_solver

# Create adjacency matrix
adj_matrix = np.zeros((5, 5))
adj_matrix[0, 1] = adj_matrix[1, 0] = 1.0
adj_matrix[0, 3] = adj_matrix[3, 0] = 1.0
adj_matrix[1, 4] = adj_matrix[4, 1] = 1.0
adj_matrix[2, 3] = adj_matrix[3, 2] = 1.0

# Convert to list of lists format (required for the C++ function)
adj_matrix_list = adj_matrix.tolist()

# Solve the graph coloring problem with 2 colors
best_coloring, energy_history = gcp_solver(
    adj_matrix_list,  # adj_matrix
    2,                # num_colors
    100,              # R = 100 runs
    20000,            # max_iter = 20000
    0.05,             # dt = 0.05
    1.0,              # A = 1.0
    0.5,              # alpha_init = 0.5
    0.999             # alpha_scale = 0.999
)

# Print final energy
print(f"Final energy: {energy_history[-1]}")

# Convert the coloring to a more usable format
vertex_colors = []
for i, colors in enumerate(best_coloring):
    for c, is_colored in enumerate(colors):
        if is_colored > 0:
            vertex_colors.append(c)
            break

print(f"Vertex colors: {vertex_colors}")

Advanced Usage

from cosbr import solve_graph_coloring

# This is a convenience function that returns additional information
best_coloring, energy_history, final_energy = solve_graph_coloring(
    adj_matrix_list,  # adj_matrix
    2                 # num_colors
)

print(f"Final energy: {final_energy}")

Features

  • Fast C++ implementation of Discrete Simulated Bifurcation algorithm
  • Python bindings with numpy support
  • Multiple runs with different initializations to find the best solution
  • Support for different parameters to tune the optimization process

License

MIT License

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

cosbr-0.1.1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cosbr-0.1.1-cp312-cp312-macosx_11_0_arm64.whl (67.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file cosbr-0.1.1.tar.gz.

File metadata

  • Download URL: cosbr-0.1.1.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cosbr-0.1.1.tar.gz
Algorithm Hash digest
SHA256 dcd64066d25cc2118d85c1713c39b42926671a0b4ae7f97a5e0809d01cae6972
MD5 0d28034707271f220d0e1876af7cd544
BLAKE2b-256 174bd3e69733ed63f2639d32790eb78fa3dfaeb40767b58f9452a7a0f935cf5c

See more details on using hashes here.

File details

Details for the file cosbr-0.1.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cosbr-0.1.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 712bfe9c36953d17b9523b18eba884405c0007f6e715f16d769af52baef70878
MD5 653e94b59e9abf18c0ee140816ed6eb0
BLAKE2b-256 d010b7251251d0d07fffd5b526eec8952fb84f9fe6e0d146280ab378446706d4

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