Last change
on this file since 10755 was
10755,
checked in by bburlacu, 11 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
|
Rev | Line | |
---|
[10347] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using HeuristicLab.Core;
|
---|
| 5 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
| 6 | using HeuristicLab.EvolutionTracking;
|
---|
| 7 |
|
---|
| 8 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
[10755] | 9 | public class SymbolicDataAnalysisExpressionAfterManipulatorOperator : AfterManipulatorOperator<ISymbolicExpressionTree> {
|
---|
[10347] | 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() {
|
---|
[10755] | 21 | var vChild = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph[ChildParameter.ActualValue];
|
---|
[10677] | 22 | var nodesBefore = (List<ISymbolicExpressionTreeNode>)vChild.InArcs.First().Data;
|
---|
[10755] | 23 | var nodesAfter = ChildParameter.ActualValue.IterateNodesPrefix().ToList();
|
---|
[10347] | 24 | IFragment<ISymbolicExpressionTreeNode> fragment = null;
|
---|
| 25 |
|
---|
| 26 | for (int i = 0; i < Math.Min(nodesAfter.Count, nodesBefore.Count); ++i) {
|
---|
[10755] | 27 | var a = nodesAfter[i];
|
---|
| 28 | var b = nodesBefore[i];
|
---|
| 29 | if (ReferenceEquals(a, b) && comparer.Equals(a, b)) continue;
|
---|
[10347] | 30 | fragment = new Fragment<ISymbolicExpressionTreeNode> {
|
---|
[10755] | 31 | Root = a,
|
---|
| 32 | Index1 = i
|
---|
[10347] | 33 | };
|
---|
| 34 | }
|
---|
| 35 |
|
---|
[10677] | 36 | vChild.InArcs.First().Data = fragment;
|
---|
[10347] | 37 | return base.Apply();
|
---|
| 38 | }
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.