Changeset 5019


Ignore:
Timestamp:
12/04/10 09:51:59 (11 years ago)
Author:
gkronber
Message:

Adapted complex program code in MATLAB exporter and reformatted code to adhere to HL coding guidelines. #1314

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis.Extensions/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Formatters/SymbolicExpressionTreeMATLABFormatter.cs

    r5017 r5019  
    2121
    2222using System.Text;
     23using System.Linq;
    2324using HeuristicLab.Core;
    2425using HeuristicLab.Common;
     
    3839    protected SymbolicExpressionTreeMATLABFormatter(SymbolicExpressionTreeMATLABFormatter original, Cloner cloner) : base(original, cloner) { }
    3940    public SymbolicExpressionTreeMATLABFormatter()
    40         : base() {
     41      : base() {
    4142      Name = "MATLAB String Formatter";
    4243    }
     
    5354
    5455      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);
    6061        foreach (string variableName in variableNames)
    6162          stringBuilder.AppendLine(variableName + " = Data(:, ???);");
     
    191192        stringBuilder.Append("*");
    192193        stringBuilder.Append(variableTreeNode.VariableName + "(i)");
    193       }
    194 
    195       else {
     194      } else {
    196195        stringBuilder.Append("ERROR");
    197196      }
     
    202201    }
    203202
    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 
    216203    public override IDeepCloneable Clone(Cloner cloner) {
    217204      return new SymbolicExpressionTreeMATLABFormatter(this, cloner);
    218205    }
    219 
    220206  }
    221 
    222207}
Note: See TracChangeset for help on using the changeset viewer.