Dulranga's Notes
Semester 3Artificial Intelligence

Constrain Satisfactory Problems (CSPs)

CSPs use a standard structure and a simple representation for states and the goal test. Search algorithms can then exploit that structure and use general-purpose heuristics instead of problem-specific ones

See the algorithm using an example:

Info

Suppose you have to color this map using four colors; Red, Green, Yellow and Blue, such that no two regions sharing a common boundary are colored in the same color. csp-us-map-uncoloured.svg

Formulate the problem

First need to Define variables and Domain for each variable. Domain can be different from one variable to the other depend on constraints.

ComponentGeneral ruleMap example
Variables XXOne variable per thing that needs a value{MT,ND,SD,NE,WY,ID,UT,CO}\{MT, ND, SD, NE, WY, ID, UT, CO\}
Domains DiD_iThe allowed values for each variableDi={R,G,Y,B}D_i=\{R,G,Y,B\}
Constraints CCThe legal value combinations for subsets of variablesXi≠XjX_i \neq X_j for every pair sharing a border (14 constraints)
Degree - No. of Constraints present for a given Variable

Constraints

Region Color ≠\neq Neighbour Color

RegionNeighbours
MTID, WY, ND, SD
NDMT, SD
SDMT, ND, WY, NE
NESD, WY, CO
WYMT, ID, UT, CO, SD, NE
IDMT, WY, UT
UTID, WY, CO
COUT, WY, NE

To make things easier draw the constraints graph

  • Edges - Constraints
  • Nodes - Variables csp-constraint-graph.svg

Judge any assignment

  • An assignment is consistent (legal) if it violates no constraint.
  • An assignment is complete if every variable has a value.
  • A solution is a complete and consistent assignment.

Complete solution: csp-us-map-solution.svg

Choose the variable

  1. MRV (Minimum Remaining Variable): pick the variable with the fewest legal values left in domain.
  2. Degree (tie-break): among ties, pick the one with the most constraints on unassigned variables.
RegionWYMTSDNEIDUTCOND
Degree64433332

In this case, all domains have 4 values at the start. so Degree will have to do the tie breaking.

Choose the Color

LCV (Least Constrained Value): try first the value that rules out the fewest values in neighbouring unassigned variables.

Example, after WY = Blue, assigning MT = Green removes only Green from ID, ND and SD. Any other colour would remove that colour from the same neighbours, so the options tie and any is fine. LCV matters when neighbours' domains already differ.

Infer after each assignment

  • Forward checking: after X=vX=v, remove vv from the domains of XX's unassigned neighbours.
  • Empty domain? Stop and backtrack now. (If domain is empty for a variable, the solution is not complete)
  • AC-3 (stronger): if pruning leaves a neighbour with one value, propagate that removal to its own neighbours.

Backtrack

When a variable has no legal value left, undo the most recent assignment, try its next value, and if none remain, undo the one before it.

On this page