Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/21/13 21:04:20 (11 years ago)
Author:
gkronber
Message:

#1270 fixed compile errors in Smalltalk and GraphViz formatters

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
Files:
2 edited

Legend:

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

    r9647 r9649  
    2323using HeuristicLab.Core;
    2424using HeuristicLab.Common;
    25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    27 using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols;
     25using HeuristicLab.Problems.DataAnalysis.Symbolic;
     26using Variable = HeuristicLab.Problems.DataAnalysis.Symbolic.Variable;
    2827
    2928namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Formatters {
    3029
    31   [Item("SymbolicExpressionTreeSmalltalkStringFormatter", "String formatter for string representations of symbolic expression trees in Smalltalk syntax.")]
     30  [Item("Smalltalk String Formatter", "String formatter for string representations of symbolic expression trees in Smalltalk syntax.")]
    3231  public class SymbolicExpressionTreeSmalltalkStringFormatter : NamedItem, ISymbolicExpressionTreeStringFormatter {
    3332
    3433    protected SymbolicExpressionTreeSmalltalkStringFormatter(SymbolicExpressionTreeSmalltalkStringFormatter original, Cloner cloner) : base(original, cloner) { }
    3534    public SymbolicExpressionTreeSmalltalkStringFormatter()
    36         : base() {
     35      : base() {
    3736      Name = "Smalltalk String Formatter";
    3837    }
    3938
    40     public string Format(SymbolicExpressionTree symbolicExpressionTree) {
     39    public string Format(ISymbolicExpressionTree symbolicExpressionTree) {
    4140      return FormatRecursively(symbolicExpressionTree.Root);
    4241    }
    4342
    44     private string FormatRecursively(SymbolicExpressionTreeNode node) {
     43    private string FormatRecursively(ISymbolicExpressionTreeNode node) {
    4544
    46       Symbol symbol = node.Symbol;
     45      ISymbol symbol = node.Symbol;
    4746
    4847      if (symbol is ProgramRootSymbol || symbol is StartSymbol)
    49         return FormatRecursively(node.SubTrees[0]);
     48        return FormatRecursively(node.GetSubtree(0));
    5049
    5150      StringBuilder stringBuilder = new StringBuilder();
     
    5453
    5554      if (symbol is Addition) {
    56         for (int i = 0; i < node.SubTrees.Count; i++) {
     55        for (int i = 0; i < node.SubtreeCount; i++) {
    5756          if (i > 0) stringBuilder.Append("+");
    58           stringBuilder.Append(FormatRecursively(node.SubTrees[i]));
     57          stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
    5958        }
    6059      } else if (symbol is And) {
    6160        stringBuilder.Append("(");
    62         for (int i = 0; i < node.SubTrees.Count; i++) {
     61        for (int i = 0; i < node.SubtreeCount; i++) {
    6362          if (i > 0) stringBuilder.Append("&");
    6463          stringBuilder.Append("((");
    65           stringBuilder.Append(FormatRecursively(node.SubTrees[i]));
     64          stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
    6665          stringBuilder.Append(")>=0)");
    6766        }
     
    6968      } else if (symbol is Average) {
    7069        stringBuilder.Append("(1/");
    71         stringBuilder.Append(node.SubTrees.Count);
     70        stringBuilder.Append(node.SubtreeCount);
    7271        stringBuilder.Append(")*(");
    73         for (int i = 0; i < node.SubTrees.Count; i++) {
     72        for (int i = 0; i < node.SubtreeCount; i++) {
    7473          if (i > 0) stringBuilder.Append("+");
    7574          stringBuilder.Append("(");
    76           stringBuilder.Append(FormatRecursively(node.SubTrees[i]));
     75          stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
    7776          stringBuilder.Append(")");
    7877        }
     
    8281        stringBuilder.Append(constantTreeNode.Value.ToString().Replace(",", "."));
    8382      } else if (symbol is Cosine) {
    84         stringBuilder.Append(FormatRecursively(node.SubTrees[0]));
     83        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    8584        stringBuilder.Append(" cos");
    8685      } else if (symbol is Division) {
    87         if (node.SubTrees.Count == 1) {
     86        if (node.SubtreeCount == 1) {
    8887          stringBuilder.Append("1/");
    89           stringBuilder.Append(FormatRecursively(node.SubTrees[0]));
     88          stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    9089        } else {
    91           stringBuilder.Append(FormatRecursively(node.SubTrees[0]));
     90          stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    9291          stringBuilder.Append("/(");
    93           for (int i = 1; i < node.SubTrees.Count; i++) {
     92          for (int i = 1; i < node.SubtreeCount; i++) {
    9493            if (i > 1) stringBuilder.Append("*");
    95             stringBuilder.Append(FormatRecursively(node.SubTrees[i]));
     94            stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
    9695          }
    9796          stringBuilder.Append(")");
    9897        }
    9998      } else if (symbol is Exponential) {
    100         stringBuilder.Append(FormatRecursively(node.SubTrees[0]));
     99        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    101100        stringBuilder.Append(" exp");
    102101      } else if (symbol is GreaterThan) {
    103102        stringBuilder.Append("(");
    104         stringBuilder.Append(FormatRecursively(node.SubTrees[0]));
     103        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    105104        stringBuilder.Append(" > ");
    106         stringBuilder.Append(FormatRecursively(node.SubTrees[1]));
     105        stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
    107106        stringBuilder.Append(") ifTrue: [1] ifFalse: [-1]");
    108107      } else if (symbol is IfThenElse) {
    109108        stringBuilder.Append("(");
    110         stringBuilder.Append(FormatRecursively(node.SubTrees[0]));
     109        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    111110        stringBuilder.Append(" > 0) ifTrue: [");
    112         stringBuilder.Append(FormatRecursively(node.SubTrees[1]));
     111        stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
    113112        stringBuilder.Append("] ifFalse: [");
    114         stringBuilder.Append(FormatRecursively(node.SubTrees[2]));
     113        stringBuilder.Append(FormatRecursively(node.GetSubtree(2)));
    115114        stringBuilder.Append("]");
    116115      } else if (symbol is LaggedVariable) {
     
    118117      } else if (symbol is LessThan) {
    119118        stringBuilder.Append("(");
    120         stringBuilder.Append(FormatRecursively(node.SubTrees[0]));
     119        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    121120        stringBuilder.Append(" < ");
    122         stringBuilder.Append(FormatRecursively(node.SubTrees[1]));
     121        stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
    123122        stringBuilder.Append(") ifTrue: [1] ifFalse: [-1]");
    124123      } else if (symbol is Logarithm) {
    125         stringBuilder.Append(FormatRecursively(node.SubTrees[0]));
     124        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    126125        stringBuilder.Append("ln");
    127126      } else if (symbol is Multiplication) {
    128         for (int i = 0; i < node.SubTrees.Count; i++) {
     127        for (int i = 0; i < node.SubtreeCount; i++) {
    129128          if (i > 0) stringBuilder.Append("*");
    130           stringBuilder.Append(FormatRecursively(node.SubTrees[i]));
     129          stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
    131130        }
    132131      } else if (symbol is Not) {
    133132        stringBuilder.Append("-1*");
    134         stringBuilder.Append(FormatRecursively(node.SubTrees[0]));
     133        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    135134      } else if (symbol is Or) {
    136135        stringBuilder.Append("(");
    137         for (int i = 0; i < node.SubTrees.Count; i++) {
     136        for (int i = 0; i < node.SubtreeCount; i++) {
    138137          if (i > 0) stringBuilder.Append("|");
    139138          stringBuilder.Append("((");
    140           stringBuilder.Append(FormatRecursively(node.SubTrees[i]));
     139          stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
    141140          stringBuilder.Append(")>=0)");
    142141        }
    143142        stringBuilder.Append(") ifTrue:[1] ifFalse:[-1]");
    144143      } else if (symbol is Sine) {
    145         stringBuilder.Append(FormatRecursively(node.SubTrees[0]));
     144        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    146145        stringBuilder.Append(" sin");
    147146      } else if (symbol is Subtraction) {
    148         if (node.SubTrees.Count == 1) {
     147        if (node.SubtreeCount == 1) {
    149148          stringBuilder.Append("-1*");
    150           stringBuilder.Append(FormatRecursively(node.SubTrees[0]));
     149          stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    151150        } else {
    152           stringBuilder.Append(FormatRecursively(node.SubTrees[0]));
    153           for (int i = 1; i < node.SubTrees.Count; i++) {
     151          stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
     152          for (int i = 1; i < node.SubtreeCount; i++) {
    154153            stringBuilder.Append("-");
    155             stringBuilder.Append(FormatRecursively(node.SubTrees[i]));
     154            stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
    156155          }
    157156        }
    158157      } else if (symbol is Tangent) {
    159         stringBuilder.Append(FormatRecursively(node.SubTrees[0]));
     158        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    160159        stringBuilder.Append("tan");
    161       } else if (symbol is HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable) {
     160      } else if (symbol is Variable) {
    162161        VariableTreeNode variableTreeNode = node as VariableTreeNode;
    163162        stringBuilder.Append(variableTreeNode.Weight.ToString().Replace(",", "."));
    164163        stringBuilder.Append("*");
    165164        stringBuilder.Append(variableTreeNode.VariableName);
    166       }
    167 
    168       else {
     165      } else {
    169166        stringBuilder.Append("ERROR");
    170167      }
     
    178175      return new SymbolicExpressionTreeSmalltalkStringFormatter(this, cloner);
    179176    }
    180 
    181177  }
    182 
    183178}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r9587 r9649  
    140140    <Compile Include="Crossovers\SymbolicDataAnalysisExpressionSemanticSimilarityCrossover.cs" />
    141141    <Compile Include="Formatters\SymbolicDataAnalysisExpressionExcelFormatter.cs" />
     142    <Compile Include="Formatters\SymbolicExpressionTreeSmalltalkStringFormatter.cs" />
    142143    <Compile Include="Interfaces\ISymbolicDataAnalysisExpressionCrossover.cs" />
    143144    <Compile Include="Interfaces\ISymbolicDataAnalysisImpactValuesCalculator.cs" />
Note: See TracChangeset for help on using the changeset viewer.