Changeset 5019
- Timestamp:
- 12/04/10 09:51:59 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis.Extensions/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Formatters/SymbolicExpressionTreeMATLABFormatter.cs
r5017 r5019 21 21 22 22 using System.Text; 23 using System.Linq; 23 24 using HeuristicLab.Core; 24 25 using HeuristicLab.Common; … … 38 39 protected SymbolicExpressionTreeMATLABFormatter(SymbolicExpressionTreeMATLABFormatter original, Cloner cloner) : base(original, cloner) { } 39 40 public SymbolicExpressionTreeMATLABFormatter() 40 41 : base() { 41 42 Name = "MATLAB String Formatter"; 42 43 } … … 53 54 54 55 if (symbol is ProgramRootSymbol) { 55 IList<VariableTreeNode> variableTreeNodesList = getVariableTreeNodes(node);56 string[] variableNames = new string[variableTreeNodesList.Count];57 for (int i = 0; i < variableTreeNodesList.Count; i++)58 variableNames[i] = variableTreeNodesList[i].VariableName;59 Array.Sort(variableNames);56 // all variable names, contains duplicates! 57 var variableNames = node.IterateNodesPostfix() 58 .OfType<VariableTreeNode>() 59 .Select(n => n.VariableName) 60 .OrderBy(x => x); 60 61 foreach (string variableName in variableNames) 61 62 stringBuilder.AppendLine(variableName + " = Data(:, ???);"); … … 191 192 stringBuilder.Append("*"); 192 193 stringBuilder.Append(variableTreeNode.VariableName + "(i)"); 193 } 194 195 else { 194 } else { 196 195 stringBuilder.Append("ERROR"); 197 196 } … … 202 201 } 203 202 204 private static IList<VariableTreeNode> getVariableTreeNodes(SymbolicExpressionTreeNode root) {205 IList<VariableTreeNode> variableTreeNodes = new List<VariableTreeNode>();206 addVariableTreeNodes(variableTreeNodes, root);207 return variableTreeNodes;208 }209 private static void addVariableTreeNodes(IList<VariableTreeNode> variableTreeNodes, SymbolicExpressionTreeNode node) {210 VariableTreeNode variableTreeNode = node as VariableTreeNode;211 if (variableTreeNode != null) variableTreeNodes.Add(variableTreeNode);212 for (int i = 0; i < node.SubTrees.Count; i++)213 addVariableTreeNodes(variableTreeNodes, node.SubTrees[i]);214 }215 216 203 public override IDeepCloneable Clone(Cloner cloner) { 217 204 return new SymbolicExpressionTreeMATLABFormatter(this, cloner); 218 205 } 219 220 206 } 221 222 207 }
Note: See TracChangeset
for help on using the changeset viewer.