AnyLogic 6 Discussion

Hi, I have wanted to use SPLIT as in duplicating the original entity with all its attributes. I also need to merge (COMBINE) those two after a while. Thanks, Yariv
The ‘split’ element passes through itself an entity (or instance of another class) and generates new instance of Entity class with default parameters. So if you want the copy of entity has the same parameters as the original you should type the word ‘original’ in the ‘New entity (copy)’ field of the ‘split’s’ general properties.
Thank you Pavel. Your answer regarding the 'split' works perfectly now. What about the 'combine' part of my question? Can I combine two entity selectivly (for example by an attribute)? I mean - Can I combine the two entity that was splited before, and not combining others? Thanks, Yariv
Using 'Match' solved the problem.
There is one important thing you should keep in mind in the solution proposed above: if you type "original" in the New entity (copy) field you will let "physicall" the same one entity to travel along two flow branches: original does not create a copy of the entity, instead it substitutes the copy with one more "reference" to the same original entity. Therefore if you modify an attribute of the entity in one branch of the flow, the entity in the other branch will change too. In many cases this is not the desirable behavior. To create a copy of an entity including all its fields you should define the method clone() in your entity class that will create such a copy and write original.clone() in the New entity field of Split.
This is a simple example of how to define a cloneable entity. Please note that the "system" fields of the Entity class, such as seized resources, network location, etc. should NOT be cloned! public class EntityWithId extends Entity implements Cloneable { // Cloning public EntityWithId clone() { EntityWithId clone = new EntityWithId(); clone.id = this.id; return clone; } // Fields long id; } To create a clone in Split object on should set its 1st generic parameter to EntityWithId and then write original.clone() in the New entity field.