Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/ep_directionconstraint_none.py
diff options
context:
space:
mode:
Diffstat (limited to 'ep_directionconstraint_none.py')
-rw-r--r--ep_directionconstraint_none.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/ep_directionconstraint_none.py b/ep_directionconstraint_none.py
new file mode 100644
index 0000000..35fb6c1
--- /dev/null
+++ b/ep_directionconstraint_none.py
@@ -0,0 +1,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)