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
Metadata
Release files for cosbr 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cosbr-0.1.1.tar.gz | 6.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cosbr-0.1.1-cp312-cp312-macosx_11_0_arm64.whl | CPython 3.12 | CPython 3.12 | macOS 11.0+ ARM64 | Details |
Total release size: 74.0 kB
Release files / cosbr-0.1.1.tar.gz
| Download URL | cosbr-0.1.1.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dcd64066d25cc2118d85c1713c39b42926671a0b4ae7f97a5e0809d01cae6972
|
|
BLAKE2b-256 checksum How to use checksums |
174bd3e69733ed63f2639d32790eb78fa3dfaeb40767b58f9452a7a0f935cf5c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / cosbr-0.1.1-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | cosbr-0.1.1-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 67.5 kB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
712bfe9c36953d17b9523b18eba884405c0007f6e715f16d769af52baef70878
|
|
BLAKE2b-256 checksum How to use checksums |
d010b7251251d0d07fffd5b526eec8952fb84f9fe6e0d146280ab378446706d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|