Set values between 0.0 and 1.0 only
This commit is contained in:
parent
a5a8108e99
commit
328064cb7c
|
@ -1,4 +1,4 @@
|
||||||
from math import pow, sin, pi
|
from math import pow, sin, pi, cos
|
||||||
from random import Random
|
from random import Random
|
||||||
|
|
||||||
rand = Random()
|
rand = Random()
|
||||||
|
@ -7,8 +7,8 @@ rand = Random()
|
||||||
class Individual(object):
|
class Individual(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.x = rand.uniform(-100, 100)
|
self.x = self.get_rand_param()
|
||||||
self.y = rand.uniform(-100, 100)
|
self.y = self.get_rand_param()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_params(cls, x, y):
|
def from_params(cls, x, y):
|
||||||
|
@ -34,6 +34,10 @@ class Individual(object):
|
||||||
|
|
||||||
def mutate(self):
|
def mutate(self):
|
||||||
if rand.randint(1, 10) % 2 == 0:
|
if rand.randint(1, 10) % 2 == 0:
|
||||||
self.x = rand.random()
|
self.x = self.get_rand_param()
|
||||||
else:
|
else:
|
||||||
self.y = rand.random()
|
self.y = self.get_rand_param()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_rand_param():
|
||||||
|
return rand.uniform(0, 1)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user