Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Franck Pommereau
/
snakes
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Franck Pommereau
2020-10-14 14:02:37 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
13f8c40ab184bf0d2208b70288095825edb4fccc
13f8c40a
1 parent
0742496e
fixed Inhibitor arcs
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
2 deletions
snakes/nets.py
snakes/nets.py
View file @
13f8c40
...
...
@@ -455,6 +455,19 @@ class ArcAnnotation (NetElement) :
@return: a value
"""
raise
NotImplementedError
(
"abstract method"
)
def
check
(
self
,
binding
,
tokens
)
:
"""Check whether the label allows to fire with tokens
>>> Value(1).check(Substitution(), MultiSet([1, 2, 3]))
True
>>> Value(4).check(Substitution(), MultiSet([1, 2, 3]))
False
>>> Variable("x").check(Substitution(x=1), MultiSet([1, 2, 3]))
True
>>> Variable("x").check(Substitution(x=4), MultiSet([1, 2, 3]))
False
"""
return
self
.
flow
(
binding
)
<=
tokens
def
flow
(
self
,
binding
)
:
"""Return the flow of tokens implied by the annotation evaluated
through `binding`.
...
...
@@ -1502,7 +1515,7 @@ class Test (ArcAnnotation) :
return
self
.
__class__
(
self
.
_annotation
.
replace
(
old
,
new
))
class
Inhibitor
(
Test
)
:
"""This is an inhibito
i
r arc that forbids the presence of some
"""This is an inhibitor arc that forbids the presence of some
tokens in a place.
"""
input_allowed
=
True
...
...
@@ -1704,6 +1717,20 @@ class Inhibitor (Test) :
"""
return
self
.
__class__
(
self
.
_annotation
.
replace
(
old
,
new
),
self
.
_condition
.
replace
(
old
,
new
))
def
check
(
self
,
binding
,
tokens
)
:
"""Check whether the label allows to fire with tokens
>>> Inhibitor(Value(1)).check(Substitution(), MultiSet([1, 2, 3]))
False
>>> Inhibitor(Value(4)).check(Substitution(), MultiSet([1, 2, 3]))
True
>>> Inhibitor(Variable("x")).check(Substitution(x=1), MultiSet([1, 2, 3]))
False
>>> Inhibitor(Variable("x")).check(Substitution(x=4), MultiSet([1, 2, 3]))
True
"""
return
(
not
self
.
_annotation
.
check
(
binding
,
tokens
)
and
self
.
_condition
(
binding
))
class
Flush
(
ArcAnnotation
)
:
"""A flush arc used as on input arc will consume all the tokens in
...
...
@@ -2430,7 +2457,7 @@ class Transition (Node) :
return
False
if
tokens
:
for
place
,
label
in
self
.
input
()
:
if
not
(
label
.
flow
(
binding
)
<=
place
.
tokens
)
:
if
not
label
.
check
(
binding
,
place
.
tokens
)
:
return
False
if
input
:
for
place
,
label
in
self
.
input
()
:
...
...
Please
register
or
login
to post a comment