Changeset 18069 for branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/StructureTemplate/StructureTemplate.cs
- Timestamp:
- 10/19/21 13:39:44 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/StructureTemplate/StructureTemplate.cs
r18068 r18069 19 19 set { 20 20 template = value; 21 tree = Parser.Parse(template); 22 GetSubFunctions(Tree); 21 Tree = Parser.Parse(template); 23 22 OnChanged(); 24 23 } … … 26 25 27 26 [Storable] 28 private ISymbolicExpressionTree tree; 29 public ISymbolicExpressionTree Tree => tree; 27 private ISymbolicExpressionTree treeWithoutLinearScaling; 28 [Storable] 29 private ISymbolicExpressionTree treeWithLinearScaling; 30 public ISymbolicExpressionTree Tree { 31 get => ApplyLinearScaling ? treeWithLinearScaling : treeWithoutLinearScaling; 32 private set { 33 treeWithLinearScaling = AddLinearScalingTerms(value); 34 treeWithoutLinearScaling = value; 35 SubFunctions = GetSubFunctions(); 36 } 37 } 30 38 31 39 [Storable] 32 public IReadOnlyDictionary<string, SubFunction> SubFunctions { get; private set; } = new Dictionary<string, SubFunction>(); 40 public IReadOnlyDictionary<string, SubFunction> SubFunctions { get; private set; } 41 42 [Storable] 43 private bool applyLinearScaling = false; 44 public bool ApplyLinearScaling { 45 get => applyLinearScaling; 46 set { 47 applyLinearScaling = value; 48 //subFunctions = GetSubFunctions(); 49 OnChanged(); 50 } 51 } 33 52 34 53 protected InfixExpressionParser Parser { get; set; } = new InfixExpressionParser(); … … 56 75 #endregion 57 76 58 private void GetSubFunctions(ISymbolicExpressionTree tree) {77 private Dictionary<string, SubFunction> GetSubFunctions() { 59 78 var subFunctions = new Dictionary<string, SubFunction>(); 60 foreach (var node in tree.IterateNodesPrefix())79 foreach (var node in Tree.IterateNodesPrefix()) 61 80 if (node is SubFunctionTreeNode subFunctionTreeNode) { 62 81 if (!subFunctionTreeNode.Arguments.Any()) … … 77 96 } 78 97 } 79 SubFunctions = subFunctions; 98 return subFunctions; 99 } 100 101 private ISymbolicExpressionTree AddLinearScalingTerms(ISymbolicExpressionTree tree) { 102 var clonedTree = (ISymbolicExpressionTree)tree.Clone(); 103 var startNode = clonedTree.Root.Subtrees.First(); 104 var template = startNode.Subtrees.First(); 105 106 var add = new Addition(); 107 var addNode = add.CreateTreeNode(); 108 109 var mul = new Multiplication(); 110 var mulNode = mul.CreateTreeNode(); 111 112 var c1 = new Constant(); 113 var c1Node = (ConstantTreeNode)c1.CreateTreeNode(); 114 c1Node.Value = 0.0; 115 var c2 = new Constant(); 116 var c2Node = (ConstantTreeNode)c2.CreateTreeNode(); 117 c2Node.Value = 1.0; 118 119 addNode.AddSubtree(c1Node); 120 addNode.AddSubtree(mulNode); 121 mulNode.AddSubtree(c2Node); 122 123 startNode.RemoveSubtree(0); 124 startNode.AddSubtree(addNode); 125 mulNode.AddSubtree(template); 126 return clonedTree; 80 127 } 81 128
Note: See TracChangeset
for help on using the changeset viewer.