Last change
on this file since 10822 was
10822,
checked in by bburlacu, 10 years ago
|
#1772: Partially fixed fragment detection and tracing in the case of mutation.
|
File size:
1.7 KB
|
Line | |
---|
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 {
|
---|
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 | Index2 = i
|
---|
34 | };
|
---|
35 | break;
|
---|
36 | }
|
---|
37 |
|
---|
38 | // if (fragment == null) {
|
---|
39 | // throw new Exception("SymbolicDataAnalysisExpressionAfterManipulatorOperator: Could not identify fragment");
|
---|
40 | // }
|
---|
41 |
|
---|
42 | vChild.InArcs.First().Data = fragment;
|
---|
43 | return base.Apply();
|
---|
44 | }
|
---|
45 | }
|
---|
46 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.