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
2014-06-13 16:42:08 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
7154071480f6a712d6461ff5c586f8bd282c436c
71540714
1 parent
7bee8a12
fixed help, added mock for Cinzia's simulations
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
13 deletions
cinzia.py
snakes/utils/abcd/simul.py
snakes/utils/simul/__init__.py
cinzia.py
0 → 100644
View file @
7154071
import
snakes.nets
as
snk
from
snakes.utils.simul
import
BaseSimulator
class
CinziaSimulator
(
BaseSimulator
)
:
def
__init__
(
self
,
**
system
)
:
net
=
snk
.
PetriNet
(
"counter machine"
)
for
var
,
spec
in
system
.
items
()
:
init
,
expr
=
spec
.
split
(
":"
,
1
)
system
[
var
]
=
snk
.
Expression
(
expr
)
net
.
add_place
(
snk
.
Place
(
var
,
[
int
(
init
)]))
for
var
,
expr
in
system
.
items
()
:
trans
=
"update_"
+
var
net
.
add_transition
(
snk
.
Transition
(
trans
))
for
v
in
set
(
expr
.
vars
()
+
[
var
])
:
net
.
add_input
(
v
,
trans
,
snk
.
Variable
(
v
))
if
v
==
var
:
net
.
add_output
(
v
,
trans
,
expr
)
else
:
net
.
add_output
(
v
,
trans
,
snk
.
Variable
(
v
))
BaseSimulator
.
__init__
(
self
,
net
)
def
getstate
(
self
,
state
)
:
ret
=
BaseSimulator
.
getstate
(
self
,
state
)
marking
=
self
.
states
[
state
]
ret
[
"variables"
]
=
dict
((
place
,
tokens
.
items
()[
0
])
for
place
,
tokens
in
marking
.
items
())
ret
[
"modes"
]
=
[]
for
i
,
(
trans
,
binding
)
in
enumerate
(
marking
.
modes
)
:
if
(
state
+
i
)
%
5
==
0
:
groups
=
[
"timed"
]
else
:
groups
=
[]
ret
[
"modes"
]
.
append
(
{
"state"
:
state
,
"mode"
:
i
,
"html"
:
"
%
s (
%
s)"
%
(
trans
.
name
[
7
:],
binding
),
"groups"
:
groups
+
[
"odd"
if
(
state
%
2
)
else
"even"
]
})
return
ret
snakes/utils/abcd/simul.py
View file @
7154071
import
tempfile
,
anydbm
,
os
from
snakes.utils.simul
import
*
from
snakes.utils.simul
import
BaseSimulator
,
BaseHTTPSimulator
import
snakes.utils.abcd.html
as
html
class
ABCDSimulator
(
BaseSimulator
)
:
...
...
@@ -33,9 +32,19 @@ class ABCDSimulator (BaseSimulator) :
return
res
def
init_help
(
self
)
:
help
=
BaseSimulator
.
init_help
(
self
)
help
.
update
({
"#model .abcd"
:
"ABCD source code"
,
"#model .tree"
:
"hierarchy of ABCD objects"
,
"#model .petrinet"
:
"Petri nets semantics"
})
help
.
update
({
"#model .abcd"
:
{
"title"
:
"Source"
,
"content"
:
"ABCD source code"
},
"#model .tree"
:
{
"title"
:
"State"
,
"content"
:
"hierarchy of ABCD objects"
,
},
"#model .petrinet"
:
{
"title"
:
"Net"
,
"content"
:
"Petri nets semantics"
}})
return
help
def
getstate
(
self
,
state
)
:
marking
=
self
.
states
[
state
]
...
...
snakes/utils/simul/__init__.py
View file @
7154071
import
snakes
from
snakes.utils.simul.httpd
import
*
from
snakes.utils.simul.html
import
H
import
multiprocessing
,
time
,
sys
,
json
,
os.path
,
signal
,
inspect
,
glob
import
multiprocessing
,
time
,
sys
,
os.path
,
signal
,
inspect
,
glob
import
operator
class
StateSpace
(
dict
)
:
...
...
@@ -109,11 +109,28 @@ class BaseSimulator (object) :
state
=
self
.
states
.
succ
(
state
,
mode
)
return
self
.
getstate
(
state
)
def
init_help
(
self
)
:
return
{
"#trace"
:
"the states and transitions explored so far"
,
"#model"
:
"the model being simulated"
,
"#alive .ui #ui-quit"
:
"stop the simulator (server side)"
,
"#alive .ui #ui-help"
:
"show this help"
,
"#alive .ui #ui-about"
:
"show information about the simulator"
}
return
{
"#trace"
:
{
"title"
:
"Trace"
,
"content"
:
"the states and transitions explored so far"
},
"#model"
:
{
"title"
:
"Model"
,
"content"
:
"the model being simulated"
},
"#alive .ui #ui-quit"
:
{
"title"
:
"Stop"
,
"content"
:
"stop the simulator (server side)"
},
"#alive .ui #ui-help"
:
{
"title"
:
"Help"
,
"content"
:
"show this help"
},
"#alive .ui #ui-about"
:
{
"title"
:
"About"
,
"content"
:
"show information about the simulator"
},
}
class
BaseHTTPSimulator
(
Node
)
:
def
__init__
(
self
,
net
,
port
=
8000
,
respatt
=
[],
simulator
=
None
)
:
...
...
@@ -139,7 +156,7 @@ class BaseHTTPSimulator (Node) :
while
True
:
try
:
httpd
=
HTTPServer
((
''
,
self
.
port
),
self
)
except
Exception
as
err
:
except
:
self
.
port
+=
1
else
:
break
...
...
@@ -206,7 +223,7 @@ class BaseHTTPSimulator (Node) :
@http
(
"application/json"
,
state
=
int
)
def
init
(
self
,
state
=-
1
)
:
ret
=
{
"ui"
:
self
.
init_ui
(),
"help"
:
self
.
init_help
()}
"help"
:
self
.
simul
.
init_help
()}
ret
.
update
(
self
.
simul
.
init
(
state
))
return
ret
@http
(
"application/json"
,
state
=
int
,
mode
=
int
)
...
...
Please
register
or
login
to post a comment