January 2017
Beginner to intermediate
446 pages
8h 46m
English
We have already discussed how Constraint Satisfaction Problems are formulated. Let's apply them to a real-world problem. In this problem, we have a list of names and each name can only take a fixed set of values. We also have a set of constraints between these people that needs to be satisfied. Let's see how to do it.
Create a new Python file and import the following packages:
from simpleai.search import CspProblem, backtrack, \
min_conflicts, MOST_CONSTRAINED_VARIABLE, \
HIGHEST_DEGREE_VARIABLE, LEAST_CONSTRAINING_VALUE
Define the constraint that specifies that all the variables in the input list should have unique values:
# Constraint that expects all the different variables # to have different values def constraint_unique(variables, ...
Read now
Unlock full access