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
|
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,
|
---|
[10822] | 32 | Index1 = i,
|
---|
| 33 | Index2 = i
|
---|
[10347] | 34 | };
|
---|
[10822] | 35 | break;
|
---|
[10347] | 36 | }
|
---|
| 37 |
|
---|
[10822] | 38 | // if (fragment == null) {
|
---|
| 39 | // throw new Exception("SymbolicDataAnalysisExpressionAfterManipulatorOperator: Could not identify fragment");
|
---|
| 40 | // }
|
---|
| 41 |
|
---|
[10677] | 42 | vChild.InArcs.First().Data = fragment;
|
---|
[10347] | 43 | return base.Apply();
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.