[Artificial Intelligence] - CSP constraint satisfaction problem, backtracking search, least residual value MRV, degree heuristic, least constraint value heuristic

Constraint Satisfaction Problem CSP

  • Standard search questions:
    • State is a "black box" - any legacy data structure that supports target testing, evaluation, follow-up
  • CSP:
    • The state is defined by variables Xiand Divalues ​​in the (value domain) field
    • A target test is a set of constraints, each of which includes some subset of variables and specifies the allowed combinations between the values ​​of these subsets

Example: Map Coloring

  • Variables WA, NT, Q, NSW, V, SA, T
    field Di={red, green, blue}
    Restrictions: Adjacent areas must have different colors
  • The original image:insert image description here
  • One solution: insert image description hereThe solution is an assignment that satisfies all constraints, e.g. {WA=red, NT =green, Q=red, NSW =green, V =red, SA=blue, T =green}

constraint graph

  • Binary CSP: each constraint is related to two variables
  • Constraint graph: nodes are variables, arcs are constraintsinsert image description here
  • The general CSP algorithm uses a graph structure to speed up the search.

Types of CSPs

  • Discrete variable:
    • finite domains finite domain:
      • n variables, domain size d → O ( dn ) d→O(d^n)dO(dn)
      • Boolean CSPs, including Boolean satisfiability (NP-complete) such as 3-SAT
    • infinite domains infinite domain (integers, strings, etc.)
      • For example, job scheduling, the variables are start/end dates for each job
      • need a constraint language
      • Linear constraints are solvable, nonlinear constraints are not
  • Continuous variable:
    • For example, start/end times for Hubble Space Telescope observations
    • Linear constraints solvable in polynomial time with linear programming (LP) methods

constraint type

  • Unary constraints contain a single variable
    • For example, SA≠green
  • Binary constraints contain pairs of variables
    • For example, SA≠WA
  • Higher-order (higher-order ) constraints contain 3 or more variables
    • For example, cryptographic operations (cipher arithmetic) column constraints
  • Preferences (soft constraints) , e.g. red is better than green
  • Usually expressed in terms of the dissipation of each individual variable assignment → constrained optimization problem

Example: Cryptographic Algorithms

insert image description here

CSPs in the real world

  • Assignment questions, such as who teaches what class and who reviews which papers
  • timetable issues, e.g. when and where to offer which class
    • Hardware Configuration
    • transportation dispatch
    • Factory Scheduling
    • floor plan
  • Note that many real-world problems involve real-valued variables
  • Enumerate one by one :
    • inefficient
    • takes exponential time d n
    • but complete
      • How to Make Exponential Time Algorithms Efficient

standard search formula

  • incremental incremental formalization
    • Let's start with the easy way and refine it
    • State is defined by the value assigned so far
      • Initial state : empty assignment, {}
      • Successor function :
        • Assign a value to an unassigned variable that does not conflict with the current assignment
        • Fails if there is no legal assignment
      • Goal Test : Current Task Completed
    1. Pros : Formal method is the same for all CSPs
    2. Each solution occurs at depth n with n variables
      • So you can use depth-first search
    3. The paths are uncorrelated, so the full state formalization can be used
    4. Disadvantages : CSP has n variables with a range size of d, and the top-level branching factor is nd, because there are n variables, and the value of each variable can be any of the d values. At the next level, the branching factor is (n-1)d, and so on for n levels. produces a search tree with n!·d n leaves, even though there are only d n possible full assignments !
    5. insert image description here

backtracking search

  • Variable assignments are commutative

    • [ WA = red then NT = green ][ NT = green then WA = red ]is the same as
  • Depth-first search of CSP with univariate assignment is called backtracking search

  • Backtracking search is the basic uninformed algorithm of CSP. Can solve the n queens problem with n≈25insert image description hereinsert image description hereinsert image description here

Improve the efficiency of backtracking searches

  • A generic approach can yield huge gains in speed:
    1. Which variable should be assigned next?
    2. In what order should its values ​​be tried?
    3. Can we find that the current scheme is not working? Fail early?
    4. Can we take advantage of problem structure?

Least Remaining Value Heuristic

Solved: which variable should be assigned next

  • Minimum remaining values ​​Minimum Remaining Values ​​(MRV): Choose the variable with the fewest legal values, but here it is not helpful to choose the first colored region, because initially each region has legal three colors to choose from - compared to insert image description hererandom or static sorting, the MRV heuristic usually performs better - it picks out the variables most likely to fail quickly

degree heuristic

Solved: which variable should be assigned next

  • Degree heuristic: Attempts to lower future branching factors by choosing the variable that is most constrained with other unassigned variables
  • The least remaining value heuristic is often a strong guide, while the degree heuristic is very useful for breaking deadlocks.
  • Here, the degree heuristic can decide to choose the first shaded regioninsert image description here

Least Constrained Value Heuristic

Solution: In what order should its values ​​be tried

  • Once a variable is selected, the algorithm needs to decide the order in which to test its values. Sometimes the least constrained value heuristic works well
  • It prefers values ​​that leave more choices for neighbor variables.
  • Exclude the one with the smallest value among the remaining variables; note that this may take some calculations to determine!insert image description here
  • Combining these heuristics, the 1000 queens problem is also feasible

Forward checking—forward checking

  • Idea: keep track of remaining legal values ​​for unassigned variables, terminate search when any variable has no legal valueinsert image description here

Constraint propagation — constraint propagation

  • Forward checking propagates information from assigned to unassigned variables, but cannot provide early detection for all failures:
  • Problem arises in the third state: NT and SA cannot both be blue! Indicating subsequent states is meaningless.insert image description here

Guess you like

Origin blog.csdn.net/weixin_56462041/article/details/129714772