Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1772: Simplified genealogy graph and fragment graph creation:

  • the genealogy graph now has a 1-1 mapping between content and vertices (as opposed to 1-n as it was previously, to account for elites); this required changes to the directed graph implementation
  • the fragment graph only contains bifurcation points (where the subtree contains the fragment so tracing must be done both ways (in the root parent AND in the other parent). in the other cases, tracing is restarted from the parent genealogy graph node.
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 = (IGenealogyGraphNode)GenealogyGraph[child];
13      var arcs = childVertex.InArcs.ToList();
14      var nodes0 = (List<ISymbolicExpressionTreeNode>)arcs[0].Data;
15      var nodes1 = (List<ISymbolicExpressionTreeNode>)arcs[1].Data;
16      var childNodes = child.IterateNodesPrefix().ToList();
17      IFragment<ISymbolicExpressionTreeNode> fragment = null;
18      for (int i = 0; i < Math.Min(nodes0.Count, childNodes.Count); ++i) {
19        if (nodes0[i] == childNodes[i]) continue;
20        fragment = new Fragment<ISymbolicExpressionTreeNode> {
21          Root = childNodes[i],
22          Index1 = i,
23        };
24        fragment.Index2 = nodes1.IndexOf(fragment.Root);
25        break;
26      }
27      // if the fragment is null then it means crossover did not do anything
28      //      if (fragment == null) throw new Exception("Could not determine fragment!");
29
30      arcs[0].Data = null;
31      arcs[1].Data = fragment;
32
33      return base.Apply();
34    }
35  }
36}
Note: See TracBrowser for help on using the repository browser.