Commit a6557ea9 authored by Dr.李's avatar Dr.李

added more constraints type

parent 89ecac54
......@@ -27,6 +27,8 @@ class BoundaryDirection(IntEnum):
class BoundaryType(IntEnum):
ABSOLUTE = 0
RELATIVE = 1
MAXABSREL = 2
MINABSREL = 3
class BoundaryImpl(object):
......@@ -34,14 +36,14 @@ class BoundaryImpl(object):
def __init__(self,
direction: BoundaryDirection,
b_type: BoundaryType,
val: float):
val):
self.direction = direction
self.b_type = b_type
self.val = val
self._validation()
def _validation(self):
pyFinAssert(self.b_type == BoundaryType.ABSOLUTE or self.b_type == BoundaryType.RELATIVE,
pyFinAssert(self.b_type in [BoundaryType.ABSOLUTE, BoundaryType.RELATIVE, BoundaryType.MAXABSREL, BoundaryType.MINABSREL],
ValueError,
"Boundary Type {0} is not recognized".format(self.b_type))
......@@ -52,6 +54,30 @@ class BoundaryImpl(object):
def __call__(self, center: float):
if self.b_type == BoundaryType.ABSOLUTE:
return self.val + center
elif self.b_type == BoundaryType.MAXABSREL:
abs_threshold = self.val[0]
rel_threshold = self.val[1]
pyFinAssert(rel_threshold >= 0., ValueError, "relative bounds only support positive value")
if self.direction == BoundaryDirection.LOWER:
rel_bound = center - abs(center) * rel_threshold
abs_bound = center - abs_threshold
return min(rel_bound, abs_bound)
elif self.direction == BoundaryDirection.UPPER:
rel_bound = center + abs(center) * rel_threshold
abs_bound = center + abs_threshold
return max(rel_bound, abs_bound)
elif self.b_type == BoundaryType.MINABSREL:
abs_threshold = self.val[0]
rel_threshold = self.val[1]
pyFinAssert(rel_threshold >= 0., ValueError, "relative bounds only support positive value")
if self.direction == BoundaryDirection.LOWER:
rel_bound = center - abs(center) * rel_threshold
abs_bound = center - abs_threshold
return max(rel_bound, abs_bound)
elif self.direction == BoundaryDirection.UPPER:
rel_bound = center + abs(center) * rel_threshold
abs_bound = center + abs_threshold
return min(rel_bound, abs_bound)
else:
pyFinAssert(center >= 0., ValueError, "relative bounds only support positive back bone value")
return self.val * center
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment