You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

260 lines
6.1 KiB

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Generalized Stochastic Petri Nets"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Loading GSPNs\n",
"\n",
"[01-gspns.py](https://github.com/moves-rwth/stormpy/blob/master/examples/gspns/01-gspns.py)\n",
"\n",
"Generalized stochastic Petri nets can be given either in the PNPRO format or in the PNML format.\n",
"We start by loading a GSPN stored in the PNML format:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
">>> import stormpy\n",
">>> import stormpy.gspn\n",
">>> import stormpy.examples\n",
">>> import stormpy.examples.files\n",
"\n",
">>> import_path = stormpy.examples.files.gspn_pnml_simple\n",
">>> gspn_parser = stormpy.gspn.GSPNParser()\n",
">>> gspn = gspn_parser.parse(import_path)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"After loading, we can display some properties of the GSPN:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
">>> print(\"Name of GSPN: {}.\".format(gspn.get_name()))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
">>> print(\"Number of places: {}.\".format(gspn.get_number_of_places()))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
">>> print(\"Number of immediate transitions: {}.\".format(gspn.get_number_of_immediate_transitions()))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
">>> print(\"Number of timed transitions: {}.\".format(gspn.get_number_of_timed_transitions()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Building GSPNs\n",
"\n",
"[02-gspns.py](https://github.com/moves-rwth/stormpy/blob/master/examples/gspns/02-gspns.py)\n",
"\n",
"In the following, we describe how to construct GSPNs via the `GSPNBuilder`.\n",
"First, we create an instance of the `GSPNBuilder` and set the name of the GSPN:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
">>> builder = stormpy.gspn.GSPNBuilder()\n",
">>> builder.set_name(\"my_gspn\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the next step, we add an immediate transition to the GSPN.\n",
"Additionally, we define the position of the transition by setting its layout information:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
">>> it_1 = builder.add_immediate_transition(1, 0.0, \"it_1\")\n",
">>> it_layout = stormpy.gspn.LayoutInfo(1.5, 2.0)\n",
">>> builder.set_transition_layout_info(it_1, it_layout)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We add a timed transition and set its layout information:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
">>> tt_1 = builder.add_timed_transition(0, 0.4, \"tt_1\")\n",
">>> tt_layout = stormpy.gspn.LayoutInfo(12.5, 2.0)\n",
">>> builder.set_transition_layout_info(tt_1, tt_layout)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next, we add two places to the GSPN and set their layouts:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
">>> place_1 = builder.add_place(1, 1, \"place_1\")\n",
">>> p1_layout = stormpy.gspn.LayoutInfo(6.5, 2.0)\n",
">>> builder.set_place_layout_info(place_1, p1_layout)\n",
"\n",
">>> place_2 = builder.add_place(1, 0, \"place_2\")\n",
">>> p2_layout = stormpy.gspn.LayoutInfo(18.5, 2.0)\n",
">>> builder.set_place_layout_info(place_2, p2_layout)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Places and transitions can be linked by input, output and inhibition arcs.\n",
"We add the arcs of our GSPN as follows:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
">>> builder.add_output_arc(it_1, place_1)\n",
">>> builder.add_inhibition_arc(place_1, it_1)\n",
">>> builder.add_input_arc(place_1, tt_1)\n",
">>> builder.add_output_arc(tt_1, place_2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can now build the GSPN:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
">>> gspn = builder.build_gspn()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"After building, we export the GSPN.\n",
"GSPNs can be saved in the PNPRO format via `export_gspn_pnpro_file(path)` and in the PNML format via `export_gspn_pnml_file(path)`.\n",
"We export the GSPN into the PNPRO format:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
">>> export_path = stormpy.examples.files.gspn_pnpro_simple\n",
">>> gspn.export_gspn_pnpro_file(export_path)"
]
}
],
"metadata": {
"date": 1598178167.1731207,
"filename": "gspns.rst",
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.2"
},
"title": "Generalized Stochastic Petri Nets"
},
"nbformat": 4,
"nbformat_minor": 4
}