-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultistart_descent.py
More file actions
29 lines (23 loc) · 912 Bytes
/
multistart_descent.py
File metadata and controls
29 lines (23 loc) · 912 Bytes
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
from hill_climbing import *
from simple_descent import *
from deepest_descent import *
TIPOS = [ (1,3), (4,6), (5,7) ]
def multistart_descent(types, max_size, max_iter):
aux = 1
state = [0 for i in types]
best_state = [0 for i in types]
while aux <= max_iter:
neighbor = getNeighbor(best_state, types, max_size)
coin = random.randint(0,1)
if coin == 0:
state = simple_descent(types, max_size, neighbor)
else:
state = deepest_descent(types, max_size, neighbor)
if stateValue(state, types) > stateValue(best_state, types):
best_state = state
aux += 1
return best_state
if __name__ == "__main__":
result = multistart_descent(TIPOS, 19, 10)
print(result)
print("Custo da solução: "+str(stateSize(result, TIPOS))+", Valor da solução: "+str(stateValue(result, TIPOS)))