Artificial Intelligence: A Modern Method Study Notes (Chapter 6)-Constraint Satisfaction Problem

definition

Insert picture description here
Each assignment will affect the next selection range

Constraint satisfaction problem refers to a given set of variables and some restrictions or some constraints that need to be satisfied, to find a solution, all solutions or optimal solutions that meet these constraints.
CSP can be divided into two sub-areas is expressed (Representation) and reasoning (Reasoning) . Representation can be divided into general and application-specific methods; reasoning is divided into search and inference.
Inference method refers to a special reasoning method based on Constraint Propagation-in the inference process, constraints are used to reduce the legal value range of a variable, and this influence is applied to it through the CSP network There is a constraint on the variables .
The search means that, from all possible values of variables, constraints values chosen subject .
Constraint propagation and search can be performed alternately, or, constraint propagation can also be used as a pre-processing step before searching. At this time, constraint propagation can eliminate subspaces that do not satisfy constraints (compression). In the search process, using constraint propagation can avoid searching for subspaces or subtrees that do not meet the constraints, thereby greatly improving the search efficiency.

Constraint propagation (constraint propagation) VS local search

Constraint propagation:

  1. partial assignment
  2. Initial state assignment to null
  3. Select one of the remaining unselected variables to perform an operation to assign a value to it , and the operation meets the corresponding constraint conditions

Local search:

  • full assignment (assign all variables at once)
  • Select a variable to modify the value each time

CSP problem formalization

Insert picture description here
Insert picture description here

csp formal example

Eight Queens Problem

Insert picture description here

Map coloring problem

In that domain, WA, NT, etc. are the abbreviations of his place names.
Insert picture description here
Insert picture description here

Types of constraints

Insert picture description here

Absolute constraint

  • Unary constraint: only limit the fetch of a single variable
  • Binary constraints: limit the fetching of multiple variables
  • Higher-order constraints (also called global constraints): constraints of multiple variables (n≥2)

Preference constraints (constrained optimization problem, COP)

Theorem: Any constraint of a finite range can be transformed into a binary constraint by adding conditions

Constraint graphs and constraint hypergraphs

Insert picture description here
Insert picture description here
Insert picture description here

Insert picture description here

Constraint propagation

concept

The basic idea of ​​constraint propagation is to convert a CSP into an equivalent, simpler and easier to solve CSP. Its main technical means is to eliminate invalid and redundant values ​​in variables, and to propagate this change through constrained variables, thereby also eliminating invalid and redundant values ​​in those variables. Constraint propagation can be performed at different granularities, thus forming different constraint propagation methods.
Insert picture description here
Insert picture description here
Insert picture description here
When the assignment of the variable in the problem satisfies all constraints, the assignment is compatible

Node compatible

Insert picture description here
The constraint in the example above:
Insert picture description here

Arc compatible

Insert picture description here
Insert picture description here

Insert picture description here
Insert picture description here
Insert picture description here

Path compatibility

Insert picture description here

K compatible

Insert picture description here

Global Constraint Compatibility Check

Insert picture description here

CSP backtracking search

Formalize a standard search

Insert picture description here
Initial state: empty assignment
Transfer model: select a variable assignment
Goal test: whether all variables are constrained to satisfy the condition
Path cost
Action
Insert picture description here

Backtracking search

Insert picture description here
Insert picture description here

Improve the efficiency of backtracking

Insert picture description here

Variable order

  • Least remaining value variable first
    Insert picture description here
    select the variable with the least number of assignments that can meet the constraint conditions for assignment.
    However, if several variables have the same assignment number remaining value, then the variable that will affect other variables the most is selected for assignment ( That is: the largest degree variable first), which can effectively reduce the branching factor afterwards

  • Maximum variable first

Value order

Which value to choose for the variable first (inference), from the point of view of value selection, try to make the remaining variables the most value they can choose (ie: the least constraint value first)

Insert picture description here

Inference algorithm

Early detection of failure: forward inspection

Insert picture description here
For example, the above picture: in the fourth step, the value range that SA can select becomes empty, and backtracking

Earlier discovery failure: maintaining arc compatibility

Insert picture description here
Insert picture description here

CSP local search

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

CSP problem structure

Insert picture description here

CSP with tree structure

Insert picture description here

Constructing a tree structure: based on the method of deleting nodes

Insert picture description here
Insert picture description here

Constructing a tree structure: based on the method of merging nodes

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

to sum up

Constraint satisfaction problem:
environment: single agent, continuation, static, fully observable,
a special search problem

Constraint Satisfaction Problem vs. Classic Search Problem:
State s: Assign part or all of a set of variables (with constraints to each other) {x1,x2,...,xn}
Action: Assign different values ​​to each variable assignment(xi, v)
State transition: Result(s, assignment(xi, v))=s', xi=v in s', the assignment of other variables is consistent with s
Goal: All variables are assigned and the constraints are met

When the assignment of the variable in the problem satisfies all constraints, the assignment is compatible.
The solution of the CSP problem is a compatible and complete assignment of all variables

Characteristics of constraint satisfaction problems
Commutability: The order of variable assignment does not affect the final result.
Constraint propagation: the assignment of one variable will change the range of other variables

The description of the constraint satisfaction problem
needs to describe the state, the successor function, and the target test. The
most important thing is to describe the constraint

Any CSP can be transformed into a CSP
higher-order constraint containing only binary constraints. It becomes a binary constraint: introducing a new variable to represent the value of a variable pair, and introducing a constraint such as "X is the first element in Y" to
change the variable range and eliminate unary constraint

Standard search process: the
state is the assignment so far.
Initial state: empty assignment, {}
successor function: assign a possible value to an unassigned variable.
Target detection: complete assignment that satisfies all constraints

The difference from classic search
Idea 1: Only one variable is considered at a time.
Idea 2: When expanding the node, only the legal assignment of the current variable is
considered. The depth-first search considering the above two points is called backtracking search.

How to solve the constraint satisfaction problem
The key characteristics of CSP: commutability and constraint propagation

Which variable to choose next time?
Choose the constraint variable with the smallest value range

Strategy 1: Minimum remaining values ​​(MRV)
attempts to reduce the branching factor

Strategy 2: Degree heuristic,
select the most constrained variable and assign it first,
reduce the branching of subsequent variables

What is the order of trying in the range of variables?

Least constraining value (Least constraining value)
selects the value that constrains the value range of the unassigned variable among all possible values ​​of the current variable

Can we detect the failure earlier?
Forward detection
Track changes in the value range of an unassigned variable.
When a variable value range is empty, the algorithm ends.
Arc compatible
X —> Y is compatible if and only if each of x The value y has an optional value. It
can do an arc compatibility test before each assignment.
Arc compatibility can detect failure earlier than the forward check.

Guess you like

Origin blog.csdn.net/weixin_44972129/article/details/109079451
Recommended