Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionAfterCrossoverOperator.cs @ 10654

Last change on this file since 10654 was 10654, checked in by bburlacu, 10 years ago

#1772: Some progress on tracking fragments and building blocks, still incomplete.

File size: 1.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using HeuristicLab.Core;
5using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
6using HeuristicLab.EvolutionTracking;
7
8namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
9  public class SymbolicDataAnalysisExpressionAfterCrossoverOperator : AfterCrossoverOperator<ISymbolicExpressionTree> {
10    public override IOperation Apply() {
11      var child = ChildParameter.ActualValue;
12      var childVertex = GenealogyGraph[child].Last();
13      var arc0 = (IGenealogyGraphArc)childVertex.InArcs[0];
14      var arc1 = (IGenealogyGraphArc)childVertex.InArcs[1];
15      var nodes0 = (List<ISymbolicExpressionTreeNode>)arc0.Data;
16      var nodes1 = (List<ISymbolicExpressionTreeNode>)arc1.Data;
17      var childNodes = child.IterateNodesPrefix().ToList();
18      IFragment<ISymbolicExpressionTreeNode> fragment = null;
19      for (int i = 0; i < Math.Min(nodes0.Count, childNodes.Count); ++i) {
20        if (nodes0[i] == childNodes[i]) continue;
21        fragment = new Fragment<ISymbolicExpressionTreeNode> {
22          Root = childNodes[i],
23          Index = i,
24        };
25        fragment.OldIndex = nodes1.IndexOf(fragment.Root);
26        break;
27      }
28      if (fragment == null) throw new Exception("Could not determine fragment!");
29
30      arc0.Data = null;
31      arc1.Data = fragment;
32
33      return base.Apply();
34    }
35  }
36}
Note: See TracBrowser for help on using the repository browser.