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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# coding: UTF8
# Copyright 2009 Thomas Jourdan
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import math
import ka_random
import model_constraintpool
import model_locus
DISTANCE_CONSTRAINT = 'distance'
RADIAN_CONSTRAINT = 'radian'
class NoneDirectionConstraint(model_locus.Locus):
"""NoneDirectionConstraint
"""
cdef = [{'bind' : DISTANCE_CONSTRAINT,
'name' : 'Distance per hop',
'domain': model_constraintpool.FLOAT_RANGE,
'min' : 0.0, 'max': 0.5,
},
{'bind' : RADIAN_CONSTRAINT,
'name' : 'Rotation in radians',
'domain': model_constraintpool.FLOAT_RANGE,
'min' : -1.0*math.pi, 'max': math.pi,
},
]
def __init__(self, trunk):
"""Direction constraint constructor
"""
super(NoneDirectionConstraint, self).__init__(trunk)
def filter(self, radian, distance):
"""No constraints for radian and distance.
post: (-1.0*math.pi) <= __return__[0] <= math.pi
post: __return__[1] >= 0.0
"""
return ka_random.radian_limitate(radian), math.fabs(distance)
def randomize(self):
"""Set radian and distance to random values.
post: (-1.0*math.pi) <= __return__[0] <= math.pi
post: __return__[1] >= 0.0
"""
cpool = model_constraintpool.ConstraintPool.get_pool()
radian_constraint = cpool.get(self, RADIAN_CONSTRAINT)
distance_constraint = cpool.get(self, DISTANCE_CONSTRAINT)
radian = ka_random.uniform_constrained(radian_constraint)
distance = ka_random.uniform_constrained(distance_constraint)
return ka_random.radian_limitate(radian), math.fabs(distance)
def mutate(self, radian, distance):
"""Make small random changes in radian and distance.
post: (-1.0*math.pi) <= __return__[0] <= math.pi
post: __return__[1] >= 0.0
"""
cpool = model_constraintpool.ConstraintPool.get_pool()
radian_constraint = cpool.get(self, RADIAN_CONSTRAINT)
distance_constraint = cpool.get(self, DISTANCE_CONSTRAINT)
radian += ka_random.jitter_constrained(radian_constraint)
distance += ka_random.jitter_constrained(distance_constraint)
return ka_random.radian_limitate(radian), math.fabs(distance)
|