/// <summary> /// Deep copy /// </summary> /// <param name="?"></param> /// <returns></returns> public KPsystem Clone() { KPsystem clone = new KPsystem(); PItem.CopyProperties(this, clone); Dictionary <MInstance, MInstance> instanceCloneRegistry = new Dictionary <MInstance, MInstance>(); foreach (KeyValuePair <string, MType> kv in types) { MType mtype = kv.Value; MType typeClone = new MType(mtype.Name); PItem.CopyProperties(mtype, typeClone); foreach (MInstance instance in mtype.Instances) { MInstance instanceClone = instance.Clone(); instanceCloneRegistry.Add(instance, instanceClone); typeClone.Instances.Add(instanceClone); } clone.AddType(typeClone); } foreach (KeyValuePair <MInstance, MInstance> kv in instanceCloneRegistry) { MInstance tar = kv.Value; foreach (MInstance connection in kv.Key.Connections) { tar.Connections.Add(instanceCloneRegistry[connection]); } } return(clone); }
/// <summary> /// Deep Copy of an membrane instance. VERY IMPORTANT!!! This will not coppy the connections to other instances, nor clone /// those instances. This must be done at a higher level where access to all instances of P system is available. /// </summary> /// <returns></returns> public MInstance Clone() { MInstance clone = new MInstance(multiset.Clone()); PItem.CopyProperties(this, clone); LabelledPItem.CopyLabels(this, clone); return(clone); }
/// <summary> /// Deep copy /// </summary> /// <returns></returns> public MType Clone() { MType clone = new MType(this.Name); PItem.CopyProperties(this, clone); foreach (MInstance instance in instances) { clone.Instances.Add(instance.Clone()); } return(clone); }