Support parsing of xml file which export color petri net from CPNTools
Project description
CPNTools4Py
CPNTools4Py is a small python 3 scripts. These scripts support parsing of xml file which export color petri net from CPNTools, define a data structure for Petri nets and labelled partial orders. It is completely open source and be used in academia.
First Example
A very simple example, to what you appetite:
import cpntools4py
xml_doc = cpntools4py.read_xml('<path_to_xml_file>')
cpn = cpntools4py.CPN(xml_doc)
print(cpn.places) # Get places
Reference
Module cpntools4py
This is CPNTools4Py main module, it holds the various Petrei net elements, arcs, places, transitions.
Method cpntools4py.read_xml
def read_xml(file_path):
Read Xml file editing by CPNTools.
xml_doc = read_xml('/path/to/PetriNet.xml')
Call API
str file_path
: Input the XML file of Petri nets editing by CPNTools.return root Element
: Return an object that holds the root element of the node information of CPNTools.
Method cpntools4py.to_snakes
def to_snakes(cpn)
Convert to SNAKES from CPNTools
xml_doc = cpntools4py.read_xml('<path_to_xml_file>')
cpn = cpntools4py.CPN(xml_doc)
net = cpntools4py.to_snakes(cpn)
Call API
object CPN
: Input the CPN object.return object net
: return the SNAKES net object.
Module cpntools4py.petri_net
This is CPNTools4Py data structure module, it holds the various Petrei net elements, arcs, places, transitions.
Class Place
A place of a Petri net.
Place
class has 4 variables, each of which returns id
, text
, type
and tokens
.
Each variable holds the Place name, color attirbute, and initial marking set by CPNTools. Since id is an identification
number, it is automatically assinged at the time of generation by CPNTools.
xml_doc = cpntools4py.read_xml('<path_to_xml_file>')
cpn = cpntools4py.CPN(xml_doc)
for place in cpn.places:
print(place.id)
# 'id0123456789'
Class Transitions
A Transition of a Petri net.
Transition
class has 3 variables, each of which returns id
, text
and time
.
Each variable holds the Transition name and time inscription. id is and identification number.
xml_doc = cpntools4py.read_xml('<path_to_xml_file>')
cpn = cpntools4py.CPN(xml_doc)
for transition in cpn.transitions:
print(transition.text)
# 'Trans1'
Class Arc
A Arc of a Petri net.
Arc
class has 4 variables, each of which returns id
, orientation
, placeend
and transend
.
The Arc
class holds the connection information between places and transitions. orientation
holds the orientation of the arc, placened
and tranend
holdes the nodes to be connected.
xml_doc = cpntools4py.read_xml('<path_to_xml_file>')
cpn = cpntools4py.CPN(xml_doc)
for arc in cpn.arcs:
print(arc.orientation)
# 'PtoT'
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for cpntools4py-1.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43280e2639be5b89cceb5de454b69819dfcbef139c69cc1ca8c8ab8b9e1ea4b3 |
|
MD5 | 3292a5e19c1866182cbb3839d6a4d8c0 |
|
BLAKE2b-256 | 7687b06f0f45e414c1983d86002b363ec2d45e312c5bb95c318811744ce66ef7 |