my_petrinet_with_MM_and_constraints.mvc 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import models/SimpleClassDiagrams as SCD
  2. include "primitives.alh"
  3. SCD PetriNets{
  4. SimpleAttribute Natural {
  5. constraint =
  6. $
  7. String function constraint_Natural(model : Element, name : String):
  8. Element self
  9. self = model["model"][name]
  10. if (is_physical_int(self)):
  11. if (integer_gte(self, 0)):
  12. return "OK"!
  13. else:
  14. return "Natural number not larger than or equal to zero"!
  15. else:
  16. return "Natural number not larger than or equal to zero"!
  17. $
  18. }
  19. Class Place{
  20. tokens : Natural
  21. }
  22. Class Transition{}
  23. Association P2T (Place, Transition) {
  24. weight : Natural
  25. }
  26. Association T2P (Transition, Place) {
  27. weight : Natural
  28. }
  29. }
  30. PetriNets my_petrinet {
  31. Place p1 {
  32. tokens = 1
  33. }
  34. Place p2 {
  35. tokens = 3
  36. }
  37. Transition t1 {}
  38. P2T (p1, t1) {
  39. weight = 1
  40. }
  41. T2P (t1, p2) {
  42. weight = 2
  43. }
  44. }
  45. export my_petrinet to models/my_petrinet