A modular constraint solver — SAT, SMT, LP, MILP, CP, MINLP
Project description
dsuni
纯 Rust 模块化约束求解器 / Modular Constraint Solver in Pure Rust
覆盖 8 个求解器模块,全部纯 Rust 实现,无外部求解器依赖。提供 Rust 库、CLI 命令行和 Python wheel 三种使用方式。
求解器模块
| 模块 | 算法 | 输入格式 |
|---|---|---|
| SAT | CDCL + Two-Watched Literals + VSIDS | DIMACS CNF |
| LP | 两阶段单纯形法(精确有理数) | 自定义文本格式 |
| SMT | CDCL(T) + Congruence Closure(QF_UF) | SMT-LIB |
| MILP | 分支定界(LP Relaxation + McCormick) | 自定义文本格式 |
| CP | 传播 + 回溯(First-Fail 搜索) | 自定义文本格式 |
| MINLP | 区间传播 + McCormick 松弛 | 自定义文本格式 |
安装
Rust
git clone https://github.com/MBpanzz/dsuni.git
cd dsuni
cargo build --release
cargo test # 150 tests
Python(从源码)
pip install maturin
maturin build --release
pip install target/wheels/dsuni-*.whl
Python(从 PyPI)
pip install dsuni
快速开始
CLI
# SAT
dsuni sat test_data/unsat_unit.cnf
# → UNSAT
# LP
dsuni lp test_data/simple.lp
# → OPTIMAL (obj=-5) / Model: [x0 -> 5]
# MILP
dsuni milp test_data/simple_milp.lp
# → OPTIMAL (obj=-5) / Model: [x0 -> 5]
Python
import dsuni
# SAT (DIMACS CNF)
r = dsuni.solve_sat("p cnf 1 2\n1 0\n-1 0\n")
print(r) # {'status': 'UNSAT'}
# LP
r = dsuni.solve_lp_text("min -1*x0\nx0 <= 5\nx0 >= 0\n")
print(r) # {'status': 'OPTIMAL', 'model': {'x0': 5}, 'objective': -5.0}
# MILP
r = dsuni.solve_milp_text("int x0\nmin -1*x0\nx0 <= 5\nx0 >= 0\n")
print(r) # {'status': 'OPTIMAL', 'model': {'x0': 5}, 'objective': -5.0}
# CP
r = dsuni.solve_cp_text("var x 0 10\nvar y 0 10\neq x y\n")
print(r) # {'status': 'SAT', 'model': {'x0': 0, 'x1': 0}}
项目结构
src/
├── core/ → 基础类型(Var / Term / Config / SolverResult)
├── sat/ → CDCL SAT 求解器
├── linear/ → Rational / 线性表达式 / 线性系统
├── lp/ → 两阶段单纯形法
├── milp/ → 分支定界 MILP
├── smt/ → CDCL(T) + QF_UF / QF_LRA
├── cp/ → 传播 + 回溯 CP
├── minlp/ → 区间传播 + McCormick 松弛
├── parser/ → DIMACS / LP / SMT-LIB / CP 格式解析器
├── cli/ → CLI 命令定义
└── python.rs → PyO3 Python 绑定
test_data/ → 14 个测试输入文件
许可证
MIT License © 2025 MBpanzz
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 Distributions
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 dsuni-0.1.1.tar.gz.
File metadata
- Download URL: dsuni-0.1.1.tar.gz
- Upload date:
- Size: 67.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19953c1bbd506196181707a9a643aaf3aaa24bb9595cac35cdda9a1149a64e20
|
|
| MD5 |
3588cbb84c86394c6914353aba1b5784
|
|
| BLAKE2b-256 |
fbe58f7e67fe3270f58fcac2019efa30aa448e8c8fecdacfa69b67d8c71509a3
|
File details
Details for the file dsuni-0.1.1-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: dsuni-0.1.1-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 188.5 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1bc72da3223a5b576b749e4d39fa054934176937276596022ec72f247792a694
|
|
| MD5 |
650bb27e130155d9947b5fbd69c3a7b8
|
|
| BLAKE2b-256 |
13c166a87e3dee9ec166d8ec1dfaa4f501ff5cb7b85e07163ac074413966055d
|
File details
Details for the file dsuni-0.1.1-cp310-cp310-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: dsuni-0.1.1-cp310-cp310-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 301.6 kB
- Tags: CPython 3.10, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d6aed2d5b062cc0e6d8bfe8239196d2b49c3abd1eba14aca963928a55698c08
|
|
| MD5 |
af761b9f2d467265dc4cb908d79e3fc9
|
|
| BLAKE2b-256 |
ce038c34cc40f05ef451136e97a3ac86609bbca69e2229e4dd43c4c4bf3eb004
|
File details
Details for the file dsuni-0.1.1-cp310-cp310-macosx_10_12_x86_64.whl.
File metadata
- Download URL: dsuni-0.1.1-cp310-cp310-macosx_10_12_x86_64.whl
- Upload date:
- Size: 286.0 kB
- Tags: CPython 3.10, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a05b52af99ccad7c37913cf2ad41c2b01f447e7bf5f7fbcd4bdbce6555adedfc
|
|
| MD5 |
50aa7341495e1235ecd69299a310b1d6
|
|
| BLAKE2b-256 |
46143aa84fd6aacb9f66a9850e39c4f82997ace0ebeb679ad0d5ee5ef984fbb7
|