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
2016-05-05 11:52:08 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
1c8b6bbef843c70d2ec84f7c5cd5d77b237bb6f5
1c8b6bbe
1 parent
f368e327
fixed Inhibitor arcs (issue #8), misc fixes/improvements
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
12 deletions
snakes/nets.py
snakes/plugins/gv.py
snakes/utils/abcd/build.py
snakes/utils/abcd/main.py
snakes/nets.py
View file @
1c8b6bb
...
...
@@ -1637,22 +1637,23 @@ class Inhibitor (Test) :
def
__hash__
(
self
)
:
return
hash
((
"inhibitor"
,
self
.
_annotation
,
self
.
_condition
))
def
bind
(
self
,
binding
)
:
"""Return
the value of the annotation evaluated through
`binding`, or raise `ValueError` of this binding does not
validate the
condition.
"""Return
no tokens since arc corresponds to an absence of tokens.
Raise `ValueError` if this binding does not validate the
condition.
>>> Inhibitor(Expression('x+1'), Expression('x>0')).bind(Substitution(x=2))
Token(3
)
(
)
>>> try : Inhibitor(Expression('x+1'), Expression('x<0')).bind(Substitution(x=2))
... except ValueError : print(sys.exc_info()[1])
condition not True for {x -> 2}
@param binding: a substitution
@type binding: `Substitution`
@return: a value
@return: empty tuple
"""
if
self
.
_condition
(
binding
)
:
return
self
.
_annotation
.
bind
(
binding
)
return
(
)
else
:
raise
ValueError
(
"condition not True for
%
s"
%
str
(
binding
))
def
modes
(
self
,
values
)
:
...
...
@@ -2731,6 +2732,9 @@ class Marking (hdict) :
"""
return
cls
(((
child
[
"id"
],
child
.
child
(
"tokens"
)
.
child
()
.
to_obj
())
for
child
in
tree
.
get_children
(
"place"
)))
def
__str__
(
self
)
:
base
=
"{
%
s}"
%
", "
.
join
(
"
%
s=
%
s"
%
pair
for
pair
in
sorted
(
self
.
items
()))
return
base
.
replace
(
"={dot}"
,
""
)
def
__call__
(
self
,
place
)
:
"""Return the marking of `place`. The empty multiset is
returned if `place` is not explicitely given in the marking.
...
...
snakes/plugins/gv.py
View file @
1c8b6bb
...
...
@@ -105,7 +105,7 @@ class Graph (Cluster) :
def
dot
(
self
)
:
self
.
done
=
set
()
return
"
\n
"
.
join
(
self
.
_dot_text
([
"digraph {"
,
'charset="UTF-8"'
,
#
'charset="UTF-8"',
[
'node [label="N",'
' fillcolor="#FFFFFF",'
' fontcolor="#000000",'
...
...
@@ -120,7 +120,9 @@ class Graph (Cluster) :
return
text
else
:
return
'"
%
s"'
%
text
.
replace
(
'"'
,
r'\"'
)
def
render
(
self
,
filename
,
engine
=
"dot"
,
debug
=
False
)
:
def
render
(
self
,
filename
,
engine
=
None
,
debug
=
False
)
:
if
engine
is
None
:
engine
=
getattr
(
self
,
"engine"
,
"dot"
)
if
engine
not
in
(
"dot"
,
"neato"
,
"twopi"
,
"circo"
,
"fdp"
)
:
raise
ValueError
(
"unknown GraphViz engine
%
r"
%
engine
)
with
codecs
.
open
(
filename
+
".dot"
,
"w"
,
"utf-8"
)
as
outfile
:
...
...
@@ -134,12 +136,15 @@ class Graph (Cluster) :
"-o"
+
filename
,
outfile
.
name
],
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
dot
.
communicate
()
stderr
=
subprocess
.
STDOUT
)
stdout
,
stderr
=
dot
.
communicate
()
if
not
debug
:
os
.
unlink
(
outfile
.
name
)
if
dot
.
returncode
!=
0
:
raise
IOError
(
"
%
s exited with status
%
s"
%
(
engine
,
dot
.
returncode
))
if
stdout
.
strip
()
+
stderr
.
strip
()
:
stdout
=
"
\n
*** Original error message follows ***
\n
"
+
stdout
raise
IOError
(
"
%
s exited with status
%
s
%
s"
%
(
engine
,
dot
.
returncode
,
stdout
))
def
layout
(
self
,
engine
=
"dot"
,
debug
=
False
)
:
if
engine
not
in
(
"dot"
,
"neato"
,
"twopi"
,
"circo"
,
"fdp"
)
:
raise
ValueError
(
"unknown GraphViz engine
%
r"
%
engine
)
...
...
@@ -226,6 +231,7 @@ def extend (module) :
for
num
,
node
in
enumerate
(
self
.
node
()))
g
=
self
.
_copy
(
nodemap
,
self
.
clusters
,
cluster_attr
,
place_attr
,
trans_attr
)
g
.
engine
=
engine
self
.
_copy_edges
(
nodemap
,
g
,
arc_attr
)
if
graph_attr
:
graph_attr
(
self
,
g
.
attr
)
...
...
snakes/utils/abcd/build.py
View file @
1c8b6bb
...
...
@@ -90,8 +90,11 @@ class Builder (object) :
"""raise an exception with appropriate location
"""
if
self
.
stack
:
try
:
pos
=
"[
%
s:
%
s]: "
%
(
self
.
stack
[
-
1
]
.
lineno
,
self
.
stack
[
-
1
]
.
col_offset
)
except
:
pos
=
""
else
:
pos
=
""
raise
error
(
pos
+
message
)
...
...
snakes/utils/abcd/main.py
View file @
1c8b6bb
...
...
@@ -297,8 +297,13 @@ def main (args=sys.argv[1:], src=None) :
if
options
.
check
:
lineno
,
trace
=
Checker
(
net
)
.
run
()
if
options
.
simul
:
engine
=
"dot"
for
eng
in
gv_engines
:
if
getattr
(
options
,
"gv
%
s"
%
eng
)
:
engine
=
eng
break
try
:
simul
=
Simulator
(
node
,
net
,
draw
(
net
,
None
),
options
.
port
)
simul
=
Simulator
(
node
,
net
,
draw
(
net
,
None
,
engine
),
options
.
port
)
except
:
bug
()
simul
.
start
()
...
...
Please
register
or
login
to post a comment