1

I'm trying to come up with an elegant solution for representing place/transition petri nets. So far I save them as follows:

{:netname {:places      {:name tokens, ...}
           :transitions #{:t1, :t2, :t3, ...}
           :edges_in    #{[:from :to tokens], ...}
           :edges_out   #{[:from :to tokens], ...}}}

tokens is a number, everything starts with a symbol with the corresponding name.

//edit - Some more clarification: The :netname and :name are unique, because it has to be possible to merge 2 nets, where the places again have to have unique names. The numerical tokens are determined by the user of the petri nets during creation of a place or edge.

I would be thankful for some pointers or links to a more elaborate / better data structure for my problem.

//edit 2 - I reworked my first take on the data-structure, because of the uniquenes of place-names. :places now references a hashmap. Also edges_in and out are now hashmaps, because every edge is unique with its origin, destination and token number.

//edit 3 - The use of the structure: It is read and written to in the same quantity i would say. The way a petri net is used, there is a back and forth between modifying the net and reading it, with maybe slightly more reading towards the end.

I also modified my structure above slightly, so :edges_in and :edges_out now saves the triplets as a vector instead of a list. This simplyfies saving the hashmap to file and reading it from it, because load-string evaluates lists as expressions.

WeGi
  • 1,908
  • 1
  • 21
  • 33
  • can you elaborate more on the larger structure? would :netname be unique? Would it be something repeated anywhere in the given net, or other nets? How would the numeric tokens be looked up and what would that datastructure look like? I think some of the edit that happened to this post may not have clarified what you meant here. – noisesmith Dec 29 '13 at 16:19
  • I eddited in some clarifying details now. – WeGi Dec 30 '13 at 11:35
  • Often, the "best" data structure is decided by what operations you need to do, and how often you need to do them. As a simple example, the "best" structure for (99.9% reads, 0.01% writes) could be very different from (50% reads, 50% writes). It gets even more complicated when you start factoring in what kinds of reads / writes you need to do. Perhaps you can update your question with what you plan on doing with this data structure? – Shepmaster Dec 30 '13 at 16:50
  • I added the Info u requested. – WeGi Jan 03 '14 at 13:52
  • 1
    Is this a question about storing the net structure in a human-readable file format? If so I wonder why PNML acronym did not pop up yet. – Dima Chubarov Jan 05 '14 at 07:31
  • It doesn't really matter if it is human readable. The Programm just has to handle it efficiently. – WeGi Jan 06 '14 at 12:38

1 Answers1

0

You could look at ISO 15909 interchange format for HLPNs called PNML. This would at least provide you with a basis for a standard interface to your data structures.

Jon Guiton
  • 1,360
  • 1
  • 9
  • 11