Algoritmos e complexidade Notas de aula - Arquivo Escolar

Algoritmos e complexidade Notas de aula - Arquivo Escolar Algoritmos e complexidade Notas de aula - Arquivo Escolar

arquivoescolar.org
from arquivoescolar.org More from this publisher
13.04.2013 Views

7. Árvores de busca, backtracking e branch-and-bound 7.1.1. Exemplo: Cobertura por vértices Considere Cobertura por vértices (ingl. vertex cover) Instância Grafo não-direcionado G = (V, E). Solução Uma cobertura C ⊆ V , i.e. ∀e ∈ E : e ∩ C = ∅. Objetivo Minimiza |C|. A versão de decisão de Cobertura por vértices é NP-completo. O que fazer? 1 3 20 21 18 19 Simplificando o problema 158 • Vértice de grau 1: Usa o vizinho. 17 2 • Vértice de grau 2 num triângulo: Usa os dois vizinhos. 23 22 24 4 16 10 25 15 5 13 14 6 9 12 8 7 11

Algoritmo 7.1 (Redução de cobertura por vértices) Entrada Grafo não-direcionado G = (V, E). 7.1. Backtracking Saída Um conjunto C ⊆ V e um grafo G ′ , tal que cada cobertura de vértices contém C, e a união de C com a cobertura mínima de G ′ é uma cobertura mínima de G. 1 Reduz (G) := 2 while ( alguma r e g r a em baixo se a p l i c a ) do 3 Regra 1 : 4 i f ∃u ∈ V : deg(u) = 1 then 5 s e j a {u, v} ∈ E 6 C := C ∪ {v} 7 G := G − {u, v} 8 end i f 9 Regra 2 : 10 i f ∃u ∈ V : deg(u) = 2 then 11 s e j a {u, v}, {u, w} ∈ E 12 i f {v, w} ∈ E then 13 C := C ∪ {v, w} 14 G := G − {u, v, w} 15 end i f 16 end while 17 return (C, G) Uma solução exata com busca exaustiva: Árvore de busca Algoritmo 7.2 (Árvore de busca) Entrada Grafo não-direcionado G = (V, E). Saída Cobertura por vértices S ⊆ V mínima. 1 minVertexCover (G):= 2 i f E = ∅ return ∅ 3 e s c o l h e {u, v} ∈ E 159

7. Árvores <strong>de</strong> busca, backtracking e branch-and-bound<br />

7.1.1. Exemplo: Cobertura por vértices<br />

Consi<strong>de</strong>re<br />

Cobertura por vértices (ingl. vertex cover)<br />

Instância Grafo não-direcionado G = (V, E).<br />

Solução Uma cobertura C ⊆ V , i.e. ∀e ∈ E : e ∩ C = ∅.<br />

Objetivo Minimiza |C|.<br />

A versão <strong>de</strong> <strong>de</strong>cisão <strong>de</strong> Cobertura por vértices é NP-completo.<br />

O que fazer?<br />

1<br />

3<br />

20 21<br />

18<br />

19<br />

Simplificando o problema<br />

158<br />

• Vértice <strong>de</strong> grau 1: Usa o vizinho.<br />

17<br />

2<br />

• Vértice <strong>de</strong> grau 2 num triângulo: Usa os dois vizinhos.<br />

23<br />

22<br />

24<br />

4<br />

16<br />

10<br />

25<br />

15<br />

5<br />

13<br />

14<br />

6<br />

9<br />

12<br />

8<br />

7<br />

11

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!