To prevent spam users, you can only post on this forum after registration, which is by invitation. If you want to post on the forum, please send me a mail (h DOT m DOT w DOT verbeek AT tue DOT nl) and I'll send you an invitation in return for an account.

Cloning/Copying a Petri Net

Ollyseus
edited October 2016 in - Development
Dear Community,

I try to copy a Petri Net into another object before I manipulate the copy. However, since a normal assertion in Java
obj1 = obj2 is not a real copy but just a copy of the reference, both objects point to the same petri net.
 
I tried using deepCopying, but it didn't work since the Petrinet object does not implement Serializable.

I also tried clone, but a clone mehtod shouldn't be used and is not visible.

Do you have any idea what else to try? Otherwise I will try to copy it variable after variable by calling the constructor and filling the new object with the values of the old one.

Best regards,

Oliver

Comments

  • I'm not aware of a Petrinet copy constructor or similar. There are conversion plug-ins between DataPetriNet and Petrinet in the DataPetriNet package. You could use those to do a 3-way conversion PN->DPN->PN and you get your cloned PN.

    If you program the copy method for PN yourself, please share it. We should put it in the Petrinets package imho.
  • Dear Oliver,

    You can use a line like follows:

      Petrinet clonedNet = PetrinetFactory.clonePetrinet(net, map);
    With
      Map<DirectedGraphElement, DirectedGraphElement> map

    Where map is optional.

    Kind regards,

    Eric.


  • Dear Mr. Mannardt, Dear Eric,

    thank you very much for your help, I appreciate it a lot!

    Best regards,

    Oliver
  • hverbeek said:
    Dear Oliver,

    You can use a line like follows:

      Petrinet clonedNet = PetrinetFactory.clonePetrinet(net, map);
    With
      Map<DirectedGraphElement, DirectedGraphElement> map

    Where map is optional.

    Kind regards,

    Eric.


    Works like a charme! :)

    for further readers: optional means overloaded method here, so you can use the method without the second parameter. Do not invoke it with null for the second parameter, as it will result in a NullPointerException

    Kind regards,

    Oliver
Sign In or Register to comment.