Changeset 16085 for trunk/HeuristicLab.Problems.DataAnalysis.Symbolic
- Timestamp:
- 08/21/18 16:42:23 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/LinearModelToTreeConverter.cs
r15583 r16085 37 37 string[] variableNames, double[] coefficients, 38 38 double @const = 0) { 39 39 40 if (factorCoefficients.Length == 0 && coefficients.Length == 0) throw new ArgumentException(); 40 ISymbolicExpressionTree p1 = null; 41 42 // Create tree for double variables 43 ISymbolicExpressionTree tree = null; 41 44 if (coefficients.Length > 0) { 42 p1 = CreateTree(variableNames, new int[variableNames.Length], coefficients, @const); 43 if (factorCoefficients.Length == 0) 44 return p1; 45 tree = CreateTree(variableNames, new int[variableNames.Length], coefficients, @const); 46 if (factorCoefficients.Length == 0) return tree; 45 47 } 48 49 // Create tree for string variables 50 ISymbolicExpressionTree factorTree = null; 46 51 if (factorCoefficients.Length > 0) { 47 var p2 = CreateTree(factors, factorCoefficients); 48 if (p1 == null) return p2; 52 factorTree = CreateTree(factors, factorCoefficients, @const); 53 if (tree == null) return factorTree; 54 } 49 55 50 // combine51 ISymbolicExpressionTreeNode add = p1.Root.GetSubtree(0).GetSubtree(0);52 foreach (var binFactorNode in p2.IterateNodesPrefix().OfType<BinaryFactorVariableTreeNode>())53 add.AddSubtree(binFactorNode);54 return p1;55 } 56 // Combine both trees 57 ISymbolicExpressionTreeNode add = tree.Root.GetSubtree(0).GetSubtree(0); 58 foreach (var binFactorNode in factorTree.IterateNodesPrefix().OfType<BinaryFactorVariableTreeNode>()) 59 add.InsertSubtree(add.SubtreeCount - 1, binFactorNode); 60 return tree; 61 56 62 throw new ArgumentException(); 57 63 }
Note: See TracChangeset
for help on using the changeset viewer.