-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex3.py
More file actions
82 lines (55 loc) · 1.81 KB
/
ex3.py
File metadata and controls
82 lines (55 loc) · 1.81 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from collections import deque
import time
from searchPlus import *
from MedoTotal import *
from GrafoAbstracto import *
def ida_star_graph_search_count(problem,f,verbose=False):
if not problem:
return None
initialState = problem.initial
fronteira = deque()
lastNode = None
initialNode = Node(initialState, None, None, 0)
fronteira.append(initialNode)
beenThereDoneThat = set()
beenThereDoneThat.add(initialState)
size = 1
cutoff = f(initialNode)
miniCut = infinity
if verbose:
print("------Cutoff at", cutoff)
i = 0
while fronteira:
node = fronteira.pop()
predict = f(node)
if verbose:
print("\n" + node.state)
print("Cost:", node.path_cost, "f=", predict)
if predict > cutoff:
miniCut = min(predict, miniCut)
if verbose:
print("Out of cutoff -- minimum out:", miniCut)
else:
if problem.goal_test(node.state):
lastNode = node
if verbose:
print("Goal found within cutoff!")
break
frontExtension = node.expand(problem)
frontExtension.reverse()
for n in frontExtension:
if n.state not in beenThereDoneThat:
fronteira.append(n)
size += 1
beenThereDoneThat.add(n.state)
i += 1
if not fronteira and miniCut != infinity:
fronteira.append(initialNode)
beenThereDoneThat.clear()
beenThereDoneThat.add(initialState)
size += 1
cutoff = miniCut
miniCut = infinity
if verbose:
print("\n\n------Cutoff at", cutoff)
return lastNode, size