11 Introdução - UFRGS

12
1 Aula 03 : Slide 1 CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1 Algoritmos de Pesquisa de Caminhos Ferramentas para Síntese Automática de Circuitos Integrados Profs: Ricardo Reis e Marcelo Johann Aula 03 : Slide 2 CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1 Aula anterior… Classes de grafo Problemas e Algoritmos Deixado como exercício… Aula 03 : Slide 3 CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1 Resumo Introdução Aplicações Modelo, Objetivo e Princípios de Pesquisa Algoritmos de Pesquisa de Caminhos DFS, BFS, Maze Router em grades O Algoritmo A* Pesquisa bi-direcional e o algoritmo LCS* Conclusões Aula 03 : Slide 4 CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1 Introdução Introdução Como sair de um labirinto? 1 algoritmo : procedimento efetivo, seqüência de operações que termina e fornece a solução desejada; Aula 03 : Slide 5 CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1 Aplicações Aplicações Encontrar caminhos entre uma origem e um destino sobre uma estrutura possuem inúmeras aplicações. Trânsito Roteamento de Circuitos Integrados Solução de Jogos (Problemas) Dedução de Fórmulas 2 Aula 03 : Slide 6 CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1 Trânsito Trânsito

Transcript of 11 Introdução - UFRGS

Page 1: 11 Introdução - UFRGS

1

Aula 03 : Slide 1CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Algoritmos de Pesquisa deCaminhos

Ferramentas para SínteseAutomática de Circuitos IntegradosProfs: Ricardo Reis e Marcelo Johann

Aula 03 : Slide 2CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Aula anterior…

Classes de grafo

Problemas e AlgoritmosDeixado como exercício…

Aula 03 : Slide 3CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Resumo Introdução Aplicações Modelo, Objetivo e Princípios de Pesquisa Algoritmos de Pesquisa de Caminhos

DFS, BFS, Maze Router em grades O Algoritmo A* Pesquisa bi-direcional e o algoritmo LCS* Conclusões

Aula 03 : Slide 4CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

IntroduçãoIntrodução

Como sair deum labirinto?

11

algoritmo : procedimento efetivo,seqüência de operações que termina efornece a solução desejada;

Aula 03 : Slide 5CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

AplicaçõesAplicações

Encontrar caminhos entre uma origem eum destino sobre uma estruturapossuem inúmeras aplicações.

Trânsito Roteamento de Circuitos Integrados Solução de Jogos (Problemas) Dedução de Fórmulas

22

Aula 03 : Slide 6CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Trânsito Trânsito

Page 2: 11 Introdução - UFRGS

2

Aula 03 : Slide 7CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Conexões em Circuitos IntegradosConexões em Circuitos Integrados

chip

conexões

Aula 03 : Slide 8CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Conexões em Circuitos IntegradosConexões em Circuitos Integrados

Aula 03 : Slide 9CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Conexões em Circuitos IntegradosConexões em Circuitos Integrados

Divisão da área em regiõesou grade de trilhas

Grafo regular

Aula 03 : Slide 10CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Em um grafo localmente finito G=(V,E),encontrar o caminho mais curto entre nodosorigem s e destino t - menor custo aditivo.

v1

v2

v3v4

v5

v6

v7v8

v9

st

Definição do ProblemaDefinição do Problema 33

Aula 03 : Slide 11CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Princípios da PesquisaPrincípios da PesquisaA partir de s, formar uma árvore de pesquisa pela

aplicação repetitiva do operador de sucessãoUm nodo é expandido quando se aplica a operação de

sucessão sobre ele (o nodo se torna fechado)Um nodo é gerado quando é retornado pela operação

de sucessão (o nodo se torna aberto)

v1

v2v3

v4

v5

v6

v7

v8

v9s t

v0

v5

v1 v6

v3v8

v7v9v2

v4 admissibility

Aula 03 : Slide 12CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Pesquisa em Profundidade; Pesquisa em Largura Pesquisa Heurística; Pesquisa Bidirecional; Pesquisa Heurística Bidirecional; Pesquisa Frente a Frente; Pesquisa por Perímetro; Pesquisa Linear em Espaço;

Algoritmos de Algoritmos de Pesquisa de Caminhos Pesquisa de Caminhos 4 4

Page 3: 11 Introdução - UFRGS

3

Aula 03 : Slide 13CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Pesquisa em Profundidade (DFS)Pesquisa em Profundidade (DFS)

(Depth-First Search)Tão logo um novo nodo é gerado ele é selecionado para

ser expandido (LIFO).

st

Aula 03 : Slide 14CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

(Breadth-First Search)Primeiro expande todos os nodos a uma mesma

distância da origem (FIFO).

origem

destino

Pesquisaintermediária

Pesquisacompleta

Pesquisa em Largura (BFS)Pesquisa em Largura (BFS)

[Moore 1957][Dijkstra 1959]

Aula 03 : Slide 15CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

The Maze RouterThe Maze RouterX X X X X X X X X X X X X X X X X X X X

X X

X X

X X

X X

X S X

X X

X X

X X

X X

X X X X X X X X X X X X X X X X

X X

X T X

X X

X X

X X

X X

X X

X X

X X X X X X X X X X X X X X X X X X X X

Aula 03 : Slide 16CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

The Maze RouterThe Maze RouterX X X X X X X X X X X X X X X X X X X X

X X

X X

X X

X 2 X

X 2 1 2 X

X 2 X

X X

X X

X X

X X X X X X X X X X X X X X X X

X X

X T X

X X

X X

X X

X X

X X

X X

X X X X X X X X X X X X X X X X X X X X

Aula 03 : Slide 17CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

The Maze RouterThe Maze RouterX X X X X X X X X X X X X X X X X X X X

X X

X X

X 4 3 X

X 4 3 2 3 X

X 4 3 2 1 2 3 X

X 4 3 2 3 X

X 4 3 X

X X

X X

X X X X X X X X X X X X X X X X

X X

X T X

X X

X X

X X

X X

X X

X X

X X X X X X X X X X X X X X X X X X X X

Aula 03 : Slide 18CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

The Maze RouterThe Maze RouterX X X X X X X X X X X X X X X X X X X X

X 7 6 5 6 X

X 7 6 5 4 5 6 7 X

X 7 6 5 4 3 4 5 6 7 X

X 6 5 4 3 2 3 4 5 6 7 X

X 5 4 3 2 1 2 3 4 5 6 7 X

X 6 5 4 3 2 3 4 5 6 7 X

X 7 6 5 4 3 4 5 6 7 X

X 7 6 5 4 5 6 X

X 7 6 5 6 X

X X X X X X X X X X X X X X X X

X X

X T X

X X

X X

X X

X X

X X

X X

X X X X X X X X X X X X X X X X X X X X

Page 4: 11 Introdução - UFRGS

4

Aula 03 : Slide 19CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

The Maze RouterThe Maze RouterX X X X X X X X X X X X X X X X X X X X

X 9 8 7 6 5 6 7 8 9 10 11 12 X

X 8 7 6 5 4 5 6 7 8 9 10 11 12 X

X 7 6 5 4 3 4 5 6 7 8 9 10 11 12 X

X 6 5 4 3 2 3 4 5 6 7 8 9 10 11 12 X

X 5 4 3 2 1 2 3 4 5 6 7 8 9 10 11 12 X

X 6 5 4 3 2 3 4 5 6 7 8 9 10 11 12 X

X 7 6 5 4 3 4 5 6 7 8 9 10 11 12 X

X 8 7 6 5 4 5 6 7 8 9 10 11 12 X

X 9 8 7 6 5 6 7 8 9 10 11 12 X

X 10 9 X X X X X X X X X X X X X X X

X 11 10 11 12 X

X 12 11 12 T X

X 12 X

X X

X X

X X

X X

X X

X X X X X X X X X X X X X X X X X X X X

Aula 03 : Slide 20CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

The Maze RouterThe Maze RouterX X X X X X X X X X X X X X X X X X X X

X 9 8 7 6 5 6 7 8 9 10 11 12 13 14 15 16 X

X 8 7 6 5 4 5 6 7 8 9 10 11 12 13 14 15 16 X

X 7 6 5 4 3 4 5 6 7 8 9 10 11 12 13 14 15 16 X

X 6 5 4 3 2 3 4 5 6 7 8 9 10 11 12 13 14 15 X

X 5 4 3 2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 X

X 6 5 4 3 2 3 4 5 6 7 8 9 10 11 12 13 14 15 X

X 7 6 5 4 3 4 5 6 7 8 9 10 11 12 13 14 15 16 X

X 8 7 6 5 4 5 6 7 8 9 10 11 12 13 14 15 16 X

X 9 8 7 6 5 6 7 8 9 10 11 12 13 14 15 16 X

X 10 9 X X X X X X X X X X X X X X X

X 11 10 11 12 13 14 15 16 X

X 12 11 12 13 14 15 16 T X

X 13 12 13 14 15 16 X

X 14 13 14 15 16 X

X 15 14 15 16 X

X 16 15 16 X

X 16 X

X X

X X X X X X X X X X X X X X X X X X X X

Aula 03 : Slide 21CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Maze RouterMaze Router’’s expansions expansion g++void print(void);int bfs(int source, int target) { queue<int> q; q.push(source); while (!q.empty()) { int n = q.front(); q.pop(); if (n==target)

return 1; if (Space[n] != 'X')

{Space[n] = 'X';print();getchar();q.push(WEST(n));q.push(EAST(n));q.push(NORTH(n));q.push(SOUTH(n));}

} return 0; }

#include <iostream>#include <queue>using namespace std;#define SIDE 20#define PLACE(x,y) ((y)*SIDE+(x))#define WEST(n) (n-1)#define EAST(n) (n+1)#define NORTH(n) (n-SIDE)#define SOUTH(n) (n+SIDE)char Space[SIDE*SIDE];void init (void) { for (int i=0; i<SIDE*SIDE; ++i) Space[i] = ' '; for (int i=0; i<SIDE; ++i) { Space[PLACE(i,0)] = 'X'; Space[PLACE(i,SIDE-1)] = 'X'; Space[PLACE(0,i)] = 'X'; Space[PLACE(SIDE-1,i)] = 'X'; } for (int i=3; i<SIDE-3; ++i) Space[PLACE(i,10)] = 'X'; }

Aula 03 : Slide 22CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

The Maze RouterThe Maze RouterX X X X X X X X X X X X X X X X X X X X

X 9 8 7 6 5 6 7 8 9 10 11 12 13 14 15 16 X

X 8 7 6 5 4 5 6 7 8 9 10 11 12 13 14 15 16 X

X 7 6 5 4 3 4 5 6 7 8 9 10 11 12 13 14 15 16 X

X 6 5 4 3 2 3 4 5 6 7 8 9 10 11 12 13 14 15 X

X 5 4 3 2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 X

X 6 5 4 3 2 3 4 5 6 7 8 9 10 11 12 13 14 15 X

X 7 6 5 4 3 4 5 6 7 8 9 10 11 12 13 14 15 16 X

X 8 7 6 5 4 5 6 7 8 9 10 11 12 13 14 15 16 X

X 9 8 7 6 5 6 7 8 9 10 11 12 13 14 15 16 X

X 10 9 X X X X X X X X X X X X X X X

X 11 10 11 12 13 14 15 16 X

X 12 11 12 13 14 15 16 T X

X 13 12 13 14 15 16 X

X 14 13 14 15 16 X

X 15 14 15 16 X

X 16 15 16 X

X 16 X

X X

X X X X X X X X X X X X X X X X X X X X

Aula 03 : Slide 23CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

The Maze RouterThe Maze RouterX X X X X X X X X X X X X X X X X X X X

X 9 8 7 6 5 6 7 8 9 10 11 12 13 14 15 16 X

X 8 7 6 5 4 5 6 7 8 9 10 11 12 13 14 15 16 X

X 7 6 5 4 3 4 5 6 7 8 9 10 11 12 13 14 15 16 X

X 6 5 4 3 2 3 4 5 6 7 8 9 10 11 12 13 14 15 X

X 5 4 3 2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 X

X 6 5 4 3 2 3 4 5 6 7 8 9 10 11 12 13 14 15 X

X 7 6 5 4 3 4 5 6 7 8 9 10 11 12 13 14 15 16 X

X 8 7 6 5 4 5 6 7 8 9 10 11 12 13 14 15 16 X

X 9 8 7 6 5 6 7 8 9 10 11 12 13 14 15 16 X

X 10 9 X X X X X X X X X X X X X X X

X 11 10 11 12 13 14 15 16 X

X 12 11 12 13 14 15 16 T X

X 13 12 13 14 15 16 X

X 14 13 14 15 16 X

X 15 14 15 16 X

X 16 15 16 X

X 16 X

X X

X X X X X X X X X X X X X X X X X X X X

Aula 03 : Slide 24CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Maze RouterMaze Router’’s trackings tracking g++typedef pair<int,int> Ref;

char Expansion[SIDE*SIDE]; // 0char Taken[SIDE*SIDE]; // ' '

int bfs(int source, int target) { queue<Ref> q; q.push(Ref(source,0)); while (!q.empty()) { int n = q.front().first; int p = q.front().second; q.pop(); if (n==target)

return 1; if (Expansion[n] == 0 &&

Taken[n] == ' '){Expansion[n] = p;q.push(Ref(WEST(n),n));. . . }

} return 0; }

1-You have to store thenode and where itcame from in the queueusing a pair<int,int>

2-Instead of Space, useExpansion[n] to storewhere the nodes camefrom and Taken[n] torepresent obstaclesand routes

4-Write backtrack(t,s)from target to sourcefollowing Expansion[n]

Page 5: 11 Introdução - UFRGS

5

Aula 03 : Slide 25CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

CCódigo BFS com custosódigo BFS com custos g++

Aula 03 : Slide 26CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Primeiro expande os nodos mais promissores,segundo a função: f(n) = g(n) + h(n)

origem destino

Pesquisaintermediária

Pesquisacompleta

g(n) h(n)

Efeito da eficiência

das estimativas

Pesquisa HeurPesquisa Heurística (A*)ística (A*) 55 [Hart et al. 1968]

Aula 03 : Slide 27CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Propriedades em pesquisa heurística Propriedades em pesquisa heurística

Admissibilidade (**): custo de n a t ≥ h(n)garante menor caminho

Consistência: k(n1,n2) + k(n2,n3) ≥ k(n1,n3)só expande nodos comcusto mínimo conhecido

n1

n2

n3k(n1,n2)

k(n2,n3)

k(n1,n3)

tn

h(n)

Menor caminhode n a t

h(n) = k(n,t)

Aula 03 : Slide 28CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

g=h=f =

1

g=0h=3f =3

7

g=h=f =

13

g=h=f =

2

g=h=f =

8

g=h=f =

14

g=h=f =

9g=h=f =

6

Open List:7

c=1 c=2 c=2

c=1

c=1

c=1

c=1

c=1

c=1

g=h=f =

3

c=1

c=2

g=h=f =

15c=1

c=2

g=h=f =

10

c=2

g=h=f =

4

c=1

c=2

g=h=f =

11c=1

c=2

Non uniform costs

Aula 03 : Slide 29CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

g=h=f =

9

Open List:8, 1, 13, 6

c=2

g=h=f =

3

c=1

c=2

g=h=f =

15c=1

c=2

g=h=f =

10

c=2

g=h=f =

4

c=1

c=2

g=h=f =

11c=1

c=2

g=1h=4f =5

1

g=0h=3f =3

7

g=1h=4f =5

13

g=h=f =

2

g=2h=2f =4

8

g=h=f =

14

g=1h=5f =5

6

c=1 c=2

c=1

c=1

c=1

c=1

c=1

c=1

Non uniform costs

Aula 03 : Slide 30CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Open List:1, 13, 6, 9, 2, 14

g=h=f =

10

c=2

g=h=f =

4

c=1

c=2

g=h=f =

11c=1

c=2

g=1h=4f =5

1

g=0h=3f =3

7

g=1h=4f =5

13

g=3h=3f =6

2

g=2h=2f =4

8

g=3h=3f =6

14

g=4h=1f =5

9g=1h=4f =5

6

c=1 c=2 c=2

c=1

c=1

c=1

c=1

c=1

c=1

g=h=f =

3

c=1

c=2

g=h=f =

15c=1

c=2

Non uniform costs

Page 6: 11 Introdução - UFRGS

6

Aula 03 : Slide 31CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

g=h=f =

10

c=2

g=h=f =

4

c=1

c=2

g=h=f =

11c=1

c=2

g=4h=1f =5

9

c=2

g=h=f =

3

c=1

c=2

g=h=f =

15c=1

c=2

g=1h=4f =5

1

7

g=1h=4f =5

13

g=3h=3f =6

2

g=2h=2f =4

8

g=3h=3f =6

14

g=1h=4f =5

6

c=1 c=2

c=1

c=1

c=1

c=1

c=1

c=1

g=0h=3f =3

Open List:1, 13, 6, 9, 2, 14 TiesTies

Non uniform costs

Aula 03 : Slide 32CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

g=h=f =

10

c=2

g=h=f =

4

c=1

c=2

g=h=f =

11c=1

c=2

g=4h=1f =5

9

c=2

g=h=f =

3

c=1

c=2

g=h=f =

15c=1

c=2

g=1h=4f =5

1

7

g=1h=4f =5

13

g=3h=3f =6

2

g=2h=2f =4

8

g=3h=3f =6

14

g=1h=4f =5

6

c=1 c=2

c=1

c=1

c=1

c=1

c=1

c=1

g=0h=3f =3

Open List:1, 13, 6, 9, 2, 14 But not critical But not critical as f * = 6as f * = 6

Non uniform costs

Aula 03 : Slide 33CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Open List:13

g=h=f =

10

c=1

g=h=f =

4

c=1

c=1

g=h=f =

11c=1

c=1

g=h=f =

1

g=h=f =

7

g=0h=4f =4

13

g=h=f =

2

g=h=f =

8

g=h=f =

14

g=h=f =

9g=h=f =

6

c=1 c=1 c=1

c=1

c=1

c=1

c=1

c=1

c=1

g=h=f =

3

c=1

c=1

g=h=f =

15c=1

c=1

Uniform costs

Aula 03 : Slide 34CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Open List:14,7

g=h=f =

10

c=1

g=h=f =

4

c=1

c=1

g=h=f =

11c=1

c=1

g=h=f =

1

g=1h=3f =4

7

g=0h=4f =4

13

g=h=f =

2

g=h=f =

8

g=1h=3f =4

14

g=h=f =

9g=h=f =

6

c=1 c=1 c=1

c=1

c=1

c=1

c=1

c=1

c=1

g=h=f =

3

c=1

c=1

g=h=f =

15c=1

c=1

Critical Ties

f(14) = f(7) = f *f(14) = f(7) = f *

Aula 03 : Slide 35CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Open List:15,8,7

g=h=f =

10

c=1

g=h=f =

4

c=1

c=1

g=h=f =

11c=1

c=1

g=h=f =

1

g=1h=3f =4

7

g=0h=4f =4

13

g=h=f =

2

g=2h=2f =4

8

g=1h=3f =4

14

g=h=f =

9g=h=f =

6

c=1 c=1 c=1

c=1

c=1

c=1

c=1

c=1

c=1

g=h=f =

3

c=1

c=1

g=2h=2f =4

15c=1

c=1

Can choose what you want

Aula 03 : Slide 36CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Open List:11,9,8,7

g=h=f =

10

c=1

g=h=f =

4

c=1

c=1

g=3h=1f =4

11c=1

c=1

g=h=f =

1

g=1h=3f =4

7

g=0h=4f =4

13

g=3h=3f =6

2

g=2h=2f =4

8

g=1h=3f =4

14

g=3h=1f =4

9g=h=f =

6

c=1 c=1 c=1

c=1

c=1

c=1

c=1

c=1

c=1

g=h=f =

3

c=1

c=1

g=2h=2f =4

15c=1

c=1

Nodes close to the target first

worst

best

Page 7: 11 Introdução - UFRGS

7

Aula 03 : Slide 37CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Open List:15,7,2,3

Nodes close to the target first

Only Only four four nodes expanded nodes expanded

g=4h=0f =4

10

c=1

g=h=f =

4

c=1

c=1

g=3h=1f =4

11c=1

c=1

g=h=f =

1

g=1h=3f =4

7

g=0h=4f =4

13

g=3h=3f =6

2

g=2h=2f =4

8

g=1h=3f =4

14

g=3h=1f =4

9g=h=f =

6

c=1 c=1 c=1

c=1

c=1

c=1

c=1

c=1

c=1

g=h=f =

3

c=1

c=1

g=2h=2f =4

15c=1

c=1

Aula 03 : Slide 38CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

g=4h=0f =4

10

c=1

g=h=f =

4

c=1

c=1

g=3h=1f =4

11c=1

c=1

g=h=f =

1

g=1h=3f =4

7

g=0h=4f =4

13

g=3h=3f =6

2

g=2h=2f =4

8

g=1h=3f =4

14

g=3h=1f =4

9g=h=f =

6

c=1 c=1 c=1

c=1

c=1

c=1

c=1

c=1

c=1

g=h=f =

3

c=1

c=1

g=2h=2f =4

15c=1

c=1

Open List:15,7,2,3

But pay attention to:

Degree of freedomDegree of freedom

Aula 03 : Slide 39CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

g=4h=0f =4

10

c=1

g=h=f =

4

c=1

c=1

g=3h=1f =4

11c=1

c=1

g=h=f =

1

g=1h=3f =4

7

g=0h=4f =4

13

g=3h=3f =6

2

g=2h=2f =4

8

g=1h=3f =4

14

g=3h=1f =4

9g=h=f =

6

c=1 c=1 c=1

c=1

c=1

c=1

c=1

c=1

c=1

g=h=f =

3

c=1

c=1

g=2h=2f =4

15c=1

c=1

Open List:15,7,2,3

But pay attention to:

Degree of freedomDegree of freedom

Aula 03 : Slide 40CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

g=4h=0f =4

10

c=1

g=h=f =

4

c=1

c=1

g=3h=1f =4

11c=1

c=1

g=h=f =

1

g=1h=3f =4

7

g=0h=4f =4

13

g=3h=3f =6

2

g=2h=2f =4

8

g=1h=3f =4

14

g=3h=1f =4

9g=h=f =

6

c=1 c=1 c=1

c=1

c=1

c=1

c=1

c=1

c=1

g=h=f =

3

c=1

c=1

g=2h=2f =4

15c=1

c=1

Open List:15,7,2,3

But pay attention to:

Degree of freedomDegree of freedom

Aula 03 : Slide 41CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

CCódigo de A*ódigo de A* g++

Aula 03 : Slide 42CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

The The A* A* AlgorithmAlgorithmX X X X X X X X X X X X X X X X X X X X

X X

X X

X X

X X

X 10 X

X X

X X

X X

X X

X X X X X X X X X X X X X X X X

X X

X T X

X X

X X

X X

X X

X X

X X

X X X X X X X X X X X X X X X X X X X X

7

3

h = estimation function

Page 8: 11 Introdução - UFRGS

8

Aula 03 : Slide 43CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

The The A* A* AlgorithmAlgorithmX X X X X X X X X X X X X X X X X X X X

X X

X X

X X

X X

X 10 X

X 10 X

X 10 X

X X

X X

X X X X X X X X X X X X X X X X

X X

X T X

X X

X X

X X

X X

X X

X X

X X X X X X X X X X X X X X X X X X X X

Min f = g + h Max g

Aula 03 : Slide 44CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

The The A* A* AlgorithmAlgorithmX X X X X X X X X X X X X X X X X X X X

X X

X X

X X

X X

X 10 X

X 10 X

X 10 X

X 10 X

X 10 10 X

X X X X X X X X X X X X X X X X

X X

X T X

X X

X X

X X

X X

X X

X X

X X X X X X X X X X X X X X X X X X X X

Min f = g + h Max g

Aula 03 : Slide 45CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

The The A* A* AlgorithmAlgorithmX X X X X X X X X X X X X X X X X X X X

X X

X X

X X

X X

X 10 X

X 10 X

X 10 X

X 10 X

X 10 10 10 10 X

X X X X X X X X X X X X X X X X

X X

X T X

X X

X X

X X

X X

X X

X X

X X X X X X X X X X X X X X X X X X X X

Straingth path from S to T

Aula 03 : Slide 46CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

The The A* A* AlgorithmAlgorithmX X X X X X X X X X X X X X X X X X X X

X X

X X

X X

X X

X 10 10 10 10 X

X 10 10 10 10 X

X 10 10 10 10 X

X 10 10 10 10 X

X 10 10 10 10 X

X X X X X X X X X X X X X X X X

X X

X T X

X X

X X

X X

X X

X X

X X

X X X X X X X X X X X X X X X X X X X X

Degrees of freedom

Aula 03 : Slide 47CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

The The A* A* AlgorithmAlgorithmX X X X X X X X X X X X X X X X X X X X

X X

X X

X X

X 12 12 12 12 X

X 12 10 10 10 10 12 X

X 12 10 10 10 10 12 X

X 12 10 10 10 10 12 X

X 12 10 10 10 10 12 X

X 12 10 10 10 10 12 X

X X X X X X X X X X X X X X X X

X X

X T X

X X

X X

X X

X X

X X

X X

X X X X X X X X X X X X X X X X X X X X

Maze router-like with obstacles

Aula 03 : Slide 48CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

X X X X X X X X X X X X X X X X X X X X

X X

X 16 16 16 16 X

X 16 14 14 14 14 16 X

X 16 14 12 12 12 12 14 16 X

X 16 14 12 10 10 10 10 12 14 16 X

X 16 14 12 10 10 10 10 12 14 16 X

X 16 14 12 10 10 10 10 12 14 16 X

X 16 14 12 10 10 10 10 12 14 16 X

X 16 14 12 10 10 10 10 12 14 16 X

X 16 X X X X X X X X X X X X X X X

X 16 X

X 16 16 16 16 16 16 T X

X X

X X

X X

X X

X X

X X

X X X X X X X X X X X X X X X X X X X X

The The A* A* AlgorithmAlgorithm

Maze router-like with obstacles

Page 9: 11 Introdução - UFRGS

9

Aula 03 : Slide 49CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

X X X X X X X X X X X X X X X X X X X X

X X

X 16 16 16 16 X

X 16 14 14 14 14 16 X

X 16 14 12 12 12 12 14 16 X

X 16 14 12 10 10 10 10 12 14 16 X

X 16 14 12 10 10 10 10 12 14 16 X

X 16 14 12 10 10 10 10 12 14 16 X

X 16 14 12 10 10 10 10 12 14 16 X

X 16 14 12 10 10 10 10 12 14 16 X

X 16 X X X X X X X X X X X X X X X

X 16 X

X 16 16 16 16 16 16 T X

X X

X X

X X

X X

X X

X X

X X X X X X X X X X X X X X X X X X X X

The The A* A* AlgorithmAlgorithm

Savedeffort

Aula 03 : Slide 50CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Duas frentes simultâneas de pesquisa nodo de encontro: reconhecido por ambas condição de término: f(n) > min[f(m)] sobreposição

origem

destino

Pesquisa daorigem

Pesquisaunidirecional

Pesquisa dodestino

Nodo deencontro

m

Pesquisa BidirecionalPesquisa Bidirecional 66

Aula 03 : Slide 51CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Objetivo: Unir as vantagens de ambasDificuldades: problema das frentes desencontradas intersecção das pesquisas condição de término

Suposto problemadas frentesdesencontradas

Objetivo

Bi-A*

Bi-BFS

Pesquisa Heurística Bidirecional Pesquisa Heurística Bidirecional

[Kwa 1989]

Aula 03 : Slide 52CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Wave-ShappingCalcula distância até cada nodo da frente opostaf(n) = gs (n) + min[k(n,pi) + gt (pi)]

gs(n) gt(pi)

k(n,pi )

s

n

t

pi

Requer tempo (ou espaço) quadrático para tal

Pesquisa Pesquisa Frente-a-FrenteFrente-a-Frente

Aula 03 : Slide 53CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Dois processos de pesquisa seguidoso primeiro BFS e o segundo A*, geralmente

gs(n)

gt(pi)

k(n,pi ) s n

t

pi

Primeira pesquisa,até um perímetrodeterminado

Segunda pesquisa,com estimativasfrente-a-frente

Demonstra potencial dos heurísticos bidirecionais

Pesquisa por Perímetro Pesquisa por Perímetro

Aula 03 : Slide 54CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Sucessivas pesquisas A* seguidascada uma limitada por um perímetro máximo.

Não precisa armazenar lista de nodos da fronteira

Pesquisa Linear em Espaço Pesquisa Linear em Espaço

Iterative Deepening A*

origem destino

Pesquisasintermediária

Pesquisacompleta

Page 10: 11 Introdução - UFRGS

10

Aula 03 : Slide 55CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

O Algoritmo LCS*O Algoritmo LCS* 66Lowerbound Cooperative Search [ISA/CI2000]Cooperation overall code is like BS* [Kwa 89] dynamic estimation (resistances e penalties) Function h of one front will be improved by the

other’s g values estimated values stored in referencescompleteness and admissibility proved [SBIA2000]

Aula 03 : Slide 56CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Condições para ExpansãoCondições para Expansão

Sufficient Condition for Expansion A* expands all nodes with f(n) < Ps-t*

Necessary Condition for Expansion A* only expands nodes with f(n) ≤ Ps-t*

Missing fronts? No, this is not the main problem! [Kaindl 95,97]

Aula 03 : Slide 57CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Poder de Poda Poder de Poda

o poder de um algoritmo heurístico admissível não estáem quão rápido ele encontra um caminho da origem aodestino, mas em quão rápido ele pode computar valoresmais altos de f() para os nodos que gera.

Aula 03 : Slide 58CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Resistência (min idea [Kaindl 96])

Penalidade (max idea [Kaindl 96])

gs(n)

gt(pi)

s n

t

pi

ht(n) hs(n)

ht(pi)

gt(pi) t

pi

k(pi ,t)

Rt = Min[gt(pi) - k(pi,t)]

Pt = Min[gt*(pi) - k(pi,s)]

F(n) = f(n) + Rt

F(n) = gs(n) + Pt - ht(n)

Estimação Dinâmica Estimação Dinâmica

Aula 03 : Slide 59CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Cooperação e VisibilidadeCooperação e Visibilidade

Function h of one front will be improved by the other’sg values

But h is under-estimated while g is over-estimatedBefore: g and h were associated with the nodes themselvesVisibility: estimated values stored in references single public closed set for both fronts

Aula 03 : Slide 60CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Expanded nodes and running time in 2D grids

200 by 200 grids with random costs, mean 100,

minimum 50, maximum 300

0

0,2

0,4

0,6

0,8

1

100140

180220

260300

340380

range of random costs

rati

o L

CS

*/A

*

nodes

runtime

Resultados de LCS* versus A*Resultados de LCS* versus A*

Page 11: 11 Introdução - UFRGS

11

Aula 03 : Slide 61CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Especificação de Custos AleatóriosEspecificação de Custos Aleatórios

maximum

minimum

Center(mean)

0

range

DCcost

ACcosts

Aula 03 : Slide 62CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Grade 200 por 200 com custos aleatórios, média

100, mínimo 50, máximo 300

0

50000

100000

150000

200000

250000

300000

350000

100140

180220

260300

340380

420460

500

variação de custos aleatórios gerados

tota

l d

e n

od

os

exp

an

did

os

LCS*

melhor A*

pior A*

Em grade, admissibilidade completa

Número de Expansões em Grade 2DNúmero de Expansões em Grade 2D

Aula 03 : Slide 63CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

LCS*/A* in 2D grids, regular cost regime

Testes de Testes de εε--admissibilidadeadmissibilidade

200 by 200 grids with random costs, mean 100,

minimum 50, maximum 300

0

0,5

1

1,5

2

2,5

3

15 25 35 45 55 65 75 85 95

range of random costs

rati

o L

CS

*/A

*

100%

96%

Aula 03 : Slide 64CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

100x100 random BFS, DFS and multi-DFS mazes

LCS* ganha nos labirintos mais difíceisLCS* ganha nos labirintos mais difíceis

Maze type Time Nodes

BFS 0.698 0.661

DFS 1.035 0.975

Multi-DFS 0.612 0.595

Aula 03 : Slide 65CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

70 nodes, all 70x70 path problems

LCS* ganha em LCS* ganha em grafos grafos aleatóriosaleatórios

Algorithm random solved

average A* 126156 78306

best A* 71576 61016

worst A* 18036 95596

LCS* 77710 59869

Aula 03 : Slide 66CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

70 nodes, all 70x70 path problems

A* quase ótimo em A* quase ótimo em grafos grafos geométricosgeométricos

Algorithm geometric plus one arc

average A* 39095 28406

best A* 24438 21428

worst A* 53752 35384

LCS* 38662 34130

Page 12: 11 Introdução - UFRGS

12

Aula 03 : Slide 67CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Pesquisa de caminhos tem diversasaplicações;

Algoritmos Heurísticos são admissíveis Existem outros algoritmos não

admissíveis; LCS* é o primeiro heurístico bidirecional e

admissível que é mais eficiente do que A*,mas é muito complexo;

Nunca esqueçam A*

ConclusõesConclusões 77

Aula 03 : Slide 68CMP241 - Ferramentas para Síntese Automática de CIs - Reis/Johann - UFRGS 2009/1

Próximas Aulas Ferramentas de Projeto, Síntese de Leiaute e

Compactação

ComputabilidadeO que é possível resolver em teoria……e o que é impossível.

TratabilidadeO que é possível resolver na prática(com tempo e memória razoáveis)…e como se resolve então!