modelling.rst 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. Modelling
  2. =========
  3. Modelling is the core activity in the Modelverse.
  4. A model is based on a meta-model, or a language, which, for the sake of this tutorial, assume to exist.
  5. Throughout this tutorial, we will focus on how to instantiate a simple Petri Net model.
  6. We assume that our language has a notion of *Place*, *Transition*, *P2T* arc, and *T2P* arc.
  7. The *Place* has a *name* and *tokens*, the *Transition* has a *name*.
  8. Both the *P2T* and *T2P*"arcs have a *weight*.
  9. This information is stored in the metamodel, which we will define later on.
  10. For now, assume that the metamodel is stored in the Modelverse using the name *PetriNets*.
  11. Creating a model
  12. ----------------
  13. Creating a new instance of PetriNets is simple, and can be done using the *model_add* operation of the wrapper::
  14. >>> model_add("my_pn", "PetriNets")
  15. The first parameter of the operation indicates the name that we would like to give to our newly created model.
  16. This name is available to all users, and is therefore a unique identifier.
  17. The second parameter is the metamodel that we want to use to conform to.
  18. The value needs to be a name that is available in the Modelverse, and readable to the current user.
  19. To get a list of currently available models, users can query the Modelverse with the *model_list* operation::
  20. >>> model_list()
  21. [("PetriNets", "SimpleClassDiagrams"), ("SimpleClassDiagrams", "SimpleClassDiagrams"), ("ProcessModel", "SimpleClassDiagrams"), ...]
  22. This list contains the various models, and the metamodel of these models.
  23. Note that this operation does not specify anything about the permissions of the supplied models.
  24. Modifying a model
  25. -----------------
  26. Now that we have created our model, we can start modifying it.
  27. To do so, we have access to several operations offered by the Modelverse.
  28. We categorize them by their effects on the Modelverse: create, read, or delete.
  29. Create and delete operations are only allowed when the user has write permission to the model, which users have by default on their own models.
  30. Create
  31. ^^^^^^
  32. 1. *instantiate* creates a new instance in the model, for example a new PetriNet place::
  33. >>> instantiate("my_pn", "Place")
  34. __12345
  35. The operation requires the model on which we are working, and the type of the element you want to instantiate.
  36. When successful, the operation returns the identifier that can be used in future operations.
  37. This identifier has no value within the model, and should only be used as a handle to that specific model element.
  38. When instantiating an edge, the optional *edge* parameter must be passed with the identifiers to connect::
  39. >>> instantiate("my_pn", "Place")
  40. p1
  41. >>> instantiate("my_pn", "Transition")
  42. t1
  43. >>> instantiate("my_pn", "P2T", edge=("p1", "t1"))
  44. p2t1
  45. 2. *attr_assign* assigns attributes of a specific model element.
  46. For example, it specifies the name and number of tokens of our PetriNet place::
  47. >>> instantiate("my_pn", "Place")
  48. p1
  49. >>> attr_assign("my_pn", "p1", "name", "place 1")
  50. >>> attr_assign("my_pn", "p1", "tokens", 2)
  51. The value of the attribute can be any simple primitive: string, integer, float, or boolean.
  52. When the attribute already exists, its value is overwritten.
  53. If it doesn't exist, it is created.
  54. Read
  55. ^^^^
  56. 1. *read* reads out basic information about a queried element, such as its type and the source and target (if it is an edge)::
  57. >>> instantiate("my_pn", "Place")
  58. p1
  59. >>> read("my_pn", "p1")
  60. ("Place, None)
  61. >>> instantiate("my_pn", "Transition")
  62. t1
  63. >>> instantiate("my_pn", "P2T", edge=("p1", "t1"))
  64. p2t1
  65. >>> read("my_pn", "p2t1")
  66. ("P2T", ("p1", "t1"))
  67. 2. *read_attrs* reads out the attributes of a specific element, in a dictionary form.
  68. This operation can be used to read out, for example, the number of tokens of a specific place::
  69. >>> instantiate("my_pn", "Place")
  70. p1
  71. >>> attr_assign("my_pn", "p1", "name", "place 1")
  72. >>> attr_assign("my_pn", "p1", "tokens", 2)
  73. >>> read_attrs("my_pn", "p1")
  74. {"name": "place 1", "tokens": 2}
  75. types
  76. element_list_nice
  77. read_outgoing
  78. read_incoming
  79. read_association_source
  80. read_association_destination
  81. connections_between
  82. all_instances
  83. Delete
  84. ^^^^^^
  85. delete_element
  86. attr_delete