Solving a problem with constraints
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, values): # Check if all the values are unique return len(values) == len(set(values))
Define the constraint that specifies that the first variable should be bigger...