-
Notifications
You must be signed in to change notification settings - Fork 0
/
deindividual.py
30 lines (21 loc) · 956 Bytes
/
deindividual.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
import random as rnd
class DeIndividual():
def __init__(self,problem):
self.F = 0.5
self.Cr = 0.9
self.tao = 0.10
self.x = [0 for _ in range(problem.dim)]
self.eval = float('inf')
def randomize(self,problem):
self.x = [problem.bounds[i][0] + rnd.random()*(problem.bounds[i][1]-problem.bounds[i][0]) for i, x in enumerate(self.x)]
def updateCtrlParams(self):
if rnd.random() < self.tao:
self.F = rnd.random()
if rnd.random() < self.tao:
self.Cr = rnd.random()
def toString(self):
print(self.x,self.eval)
def __gt__(self, other):
return self.eval < other.eval
def repair(self,problem):
self.x = [problem.bounds[i][0] + rnd.random()*(problem.bounds[i][1]-problem.bounds[i][0]) if x < problem.bounds[i][0] or x > problem.bounds[i][1] else x for i, x in enumerate(self.x)]