-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheuristica.py
More file actions
51 lines (35 loc) · 1.26 KB
/
heuristica.py
File metadata and controls
51 lines (35 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class HeuristicaLabirinto():
def __init__(self, origem, destino):
self.h = None
self.g = 0
self.valor = None
"""Objetos do tipo espaco_estados"""
self.origem = origem
self.destino = destino
def calculaHeuristica(self):
"""Calculo pela distancia de Manhattan"""
valor_calculado = 0
vx = self.origem.getValorLetra()
vx_aux = self.destino.getValorLetra()
n = self.origem.getNumero()
n_aux = self.destino.getNumero()
distancia_horizontal = n - n_aux if n >= n_aux else n_aux - n
distancia_vertical = vx - vx_aux if vx >= vx_aux else vx_aux - vx
valor_calculado = distancia_horizontal + distancia_vertical
self.h = valor_calculado
def getValor(self):
if self.valor == None:
self.calculaHeuristica()
return self.valor
def getValorH(self):
if self.valor == None:
self.calculaHeuristica()
return self.valor
def is_admissivel(self):
"""
heurística de avaliacao f(n) = g(n) + h(n),
tal que h(n) ≤ h∗(n) é uma heurística admissível.
"""
return False
def is_monotonica(self):
return False