cs 561, session 6 1 last time: problem-solving problem solving: goal formulation problem formulation...

37
CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation: Initial state •? •? •? Problem types: single state: accessible and deterministic environment multiple state: ? • contingency: ? • exploration: ?

Upload: internet

Post on 17-Apr-2015

110 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 1

Last time: Problem-Solving

• Problem solving: • Goal formulation • Problem formulation (states, operators) • Search for solution

• Problem formulation:• Initial state• ?• ?• ?

• Problem types: • single state: accessible and deterministic environment• multiple state: ?• contingency: ?• exploration: ?

Page 2: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 2

Last time: Problem-Solving

• Problem solving: • Goal formulation • Problem formulation (states, operators) • Search for solution

• Problem formulation:• Initial state• Operators• Goal test• Path cost

• Problem types: • single state: accessible and deterministic environment• multiple state: ?• contingency: ?• exploration: ?

Page 3: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 3

Last time: Problem-Solving

• Problem solving: • Goal formulation • Problem formulation (states, operators) • Search for solution

• Problem formulation:• Initial state• Operators• Goal test• Path cost

• Problem types: • single state: accessible and deterministic environment• multiple state: inaccessible and deterministic environment• contingency: inaccessible and nondeterministic environment• exploration: unknown state-space

Page 4: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 4

Last time: Finding a solution

Function General-Search(problem, strategy) returns a solution, or failureinitialize the search tree using the initial state problemloop do

if there are no candidates for expansion then return failurechoose a leaf node for expansion according to strategyif the node contains a goal state then return the corresponding

solutionelse expand the node and add resulting nodes to the search tree

end

Solution: is ???

Basic idea: offline, systematic exploration of simulated state-space by generating successors of explored states (expanding)

Page 5: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 5

Last time: Finding a solution

Function General-Search(problem, strategy) returns a solution, or failureinitialize the search tree using the initial state problemloop do

if there are no candidates for expansion then return failurechoose a leaf node for expansion according to strategyif the node contains a goal state then return the corresponding

solutionelse expand the node and add resulting nodes to the search tree

end

Solution: is a sequence of operators that bring you from current state to the goal state.

Basic idea: offline, systematic exploration of simulated state-space by generating successors of explored states (expanding).

Strategy: The search strategy is determined by ???

Page 6: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 6

Last time: Finding a solution

Function General-Search(problem, strategy) returns a solution, or failureinitialize the search tree using the initial state problemloop do

if there are no candidates for expansion then return failurechoose a leaf node for expansion according to strategyif the node contains a goal state then return the corresponding

solutionelse expand the node and add resulting nodes to the search tree

end

Solution: is a sequence of operators that bring you from current state to the goal state

Basic idea: offline, systematic exploration of simulated state-space by generating successors of explored states (expanding)

Strategy: The search strategy is determined by the order in which the nodes are expanded.

Page 7: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 7

Last time: search strategies

Uninformed: Use only information available in the problem formulation• Breadth-first• Uniform-cost• Depth-first• Depth-limited• Iterative deepening

Informed: Use heuristics to guide the search• Best first• A*

Page 8: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 8

Evaluation of search strategies

• Search algorithms are commonly evaluated according to the following four criteria:• Completeness: does it always find a solution if one exists?• Time complexity: how long does it take as a function of number of

nodes?• Space complexity: how much memory does it require?• Optimality: does it guarantee the least-cost solution?

• Time and space complexity are measured in terms of:• b – max branching factor of the search tree• d – depth of the least-cost solution• m – max depth of the search tree (may be infinity)

Page 9: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 9

Last time: uninformed search strategies

Uninformed search:Use only information available in the problem formulation• Breadth-first• Uniform-cost• Depth-first• Depth-limited• Iterative deepening

Page 10: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 10

Um algoritmo robusto e limpo

Function UniformCost-Search(problem, Queuing-Fn) returns a solution, or failureopen make-queue(make-node(initial-state[problem]))closed [empty]loop do

if open is empty then return failurecurrnode Remove-Front(open)if Goal-Test[problem] applied to State(currnode) then return

currnodechildren Expand(currnode, Operators[problem])while children not empty

[… see next slide …]endclosed Insert(closed, currnode)open Sort-By-PathCost(open)

end

Page 11: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 11

Um algoritmo robusto e limpo

[… see previous slide …]children Expand(currnode, Operators[problem])while children not empty

child Remove-Front(children)if no node in open or closed has child’s state

open Queuing-Fn(open, child)else if there exists node in open that has child’s state

if PathCost(child) < PathCost(node)open Delete-Node(open, node)open Queuing-Fn(open, child)

else if there exists node in closed that has child’s state

if PathCost(child) < PathCost(node)closed Delete-Node(closed, node)open Queuing-Fn(open, child)

end[… see previous slide …]

Page 12: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 12

Informed search (busca com informação)

Informed search:Uso de heurísticas para guiar a busca• Best first• A*• Heuristica• Hill-climbing• Simulated annealing

Page 13: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 13

Best-first search

• Idéia:usar uma função de avaliação para cada nó; estimação de “desejabilidade”

Expandir nó não expandido mais desejável.

• Implementação:

QueueingFn = insere successores em ordem decrescente de desejabilidade

• Casos especiais:greedy searchA* search

Page 14: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 14

Romania com custo de cada passo em km

Page 15: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 15

Greedy search (gula é um pecado capital)

• Função de estimação:h(n) = estimação do custo de nó ao objetivo

(heuristica)

• Por exemplo:hSLD(n) = distância em linha reta do nó a Bucharest

• Greedy search expande primeiro o nó que aparentemente é o mais próximo do objetivo, de acordo com h(n).

Page 16: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 16

Page 17: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 17

Page 18: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 18

Page 19: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 19

Page 20: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 20

Propriedades do Greedy Search

• Completo?

• Tempo?

• Memória?

• Ótimo?

Page 21: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 21

Properties of Greedy Search

• Completo? Não – pode ficar parado em loopse.g., Iasi > Neamt > Iasi > Neamt > …Completo espaço finito com teste de estado

repetido.

• Tempo? O(b^m) mas uma boa heurística pode daruma melhora dramática

• Memória? O(b^m) – mantém todos os nós em memória

• Ótimo?Não.

Page 22: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 22

A* search

• Idéia: evitar expandir caminhos que já são caros

função de avaliação: f(n) = g(n) + h(n) com:g(n) – custo do caminho para atingir o nóh(n) – custo estimado ao objetivo, do nóf(n) – custo estimado total do caminho pelo nó ao

objetivo

• A* search usa uma heurística admissível, isto é,h(n) h*(n) onde h*(n) é o custo verdadeiro a partir

de n.Por exemplo: hSLD(n) nunca sobre-estima distância real da estrada.

• Teorema: A* search é ótimo

Page 23: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 23

Page 24: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 24

Page 25: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 25

Page 26: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 26

Page 27: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 27

Page 28: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 28

Page 29: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 29

Properties of A*

• Complete?

• Time?

• Space?

• Optimal?

Page 30: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 30

Properties of A*

• Complete? Yes, unless infinitely many nodes with f f(G)

• Time? Exponential in [(relative error in h) x (length of solution)]

• Space?Keeps all nodes in memory

• Optimal? Yes – cannot expand fi+1 until fi is finished

Page 31: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 31

Prova do lema: caminho máximo

Page 32: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 32

Otimalidade de A* (prova mais usual)

Page 33: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 33

Otimalidade de A* (prova standard)

Suponha que um objetivo G sub-ótimo2 foi gerado e está na fila. Seja n um nó não expandido num caminho mais curto para um objetivo G ótimo.

Page 34: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 34

Heurísticas admissíveis

Page 35: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 35

Heurísticas admissíveis

Page 36: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 36

Problema relaxado

• Heurísticas admissíveis podem ser derivadas do custo exato de uma solução para uma versão relaxada do problema.

• Se as regras do 8-puzzle forem relaxadas de maneira que uma casa possa mover a qualquer lugar, então h1(n) produz a solução mais curta.

• Se as regras são relaxadas de modo que uma casa possa se mover a qualquer posição adjacente, então h2(n) produz a solução mais curta.

Page 37: CS 561, Session 6 1 Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:

CS 561, Session 6 37

Next time

• Iterative improvement• Hill climbing• Simulated annealing