NanoByte.SatSolver
0.5.0
dotnet add package NanoByte.SatSolver --version 0.5.0
NuGet\Install-Package NanoByte.SatSolver -Version 0.5.0
<PackageReference Include="NanoByte.SatSolver" Version="0.5.0" />
<PackageVersion Include="NanoByte.SatSolver" Version="0.5.0" />
<PackageReference Include="NanoByte.SatSolver" />
paket add NanoByte.SatSolver --version 0.5.0
#r "nuget: NanoByte.SatSolver, 0.5.0"
#:package NanoByte.SatSolver@0.5.0
#addin nuget:?package=NanoByte.SatSolver&version=0.5.0
#tool nuget:?package=NanoByte.SatSolver&version=0.5.0
NanoByte SAT Solver
NanoByte SAT Solver is a CDCL Boolean Satisfiability Solver for .NET.
Usage
Add a reference to the NanoByte.SatSolver NuGet package to your project.
You need to choose the underlying type to use for Literals in Boolean Formulas. This will often be int or string but you can also use any other type that implements the IEquatable<T> interface. Create an instance of SatProblem<T> and declare your variables:
var problem = new SatProblem<string>();
var a = problem.AddVariable("a");
var b = problem.AddVariable("b");
var c = problem.AddVariable("c");
var d = problem.AddVariable("d");
Add constraints as clauses (disjunctions of literals where at least one must be true). The ! operator negates a literal:
problem.AddClause(a, b); // a OR b
problem.AddClause(!a, c); // NOT a OR c
problem.AddClause(!c, d); // NOT c OR d
problem.AddClause(a); // a must be true (unit clause / unconditional fact)
You can also use | and & operator expressions with += to add multiple clauses at once in a compact form:
problem += (a | b) & (!a | c) & (!c | d) & a;
For common implication patterns there is a dedicated helper:
problem.Implies(a, c); // a implies c (equivalent to: NOT a OR c)
problem.Implies(c, d); // c implies d
You can also add an at-most-one constraint to express that no two literals in a group may be true simultaneously:
problem.AtMostOne(a, b, c);
Call Solve() to find a satisfying assignment. It returns null when the problem is unsatisfiable:
Model<string>? model = problem.Solve();
if (model != null)
{
// Satisfiable: inspect which variables were assigned true
foreach (var value in model.SelectedValues)
Console.WriteLine($"{value} = true");
// Or query a specific variable
bool? aValue = model["a"];
}
When the solver needs to choose which unassigned variable to branch on next, it picks one arbitrarily. You can supply a decider callback with domain-specific branching logic for better performance:
Model<string>? model = problem.Solve(decider: () =>
{
// Return a preferred literal to branch on, or null to let the solver decide
return somePreferredLiteral;
});
Building
The source code is in src/, config for building the API documentation is in doc/ and generated build artifacts are placed in artifacts/. The source code does not contain version numbers. Instead the version is determined during CI using GitVersion.
To build run .\build.ps1 or ./build.sh (.NET SDK is automatically downloaded if missing using 0install).
Contributing
We welcome contributions to this project such as bug reports, recommendations and pull requests.
This repository contains an EditorConfig file. Please make sure to use an editor that supports it to ensure consistent code style, file encoding, etc.. For full tooling support for all style and naming conventions consider using JetBrains' ReSharper or Rider products.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 is compatible. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- Microsoft.Bcl.HashCode (>= 6.0.0)
- System.ValueTuple (>= 4.6.2)
-
.NETFramework 4.7.2
- Microsoft.Bcl.HashCode (>= 6.0.0)
- System.ValueTuple (>= 4.6.2)
-
.NETStandard 2.0
- Microsoft.Bcl.HashCode (>= 6.0.0)
- System.ValueTuple (>= 4.6.2)
-
.NETStandard 2.1
- Microsoft.Bcl.HashCode (>= 6.0.0)
- System.ValueTuple (>= 4.6.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.