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

Apache

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.0.tar.gz (9.8 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.0-cp312-cp312-macosx_11_0_arm64.whl (70.8 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: cosbr-0.1.0.tar.gz
  • Upload date:
  • Size: 9.8 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.0.tar.gz
Algorithm Hash digest
SHA256 5b067691f0ac3598123a2f5ad19948730793b59d180503419ffdac542001b2cf
MD5 62a1047779875124198d969fd565ce76
BLAKE2b-256 048b0261de1d946dcd29f87df0dfdb0899b9a820984f7127f849de169d536695

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosbr-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 14bfde87dabd3723fa29b5626212eb1677913ad4d38fe21475226a69ec6d15a1
MD5 a65267a5e05ca7b6a157f3ea66e5ef8a
BLAKE2b-256 3af2f81cceb3b2b630c8f52a93ec7942f87820b735f23e0db24dddf392877c44

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