Decider 5.0.0

dotnet add package Decider --version 5.0.0
                    
NuGet\Install-Package Decider -Version 5.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Decider" Version="5.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Decider" Version="5.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Decider" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Decider --version 5.0.0
                    
#r "nuget: Decider, 5.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Decider@5.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Decider&version=5.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Decider&version=5.0.0
                    
Install as a Cake Tool

Decider

main ci pipeline nuget package nuget package

An Open Source .Net Constraint Programming Solver

Installation

Install using nuget for .Net 10.0 (.Net 8.0, .Net Standard 2.0 and 2.1 also supported)

 dotnet add package Decider

Variables

Create constrained integer variables

var s = new VariableInteger("s", 0, 9);
var e = new VariableInteger("e", 0, 9);
var n = new VariableInteger("n", 0, 9);
var d = new VariableInteger("d", 0, 9);
var m = new VariableInteger("m", 1, 9);
var o = new VariableInteger("o", 0, 9);
var r = new VariableInteger("r", 0, 9);
var y = new VariableInteger("y", 0, 9);
var c0 = new VariableInteger("c0", 0, 1);
var c1 = new VariableInteger("c1", 0, 1);
var c2 = new VariableInteger("c2", 0, 1);
var c3 = new VariableInteger("c3", 0, 1);

Constraints

Define the constraints of your problem

var constraints = new List<IConstraint>
{
    new AllDifferentInteger(new [] { s, e, n, d, m, o, r, y }),
    new ConstraintInteger(d + e == (10 * c0) + y),
    new ConstraintInteger(n + r + c0 == (10 * c1) + e),
    new ConstraintInteger(e + o + c1 == (10 * c2) + n),
    new ConstraintInteger(s + m + c2 == (10 * c3) + o),
    new ConstraintInteger(c3 == m)
};

Find a solution using Decider's search routines

var variables = new [] { c0, c1, c2, c3, s, e, n, d, m, o, r, y };
var state = new StateInteger(variables, constraints);
var searchResult = state.Search();

Console.WriteLine($"    {s} {e} {n} {d} ");
Console.WriteLine($"  + {m} {o} {r} {e} ");
Console.WriteLine("  ---------");
Console.WriteLine($"  {m} {o} {n} {e} {y} ");

Console.WriteLine($"Runtime:\t{state.Runtime}\nBacktracks:\t{state.Backtracks}\n");

Which results in

    9 5 6 7
  + 1 0 8 5
  ---------
  1 0 6 5 2

Runtime:        00:00:00.0290211
Backtracks:     85

Find All Solutions

Display all solutions to the n-queens problem

var searchResult = state.SearchAllSolutions();

foreach (var solution in state.Solutions)
{
    for (var i = 0; i < variables.Length; ++i)
    {
        for (var j = 0; j < variables.Length; ++j)
            Console.Write(solution[i.ToString()].InstantiatedValue == j ? "Q " : ". ");

        Console.WriteLine();
    }
    Console.WriteLine();
}

Which results in

Q . . . . . . .
. . . . Q . . .
. . . . . . . Q
. . . . . Q . .
. . Q . . . . .
. . . . . . Q .
. Q . . . . . .
. . . Q . . . .

Q . . . . . . .
. . . . . Q . .
. . . . . . . Q
. . Q . . . . .
. . . . . . Q .
. . . Q . . . .
. Q . . . . . .
. . . . Q . . .

and a further ninety solutions.

Progress Reporting

For long-running searches, track progress through the search space with a callback

state.OnProgress = progress =>
{
    var filled = (int)(progress * 50);
    Console.Write($"\r[{new string('#', filled)}{new string('-', 50 - filled)}] {progress:P1}  " +
        $"{state.Backtracks} backtracks, {state.Solutions.Count} solutions");
};

state.SearchAllSolutions();
Console.WriteLine();

Which displays a live updating progress bar

[####################------------------------------] 40.2%  15234 backtracks, 42 solutions

The progress value represents the fraction of the combinatorial search space that has been explored. Progress reports occur every second by default, configurable via ProgressInterval.

Optimise

Create an integer variable to optimise i.e. make as small as possible

var optimise = new VariableInteger("optimise");
new ConstraintInteger(optimise == a + b + c + d + e + f + g + h)

Specify an upper time bound on how long you search using a CancellationToken

using var cts = new CancellationTokenSource(TimeSpan.FromMinutes(5));
var searchResult = state.Search(optimise, cts.Token);
Console.WriteLine($"Optimal answer found is {state.OptimalSolution["optimise"]}");

Constrained Arrays

Index integer arrays with constrained integer variables

var a = new VariableInteger("a", 0, 9);
var array = new ConstrainedArray(new int[] { 0, 23, 52, 62, 75, 73, 47, 20, 87, 27 });

var constraint = new ConstraintInteger(array[a] < 40)

Cumulative Constraint

Schedule tasks with limited resources using start times, durations, demands and capacity

var starts = new List<VariableInteger> { task1, task2, task3 };
var durations = new List<int> { 3, 2, 4 };
var demands = new List<int> { 2, 1, 2 };
var capacity = 3;

var constraint = new CumulativeInteger(starts, durations, demands, capacity)

F#

Thanks to contributor @toburger, there's a simple example of using Decider in F#.

let constraints: IConstraint list = [
    ConstraintInteger(kickboards + cityrollers == expr rollers)
    ConstraintInteger(kickboards * expr 3 + cityrollers * expr 2 == expr rolls)
]

See Examples/FSharp for full details.

More Examples?

Fork the repo to see more examples, some toy and some real world, of Decider in action.

Licence

Released under the MIT licence, Decider is freely available for commercial use.

Author

I have a PhD in Constraint Programming and love turning NP-complete problems into CSPs. Visit my blog at https://lifebeyondfife.com/.

Product 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 is compatible.  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 is compatible.  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 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
5.0.0 138 2/17/2026
4.0.0 111 2/9/2026
3.0.0 111 2/8/2026
2.3.0 113 2/8/2026
2.2.1 118 2/7/2026
2.2.0 116 2/7/2026
2.1.3 119 2/7/2026
2.1.2 114 2/7/2026
2.1.1 114 2/7/2026
2.1.0 113 2/7/2026
2.0.3 114 2/7/2026
2.0.2 5,177 4/20/2025
2.0.1 272 11/10/2024
1.0.5 654 2/21/2024
1.0.4 3,344 8/21/2022
1.0.2 634 7/23/2022
1.0.1 610 7/23/2022
0.5.4 613 7/23/2022
0.5.3 610 7/23/2022
0.5.2 1,308 5/8/2021
Loading failed