public static Tree[] crossTrees(Tree t1, Tree t2) { var child1 = Clone(t1); var child2 = Clone(t2); //var child1 = (Tree)t1.Clone(); //var child2 = (Tree)t1.Clone(); Tree [] ret = new Tree[2]; int MAX_DEPTH = 1 + Math.Max(t1.Depth(), t2.Depth()); int depth1 = 0, depth2 = 0; //MAX_DEPTH = 100; depth1 = functions.r.Next(1, MAX_DEPTH); depth2 = r.Next(1, MAX_DEPTH); if (depth1 > MAX_DEPTH) { depth1 = MAX_DEPTH; } if (depth2 > MAX_DEPTH) { depth2 = MAX_DEPTH; } List <Node> w1 = child1.TreeRoot.Way(); List <Node> w2 = child2.TreeRoot.Way(); int depthFilter = 0; if (depth1 > w1.Count) { depth1 = w1.Count - depthFilter; } if (depth2 > w2.Count) { depth2 = w2.Count - depthFilter; } ////lalka hardcode //depth1 = 2; //depth2 = 2; ////eoh //depth1--; //depth2--; //genomes Node g1 = w1[w1.Count - depth1]; Node g2 = w2[w2.Count - depth2]; if ((g1.WayLoRs == 'C') && (g2.WayLoRs == 'C')) //both genomes are treeRoots. { ((Tree)(g1.parent)).TreeRoot = g2; ((Tree)(g2.parent)).TreeRoot = g1; } else //genomes both are not treeRoots. { if ((g1.WayLoRs == 'C') && (g2.WayLoRs != 'C')) { ((Tree)(g1.parent)).TreeRoot = g2; switch (g2.WayLoRs) { case 'R': { ((Node)g2.parent).n2 = g1; break; } case 'L': { ((Node)g2.parent).n1 = g1; break; } } } else if ((g1.WayLoRs != 'C') && (g2.WayLoRs == 'C')) { ((Tree)(g2.parent)).TreeRoot = g1; switch (g1.WayLoRs) { case 'R': { ((Node)g1.parent).n2 = g2; break; } case 'L': { ((Node)g1.parent).n1 = g2; break; } } } else if ((g1.WayLoRs != 'C') && (g2.WayLoRs != 'C')) { if (g1.WayLoRs == 'R') { ((Node)g1.parent).n2 = g2; } else { ((Node)g1.parent).n1 = g2; } if (g2.WayLoRs == 'R') { ((Node)g2.parent).n2 = g1; } else { ((Node)g2.parent).n1 = g1; } } } g1.crossed++; g2.crossed++; //w2[w2.Count - depth2].crossed++; //w1[w1.Count - depth1].crossed++; #region SHIT if (false) { if ((w1[w1.Count - depth1].parent != null) && (w2[w2.Count - depth2].parent != null)) { Node temp = w1[w1.Count - depth1]; //|| (w1[w1.Count - depth1].WayLoRs=='C') if ((w1[w1.Count - depth1].WayLoRs == 'R')) { ((Node)(w1[w1.Count - depth1].parent)).n2 = w2[w2.Count - depth2]; w1[w1.Count - depth1].parent = w2[w2.Count - depth2].parent; } else if ((w1[w1.Count - depth1].WayLoRs == 'L')) { ((Node)(w1[w1.Count - depth1].parent)).n1 = w2[w2.Count - depth2]; w1[w1.Count - depth1].parent = w2[w2.Count - depth2].parent; } else if ((w1[w1.Count - depth1].WayLoRs == 'C')) { ((Tree)(w1[w1.Count - depth1].parent)).TreeRoot = w2[w2.Count - depth2]; if (w2[w2.Count - depth2].WayLoRs == 'C') { ((Tree)(w1[w1.Count - depth1].parent)).TreeRoot = ((Tree)(w2[w2.Count - depth2].parent)).TreeRoot; } else { ((Tree)(w1[w1.Count - depth1].parent)).TreeRoot = (Node)w2[w2.Count - depth2].parent; } } if (w2[w2.Count - depth2].WayLoRs == 'R') { ((Node)(w2[w2.Count - depth2].parent)).n2 = temp; w2[w2.Count - depth2].parent = temp.parent; } else if (w2[w2.Count - depth2].WayLoRs == 'L') { ((Node)(w2[w2.Count - depth2].parent)).n1 = temp; w2[w2.Count - depth2].parent = temp.parent; } else if (w2[w2.Count - depth2].WayLoRs == 'C') { ((Tree)(w2[w2.Count - depth2].parent)).TreeRoot = temp; if ((w1[w1.Count - depth1].WayLoRs == 'C')) { ((Tree)(w2[w2.Count - depth2].parent)).TreeRoot = ((Tree)temp.parent).TreeRoot; } else { ((Tree)(w2[w2.Count - depth2].parent)).TreeRoot = (Node)temp;//.parent } } w2[w2.Count - depth2].crossed++; w1[w1.Count - depth1].crossed++; //w2[w2.Count - depth2].parent.crossed++; //w1[w1.Count - depth1].parent.crossed++; } } #endregion //Node n2 = Clone(w2[w2.Count - depth2]); //Node temp = w1[0]; //w1[0] = w2[0]; //w2[0] = temp; int k = 0; if (child1.Count() == child2.Count()) { k++; } ret[0] = child1; ret[1] = child2; //w2[w2.Count - depth2] = n1; //w1[w1.Count - depth1] = n2; return(ret); // seems ok... }