All Projects → lifebeyondfife → Decider

lifebeyondfife / Decider

Licence: MIT License
An Open Source .Net Constraint Programming Solver

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to Decider

Optaplanner
AI constraint solver in Java to optimize the vehicle routing problem, employee rostering, task assignment, maintenance scheduling, conference scheduling and other planning problems.
Stars: ✭ 2,454 (+2091.07%)
Mutual labels:  constraint-satisfaction-problem, constraint-programming, constraint-solver
pycsp3
A Python Library for modeling combinatorial constrained problems
Stars: ✭ 39 (-65.18%)
Mutual labels:  constraint-satisfaction-problem, constraint-programming
facile
Python constraint programming library
Stars: ✭ 21 (-81.25%)
Mutual labels:  constraint-satisfaction-problem, constraint-programming
GHOST
General meta-Heuristic Optimization Solving Toolkit
Stars: ✭ 28 (-75%)
Mutual labels:  constraint-satisfaction-problem, constraint-programming
ConstraintSolver.jl
ConstraintSolver in Julia: Blog posts ->
Stars: ✭ 107 (-4.46%)
Mutual labels:  constraint-programming, constraint-solver
ordered
Entropy-controlled contexts in Python
Stars: ✭ 36 (-67.86%)
Mutual labels:  constraint-satisfaction-problem, constraint-programming
LocalSearchSolvers.jl
A Julia package to manage Constraint-Based Local Search (CBLS) solvers.
Stars: ✭ 18 (-83.93%)
Mutual labels:  constraint-programming, constraint-solver
powered-cache
The most powerful caching and performance suite for WordPress.
Stars: ✭ 31 (-72.32%)
Mutual labels:  optimisation
ConstraintTP
Constraint Type provider is a Type provider that provides constraints over F# Types.
Stars: ✭ 12 (-89.29%)
Mutual labels:  constraint-programming
memalloy
Memory consistency modelling using Alloy
Stars: ✭ 23 (-79.46%)
Mutual labels:  constraint-solver
ccache-gui
macOS GUI helper for ccache
Stars: ✭ 52 (-53.57%)
Mutual labels:  optimisation
Windows11-Optimization
Community repository, to improve security and performance of Windows 10 and windows 11 with tweaks, commands, scripts, registry keys, configuration, tutorials and more
Stars: ✭ 17 (-84.82%)
Mutual labels:  optimisation
bayesopt-tutorial-r
Tutorial on Bayesian optimization in R
Stars: ✭ 15 (-86.61%)
Mutual labels:  optimisation
sudoku
Solve a Sudoku puzzle with a quantum computer
Stars: ✭ 20 (-82.14%)
Mutual labels:  constraint-satisfaction-problem
cplex-example
Solving a TSP with the CPLEX C++ API.
Stars: ✭ 40 (-64.29%)
Mutual labels:  optimisation
biteopt
Derivative-Free Optimization Method for Global Optimization (C++)
Stars: ✭ 91 (-18.75%)
Mutual labels:  constraint-programming
GA
An R package for optimization using genetic algorithms
Stars: ✭ 76 (-32.14%)
Mutual labels:  optimisation
Cassowary
High performance swift implement of constraint solving algorithm cassowary
Stars: ✭ 45 (-59.82%)
Mutual labels:  constraint-solver
profiling
Non-discriminatory profiling of Ruby code leveraging the ruby-prof gem
Stars: ✭ 12 (-89.29%)
Mutual labels:  optimisation
ev chargingcoordination2017
Optimal Scheduling of Electric Vehicle Charging in Distribution Networks
Stars: ✭ 51 (-54.46%)
Mutual labels:  optimisation

Decider

main ci pipeline nuget package

An Open Source .Net Constraint Programming Solver

Installation

Install using nuget for .Net Standard 2.1

 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)
};

Search

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.

Optimise

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

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

Specify an upper time bound on how long you search, say, five minutes

var timeout = 60 * 5;
var searchResult = state.Search(optimise, timeout);
Console.WriteLine($"Optimal answer found is ${state.OptimalSolution["optimalAnswer"]}");

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)

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 http://lifebeyondfife.com/.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].