Browse Source

created gspn example

refactoring
hannah 5 years ago
committed by Matthias Volk
parent
commit
339781db4a
  1. 56
      examples/gspns/01-gspns.py
  2. 2
      lib/stormpy/examples/files.py
  3. 16
      lib/stormpy/examples/files/gspn/gspn_simple.pnpro

56
examples/gspns/01-gspns.py

@ -0,0 +1,56 @@
import stormpy
import stormpy.gspn
import stormpy.examples
import stormpy.examples.files
def example_gspns_01():
# construct gspn with gspn builder
builder = stormpy.gspn.GSPNBuilder()
builder.set_name("gspn")
it_0 = builder.add_immediate_transition(1, 0.0, "it_0")
it_layout = stormpy.gspn.LayoutInfo(1.5, 1.5)
builder.set_transition_layout_info(it_0, it_layout)
tt_0 = builder.add_timed_transition(0, 0.4, "tt_0")
tt_layout = stormpy.gspn.LayoutInfo(12.5, 1.5)
builder.set_transition_layout_info(tt_0, tt_layout)
place_0 = builder.add_place(1, 1, "place_0")
p0_layout = stormpy.gspn.LayoutInfo(6.5, 1.5)
builder.set_place_layout_info(place_0, p0_layout)
place_1 = builder.add_place(1, 0, "place_1")
p1_layout = stormpy.gspn.LayoutInfo(18.5, 1.5)
builder.set_place_layout_info(place_1, p1_layout)
# arcs
builder.add_output_arc(it_0, place_0)
builder.add_inhibition_arc(place_0, it_0)
builder.add_input_arc(place_0, tt_0)
builder.add_output_arc(tt_0, place_1)
# build gspn
gspn = builder.build_gspn()
print("GSPN with {} places, {} immediate transitions and {} timed transitions.".format(gspn.get_number_of_places(),
gspn.get_number_of_immediate_transitions(),
gspn.get_number_of_timed_transitions()))
path = stormpy.examples.files.gspn_pnpro_simple
# export gspn to pnpro format
gspn.export_gspn_pnpro_file(path)
# import gspn
gspn_parser = stormpy.gspn.GSPNParser()
gspn_import = gspn_parser.parse(path)
print("GSPN with {} places, {} immediate transitions and {} timed transitions.".format(
gspn_import.get_number_of_places(), gspn.get_number_of_immediate_transitions(),
gspn.get_number_of_timed_transitions()))
if __name__ == '__main__':
example_gspns_01()

2
lib/stormpy/examples/files.py

@ -41,3 +41,5 @@ dft_galileo_hecs = _path("dft", "hecs.dft")
"""DFT example for HECS (Galileo format)""" """DFT example for HECS (Galileo format)"""
dft_json_and = _path("dft", "and.json") dft_json_and = _path("dft", "and.json")
"""DFT example for AND gate (JSON format)""" """DFT example for AND gate (JSON format)"""
gspn_pnpro_simple = _path("gspn", "gspn_simple.pnpro")
"""GSPN example (PNPRO format)"""

16
lib/stormpy/examples/files/gspn/gspn_simple.pnpro

@ -0,0 +1,16 @@
<project name="storm-export" version="121">
<gspn name="gspn" >
<nodes>
<place marking="1" name ="place_0" x="6.5" y="1.5" />
<place marking="0" name ="place_1" x="18.5" y="1.5" />
<transition name="tt_0" type="EXP" nservers="1" delay="0.4000000000" x="12.50000000" y="1.500000000" />
<transition name="it_0" type="IMM" priority="1" weight="1.000000000" x="1.500000000" y="1.500000000" />
</nodes>
<edges>
<arc head="tt_0" tail="place_0" kind="INPUT" mult="1" />
<arc head="place_1" tail="tt_0" kind="OUTPUT" mult="1" />
<arc head="it_0" tail="place_0" kind="INHIBITOR" mult="1" />
<arc head="place_0" tail="it_0" kind="OUTPUT" mult="1" />
</edges>
</gspn>
</project>
Loading…
Cancel
Save