# Changeset 5021

Ignore:
Timestamp:
12/04/10 13:07:50 (11 years ago)
Message:

Corrected evaluation of logical expressions in MATLAB formatter. (#1314)

File:
1 edited

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

 r5020 } } else if (symbol is And) { stringBuilder.Append("("); stringBuilder.Append("(("); for (int i = 0; i < node.SubTrees.Count; i++) { if (i > 0) stringBuilder.Append("&"); stringBuilder.Append(")>0)"); } stringBuilder.Append(")-0.5"); // MATLAB maps false and true to 0 and 1, resp., so we map this result to -0.5 and +0.5, resp. stringBuilder.Append(")-0.5)*2"); // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp. } else if (symbol is Average) { stringBuilder.Append("(1/"); stringBuilder.Append(")"); } else if (symbol is GreaterThan) { stringBuilder.Append("("); stringBuilder.Append("(("); stringBuilder.Append(FormatRecursively(node.SubTrees[0])); stringBuilder.Append(">"); stringBuilder.Append(FormatRecursively(node.SubTrees[1])); stringBuilder.Append(")-0.5"); // MATLAB maps false and true to 0 and 1, resp., so we map this result to -0.5 and +0.5, resp. stringBuilder.Append(")-0.5)*2"); // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp. } else if (symbol is IfThenElse) { stringBuilder.Append("("); stringBuilder.Append("("); stringBuilder.Append(FormatRecursively(node.SubTrees[0])); stringBuilder.Append("<0)*"); stringBuilder.Append("<=0)*"); stringBuilder.Append(FormatRecursively(node.SubTrees[2])); } else if (symbol is LaggedVariable) { stringBuilder.Append(laggedVariableTreeNode.VariableName + "(i-" + laggedVariableTreeNode.Lag + ")"); } else if (symbol is LessThan) { stringBuilder.Append("("); stringBuilder.Append("(("); stringBuilder.Append(FormatRecursively(node.SubTrees[0])); stringBuilder.Append("<"); stringBuilder.Append(FormatRecursively(node.SubTrees[1])); stringBuilder.Append(")-0.5"); stringBuilder.Append(")-0.5)*2"); // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp. } else if (symbol is Logarithm) { stringBuilder.Append("log("); stringBuilder.Append("*-1"); } else if (symbol is Or) { stringBuilder.Append("("); stringBuilder.Append("(("); for (int i = 0; i < node.SubTrees.Count; i++) { if (i > 0) stringBuilder.Append("|"); stringBuilder.Append(")>0)"); } stringBuilder.Append(")-0.5"); // MATLAB maps false and true to 0 and 1, resp., so we map this result to -0.5 and +0.5, resp. stringBuilder.Append(")-0.5)*2"); // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp. } else if (symbol is Sine) { stringBuilder.Append("sin(");
Note: See TracChangeset for help on using the changeset viewer.