liveBook · Manning

Constraint-satisfaction problem

As explained in Optimization Algorithms: AI techniques for design, planning, and control problems

A constraint-satisfaction problem is a problem formulation whose goal is to find an assignment satisfying a specified set of constraints without requiring an explicit objective function.

A constraint-satisfaction problem (CSP) asks for an assignment that satisfies a specified set of constraints, without defining an explicit objective function. Feasibility is the requirement: multiple valid solutions may exist without one being objectively better. section 1.3.2

The n-queens problem

Place n queens on an n × n chessboard so that no two share a row, column, or diagonal. In the 4-queens version, two solutions satisfy the constraints; neither is inherently superior. A 7-queens instance can be represented as an ordering, evaluated by counting collisions, and improved through candidate swaps. section 1.3.2 section 6.3

Tabu search handles the 7-queens CSP by generating neighboring configurations, selecting promising moves, and recording recent moves in a tabu structure. With a tabu tenure of three iterations, recently performed swaps are temporarily forbidden; aspiration criteria can still admit a tabu move when appropriate. section 6.3

Listing 6.1 Solving the 7-queens problem
import random
import numpy as np
import matplotlib.pyplot as plt
def get_initial_state(board_size):
    queens = list(range(board_size))
    random.shuffle(queens)
    return queens

Use the Python implementation to connect the formulation to practice: initialize a randomized state, count attacking queens, select non-tabu moves, update the tabu list, and stop after configured iterations or non-improvement. section 6.3

How Optimization Algorithms: AI techniques for design, planning, and control problems covers it

How deep it goes
Defines feasibility, works through 7-queens iterations, and supplies Python components for tabu-search implementation.
Examples
Uses 4-queens and 7-queens boards, collision counts, queen orderings, candidate swaps, figures, and Python listings.
What you can do after
Apply it via tabu search and Python by representing states, measuring constraint violations, filtering moves, and tracking improvements.
How it connects
Connects constraint-satisfaction problems with objective functions, tabu search, simulated annealing, and discrete optimization.

Also explained in

Compare how 2 books explain constraint-satisfaction problem →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Optimization Algorithms: AI techniques for design, planning, and control problems. The section links point to the parts of the book it draws on.