using System; using System.Collections.Generic; using System.Linq; using HeuristicLab.Core; using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; using HeuristicLab.EvolutionTracking; namespace HeuristicLab.Problems.DataAnalysis.Symbolic { public class SymbolicDataAnalysisExpressionAfterCrossoverOperator : AfterCrossoverOperator { public override IOperation Apply() { var child = ChildParameter.ActualValue; var childVertex = (IGenealogyGraphNode)GenealogyGraph[child]; var arcs = childVertex.InArcs.ToList(); var nodes0 = (List)arcs[0].Data; var nodes1 = (List)arcs[1].Data; var childNodes = child.IterateNodesPrefix().ToList(); IFragment fragment = null; for (int i = 0; i < Math.Min(nodes0.Count, childNodes.Count); ++i) { if (nodes0[i] == childNodes[i]) continue; fragment = new Fragment { Root = childNodes[i], Index1 = i, }; fragment.Index2 = nodes1.IndexOf(fragment.Root); break; } // if the fragment is null then it means crossover did not do anything // if (fragment == null) throw new Exception("Could not determine fragment!"); arcs[0].Data = null; arcs[1].Data = fragment; return base.Apply(); } } }