Last change
on this file since 10459 was
10459,
checked in by bburlacu, 11 years ago
|
#1772: Merged uncomitted pruning code from trunk. Removed Plugin.cs file. Renamed SymbolicDataAnalysisExpressionAfterCrossoverOperator.cs and SymbolicDataAnalysisExpressionBeforeCrossoverOperator.cs
|
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 SymbolicDataAnalysisExpressionAfterCrossoverOperator : AfterCrossoverOperator<ISymbolicExpressionTree> {
|
---|
10 | public override IOperation Apply() {
|
---|
11 | var childVertex = GenealogyGraph[ChildParameter.ActualValue].Last();
|
---|
12 | var arc0 = (IGenealogyGraphArc)childVertex.InArcs[0];
|
---|
13 | var arc1 = (IGenealogyGraphArc)childVertex.InArcs[1];
|
---|
14 | var nodes0 = (List<ISymbolicExpressionTreeNode>)arc0.Data;
|
---|
15 | var nodes1 = (List<ISymbolicExpressionTreeNode>)arc1.Data;
|
---|
16 | var childNodes = ChildParameter.ActualValue.IterateNodesBreadth().ToList();
|
---|
17 | IFragment<ISymbolicExpressionTreeNode> fragment = null;
|
---|
18 |
|
---|
19 | for (int i = 0; i < Math.Min(nodes0.Count, childNodes.Count); ++i) {
|
---|
20 | if (nodes0[i] == childNodes[i]) continue;
|
---|
21 | fragment = new Fragment<ISymbolicExpressionTreeNode> {
|
---|
22 | Root = childNodes[i],
|
---|
23 | NewPos = i
|
---|
24 | };
|
---|
25 | }
|
---|
26 | if (fragment == null) throw new Exception("Could not determine fragment!");
|
---|
27 |
|
---|
28 | for (int i = 0; i < nodes1.Count; ++i) {
|
---|
29 | if (nodes1[i] != fragment.Root) continue;
|
---|
30 | fragment.OldPos = i;
|
---|
31 | }
|
---|
32 |
|
---|
33 | arc0.Data = null;
|
---|
34 | arc1.Data = fragment;
|
---|
35 |
|
---|
36 | return base.Apply();
|
---|
37 | }
|
---|
38 | }
|
---|
39 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.