Franck Pommereau

fixed Inhibitor arcs

...@@ -455,6 +455,19 @@ class ArcAnnotation (NetElement) : ...@@ -455,6 +455,19 @@ class ArcAnnotation (NetElement) :
455 @return: a value 455 @return: a value
456 """ 456 """
457 raise NotImplementedError("abstract method") 457 raise NotImplementedError("abstract method")
458 + def check (self, binding, tokens) :
459 + """Check whether the label allows to fire with tokens
460 +
461 + >>> Value(1).check(Substitution(), MultiSet([1, 2, 3]))
462 + True
463 + >>> Value(4).check(Substitution(), MultiSet([1, 2, 3]))
464 + False
465 + >>> Variable("x").check(Substitution(x=1), MultiSet([1, 2, 3]))
466 + True
467 + >>> Variable("x").check(Substitution(x=4), MultiSet([1, 2, 3]))
468 + False
469 + """
470 + return self.flow(binding) <= tokens
458 def flow (self, binding) : 471 def flow (self, binding) :
459 """Return the flow of tokens implied by the annotation evaluated 472 """Return the flow of tokens implied by the annotation evaluated
460 through `binding`. 473 through `binding`.
...@@ -1502,7 +1515,7 @@ class Test (ArcAnnotation) : ...@@ -1502,7 +1515,7 @@ class Test (ArcAnnotation) :
1502 return self.__class__(self._annotation.replace(old, new)) 1515 return self.__class__(self._annotation.replace(old, new))
1503 1516
1504 class Inhibitor (Test) : 1517 class Inhibitor (Test) :
1505 - """This is an inhibitoir arc that forbids the presence of some 1518 + """This is an inhibitor arc that forbids the presence of some
1506 tokens in a place. 1519 tokens in a place.
1507 """ 1520 """
1508 input_allowed = True 1521 input_allowed = True
...@@ -1704,6 +1717,20 @@ class Inhibitor (Test) : ...@@ -1704,6 +1717,20 @@ class Inhibitor (Test) :
1704 """ 1717 """
1705 return self.__class__(self._annotation.replace(old, new), 1718 return self.__class__(self._annotation.replace(old, new),
1706 self._condition.replace(old, new)) 1719 self._condition.replace(old, new))
1720 + def check (self, binding, tokens) :
1721 + """Check whether the label allows to fire with tokens
1722 +
1723 + >>> Inhibitor(Value(1)).check(Substitution(), MultiSet([1, 2, 3]))
1724 + False
1725 + >>> Inhibitor(Value(4)).check(Substitution(), MultiSet([1, 2, 3]))
1726 + True
1727 + >>> Inhibitor(Variable("x")).check(Substitution(x=1), MultiSet([1, 2, 3]))
1728 + False
1729 + >>> Inhibitor(Variable("x")).check(Substitution(x=4), MultiSet([1, 2, 3]))
1730 + True
1731 + """
1732 + return (not self._annotation.check(binding, tokens)
1733 + and self._condition(binding))
1707 1734
1708 class Flush (ArcAnnotation) : 1735 class Flush (ArcAnnotation) :
1709 """A flush arc used as on input arc will consume all the tokens in 1736 """A flush arc used as on input arc will consume all the tokens in
...@@ -2430,7 +2457,7 @@ class Transition (Node) : ...@@ -2430,7 +2457,7 @@ class Transition (Node) :
2430 return False 2457 return False
2431 if tokens : 2458 if tokens :
2432 for place, label in self.input() : 2459 for place, label in self.input() :
2433 - if not (label.flow(binding) <= place.tokens) : 2460 + if not label.check(binding, place.tokens) :
2434 return False 2461 return False
2435 if input : 2462 if input :
2436 for place, label in self.input() : 2463 for place, label in self.input() :
......