Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionAfterManipulatorOperator.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.5 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 SymbolicDataAnalysisExpressionAfterManipulatorOperator : AfterManipulatorOperator<ISymbolicExpressionTree> {
10    private readonly SymbolicExpressionTreeNodeSimilarityComparer comparer;
11
12    public SymbolicDataAnalysisExpressionAfterManipulatorOperator() {
13      comparer = new SymbolicExpressionTreeNodeSimilarityComparer {
14        MatchVariableNames = true,
15        MatchVariableWeights = true,
16        MatchConstantValues = true
17      };
18    }
19
20    public override IOperation Apply() {
21      var vChild = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph[ChildParameter.ActualValue];
22      var nodesBefore = (List<ISymbolicExpressionTreeNode>)vChild.InArcs.First().Data;
23      var nodesAfter = ChildParameter.ActualValue.IterateNodesPrefix().ToList();
24      IFragment<ISymbolicExpressionTreeNode> fragment = null;
25
26      for (int i = 0; i < Math.Min(nodesAfter.Count, nodesBefore.Count); ++i) {
27        var a = nodesAfter[i];
28        var b = nodesBefore[i];
29        if (ReferenceEquals(a, b) && comparer.Equals(a, b)) continue;
30        fragment = new Fragment<ISymbolicExpressionTreeNode> {
31          Root = a,
32          Index1 = i
33        };
34      }
35
36      vChild.InArcs.First().Data = fragment;
37      return base.Apply();
38    }
39  }
40}
Note: See TracBrowser for help on using the repository browser.