Last change
on this file since 10638 was
10347,
checked in by bburlacu, 11 years ago
|
#1772: Small changes to the GenealogyGraph. Added generic Fragment class and interface. Added the SymbolicDataAnalysisPopulationDiversityAnalyzer. Added specialized tracking operators for symbolic data analysis. Merged trunk changes.
|
File size:
1.5 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 : BeforeManipulatorOperator<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].First();
|
---|
22 | var nodesBefore = (List<ISymbolicExpressionTreeNode>)vChild.InArcs[0].Data;
|
---|
23 | var nodesAfter = ChildParameter.ActualValue.IterateNodesBreadth().ToList();
|
---|
24 | IFragment<ISymbolicExpressionTreeNode> fragment = null;
|
---|
25 |
|
---|
26 | for (int i = 0; i < Math.Min(nodesAfter.Count, nodesBefore.Count); ++i) {
|
---|
27 | if (comparer.Equals(nodesAfter[i], nodesBefore[i])) continue;
|
---|
28 | fragment = new Fragment<ISymbolicExpressionTreeNode> {
|
---|
29 | Root = nodesAfter[i],
|
---|
30 | NewPos = i
|
---|
31 | };
|
---|
32 | }
|
---|
33 |
|
---|
34 | vChild.InArcs[0].Data = fragment;
|
---|
35 | return base.Apply();
|
---|
36 | }
|
---|
37 | }
|
---|
38 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.