-
Notifications
You must be signed in to change notification settings - Fork 0
/
hillclimber.py
39 lines (30 loc) · 971 Bytes
/
hillclimber.py
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
import pybullet as p
from solution import SOLUTION
import constants as c
import copy
class HILL_CLIMBER:
def __init__(self):
self.parent = SOLUTION()
print("Out HILL_CLIMBER")
def Evolve(self):
self.parent.Evaluate("GUI")
for currentGeneration in range(0, c.numberOfGenerations):
self.Evolve_For_One_Generation()
def Evolve_For_One_Generation(self):
self.Spawn()
self.Mutate()
self.child.Evaluate("DIRECT")
self.Print()
self.Select()
def Spawn(self):
self.child = copy.deepcopy(self.parent)
def Mutate(self):
self.child.Mutate()
def Select(self):
if self.child.fitness < self.parent.fitness:
self.parent = self.child
def Print(self):
print('Parent fitness: ' + str(self.parent.fitness))
print('Child fitness: ' + str(self.child.fitness))
def Show_Best(self):
self.parent.Evaluate("GUI")