Index: /branches/HivePerformance/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Formatters/SymbolicExpressionTreeGraphvizFormatter.cs
===================================================================
--- /branches/HivePerformance/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Formatters/SymbolicExpressionTreeGraphvizFormatter.cs (revision 9655)
+++ /branches/HivePerformance/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Formatters/SymbolicExpressionTreeGraphvizFormatter.cs (revision 9655)
@@ -0,0 +1,97 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System.Text;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
+using System.Collections.Generic;
+using HeuristicLab.Core;
+using HeuristicLab.Common;
+
+namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Formatters {
+ [Item("GraphViz String Formatter", "Formatter for symbolic expression trees for visualization with GraphViz.")]
+ public sealed class SymbolicExpressionTreeGraphvizFormatter : NamedItem, ISymbolicExpressionTreeStringFormatter {
+ public bool Indent { get; set; }
+
+ private readonly static Dictionary symbolNameMap = new Dictionary() {
+ // match Koza style
+ {"ProgramRootSymbol", "Prog"},
+ {"StartSymbol", "RPB"},
+ };
+
+ public SymbolicExpressionTreeGraphvizFormatter()
+ : base("GraphViz String Formatter", "Formatter for symbolic expression trees for visualization with GraphViz.") {
+ Indent = true;
+ }
+ private SymbolicExpressionTreeGraphvizFormatter(SymbolicExpressionTreeGraphvizFormatter original, Cloner cloner)
+ : base(original, cloner) {
+ this.Indent = original.Indent;
+ }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new SymbolicExpressionTreeGraphvizFormatter(this, cloner);
+ }
+
+ public string Format(ISymbolicExpressionTree symbolicExpressionTree) {
+ int nodeCounter = 1;
+ StringBuilder strBuilder = new StringBuilder();
+ strBuilder.AppendLine("graph {");
+ strBuilder.AppendLine(FormatRecursively(symbolicExpressionTree.Root, 0, ref nodeCounter));
+ strBuilder.AppendLine("}");
+ return strBuilder.ToString();
+ }
+
+ private string FormatRecursively(ISymbolicExpressionTreeNode node, int indentLength, ref int nodeId) {
+ // save id of current node
+ int currentNodeId = nodeId;
+ // increment id for next node
+ nodeId++;
+
+ StringBuilder strBuilder = new StringBuilder();
+ if (Indent) strBuilder.Append(' ', indentLength);
+
+ // get label for node and map if necessary
+ string nodeLabel = node.ToString();
+ if (symbolNameMap.ContainsKey(nodeLabel)) {
+ nodeLabel = symbolNameMap[nodeLabel];
+ }
+
+ strBuilder.Append("node" + currentNodeId + "[label=\"" + nodeLabel + "\"");
+ // leaf nodes should have box shape
+ if (node.SubtreeCount == 0) {
+ strBuilder.AppendLine(", shape=\"box\"];");
+ } else {
+ strBuilder.AppendLine("];");
+ }
+
+ // internal nodes or leaf nodes?
+ foreach (ISymbolicExpressionTreeNode subTree in node.Subtrees) {
+ // add an edge
+ if (Indent) strBuilder.Append(' ', indentLength);
+ strBuilder.AppendLine("node" + currentNodeId + " -- node" + nodeId + ";");
+ // format the whole subtree
+ strBuilder.Append(FormatRecursively(subTree, indentLength + 2, ref nodeId));
+ }
+
+ return strBuilder.ToString();
+ }
+ }
+}
Index: /branches/HivePerformance/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Formatters/SymbolicExpressionTreeStringFormatter.cs
===================================================================
--- /branches/HivePerformance/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Formatters/SymbolicExpressionTreeStringFormatter.cs (revision 9654)
+++ /branches/HivePerformance/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Formatters/SymbolicExpressionTreeStringFormatter.cs (revision 9655)
@@ -28,5 +28,5 @@
namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
- [Item("SymbolicExpressionTreeStringFormatter", "The default string formatter for symbolic expression trees.")]
+ [Item("Default String Formatter", "The default string formatter for symbolic expression trees.")]
[StorableClass]
public class SymbolicExpressionTreeStringFormatter : NamedItem, ISymbolicExpressionTreeStringFormatter {
Index: /branches/HivePerformance/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj
===================================================================
--- /branches/HivePerformance/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj (revision 9654)
+++ /branches/HivePerformance/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj (revision 9655)
@@ -132,4 +132,5 @@
+
Index: /branches/HivePerformance/sources/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ControlExtensions.cs
===================================================================
--- /branches/HivePerformance/sources/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ControlExtensions.cs (revision 9654)
+++ /branches/HivePerformance/sources/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ControlExtensions.cs (revision 9655)
@@ -21,4 +21,5 @@
using System;
+using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Windows.Forms;
@@ -45,4 +46,19 @@
}
}
+
+ public static IEnumerable GetNestedControls(this Control control, Func condition = null) {
+ if (control == null) yield break;
+ if (condition == null) condition = (c) => true;
+
+ Queue unprocessed = new Queue();
+ unprocessed.Enqueue(control);
+
+ while (unprocessed.Count > 0) {
+ Control c = unprocessed.Dequeue();
+ if (condition(c)) yield return c;
+ foreach (Control child in c.Controls)
+ unprocessed.Enqueue(child);
+ }
+ }
}
}
Index: /branches/HivePerformance/sources/HeuristicLab.MainForm.WindowsForms/3.3/MainForms/MainForm.cs
===================================================================
--- /branches/HivePerformance/sources/HeuristicLab.MainForm.WindowsForms/3.3/MainForms/MainForm.cs (revision 9654)
+++ /branches/HivePerformance/sources/HeuristicLab.MainForm.WindowsForms/3.3/MainForms/MainForm.cs (revision 9655)
@@ -386,4 +386,5 @@
ToolStripMenuItem item = new ToolStripMenuItem();
this.SetToolStripItemProperties(item, menuItem);
+ this.InsertItem(menuItem.Structure, typeof(ToolStripMenuItem), item, menuStrip.Items);
if (menuItem is MenuItem) {
MenuItem menuItemBase = (MenuItem)menuItem;
@@ -392,5 +393,4 @@
item.DisplayStyle = menuItemBase.ToolStripItemDisplayStyle;
}
- this.InsertItem(menuItem.Structure, typeof(ToolStripMenuItem), item, menuStrip.Items);
}
Index: /branches/HivePerformance/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/MenuItems/ExportSymbolicSolutionToExcelMenuItem.cs
===================================================================
--- /branches/HivePerformance/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/MenuItems/ExportSymbolicSolutionToExcelMenuItem.cs (revision 9654)
+++ /branches/HivePerformance/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/MenuItems/ExportSymbolicSolutionToExcelMenuItem.cs (revision 9655)
@@ -22,4 +22,5 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel;
using System.IO;
using System.Linq;
@@ -27,4 +28,5 @@
using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
using HeuristicLab.MainForm;
+using HeuristicLab.MainForm.WindowsForms;
using HeuristicLab.Optimizer;
using OfficeOpenXml;
@@ -52,17 +54,28 @@
protected override void OnToolStripItemSet(EventArgs e) {
+ base.OnToolStripItemSet(e);
ToolStripItem.Enabled = false;
- }
- protected override void OnActiveViewChanged(object sender, EventArgs e) {
+ var menuItem = ToolStripItem.OwnerItem as ToolStripMenuItem;
+ if (menuItem != null)
+ menuItem.DropDownOpening += menuItem_DropDownOpening;
+ }
+
+ private void menuItem_DropDownOpening(object sender, EventArgs e) {
IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
- ToolStripItem.Enabled = activeView != null && activeView.Content is ISymbolicDataAnalysisSolution;
+ Control control = activeView as Control;
+ activeView = control.GetNestedControls((c) => c.Visible)
+ .OfType().FirstOrDefault(v => v.Content is ISymbolicDataAnalysisSolution && v.Content is IRegressionSolution);
+ ToolStripItem.Enabled = activeView != null;
}
public override void Execute() {
- var activeView = (IContentView)MainFormManager.MainForm.ActiveView;
+ IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
+ Control control = activeView as Control;
+ activeView = control.GetNestedControls((c) => c.Visible)
+ .OfType().First(v => v.Content is ISymbolicDataAnalysisSolution && v.Content is IRegressionSolution);
var solution = (ISymbolicDataAnalysisSolution)activeView.Content;
var formatter = new SymbolicDataAnalysisExpressionExcelFormatter();
- var formula = formatter.Format(solution.Model.SymbolicExpressionTree);
- var formulaParts = formula.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
+ var formula = formatter.Format(solution.Model.SymbolicExpressionTree, solution.ProblemData.Dataset);
+
SaveFileDialog saveFileDialog = new SaveFileDialog();
@@ -71,32 +84,41 @@
if (saveFileDialog.ShowDialog() == DialogResult.OK) {
string fileName = saveFileDialog.FileName;
- FileInfo newFile = new FileInfo(fileName);
- if (newFile.Exists) {
- newFile.Delete();
- newFile = new FileInfo(fileName);
+ using (BackgroundWorker bg = new BackgroundWorker()) {
+ bg.DoWork += (b, e) => ExportChart(fileName, solution, formula);
+ bg.RunWorkerAsync();
}
- using (ExcelPackage package = new ExcelPackage(newFile)) {
- ExcelWorksheet modelWorksheet = package.Workbook.Worksheets.Add("Model");
- FormatModelSheet(modelWorksheet, solution, formulaParts);
-
- ExcelWorksheet datasetWorksheet = package.Workbook.Worksheets.Add("Dataset");
- WriteDatasetToExcel(datasetWorksheet, solution.ProblemData);
-
- ExcelWorksheet inputsWorksheet = package.Workbook.Worksheets.Add("Inputs");
- WriteInputSheet(inputsWorksheet, datasetWorksheet, formulaParts.Skip(2), solution.ProblemData.Dataset);
-
- if (solution is IRegressionSolution) {
- ExcelWorksheet estimatedWorksheet = package.Workbook.Worksheets.Add("Estimated Values");
- WriteEstimatedWorksheet(estimatedWorksheet, datasetWorksheet, formulaParts, solution as IRegressionSolution);
-
- ExcelWorksheet chartsWorksheet = package.Workbook.Worksheets.Add("Charts");
- AddCharts(chartsWorksheet);
- }
- package.Workbook.Properties.Title = "Excel Export";
- package.Workbook.Properties.Author = "HEAL";
- package.Workbook.Properties.Comments = "Excel export of a symbolic data analysis solution from HeuristicLab";
-
- package.Save();
+ }
+ }
+
+ private void ExportChart(string fileName, ISymbolicDataAnalysisSolution solution, string formula) {
+ FileInfo newFile = new FileInfo(fileName);
+ if (newFile.Exists) {
+ newFile.Delete();
+ newFile = new FileInfo(fileName);
+ }
+ var formulaParts = formula.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
+
+ using (ExcelPackage package = new ExcelPackage(newFile)) {
+ ExcelWorksheet modelWorksheet = package.Workbook.Worksheets.Add("Model");
+ FormatModelSheet(modelWorksheet, solution, formulaParts);
+
+ ExcelWorksheet datasetWorksheet = package.Workbook.Worksheets.Add("Dataset");
+ WriteDatasetToExcel(datasetWorksheet, solution.ProblemData);
+
+ ExcelWorksheet inputsWorksheet = package.Workbook.Worksheets.Add("Inputs");
+ WriteInputSheet(inputsWorksheet, datasetWorksheet, formulaParts.Skip(2), solution.ProblemData.Dataset);
+
+ if (solution is IRegressionSolution) {
+ ExcelWorksheet estimatedWorksheet = package.Workbook.Worksheets.Add("Estimated Values");
+ WriteEstimatedWorksheet(estimatedWorksheet, datasetWorksheet, formulaParts, solution as IRegressionSolution);
+
+ ExcelWorksheet chartsWorksheet = package.Workbook.Worksheets.Add("Charts");
+ AddCharts(chartsWorksheet);
}
+ package.Workbook.Properties.Title = "Excel Export";
+ package.Workbook.Properties.Author = "HEAL";
+ package.Workbook.Properties.Comments = "Excel export of a symbolic data analysis solution from HeuristicLab";
+
+ package.Save();
}
}
Index: /branches/HivePerformance/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs
===================================================================
--- /branches/HivePerformance/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs (revision 9654)
+++ /branches/HivePerformance/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs (revision 9655)
@@ -23,4 +23,5 @@
using System.Collections.Generic;
using System.Globalization;
+using System.Linq;
using System.Text;
using HeuristicLab.Common;
@@ -66,9 +67,15 @@
return string.Format("${0}1", variableNameMapping[variabelName]);
}
-
public string Format(ISymbolicExpressionTree symbolicExpressionTree) {
+ return Format(symbolicExpressionTree, null);
+ }
+
+ public string Format(ISymbolicExpressionTree symbolicExpressionTree, Dataset dataset) {
var stringBuilder = new StringBuilder();
+ if (dataset != null) CalculateVariableMapping(symbolicExpressionTree, dataset);
+
stringBuilder.Append("=");
stringBuilder.Append(FormatRecursively(symbolicExpressionTree.Root));
+
foreach (var variable in variableNameMapping) {
stringBuilder.AppendLine();
@@ -76,4 +83,16 @@
}
return stringBuilder.ToString();
+ }
+
+ private void CalculateVariableMapping(ISymbolicExpressionTree tree, Dataset dataset) {
+ int columnIndex = 0;
+ int inputIndex = 0;
+ var usedVariables = tree.IterateNodesPrefix().OfType().Select(v => v.VariableName).Distinct();
+ foreach (var variable in dataset.VariableNames) {
+ columnIndex++;
+ if (!usedVariables.Contains(variable)) continue;
+ inputIndex++;
+ variableNameMapping[variable] = GetExcelColumnName(inputIndex);
+ }
}
@@ -137,7 +156,7 @@
stringBuilder.Append(")");
} else if (symbol is Logarithm) {
- stringBuilder.Append("LOG(");
- stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
- stringBuilder.Append(", EXP(1))"); // Excel does not use the natural logarithm, therefor the base has to be set
+ stringBuilder.Append("LN(");
+ stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
+ stringBuilder.Append(")");
} else if (symbol is Multiplication) {
for (int i = 0; i < node.SubtreeCount; i++) {
Index: /branches/HivePerformance/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicExpressionTreeSmalltalkStringFormatter.cs
===================================================================
--- /branches/HivePerformance/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicExpressionTreeSmalltalkStringFormatter.cs (revision 9655)
+++ /branches/HivePerformance/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicExpressionTreeSmalltalkStringFormatter.cs (revision 9655)
@@ -0,0 +1,178 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System.Text;
+using HeuristicLab.Core;
+using HeuristicLab.Common;
+using HeuristicLab.Problems.DataAnalysis.Symbolic;
+using Variable = HeuristicLab.Problems.DataAnalysis.Symbolic.Variable;
+
+namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Formatters {
+
+ [Item("Smalltalk String Formatter", "String formatter for string representations of symbolic expression trees in Smalltalk syntax.")]
+ public class SymbolicExpressionTreeSmalltalkStringFormatter : NamedItem, ISymbolicExpressionTreeStringFormatter {
+
+ protected SymbolicExpressionTreeSmalltalkStringFormatter(SymbolicExpressionTreeSmalltalkStringFormatter original, Cloner cloner) : base(original, cloner) { }
+ public SymbolicExpressionTreeSmalltalkStringFormatter()
+ : base() {
+ Name = "Smalltalk String Formatter";
+ }
+
+ public string Format(ISymbolicExpressionTree symbolicExpressionTree) {
+ return FormatRecursively(symbolicExpressionTree.Root);
+ }
+
+ private string FormatRecursively(ISymbolicExpressionTreeNode node) {
+
+ ISymbol symbol = node.Symbol;
+
+ if (symbol is ProgramRootSymbol || symbol is StartSymbol)
+ return FormatRecursively(node.GetSubtree(0));
+
+ StringBuilder stringBuilder = new StringBuilder();
+
+ stringBuilder.Append("(");
+
+ if (symbol is Addition) {
+ for (int i = 0; i < node.SubtreeCount; i++) {
+ if (i > 0) stringBuilder.Append("+");
+ stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
+ }
+ } else if (symbol is And) {
+ stringBuilder.Append("(");
+ for (int i = 0; i < node.SubtreeCount; i++) {
+ if (i > 0) stringBuilder.Append("&");
+ stringBuilder.Append("((");
+ stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
+ stringBuilder.Append(")>=0)");
+ }
+ stringBuilder.Append(") ifTrue:[1] ifFalse:[-1]");
+ } else if (symbol is Average) {
+ stringBuilder.Append("(1/");
+ stringBuilder.Append(node.SubtreeCount);
+ stringBuilder.Append(")*(");
+ for (int i = 0; i < node.SubtreeCount; i++) {
+ if (i > 0) stringBuilder.Append("+");
+ stringBuilder.Append("(");
+ stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
+ stringBuilder.Append(")");
+ }
+ stringBuilder.Append(")");
+ } else if (symbol is Constant) {
+ ConstantTreeNode constantTreeNode = node as ConstantTreeNode;
+ stringBuilder.Append(constantTreeNode.Value.ToString().Replace(",", "."));
+ } else if (symbol is Cosine) {
+ stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
+ stringBuilder.Append(" cos");
+ } else if (symbol is Division) {
+ if (node.SubtreeCount == 1) {
+ stringBuilder.Append("1/");
+ stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
+ } else {
+ stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
+ stringBuilder.Append("/(");
+ for (int i = 1; i < node.SubtreeCount; i++) {
+ if (i > 1) stringBuilder.Append("*");
+ stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
+ }
+ stringBuilder.Append(")");
+ }
+ } else if (symbol is Exponential) {
+ stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
+ stringBuilder.Append(" exp");
+ } else if (symbol is GreaterThan) {
+ stringBuilder.Append("(");
+ stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
+ stringBuilder.Append(" > ");
+ stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
+ stringBuilder.Append(") ifTrue: [1] ifFalse: [-1]");
+ } else if (symbol is IfThenElse) {
+ stringBuilder.Append("(");
+ stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
+ stringBuilder.Append(" > 0) ifTrue: [");
+ stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
+ stringBuilder.Append("] ifFalse: [");
+ stringBuilder.Append(FormatRecursively(node.GetSubtree(2)));
+ stringBuilder.Append("]");
+ } else if (symbol is LaggedVariable) {
+ stringBuilder.Append("not implemented");
+ } else if (symbol is LessThan) {
+ stringBuilder.Append("(");
+ stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
+ stringBuilder.Append(" < ");
+ stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
+ stringBuilder.Append(") ifTrue: [1] ifFalse: [-1]");
+ } else if (symbol is Logarithm) {
+ stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
+ stringBuilder.Append("ln");
+ } else if (symbol is Multiplication) {
+ for (int i = 0; i < node.SubtreeCount; i++) {
+ if (i > 0) stringBuilder.Append("*");
+ stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
+ }
+ } else if (symbol is Not) {
+ stringBuilder.Append("-1*");
+ stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
+ } else if (symbol is Or) {
+ stringBuilder.Append("(");
+ for (int i = 0; i < node.SubtreeCount; i++) {
+ if (i > 0) stringBuilder.Append("|");
+ stringBuilder.Append("((");
+ stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
+ stringBuilder.Append(")>=0)");
+ }
+ stringBuilder.Append(") ifTrue:[1] ifFalse:[-1]");
+ } else if (symbol is Sine) {
+ stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
+ stringBuilder.Append(" sin");
+ } else if (symbol is Subtraction) {
+ if (node.SubtreeCount == 1) {
+ stringBuilder.Append("-1*");
+ stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
+ } else {
+ stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
+ for (int i = 1; i < node.SubtreeCount; i++) {
+ stringBuilder.Append("-");
+ stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
+ }
+ }
+ } else if (symbol is Tangent) {
+ stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
+ stringBuilder.Append("tan");
+ } else if (symbol is Variable) {
+ VariableTreeNode variableTreeNode = node as VariableTreeNode;
+ stringBuilder.Append(variableTreeNode.Weight.ToString().Replace(",", "."));
+ stringBuilder.Append("*");
+ stringBuilder.Append(variableTreeNode.VariableName);
+ } else {
+ stringBuilder.Append("ERROR");
+ }
+
+ stringBuilder.Append(")");
+
+ return stringBuilder.ToString();
+ }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new SymbolicExpressionTreeSmalltalkStringFormatter(this, cloner);
+ }
+ }
+}
Index: /branches/HivePerformance/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
===================================================================
--- /branches/HivePerformance/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj (revision 9654)
+++ /branches/HivePerformance/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj (revision 9655)
@@ -140,4 +140,5 @@
+
Index: /branches/HivePerformance/sources/HeuristicLab.Problems.Instances.DataAnalysis.Views/3.3/DataAnalysisImportTypeDialog.Designer.cs
===================================================================
--- /branches/HivePerformance/sources/HeuristicLab.Problems.Instances.DataAnalysis.Views/3.3/DataAnalysisImportTypeDialog.Designer.cs (revision 9654)
+++ /branches/HivePerformance/sources/HeuristicLab.Problems.Instances.DataAnalysis.Views/3.3/DataAnalysisImportTypeDialog.Designer.cs (revision 9655)
@@ -103,5 +103,5 @@
// TrainingTestTrackBar
//
- this.TrainingTestTrackBar.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ this.TrainingTestTrackBar.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.TrainingTestTrackBar.Location = new System.Drawing.Point(6, 43);
@@ -167,5 +167,5 @@
// ProblemTextBox
//
- this.ProblemTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ this.ProblemTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.ProblemTextBox.Location = new System.Drawing.Point(91, 6);
@@ -181,5 +181,5 @@
// DateTimeFormatComboBox
//
- this.DateTimeFormatComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ this.DateTimeFormatComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.DateTimeFormatComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
@@ -194,5 +194,5 @@
// DecimalSeparatorComboBox
//
- this.DecimalSeparatorComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ this.DecimalSeparatorComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.DecimalSeparatorComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
@@ -234,5 +234,5 @@
// SeparatorComboBox
//
- this.SeparatorComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ this.SeparatorComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.SeparatorComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
@@ -247,5 +247,5 @@
// CSVSettingsGroupBox
//
- this.CSVSettingsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ this.CSVSettingsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.CSVSettingsGroupBox.Controls.Add(this.CheckboxColumnNames);
@@ -304,6 +304,6 @@
// ProblemDataSettingsGroupBox
//
- this.ProblemDataSettingsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
+ this.ProblemDataSettingsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.ProblemDataSettingsGroupBox.Controls.Add(this.ErrorTextBox);
@@ -324,4 +324,5 @@
// ErrorTextBox
//
+ this.ErrorTextBox.Anchor = System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right;
this.ErrorTextBox.Location = new System.Drawing.Point(6, 15);
this.ErrorTextBox.Multiline = true;
@@ -354,6 +355,6 @@
// PreviewDatasetMatrix
//
- this.PreviewDatasetMatrix.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
+ this.PreviewDatasetMatrix.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.PreviewDatasetMatrix.Caption = "Dataset Preview";
Index: /branches/HivePerformance/sources/HeuristicLab.Problems.Instances.DataAnalysis.Views/3.3/DataAnalysisImportTypeDialog.cs
===================================================================
--- /branches/HivePerformance/sources/HeuristicLab.Problems.Instances.DataAnalysis.Views/3.3/DataAnalysisImportTypeDialog.cs (revision 9654)
+++ /branches/HivePerformance/sources/HeuristicLab.Problems.Instances.DataAnalysis.Views/3.3/DataAnalysisImportTypeDialog.cs (revision 9655)
@@ -42,5 +42,6 @@
new KeyValuePair(';', "; (Semicolon)" ),
new KeyValuePair(',', ", (Comma)" ),
- new KeyValuePair('\t', "\\t (Tab)")
+ new KeyValuePair('\t', "\\t (Tab)"),
+ new KeyValuePair((char)0, "all whitespaces (including tabs and spaces)")
};
Index: /branches/HivePerformance/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/TableFileParser.cs
===================================================================
--- /branches/HivePerformance/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/TableFileParser.cs (revision 9654)
+++ /branches/HivePerformance/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/TableFileParser.cs (revision 9655)
@@ -28,10 +28,11 @@
using System.Linq;
using System.Runtime.Serialization;
-using System.Text;
namespace HeuristicLab.Problems.Instances.DataAnalysis {
public class TableFileParser {
private const int BUFFER_SIZE = 65536;
- private static readonly char[] POSSIBLE_SEPARATORS = new char[] { ',', ';', '\t' };
+ // char used to symbolize whitespaces (no missing values can be handled with whitespaces)
+ private const char WHITESPACECHAR = (char)0;
+ private static readonly char[] POSSIBLE_SEPARATORS = new char[] { ',', ';', '\t', WHITESPACECHAR };
private Tokenizer tokenizer;
private List> rowValues;
@@ -360,16 +361,20 @@
private IEnumerable Split(string line) {
- StringBuilder subStr = new StringBuilder();
- foreach (char c in line) {
- if (c == separator) {
- yield return subStr.ToString();
- subStr = new StringBuilder();
- // all separator characters are transformed to the internally used separator character
+ IEnumerable splitString;
+ if (separator == WHITESPACECHAR) {
+ //separate whitespaces
+ splitString = line.Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
+ } else {
+ splitString = line.Split(separator);
+ }
+ int cur = splitString.Count();
+ foreach (var str in splitString) {
+ yield return str;
+ cur--;
+ // do not return the INTERNAL_SEPARATOR after the last string
+ if (cur != 0) {
yield return INTERNAL_SEPARATOR;
- } else {
- subStr.Append(c);
}
}
- yield return subStr.ToString();
}