Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Threading.Tasks;
|
---|
6 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
7 |
|
---|
8 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
9 | public static class ConstantsToNumberConverter {
|
---|
10 |
|
---|
11 | public static ISymbolicExpressionTree Convert(ISymbolicExpressionTree original) {
|
---|
12 | var tree = original.Clone() as SymbolicExpressionTree;
|
---|
13 |
|
---|
14 | foreach (var constantNode in tree.IterateNodesPostfix().OfType<ConstantTreeNode>()) {
|
---|
15 | var parent = constantNode.Parent;
|
---|
16 | var index = parent.IndexOfSubtree(constantNode);
|
---|
17 | var value = constantNode.Value;
|
---|
18 | var newNode = new NumberTreeNode(value);
|
---|
19 |
|
---|
20 | parent.RemoveSubtree(index);
|
---|
21 | parent.InsertSubtree(index, newNode);
|
---|
22 | }
|
---|
23 |
|
---|
24 | return tree;
|
---|
25 | }
|
---|
26 | }
|
---|
27 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.