Changeset 9584


Ignore:
Timestamp:
06/05/13 10:33:30 (6 years ago)
Author:
mkommend
Message:

#1730: Minor code changes and organization in the export to excel functionality.

Location:
branches/ExportSymbolicDataAnalysisSolutions
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/ExportSymbolicDataAnalysisSolutions/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/MenuItems/ExportSymbolicSolutionToExcelMenuItem.cs

    r9583 r9584  
    5757    protected override void OnActiveViewChanged(object sender, EventArgs e) {
    5858      IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
    59       ToolStripItem.Enabled = activeView != null && activeView.Content as ISymbolicDataAnalysisSolution != null;
     59      ToolStripItem.Enabled = activeView != null && activeView.Content is ISymbolicDataAnalysisSolution;
    6060    }
    6161
    6262    public override void Execute() {
    63       IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
    64       var solution = activeView.Content as ISymbolicDataAnalysisSolution;
     63      var activeView = (IContentView)MainFormManager.MainForm.ActiveView;
     64      var solution = (ISymbolicDataAnalysisSolution)activeView.Content;
    6565      var formatter = new SymbolicDataAnalysisExpressionExcelFormatter();
    6666      var formula = formatter.Format(solution.Model.SymbolicExpressionTree);
  • branches/ExportSymbolicDataAnalysisSolutions/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs

    r9580 r9584  
    3333  [StorableClass]
    3434  public sealed class SymbolicDataAnalysisExpressionExcelFormatter : NamedItem, ISymbolicExpressionTreeStringFormatter {
    35     //private int currentLag;
    36 
    3735    [StorableConstructor]
    3836    private SymbolicDataAnalysisExpressionExcelFormatter(bool deserializing) : base(deserializing) { }
     
    6866      return string.Format("${0}1", variableNameMapping[variabelName]);
    6967    }
    70     //public string CurrentIndexVariable {
    71     //  get {
    72     //    return "i" + currentIndexNumber;
    73     //  }
    74     //}
    75     //private void ReleaseIndexVariable() {
    76     //  currentIndexNumber--;
    77     //}
    78 
    79     //private string AllocateIndexVariable() {
    80     //  currentIndexNumber++;
    81     //  return CurrentIndexVariable;
    82     //}
    8368
    8469    public string Format(ISymbolicExpressionTree symbolicExpressionTree) {
     
    10893        }
    10994        stringBuilder.Append(")");
    110         //} else if (symbol is And) {
    111         //  stringBuilder.Append("((");
    112         //  for (int i = 0; i < node.SubtreeCount; i++) {
    113         //    if (i > 0) stringBuilder.Append("&");
    114         //    stringBuilder.Append("((");
    115         //    stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
    116         //    stringBuilder.Append(")>0)");
    117         //  }
    118         //  stringBuilder.Append(")-0.5)*2");
    119         //  // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp.
    12095      } else if (symbol is Average) {
    12196        stringBuilder.Append("(1/");
     
    161136        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    162137        stringBuilder.Append(")");
    163         //} else if (symbol is GreaterThan) {
    164         //  stringBuilder.Append("((");
    165         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    166         //  stringBuilder.Append(">");
    167         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
    168         //  stringBuilder.Append(")-0.5)*2");
    169         //  // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp.
    170         //} else if (symbol is IfThenElse) {
    171         //  stringBuilder.Append("(");
    172         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    173         //  stringBuilder.Append(">0)*");
    174         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
    175         //  stringBuilder.Append("+");
    176         //  stringBuilder.Append("(");
    177         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    178         //  stringBuilder.Append("<=0)*");
    179         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(2)));
    180         //} else if (symbol is LaggedVariable) {
    181         //  // this if must be checked before if(symbol is LaggedVariable)
    182         //  LaggedVariableTreeNode laggedVariableTreeNode = node as LaggedVariableTreeNode;
    183         //  stringBuilder.Append(laggedVariableTreeNode.Weight.ToString(CultureInfo.InvariantCulture));
    184         //  stringBuilder.Append("*");
    185         //  stringBuilder.Append(laggedVariableTreeNode.VariableName +
    186         //                       LagToString(currentLag + laggedVariableTreeNode.Lag));
    187         //} else if (symbol is LessThan) {
    188         //  stringBuilder.Append("((");
    189         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    190         //  stringBuilder.Append("<");
    191         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
    192         //  stringBuilder.Append(")-0.5)*2");
    193         //  // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp.
    194138      } else if (symbol is Logarithm) {
    195139        stringBuilder.Append("LOG(");
     
    201145          stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
    202146        }
    203         //} else if (symbol is Not) {
    204         //  stringBuilder.Append("NOT(");
    205         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    206         //  stringBuilder.Append(" > 0 )");
    207         //} else if (symbol is Or) {
    208         //  stringBuilder.Append("((");
    209         //  for (int i = 0; i < node.SubtreeCount; i++) {
    210         //    if (i > 0) stringBuilder.Append("|");
    211         //    stringBuilder.Append("((");
    212         //    stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
    213         //    stringBuilder.Append(")>0)");
    214         //  }
    215         //  stringBuilder.Append(")-0.5)*2");
    216         //  // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp.
    217147      } else if (symbol is Sine) {
    218148        stringBuilder.Append("SIN(");
     
    236166        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    237167        stringBuilder.Append(")");
    238         //} else if (node.Symbol is AiryA) {
    239         //  stringBuilder.Append("airy(");
    240         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    241         //  stringBuilder.Append(")");
    242         //} else if (node.Symbol is AiryB) {
    243         //  stringBuilder.Append("airy(2, ");
    244         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    245         //  stringBuilder.Append(")");
    246         //} else if (node.Symbol is Bessel) {
    247         //  stringBuilder.Append("besseli(0.0,");
    248         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    249         //  stringBuilder.Append(")");
    250         //} else if (node.Symbol is CosineIntegral) {
    251         //  stringBuilder.Append("cosint(");
    252         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    253         //  stringBuilder.Append(")");
    254         //} else if (node.Symbol is Dawson) {
    255         //  stringBuilder.Append("dawson(");
    256         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    257         //  stringBuilder.Append(")");
    258         //} else if (node.Symbol is Erf) {
    259         //  stringBuilder.Append("erf(");
    260         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    261         //  stringBuilder.Append(")");
    262         //} else if (node.Symbol is ExponentialIntegralEi) {
    263         //  stringBuilder.Append("expint(");
    264         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    265         //  stringBuilder.Append(")");
    266         //} else if (node.Symbol is FresnelCosineIntegral) {
    267         //  stringBuilder.Append("FresnelC(");
    268         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    269         //  stringBuilder.Append(")");
    270         //} else if (node.Symbol is FresnelSineIntegral) {
    271         //  stringBuilder.Append("FresnelS(");
    272         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    273         //  stringBuilder.Append(")");
    274         //} else if (node.Symbol is Gamma) {
    275         //  stringBuilder.Append("gamma(");
    276         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    277         //  stringBuilder.Append(")");
    278         //} else if (node.Symbol is HyperbolicCosineIntegral) {
    279         //  stringBuilder.Append("Chi(");
    280         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    281         //  stringBuilder.Append(")");
    282         //} else if (node.Symbol is HyperbolicSineIntegral) {
    283         //  stringBuilder.Append("Shi(");
    284         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    285         //  stringBuilder.Append(")");
    286         //} else if (node.Symbol is Norm) {
    287         //  stringBuilder.Append("normpdf(");
    288         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    289         //  stringBuilder.Append(")");
    290         //} else if (node.Symbol is Psi) {
    291         //  stringBuilder.Append("psi(");
    292         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    293         //  stringBuilder.Append(")");
    294         //} else if (node.Symbol is SineIntegral) {
    295         //  stringBuilder.Append("sinint(");
    296         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    297         //  stringBuilder.Append(")");
     168
    298169      } else if (symbol is HeuristicLab.Problems.DataAnalysis.Symbolic.Variable) {
    299170        VariableTreeNode variableTreeNode = node as VariableTreeNode;
     
    313184        stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
    314185        stringBuilder.Append(",0))");
    315         //} else if (symbol is Derivative) {
    316         //  stringBuilder.Append("fivePoint(");
    317         //  // f0
    318         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    319         //  stringBuilder.Append(", ");
    320         //  // f1
    321         //  currentLag--;
    322         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    323         //  stringBuilder.Append(", ");
    324         //  // f3
    325         //  currentLag -= 2;
    326         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    327         //  stringBuilder.Append(", ");
    328         //  currentLag--;
    329         //  // f4
    330         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    331         //  stringBuilder.Append(")");
    332         //  currentLag += 4;
    333         //} else if (symbol is Integral) {
    334         //  var laggedNode = node as LaggedTreeNode;
    335         //  string prevCounterVariable = CurrentIndexVariable;
    336         //  string counterVariable = AllocateIndexVariable();
    337         //  stringBuilder.AppendLine(" sum (map(@(" + counterVariable + ") " + FormatRecursively(node.GetSubtree(0)) +
    338         //                           ", (" + prevCounterVariable + "+" + laggedNode.Lag + "):" + prevCounterVariable +
    339         //                           "))");
    340         //  ReleaseIndexVariable();
    341         //} else if (symbol is TimeLag) {
    342         //  var laggedNode = node as LaggedTreeNode;
    343         //  currentLag += laggedNode.Lag;
    344         //  stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    345         //currentLag -= laggedNode.Lag;
    346186      } else {
    347187        stringBuilder.Append("ERROR");
     
    349189      return stringBuilder.ToString();
    350190    }
    351 
    352 
    353     //private string LagToString(int lag) {
    354     //  if (lag < 0) {
    355     //    return "(" + CurrentIndexVariable + "" + lag + ")";
    356     //  } else if (lag > 0) {
    357     //    return "(" + CurrentIndexVariable + "+" + lag + ")";
    358     //  } else return "(" + CurrentIndexVariable + ")";
    359     //}
    360 
    361191  }
    362192}
Note: See TracChangeset for help on using the changeset viewer.