|
From: North, M. <no...@an...> - 2001-08-29 21:41:11
|
Skye: One approach that has worked for me is to serialize objects to a memory buffer and then deserialize them. The result is a new, deep copy of the objects. Only a few lines of code are required. These lines could be added to RePast as a generic Factory-type service method. I can send the details if you are interested. Mike Michael J. North Software Engineer Argonne National Laboratory Decision and Information Sciences Division Complex Adaptive Systems Section 9700 S. Cass Avenue Argonne, IL 60349 E-mail: no...@an... Telephone: (630) 252-6234 Facsimile: (630) 252-6073 -----Original Message----- From: Skye Bender-deMoll [mailto:sky...@sa...] Sent: Wednesday, August 29, 2001 4:39 PM To: rep...@li... Subject: [Repast-developer] interesting copy question Nick, Tom, So I'm doing some network stuff where I want to make changes to the network (removing duplicate ties as preperation for stats methods) without makeing changes to the actual node "Agents" of the model. Unfortunatly, methods like ArrayList.clone() only return shallow copies, so any changes to the copied nodes will change the origial nodes. Now in my case, I can probably come up with a workaround: 1) modify the stat function to check the condition (very awkward, but probably the least expensive) 2) since I am only interested in edges (and not the rest of nodes properties), I can make a method which constructs a new network, identical to the old one, but constructed from default nodes and edges, and perform operations on it. However, there may be other cases in which people want to do things to agents, without changeing the "real" agents. I was thinking that we should add copy methods to the existing node structures, and add getCopy() to the Node interface, but this would break all existing nodes, and still not insure that all relevent variables would be copied. Tom suggested creating a "copyable" interface and having the abstract classes implement it... Nick, do you know of any other way of getting deep copies of objects? (clone() is protected) This would still be a problem for networks, as a deep copy of a node would necessarily have to return the whole network, as each edge contains nodes, which contain edges.... Something to think about anyway! (in the meantime, I just won't let people work with multiplex networks!) -skye _______________________________________________ Repast-developer mailing list Rep...@li... http://lists.sourceforge.net/lists/listinfo/repast-developer |