|
@@ -97,17 +97,93 @@ Read
|
|
|
>>> read_attrs("my_pn", "p1")
|
|
|
{"name": "place 1", "tokens": 2}
|
|
|
|
|
|
-types
|
|
|
-element_list_nice
|
|
|
-read_outgoing
|
|
|
-read_incoming
|
|
|
-read_association_source
|
|
|
-read_association_destination
|
|
|
-connections_between
|
|
|
-all_instances
|
|
|
+3. *types* reads out the list of types that can be instantiated in this model.
|
|
|
+ All calls to instantiate should act upon one of these types.
|
|
|
+ For PetriNets, this returns the concepts of the domain::
|
|
|
+
|
|
|
+ >>> types()
|
|
|
+ ["Place", "Transition", "P2T", "T2P", ...]
|
|
|
+
|
|
|
+4. *element_list_nice* reads out a simple JSON-like representation of the model.
|
|
|
+ This includes all information about the model and can be used to fetch the complete model in one go.
|
|
|
+ For example, to read out a simple PetriNet::
|
|
|
+
|
|
|
+ >>> element_list_nice("my_pn")
|
|
|
+ [{"id": "p1", "type": "Place", "name": "place 1", "tokens": 1},
|
|
|
+ {"id": "p2", "type": "Place", "name": "place 2", "tokens": 2},
|
|
|
+ {"id": "t1", "type": "Transition"},
|
|
|
+ {"id": "p2t", "type": "P2T", "__source": "p1", "__target": "t1", "weight": 1},
|
|
|
+ {"id": "t2p", "type": "T2P", "__source": "t1", "__target": "p2", "weight": 2},
|
|
|
+ ]
|
|
|
+
|
|
|
+5. *read_outgoing* reads the outgoing associations of a certain type, for a specific element.
|
|
|
+ This takes into account inheritance relation.
|
|
|
+ For example, to read out all outgoing P2T links of a place::
|
|
|
+
|
|
|
+ >>> read_outgoing("my_pn", "p1", "P2T")
|
|
|
+ ["p2t"]
|
|
|
+
|
|
|
+ It is possible to get all outgoing associations as well, by leaving the type empty (the empty string).
|
|
|
+
|
|
|
+6. *read_incoming* similarly reads out all incoming associations of a certain type, for a specific element.
|
|
|
+ For example, to read out all incoming T2P links of a place::
|
|
|
+
|
|
|
+ >>> read_incoming("my_pn", "p2", "T2P")
|
|
|
+ ["t2p"]
|
|
|
+
|
|
|
+ Again, the type can be set to the empty string to return all incoming associations.
|
|
|
+
|
|
|
+7. *read_association_source* reads out the source of a specific association, and can be used in conjunction with *read_outgoing* and *read_incoming*.
|
|
|
+ For example, to read out which is the source of an arc::
|
|
|
+
|
|
|
+ >>> read_association_source("my_pn", "p2t")
|
|
|
+ p1
|
|
|
+
|
|
|
+8. *read_association_destination* similarly reads out the destination of a specific association.
|
|
|
+ For example, to read out the target of an arc::
|
|
|
+
|
|
|
+ >>> read_association_destination("my_pn", "p2t")
|
|
|
+ t1
|
|
|
+
|
|
|
+9. *connections_between* reads out the set of all association types that can be created between two elements in the model.
|
|
|
+ This also takes into account inheritance information.
|
|
|
+ For example, to find out which association types can connect a place and transition::
|
|
|
+
|
|
|
+ >>> connections_between("my_pn", "p1", "t1")
|
|
|
+ ["P2T"]
|
|
|
+
|
|
|
+ If no associations are allowed, the list is empty.
|
|
|
+
|
|
|
+10. *all_instances* read out the set of all instances of a specific type in the model.
|
|
|
+ For example, to find all Places in our PetriNet model::
|
|
|
+
|
|
|
+ >>> all_instances("my_pn", "Place")
|
|
|
+ ["p1", "p2"]
|
|
|
|
|
|
Delete
|
|
|
^^^^^^
|
|
|
|
|
|
-delete_element
|
|
|
-attr_delete
|
|
|
+1. *delete_element* deletes the element from the model and the type mapping.
|
|
|
+ Note that currently, attribute values are not automatically removed from the model, and they will remain dangling.
|
|
|
+ Therefore, to prevent strange errors, it is safest to first delete all attributes of an element before deleting it.
|
|
|
+ Associations, however, are removed.
|
|
|
+ For example, to remove place p1::
|
|
|
+
|
|
|
+ >>> element_list_nice("my_pn")
|
|
|
+ [{"id": "p1", "type": "Place", "name": "place 1", "tokens": 1},
|
|
|
+ {"id": "p2", "type": "Place", "name": "place 2", "tokens": 2},
|
|
|
+ {"id": "t1", "type": "Transition"},
|
|
|
+ {"id": "p2t", "type": "P2T", "__source": "p1", "__target": "t1", "weight": 1},
|
|
|
+ {"id": "t2p", "type": "T2P", "__source": "t1", "__target": "p2", "weight": 2},
|
|
|
+ ]
|
|
|
+ >>> delete_element("my_pn", "p1")
|
|
|
+ >>> element_list_nice("my_pn")
|
|
|
+ [{"id": "p2", "type": "Place", "name": "place 2", "tokens": 2},
|
|
|
+ {"id": "t1", "type": "Transition"},
|
|
|
+ {"id": "t2p", "type": "T2P", "__source": "t1", "__target": "p2", "weight": 2},
|
|
|
+ ]
|
|
|
+
|
|
|
+2. *attr_delete* deletes an attribute from a model element.
|
|
|
+ The attribute is removed, basically rendering it undefined.
|
|
|
+ Nonetheless, if the attribute is optional, a subsequent *attr_assign* call is required to make sure that the model conforms.
|
|
|
+ Note that *attr_assign* automatically updates the attribute, so *attr_delete* is only necessary for optional attributes that must be unset.
|