Centralized and distributed CSP framework (CSP/DCSP)
Project description
CSP / DCSP Framework
A Python framework for centralized and distributed constraint satisfaction:
csp/: core CSP modeling, propagation, search, encoding, benchmark definitionsdcsp/: distributed architectures and algorithms (variable-agent and constraint-agent models)
The framework is designed so you can model once and solve either centrally or distributed with minimal API changes.
Table of Contents
- Feature Overview
- Repository Structure
- Installation
- Import Cheat Sheet (what to import for what)
- Central CSP Workflows
- Distributed CSP Workflows
- Tree-based / Constraint-Agent Mapping Workflow
- Graph Export and Visualization
- Benchmarks
- Testing and Verification
- Documentation Website (MkDocs + GitHub Pages)
- Contributing
1) Feature Overview
Central CSP (csp)
- CSP modeling (
CSP, variables, constraints) - Propagation:
gac,vlac - Search:
bt,fc,mac,mc(+ aliases/suffix forms) - Optional binarization support:
dual,hidden,double - Built-in benchmark registry (
csp.benchmarks)
Distributed CSP (dcsp)
- Architectures:
- variable-agent (
variable,var,one-var) - constraint-agent (
constraint,cons)
- variable-agent (
- Distributed propagation:
dgac(distributed-gac,distributed_gac)
- Distributed search:
sbt,abt,awcs,afc,dba,dsa,aas,compapo
- Constraint-agent utilities:
- assignment validation
- pseudo-tree assignment generation
2) Repository Structure
csp/ # Centralized CSP package
api.py # run_propagation, run_search, print_result
core.py # CSP data model
solvers.py # search backends
propagation.py # GAC
propagation_vlac.py # VLAC
encodings.py # dual/hidden/double encoding
benchmarks.py # benchmark registry + factories
dcsp/ # Distributed CSP package
api.py # run_distributed_search/propagation
architectures/ # agent-model builders
algorithms/ # distributed algorithms
propagation.py # DGAC implementation
mapping.py # model mapping helpers
main.py # Comment-first usage guide (all calls disabled)
README.md # This document
docs/ # MkDocs documentation source
tests/ # Unit tests
mkdocs.yml # MkDocs site config
3) Installation
Use Python 3.10+.
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
python -m pip install -U pip
Optional dependencies by feature:
sympy→ required for VLAC symbolic processingnumpy→ required by constraints that usenp.*(e.g. some engineering constraints)networkx+matplotlib→ graph export/visualizationpytest(optional) or built-inunittestfor testsmkdocs+mkdocs-materialfor docs site
4) Import Cheat Sheet (what to import for what)
4.1 Minimal central CSP solving
from csp.core import CSP
from csp.api import run_search, print_result
4.2 Central propagation
from csp.core import CSP
from csp.api import run_propagation, print_result
4.3 Binarization support
from csp import binarize_csp
4.4 Benchmark loading
from csp import benchmarks
4.5 Distributed search (CSP or prebuilt model)
from dcsp.api import run_distributed_search
from csp.api import print_result
4.6 Distributed propagation (DGAC)
from dcsp.api import run_distributed_propagation
from csp.api import print_result
4.7 Constraint-agent model building and mapping helpers
from dcsp import (
build_constraint_agent_model,
validate_constraint_assignment,
build_pseudotree_constraint_assignment,
)
4.8 Graph export / visualization
from csp.core import CSP
# then use csp.to_graph(), csp.visualize_graph(...)
5) Central CSP Workflows
5.1 Build a model manually
from csp.core import CSP
csp = CSP()
csp.add_variable("x", {1, 2, 3})
csp.add_variable("y", {1, 2, 3})
csp.add_constraint("c1", "x < y")
5.2 Run propagation
from csp.api import run_propagation, print_result
pr = run_propagation("gac", csp)
print_result(pr)
if pr.ok:
csp_reduced = pr.reduced_csp
else:
csp_reduced = csp
Supported run_propagation algorithms:
gac(aliases:ac,ac3,arc)vlac
5.3 Run search
from csp.api import run_search, print_result
sr = run_search(
"mac-gac",
csp,
deterministic=True,
heuristics=["mrv", "lcv"],
find_all_solutions=False,
)
print_result(sr)
Supported run_search algorithms:
bt/backtrackingfc/forward-checking/forward_checkingmac/maintaining-arc-consistency/maintaining_arc_consistencymc/min-conflicts/minconflicts- suffix variants:
fc-gac,fc-vlac,mac-gac,mac-vlac
Important options:
deterministic: deterministic tie-break/order behaviorheuristics:mrv,degree,lcv,shuffle_variable,shuffle_valuesfind_all/find_all_solutionsmax_solutionspropagation(gac/vlacfor FC/MAC)decode_solutions,keep_aux_vars(for binarized CSPs)
6) Distributed CSP Workflows
6.1 Distributed search from raw CSP
from csp.core import CSP
from dcsp.api import run_distributed_search
from csp.api import print_result
csp = CSP()
csp.add_variable("x", {1, 2, 3})
csp.add_variable("y", {1, 2, 3})
csp.add_constraint("c1", "x != y")
res = run_distributed_search(
"abt",
csp,
architecture="variable",
max_delay=3,
random_seed=0,
deterministic_init=True,
)
print_result(res)
6.2 Distributed search from prebuilt model
from dcsp import build_constraint_agent_model
from dcsp.api import run_distributed_search
assignment = [("c1",)]
model = build_constraint_agent_model(csp, assignment=assignment)
res = run_distributed_search("aas", model, runtime="mp", max_events=400_000)
Supported distributed algorithms (and aliases):
- SBT:
sbt,sync,synchronous - ABT:
abt,async - AWCS:
awcs,weak,weak-commitment - AFC:
afc,forward,asynchronous-forward-checking - DBA:
dba,breakout,distributed-breakout - DSA:
dsa,stochastic,distributed-stochastic - AAS:
aas,asynchronous-aggregation - CompAPO:
compapo,apo,mediation
Key options:
architecture,architecture_kwargs(if input is raw CSP)max_delay,max_events,random_seeddeterministic_initruntime:simormpfind_all_solutions,max_solutionsrecord_protocol,protocol_path
7) Tree-based / Constraint-Agent Mapping Workflow
Use this when you want constraint-agent decomposition (including tree-style workflows):
from dcsp import (
build_pseudotree_constraint_assignment,
validate_constraint_assignment,
build_constraint_agent_model,
)
assignment = build_pseudotree_constraint_assignment(csp, bundle_size=None)
validate_constraint_assignment(csp, assignment)
model = build_constraint_agent_model(csp, assignment=assignment)
bundle_size behavior:
None→ automatic low-coupling grouping (non-uniform group sizes possible)1→ one constraint per agent>1→ fixed chunk size in DFS order
8) Graph Export and Visualization
from csp.core import CSP
# ... build csp ...
g = csp.to_graph()
ax = csp.visualize_graph(layout="bipartite", show=False)
visualize_graph(...) options include:
layout:spring,bipartite,kamada_kawai,circularwith_labels,node_size,font_sizevariable_color,constraint_color,edge_colorfigsize,show
9) Benchmarks
Load by name:
from csp import benchmarks
spec = benchmarks.load(["send_more_money_single"])[0]
csp = spec.factory()
Available built-ins include:
send_more_money_singlesend_more_money_carriessudoku_binarysudoku_productwarehouse_locationmanufacturbility_problem(translated engineering benchmark)
10) Testing and Verification
Run unit tests:
python -m unittest discover -s tests -p "test_*.py" -v
Run bytecode checks:
python -m compileall csp dcsp tests main.py
Current tests cover:
- benchmark registration/build
run_searchalias behavior andmax_solutions- mapping consistency and validation
- DGAC incomplete vs quiescent termination diagnostics
- safe-eval support for
round(...)
11) Documentation Website (MkDocs + GitHub Pages)
This repo includes full docs in docs/ with mkdocs.yml.
Local preview:
python -m pip install mkdocs mkdocs-material
mkdocs serve
Static build:
mkdocs build
GitHub Pages deployment:
- workflow file:
.github/workflows/docs.yml - action builds MkDocs and publishes
site/
Update
site_urlandrepo_urlinmkdocs.ymlto your real GitHub org/repo.
12) Contributing
- Keep public APIs backward compatible where feasible.
- Add/update tests with behavior changes.
- Keep docs and comments in English.
- Prefer deterministic settings in examples for reproducibility.
13) Publish to PyPI (pip install ready)
This repository is now structured for PEP 517/518 packaging via pyproject.toml.
13.1 Build distributions locally
python -m pip install --upgrade build twine
python -m build
Artifacts are generated in dist/ (.whl and .tar.gz).
13.2 Validate package metadata and files
python -m twine check dist/*
13.3 Upload to TestPyPI first (recommended)
python -m twine upload --repository testpypi dist/*
Then verify installation:
python -m pip install --index-url https://test.pypi.org/simple/ raven-csp
13.4 Upload to PyPI
python -m twine upload dist/*
13.5 What else you need before first release
- Create PyPI and TestPyPI accounts.
- Generate API tokens and store them securely (
~/.pypircor CI secrets). - Replace placeholder URLs in
pyproject.toml:HomepageDocumentationRepositoryIssues
- Tag a release in Git (
v0.1.0, etc.). - Optionally add CI publish workflow (GitHub Actions) that publishes on tags.
13.6 Optional dependency installs for users
pip install raven-csp[all]
pip install raven-csp[vlac]
pip install raven-csp[graph]
pip install raven-csp[engineering]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file raven_csp-0.1.0.tar.gz.
File metadata
- Download URL: raven_csp-0.1.0.tar.gz
- Upload date:
- Size: 94.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42bc4fe16699429f21a523b47fbabde39a91c66056ddfc05e3a080dabe0f17b2
|
|
| MD5 |
7559ac0150985c7f2f83023e361785cb
|
|
| BLAKE2b-256 |
b8aefd53565fa2125c2b3a9a5b6803ed3522b56e40958169fd5d5582b8406b6c
|
File details
Details for the file raven_csp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: raven_csp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 111.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ee0349552b539ececd58ad7c08ebacae67c9e7cb321bc923cea15d1f6148d90
|
|
| MD5 |
7d709d46c4597b4ec1cca58090ad6835
|
|
| BLAKE2b-256 |
edc15732c1b6d8eda5412d25703f089c9041cc6eaa807594a3084ee176af0eee
|