Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/04/15 16:20:21 (9 years ago)
Author:
mkommend
Message:

#2485: Corrected C# formatter for SymbolicExpressionTrees to handle subtractions correctly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionCSharpFormatter.cs

    r12982 r13116  
    8989          FormatFunction(node, "Math.Sin", strBuilder);
    9090        } else if (node.Symbol is Subtraction) {
    91           FormatOperator(node, "-", strBuilder);
     91          FormatSubtraction(node, strBuilder);
    9292        } else if (node.Symbol is Tangent) {
    9393          FormatFunction(node, "Math.Tan", strBuilder);
     
    145145    }
    146146
     147    private void FormatSubtraction(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
     148      if (node.SubtreeCount == 1) {
     149        strBuilder.Append("-");
     150        FormatRecursively(node.GetSubtree(0), strBuilder);
     151        return;
     152      }
     153      //Default case: more than 1 child
     154      FormatOperator(node, "-", strBuilder);
     155    }
     156
    147157    private void FormatOperator(ISymbolicExpressionTreeNode node, string symbol, StringBuilder strBuilder) {
    148158      strBuilder.Append("(");
     
    179189      }
    180190
    181       var orderedNames = varNames.OrderBy(n => n, new NaturalStringComparer()).Select(n=> "double " + n);
     191      var orderedNames = varNames.OrderBy(n => n, new NaturalStringComparer()).Select(n => "double " + n);
    182192      strBuilder.Append(string.Join(", ", orderedNames));
    183193
Note: See TracChangeset for help on using the changeset viewer.