0% found this document useful (0 votes)
28 views

Constraint Satisfaction Problem: Artificial Intelligence Sessional Lab-5

A constraint satisfaction problem (CSP) involves variables with domains of possible values, and constraints that limit the values the variables can take. Common CSP problems include map coloring, sudoku, and the n-queens problem. To model a problem as a CSP in Choco solver, variables and their domains are defined, along with constraints specifying allowed combinations of values. Choco is an open-source Java library for constraint programming that includes predefined variable and constraint types to declaratively model combinatorial problems and find solutions.

Uploaded by

Rafin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Constraint Satisfaction Problem: Artificial Intelligence Sessional Lab-5

A constraint satisfaction problem (CSP) involves variables with domains of possible values, and constraints that limit the values the variables can take. Common CSP problems include map coloring, sudoku, and the n-queens problem. To model a problem as a CSP in Choco solver, variables and their domains are defined, along with constraints specifying allowed combinations of values. Choco is an open-source Java library for constraint programming that includes predefined variable and constraint types to declaratively model combinatorial problems and find solutions.

Uploaded by

Rafin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Constraint Satisfaction Problem

Artificial Intelligence Sessional


Lab-5
Recap on CSP
A constraint satisfaction problem (CSP) is a problem that requires its solution
within some conditions also known as constraints.

It consists of –
 A finite set of variables
V = {V1, V2, V3,....., Vn}
 A set of discrete values known as domain
D = {D1, D2, D3,.....,Dn}
 A finite set of constraints
C = {C1, C2, C3,......, Cn}
Popular Problems of CSP
 CryptArithmetic (Coding alphabets to numbers.)
 n-Queen (In an n-queen problem, n queens should be placed in a nXn
matrix such that no queen shares the same row, column or diagonal.)
 Map Coloring (Coloring different regions of map ensuring no adjacent
regions have the same color.)
 Crossword (Everyday puzzles appearing in newspapers.)
 Sudoku (A number grid.)
Converting problems to CSPs
A problem to be converted to CSP requires the following steps:

1. Create a variable set.


2. Create a domain set.
3. Create a constraint set with variables and domains (if possible) after
considering the constraints.
4. Find an optimal solution.
Orientation with choco solver

Official website: https://choco-solver.org/


Online IDE: https://chocoide.herokuapp.com/
What is Choco ?
Choco is a Free and Open-Source Java library dedicated to
Constraint Programming. It aims at describing hard combinatorial
problems in the form of Constraint Satisfaction Problems and
solving them with Constraint Programming techniques.
What is Choco ?
Having-
various type of variables (integer, boolean, set and real),
many constraints (alldifferent, count, nvalues, etc.),
a configurable search (custom search, activity-based search, large
neighborhood search, etc.),
conflict explanations (conflict-based back jumping, dynamic
backtracking, path repair, etc.).
Main components of choco
The model – the key component of the library and needed to
describe any problem.
The variables – A variable is an unknown which has to be assigned
to value in a solution. The values a variable can take is defined by its
domain.
The constraints – To activate a constraint, it has to be posted using
post() method
Solving the problem – by calling getSolver().findSolution() method
Integer variable

// A variable with a unique value in its domain, in other words, a


constant
IntVar two = model.intVar("TWO", 2);
// Any value in [1..4] can be assigned to this variable
IntVar x = model.intVar("X", 1, 4);
// Only the values 1, 3 and 4 can be assigned to this variable
IntVar y = model.intVar("X", new int[]{1, 3, 4});
Sudoku
2

8 3 7

3 5 6 4

2 8

8 3 1

4 7 3 5 1

7 5 6 4

5 4 1 6
Sudoku
5 1 2 8 7 9 4 6 3

6 8 4 1 3 2 5 7 9

3 9 7 5 6 4 1 8 2

7 5 1 6 4 3 9 2 8

8 3 9 2 1 5 7 4 6

2 4 6 7 9 8 3 5 1

1 7 8 3 5 6 2 9 4

4 6 3 9 2 7 8 1 5

9 2 5 4 8 1 6 3 7
Let’s solving Sudoku using choco-solver

You might also like