lecture 5: on-line search constraint satisfaction problems
DESCRIPTION
Lecture 5: On-line search Constraint Satisfaction Problems. Reading: Sec. 4.5 & Ch. 5, AIMA. Recap. Blind search (BFS, DFS) Informed search (Greedy, A*) Local search (Hill-climbing, SA, GA 1 ) Today: On-line search Constraint satisfaction problems. On-line search. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/1.jpg)
Rutgers CS440, Fall 2003
Lecture 5:On-line search
Constraint Satisfaction Problems
Reading: Sec. 4.5 & Ch. 5, AIMA
![Page 2: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/2.jpg)
Rutgers CS440, Fall 2003
Recap
• Blind search (BFS, DFS)• Informed search (Greedy, A*)• Local search (Hill-climbing, SA, GA1)• Today:
– On-line search
– Constraint satisfaction problems
![Page 3: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/3.jpg)
Rutgers CS440, Fall 2003
On-line search
• So far, off-line search: – Observe environment, determine best set of actions (shortest path)
that leads from start to goal
– Good for static environments
• On-line search: – Perform action, observe environment, perform, observe, …
– Dynamic, stochastic domains: exploration
– Similar to…
– …local search, but to get to all successor states, agent has to explore all actions
![Page 4: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/4.jpg)
Rutgers CS440, Fall 2003
Depth-first online
• Online algorithms cannot simultaneously explore distant states (i.e., jump from current state to a very distant state, like, e.g., A*)
• Similar to DFS– Try unexplored actions– Once all tried, and the goal is not reached, backtrack to unbacktracked previous state
![Page 5: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/5.jpg)
Rutgers CS440, Fall 2003
DFS-Online
function action = DFS-Online(percept)s = GetState(percept);
if GoalTest(s) return stop;if NewState(s) unexplored[s] = Actions(s);if NonEmpty(sp)
Result[sp,ap] = s;Unbacktracked[s] = sp;
endIf Empty(unexpolred[s])
If Empty(unbacktracked[s]) return stop;else
a: Result[ s, a ] = Pop( unbacktracked[s] );else
a = Pop( unexplored[s] );endsp = s;return a;
endcc
![Page 6: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/6.jpg)
Rutgers CS440, Fall 2003
Maze
s0
G
![Page 7: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/7.jpg)
Rutgers CS440, Fall 2003
Online local search
• Hill-climbing…– Is an online search!
– However, it does not have any memory.
– Can one use random restarts?
• Instead…– Random wandering by choosing random actions (random walk) ---
eventually, visits all points
– Augment HC with memory of sorts: keep track of estimates of h(s) and updated them as the search proceeds
– LRTA* - learning real-time A*
![Page 8: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/8.jpg)
Rutgers CS440, Fall 2003
LRTA*
function action = LRTA*(percept)s = GetState(percept);
if GoalTest(s) return stop;if NewState(s) H[s] = h(s);if NonEmpty(sp)
Result[sp,ap] = s;H[sp] = min b Actions(sp) { c(sp,b,s) + H(s) };
enda = arg min b Actions(s) { c(s,b, Result[s,b] ) + H(Result[s,b] ) };endsp = s;return a;
endcc
![Page 9: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/9.jpg)
Rutgers CS440, Fall 2003
Maze – LRTA*
4
s0
4
3
3
3
4
2
2
2
3
4
1
1
2
3
4
G1
2
3
4
3 3 4
44
![Page 10: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/10.jpg)
Rutgers CS440, Fall 2003
Constraint satisfaction problems - CSP
• Slightly different from standard search formulation– Standard search: abstract notion of state + successor function +
goal test
• CSP:– State: a set of variables V = {V1, …, VN} and values that can be
assigned to them specified by their domains D = {D1, …, DN}, Vi Di
– Goal: a set of constraints on the values that combinations of V can take
• Examples:– Map coloring, scheduling, transportation, configuration, crossword
puzzle, N-queens, minesweeper, …
![Page 11: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/11.jpg)
Rutgers CS440, Fall 2003
Map coloring
• Vi = { WA, NT, SA, Q, NSW, V, T }• Di = { R, G, B }• Goal / constraint: adjacent regions must have different color
• Solution: { (WA,R), (NT,G), (SA,B), (Q,R), (NSW,G), (V,R), (T,G) }
![Page 12: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/12.jpg)
Rutgers CS440, Fall 2003
Constraint graph
• Nodes: variables, links: constraints
WA
NT
SA
Q
NSW
V
T
![Page 13: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/13.jpg)
Rutgers CS440, Fall 2003
Types of CSPs
• Discrete-valued variables– Finite: O(dN) assignments, d = |D|
• Map coloring, Boolean satisfiability
– Infinite: D is infinite, e.g., strings or natural numbers• Scheduling
• Linear constraints: aV1 + bV2 < V3
• Continuous-valued variables– Functional optimization
– Linear programming
![Page 14: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/14.jpg)
Rutgers CS440, Fall 2003
Types of constraints
• Unary: V blue• Binary: V Q• Higher order• Preferences: different values of V have different “scores”
![Page 15: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/15.jpg)
Rutgers CS440, Fall 2003
CSP as search
• Generic: fits all CSP• Depth N, N = number of variables• DFS, but path irrelevant• Problem: # leaves is n!dN > dN
• Luckily, we only need consider one variable per depth! – Assignment is commutative.
function assignment = NaiveCSP(V,D,C)1) Initial state = {};2) Successor function: assign value to unassigned variable that does not conflict with current assignments.3) Goal: Assignment complete?
end
![Page 16: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/16.jpg)
Rutgers CS440, Fall 2003
Backtracking search
• DFS with single variable assignment
![Page 17: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/17.jpg)
Rutgers CS440, Fall 2003
Map coloring example
WA
NT
SA
Q
NSW
V
T
WA
NTQ
![Page 18: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/18.jpg)
Rutgers CS440, Fall 2003
How to improve efficiency?
• Address the following questions1. Which variable to pick next?
2. What value to assign next?
3. Can one detect failure early?
4. Take advantage of problem structure?
![Page 19: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/19.jpg)
Rutgers CS440, Fall 2003
Most constrained variable
• Choose next the variable that is most constrained based on current assignment
WA
NT
SA
Q
NSW
V
T
WA
NT
SA
![Page 20: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/20.jpg)
Rutgers CS440, Fall 2003
Most constraining variable
• Tie breaker among most constrained variables
WA
NT
SA
Q
NSW
V
T
SA
NTQ
![Page 21: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/21.jpg)
Rutgers CS440, Fall 2003
Least constraining value
• Select the value that least constrains the other variables (rules our fewest other variables)
![Page 22: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/22.jpg)
Rutgers CS440, Fall 2003
Forward checking
• Terminate search early, if necessary: – keep track of values of unassigned variables
![Page 23: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/23.jpg)
Rutgers CS440, Fall 2003
Constraint propagation
• FC propagates assignment from assigned to unassigned variables, but does not provide early detection of all failures
• NT & SA cannot both be blue!• CP repeatedly enforces constraints
![Page 24: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/24.jpg)
Rutgers CS440, Fall 2003
Arc consistency
• Simplest form of propagation makes each arcs consistent:• X -> Y is consistent iff for all x X, there is y Y that satisfies
constraints
• Detects failure earlier than FC.• Either preprocessor or after each assignment• AC-3 algorithm
![Page 25: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/25.jpg)
Rutgers CS440, Fall 2003
Problem structure
• Knowing something about the problem can significantly reduce search time
WA
NT
SA
Q
NSW
V
T
• T is independent of the rest! Connected components.• c-components => O(dcn/c)
![Page 26: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/26.jpg)
Rutgers CS440, Fall 2003
Tree-structured CSP
• If graph is a tree, CSP can be accomplished in O(nd2)
WA
NT
SA
Q
NSW
V
T
WA NT SAQ NSW V
1. Flatten tree into a “chain” where each node is preceded by its parent
2. Propagate constraints from last to second node
3. Make assignment from first to last
![Page 27: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/27.jpg)
Rutgers CS440, Fall 2003
Nearly tree-structured problems
• What if a graph is not a tree?• Maybe can be made into a tree by constraining it on a variable.
WA
NT
SA
Q
NSW
V
T
WA
NT
SA
Q
NSW
V
T
• If c is cutset size, then O(dc (N-c)d2 )
![Page 28: Lecture 5: On-line search Constraint Satisfaction Problems](https://reader033.vdocument.in/reader033/viewer/2022050908/56814502550346895db1cc5a/html5/thumbnails/28.jpg)
Rutgers CS440, Fall 2003
Iterative CSP
• Local search for CSP• Start from (invalid) initial assignment, modify it to reduce the
number of violated constraints1. Randomly pick a variable
2. Reassign a value such that constraints are least violated (min-conflict heuristic)
– Hill-climbing with h(s) = min-conflict