-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_descent.py
More file actions
29 lines (23 loc) · 862 Bytes
/
simple_descent.py
File metadata and controls
29 lines (23 loc) · 862 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 *
import random
TIPOS = [ (1,3), (4,6), (5,7) ]
def simple_descent(types, max_size, state):
best_state = state
while True:
expandedStates = expandState(best_state)
validStates = list(
filter(
lambda state: stateIsValid(state, types, max_size),
expandedStates,
)
)
if not validStates:
return best_state
#Seleciona aleatoriamente um vizinho
aux = random.randint(0,len(validStates)-1)
neighbor = validStates.pop(aux)
best_state = neighbor
if __name__ == "__main__":
result = simple_descent(TIPOS, 19, [0,0,0])
print(str(result)+" - Simple Descent")
print("Custo da solução: "+str(stateSize(result, TIPOS))+", Valor da solução: "+str(stateValue(result, TIPOS)))