|
1 | | -# BooleanInference |
| 1 | +# BooleanInference.jl |
2 | 2 |
|
3 | 3 | [](https://nzy1997.github.io/BooleanInference.jl/stable/) |
4 | 4 | [](https://nzy1997.github.io/BooleanInference.jl/dev/) |
5 | 5 | [](https://github.com/nzy1997/BooleanInference.jl/actions/workflows/CI.yml?query=branch%3Amain) |
6 | 6 | [](https://codecov.io/gh/nzy1997/BooleanInference.jl) |
| 7 | + |
| 8 | +A high-performance Julia package for solving Boolean satisfiability problems using tensor network contraction and optimal branching strategies. |
| 9 | + |
| 10 | +## Features |
| 11 | + |
| 12 | +- **Tensor Network Representation**: Efficiently represents Boolean satisfiability problems as tensor networks |
| 13 | +- **Optimal Branching**: Uses advanced branching strategies to minimize search space |
| 14 | +- **Multiple Problem Types**: Supports CNF, circuit, and factoring problems |
| 15 | +- **High Performance**: Optimized for speed with efficient propagation and contraction algorithms |
| 16 | +- **Flexible Interface**: Easy-to-use API for various constraint satisfaction problems |
| 17 | + |
| 18 | +## Installation |
| 19 | + |
| 20 | +```julia |
| 21 | +using Pkg |
| 22 | +Pkg.add("BooleanInference") |
| 23 | +``` |
| 24 | + |
| 25 | +## Quick Start |
| 26 | + |
| 27 | +### Solving SAT Problems |
| 28 | + |
| 29 | +```julia |
| 30 | +using BooleanInference |
| 31 | +using GenericTensorNetworks: ∧, ∨, ¬ |
| 32 | + |
| 33 | +# Define a CNF formula |
| 34 | +@bools a b c d e f g |
| 35 | +cnf = ∧(∨(a, b, ¬d, ¬e), ∨(¬a, d, e, ¬f), ∨(f, g), ∨(¬b, c), ∨(¬a)) |
| 36 | + |
| 37 | +# Solve and get assignments |
| 38 | +sat = Satisfiability(cnf; use_constraints=true) |
| 39 | +satisfiable, assignments, depth = solve_sat_with_assignments(sat) |
| 40 | + |
| 41 | +println("Satisfiable: ", satisfiable) |
| 42 | +println("Assignments: ", assignments) |
| 43 | +``` |
| 44 | + |
| 45 | +### Solving Factoring Problems |
| 46 | + |
| 47 | +```julia |
| 48 | +# Factor a semiprime number |
| 49 | +a, b = solve_factoring(5, 5, 31*29) |
| 50 | +println("Factors: $a × $b = $(a*b)") |
| 51 | +``` |
| 52 | + |
| 53 | +### Circuit Problems |
| 54 | + |
| 55 | +```julia |
| 56 | +# Solve circuit satisfiability |
| 57 | +circuit = @circuit begin |
| 58 | + c = x ∧ y |
| 59 | +end |
| 60 | +push!(circuit.exprs, Assignment([:c], BooleanExpr(true))) |
| 61 | + |
| 62 | +tnproblem = setup_from_circuit(circuit) |
| 63 | +result, depth = solve(tnproblem, BranchingStrategy(), NoReducer()) |
| 64 | +``` |
| 65 | + |
| 66 | +## Core Components |
| 67 | + |
| 68 | +### Problem Types |
| 69 | +- `TNProblem`: Main problem representation |
| 70 | +- `TNStatic`: Static problem structure |
| 71 | +- `DomainMask`: Variable domain representation |
| 72 | + |
| 73 | +### Solvers |
| 74 | +- `TNContractionSolver`: Tensor network contraction-based solver |
| 75 | +- `LeastOccurrenceSelector`: Variable selection strategy |
| 76 | +- `NumUnfixedVars`: Measurement strategy |
| 77 | + |
| 78 | +### Key Functions |
| 79 | +- `solve()`: Main solving function |
| 80 | +- `setup_from_cnf()`: Setup from CNF formulas |
| 81 | +- `setup_from_circuit()`: Setup from circuit descriptions |
| 82 | +- `solve_factoring()`: Solve integer factoring problems |
| 83 | + |
| 84 | +## Advanced Usage |
| 85 | + |
| 86 | +### Custom Branching Strategy |
| 87 | + |
| 88 | +```julia |
| 89 | +using OptimalBranchingCore: BranchingStrategy |
| 90 | + |
| 91 | +# Configure custom solver |
| 92 | +bsconfig = BranchingStrategy( |
| 93 | + table_solver=TNContractionSolver(), |
| 94 | + selector=LeastOccurrenceSelector(2, 10), |
| 95 | + measure=NumUnfixedVars() |
| 96 | +) |
| 97 | + |
| 98 | +# Solve with custom configuration |
| 99 | +result, depth = solve(problem, bsconfig, NoReducer()) |
| 100 | +``` |
| 101 | + |
| 102 | +### Benchmarking |
| 103 | + |
| 104 | +The package includes comprehensive benchmarking tools: |
| 105 | + |
| 106 | +```julia |
| 107 | +using BooleanInferenceBenchmarks |
| 108 | + |
| 109 | +# Compare different solvers |
| 110 | +configs = [(10,10), (12,12), (14,14)] |
| 111 | +results = run_solver_comparison(FactoringProblem, configs) |
| 112 | +print_solver_comparison_summary(results) |
| 113 | +``` |
| 114 | + |
0 commit comments