Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5750


Ignore:
Timestamp:
03/18/11 12:50:28 (14 years ago)
Author:
gkronber
Message:

#1418 Implemented variable view that allows to add and remove variable strings (ported from external evaluation views). Implemented formatter and grammar for external evaluation plugin. Fixed bug in symbolic expression view. Fixed bug in run collection variable impact view. Removed unused plugin HeuristicLab.Problems.ExternalEvaluation.GP.Views. Renamed files.

Location:
branches/DataAnalysis Refactoring
Files:
1 deleted
8 edited
3 copied
3 moved

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionView.cs

    r5513 r5750  
    2525using HeuristicLab.MainForm.WindowsForms;
    2626using HeuristicLab.PluginInfrastructure;
     27using System;
    2728
    2829namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
     
    6061      if (Content == null || formattersComboBox.SelectedIndex < 0)
    6162        textBox.Text = string.Empty;
    62       else
    63         textBox.Text = treeFormattersList[formattersComboBox.SelectedIndex].Format(Content);
     63      else {
     64        try {
     65          textBox.Text = treeFormattersList[formattersComboBox.SelectedIndex].Format(Content);
     66        }
     67        catch (ArgumentException) { textBox.Text = "Cannot format the symbolic expression tree with the selected formatter."; }
     68        catch (NotSupportedException) { textBox.Text = "Formatting of the symbolic expression tree is not supported by the selected formatter."; }
     69      }
    6470    }
    6571
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/RunCollectionVariableImpactView.cs

    r5693 r5750  
    3434  [View("RunCollection Variable Impact View")]
    3535  public sealed partial class RunCollectionVariableImpactView : AsynchronousContentView {
    36     private const string variableImpactResultName = "Integrated variable frequencies";
     36    private const string variableImpactResultName = "Variable impacts";
    3737    public RunCollectionVariableImpactView() {
    3838      InitializeComponent();
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Symbols/VariableView.Designer.cs

    r5693 r5750  
    5555      this.additiveWeightChangeLabel = new System.Windows.Forms.Label();
    5656      this.additiveWeightChangeSigmaTextBox = new System.Windows.Forms.TextBox();
     57      this.tabControl = new System.Windows.Forms.TabControl();
     58      this.variableNamesTabPage = new System.Windows.Forms.TabPage();
     59      this.parametersTabPage = new System.Windows.Forms.TabPage();
    5760      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    5861      this.initializationGroupBox.SuspendLayout();
    5962      this.mutationGroupBox.SuspendLayout();
     63      this.tabControl.SuspendLayout();
     64      this.parametersTabPage.SuspendLayout();
    6065      this.SuspendLayout();
    6166      //
     
    6772      //
    6873      this.errorProvider.SetIconAlignment(this.initialFrequencyTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
    69       this.initialFrequencyTextBox.Size = new System.Drawing.Size(203, 20);
     74      this.initialFrequencyTextBox.Size = new System.Drawing.Size(285, 20);
    7075      //
    7176      // nameTextBox
     
    7378      this.errorProvider.SetIconAlignment(this.nameTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
    7479      this.errorProvider.SetIconPadding(this.nameTextBox, 2);
    75       this.nameTextBox.Size = new System.Drawing.Size(203, 20);
     80      this.nameTextBox.Size = new System.Drawing.Size(285, 20);
    7681      //
    7782      // descriptionTextBox
    7883      //
    7984      this.errorProvider.SetIconAlignment(this.descriptionTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
    80       this.descriptionTextBox.Size = new System.Drawing.Size(203, 20);
     85      this.descriptionTextBox.Size = new System.Drawing.Size(285, 20);
    8186      //
    8287      // weightMuLabel
     
    96101      this.weightInitializationMuTextBox.Location = new System.Drawing.Point(92, 19);
    97102      this.weightInitializationMuTextBox.Name = "weightInitializationMuTextBox";
    98       this.weightInitializationMuTextBox.Size = new System.Drawing.Size(222, 20);
     103      this.weightInitializationMuTextBox.Size = new System.Drawing.Size(266, 20);
    99104      this.weightInitializationMuTextBox.TabIndex = 7;
    100105      this.toolTip.SetToolTip(this.weightInitializationMuTextBox, "The mu (mean) parameter of the normal distribution from which to sample the initi" +
     
    110115      this.initializationGroupBox.Controls.Add(this.weightMuLabel);
    111116      this.initializationGroupBox.Controls.Add(this.weightInitializationMuTextBox);
    112       this.initializationGroupBox.Location = new System.Drawing.Point(3, 79);
     117      this.initializationGroupBox.Location = new System.Drawing.Point(6, 6);
    113118      this.initializationGroupBox.Name = "initializationGroupBox";
    114       this.initializationGroupBox.Size = new System.Drawing.Size(320, 73);
     119      this.initializationGroupBox.Size = new System.Drawing.Size(364, 73);
    115120      this.initializationGroupBox.TabIndex = 8;
    116121      this.initializationGroupBox.TabStop = false;
     
    133138      this.weightInitializationSigmaTextBox.Location = new System.Drawing.Point(92, 45);
    134139      this.weightInitializationSigmaTextBox.Name = "weightInitializationSigmaTextBox";
    135       this.weightInitializationSigmaTextBox.Size = new System.Drawing.Size(222, 20);
     140      this.weightInitializationSigmaTextBox.Size = new System.Drawing.Size(266, 20);
    136141      this.weightInitializationSigmaTextBox.TabIndex = 9;
    137142      this.toolTip.SetToolTip(this.weightInitializationSigmaTextBox, "The sigma parameter for the normal distribution from which to sample the initial " +
     
    147152      this.mutationGroupBox.Controls.Add(this.additiveWeightChangeLabel);
    148153      this.mutationGroupBox.Controls.Add(this.additiveWeightChangeSigmaTextBox);
    149       this.mutationGroupBox.Location = new System.Drawing.Point(3, 158);
     154      this.mutationGroupBox.Location = new System.Drawing.Point(6, 85);
    150155      this.mutationGroupBox.Name = "mutationGroupBox";
    151       this.mutationGroupBox.Size = new System.Drawing.Size(320, 73);
     156      this.mutationGroupBox.Size = new System.Drawing.Size(364, 73);
    152157      this.mutationGroupBox.TabIndex = 9;
    153158      this.mutationGroupBox.TabStop = false;
     
    171176      this.multiplicativeWeightChangeSigmaTextBox.Location = new System.Drawing.Point(201, 45);
    172177      this.multiplicativeWeightChangeSigmaTextBox.Name = "multiplicativeWeightChangeSigmaTextBox";
    173       this.multiplicativeWeightChangeSigmaTextBox.Size = new System.Drawing.Size(113, 20);
     178      this.multiplicativeWeightChangeSigmaTextBox.Size = new System.Drawing.Size(157, 20);
    174179      this.multiplicativeWeightChangeSigmaTextBox.TabIndex = 9;
    175180      this.toolTip.SetToolTip(this.multiplicativeWeightChangeSigmaTextBox, "The sigma (std.dev.) parameter for the normal distribution to sample a multiplica" +
     
    194199      this.additiveWeightChangeSigmaTextBox.Location = new System.Drawing.Point(201, 19);
    195200      this.additiveWeightChangeSigmaTextBox.Name = "additiveWeightChangeSigmaTextBox";
    196       this.additiveWeightChangeSigmaTextBox.Size = new System.Drawing.Size(113, 20);
     201      this.additiveWeightChangeSigmaTextBox.Size = new System.Drawing.Size(157, 20);
    197202      this.additiveWeightChangeSigmaTextBox.TabIndex = 7;
    198203      this.toolTip.SetToolTip(this.additiveWeightChangeSigmaTextBox, "The sigma (std.dev.) parameter for the normal distribution to sample an additive " +
     
    200205      this.additiveWeightChangeSigmaTextBox.TextChanged += new System.EventHandler(this.additiveWeightChangeSigmaTextBox_TextChanged);
    201206      //
     207      // tabControl
     208      //
     209      this.tabControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     210                  | System.Windows.Forms.AnchorStyles.Left)
     211                  | System.Windows.Forms.AnchorStyles.Right)));
     212      this.tabControl.Controls.Add(this.variableNamesTabPage);
     213      this.tabControl.Controls.Add(this.parametersTabPage);
     214      this.tabControl.Location = new System.Drawing.Point(3, 79);
     215      this.tabControl.Name = "tabControl";
     216      this.tabControl.SelectedIndex = 0;
     217      this.tabControl.Size = new System.Drawing.Size(399, 212);
     218      this.tabControl.TabIndex = 10;
     219      //
     220      // variableNamesTabPage
     221      //
     222      this.variableNamesTabPage.Location = new System.Drawing.Point(4, 22);
     223      this.variableNamesTabPage.Name = "variableNamesTabPage";
     224      this.variableNamesTabPage.Padding = new System.Windows.Forms.Padding(3);
     225      this.variableNamesTabPage.Size = new System.Drawing.Size(391, 186);
     226      this.variableNamesTabPage.TabIndex = 0;
     227      this.variableNamesTabPage.Text = "Variable Names";
     228      this.variableNamesTabPage.UseVisualStyleBackColor = true;
     229      //
     230      // parametersTabPage
     231      //
     232      this.parametersTabPage.Controls.Add(this.mutationGroupBox);
     233      this.parametersTabPage.Controls.Add(this.initializationGroupBox);
     234      this.parametersTabPage.Location = new System.Drawing.Point(4, 22);
     235      this.parametersTabPage.Name = "parametersTabPage";
     236      this.parametersTabPage.Padding = new System.Windows.Forms.Padding(3);
     237      this.parametersTabPage.Size = new System.Drawing.Size(391, 186);
     238      this.parametersTabPage.TabIndex = 1;
     239      this.parametersTabPage.Text = "Parameters";
     240      this.parametersTabPage.UseVisualStyleBackColor = true;
     241      //
    202242      // VariableView
    203243      //
    204244      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    205245      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    206       this.Controls.Add(this.mutationGroupBox);
    207       this.Controls.Add(this.initializationGroupBox);
     246      this.Controls.Add(this.tabControl);
    208247      this.Name = "VariableView";
    209       this.Size = new System.Drawing.Size(326, 235);
    210       this.Controls.SetChildIndex(this.initializationGroupBox, 0);
     248      this.Size = new System.Drawing.Size(408, 294);
    211249      this.Controls.SetChildIndex(this.initialFrequencyTextBox, 0);
    212250      this.Controls.SetChildIndex(this.initialFrequencyLabel, 0);
     
    215253      this.Controls.SetChildIndex(this.nameTextBox, 0);
    216254      this.Controls.SetChildIndex(this.descriptionTextBox, 0);
    217       this.Controls.SetChildIndex(this.mutationGroupBox, 0);
     255      this.Controls.SetChildIndex(this.tabControl, 0);
    218256      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
    219257      this.initializationGroupBox.ResumeLayout(false);
     
    221259      this.mutationGroupBox.ResumeLayout(false);
    222260      this.mutationGroupBox.PerformLayout();
     261      this.tabControl.ResumeLayout(false);
     262      this.parametersTabPage.ResumeLayout(false);
    223263      this.ResumeLayout(false);
    224264      this.PerformLayout();
     
    238278    private System.Windows.Forms.Label additiveWeightChangeLabel;
    239279    private System.Windows.Forms.TextBox additiveWeightChangeSigmaTextBox;
    240 
     280    private System.Windows.Forms.TabControl tabControl;
     281    private System.Windows.Forms.TabPage variableNamesTabPage;
     282    private System.Windows.Forms.TabPage parametersTabPage;
    241283  }
    242284}
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Symbols/VariableView.cs

    r5693 r5750  
    2121
    2222using System;
     23using System.Linq;
    2324using System.Windows.Forms;
    2425using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
    2526using HeuristicLab.MainForm;
    2627using HeuristicLab.MainForm.WindowsForms;
     28using HeuristicLab.Core;
     29using HeuristicLab.Data;
     30using HeuristicLab.Core.Views;
     31using HeuristicLab.Collections;
    2732
    2833
    2934namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
     35
    3036  [View("Variable View")]
    3137  [Content(typeof(Variable), true)]
    3238  public partial class VariableView : SymbolView {
     39    private CheckedItemCollectionView<StringValue> variableNamesView;
     40
    3341    public new Variable Content {
    3442      get { return (Variable)base.Content; }
     
    3846    public VariableView() {
    3947      InitializeComponent();
     48      variableNamesView = new CheckedItemCollectionView<StringValue>();
     49      variableNamesView.Dock = DockStyle.Fill;
     50      variableNamesTabPage.Controls.Add(variableNamesView);
     51      variableNamesView.Content = new CheckedItemCollection<StringValue>();
     52
     53      RegisterVariableNamesViewContentEvents();
    4054    }
     55
     56    private void RegisterVariableNamesViewContentEvents() {
     57      variableNamesView.Content.ItemsAdded += new CollectionItemsChangedEventHandler<StringValue>(variableNames_Changed);
     58      variableNamesView.Content.ItemsRemoved += new CollectionItemsChangedEventHandler<StringValue>(variableNames_Changed);
     59      variableNamesView.Content.CheckedItemsChanged += new CollectionItemsChangedEventHandler<StringValue>(variableNames_Changed);
     60      variableNamesView.Content.CollectionReset += new CollectionItemsChangedEventHandler<StringValue>(variableNames_Changed);
     61    }
     62
     63    private void DeregisterVariableNamesViewContentEvents() {
     64      variableNamesView.Content.ItemsAdded -= new CollectionItemsChangedEventHandler<StringValue>(variableNames_Changed);
     65      variableNamesView.Content.ItemsRemoved -= new CollectionItemsChangedEventHandler<StringValue>(variableNames_Changed);
     66      variableNamesView.Content.CheckedItemsChanged -= new CollectionItemsChangedEventHandler<StringValue>(variableNames_Changed);
     67      variableNamesView.Content.CollectionReset -= new CollectionItemsChangedEventHandler<StringValue>(variableNames_Changed);
     68    }
     69
    4170
    4271    protected override void RegisterContentEvents() {
     
    74103
    75104    #region control event handlers
     105    private void variableNames_Changed(object sender, CollectionItemsChangedEventArgs<StringValue> args) {
     106      if (Content != null) {
     107        Content.VariableNames = variableNamesView.Content.CheckedItems.Select(x => x.Value).ToList();
     108      }
     109    }
     110
    76111    private void weightMuTextBox_TextChanged(object sender, EventArgs e) {
    77112      double nu;
     
    121156        additiveWeightChangeSigmaTextBox.Text = string.Empty;
    122157        multiplicativeWeightChangeSigmaTextBox.Text = string.Empty;
     158        // temporarily deregister to prevent circular calling of events
     159        DeregisterVariableNamesViewContentEvents();
     160        variableNamesView.Content.Clear();
     161        RegisterVariableNamesViewContentEvents();
    123162      } else {
     163        var existingEntries = variableNamesView.Content.Select(x => x.Value);
     164       
     165        // temporarily deregister to prevent circular calling of events
     166        DeregisterVariableNamesViewContentEvents();
     167        // add additional entries
     168        foreach (var variableName in Content.VariableNames.Except(existingEntries)) {
     169          variableNamesView.Content.Add(new StringValue(variableName), true);
     170        }
     171        RegisterVariableNamesViewContentEvents();
     172
    124173        weightInitializationMuTextBox.Text = Content.WeightMu.ToString();
    125174        weightInitializationSigmaTextBox.Text = Content.WeightSigma.ToString();
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/ILaggedTreeNode.cs

    r5532 r5750  
    2222
    2323using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    24 namespace HeuristicLab.Problems.DataAnalysis {
     24namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    2525  public interface ILaggedTreeNode : ISymbolicExpressionTreeNode {
    2626    int Lag { get; set; }
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.ExternalEvaluation.GP/3.4/ExternalEvaluationExpressionGrammar.cs

    r5745 r5750  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
     25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     26using HeuristicLab.Problems.DataAnalysis.Symbolic;
    2527using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2828
    2929namespace HeuristicLab.Problems.ExternalEvaluation.GP {
    3030  [StorableClass]
    31   [Item("FullFunctionalExpressionGrammar", "Represents a grammar for functional expressions using all available functions.")]
    32   public class FullFunctionalExpressionGrammar : DefaultSymbolicExpressionGrammar {
     31  [Item("ExternalEvaluationExpressionGrammar", "Represents a grammar for functional expressions using all available functions.")]
     32  public class ExternalEvaluationExpressionGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {
    3333    [Storable]
    34     private HeuristicLab.Problems.ExternalEvaluation.GP.Variable variableSymbol;
     34    private HeuristicLab.Problems.DataAnalysis.Symbolic.Variable variableSymbol;
    3535    [StorableConstructor]
    36     protected FullFunctionalExpressionGrammar(bool deserializing) : base(deserializing) { }
    37     protected FullFunctionalExpressionGrammar(FullFunctionalExpressionGrammar original, Cloner cloner) : base(original, cloner) { }
     36    protected ExternalEvaluationExpressionGrammar(bool deserializing) : base(deserializing) { }
     37    protected ExternalEvaluationExpressionGrammar(ExternalEvaluationExpressionGrammar original, Cloner cloner) : base(original, cloner) { }
    3838    public override IDeepCloneable Clone(Cloner cloner) {
    39       return new FullFunctionalExpressionGrammar(this, cloner);
     39      return new ExternalEvaluationExpressionGrammar(this, cloner);
    4040    }
    4141
    42     public FullFunctionalExpressionGrammar()
    43       : base() {
     42    public ExternalEvaluationExpressionGrammar()
     43      : base("ExternalEvaluationExpressionGrammar", "Represents a grammar for functional expressions using all available functions.") {
    4444      Initialize();
    4545    }
    4646
    47     private void Initialize() {
    48       var originalStart = StartSymbol;
    49       if (!(originalStart is ProgramRootSymbol)) {
    50         var root = new ProgramRootSymbol();
    51         AddSymbol(root);
    52         SetMinSubtreeCount(root, 1);
    53         SetMaxSubtreeCount(root, 1);
    54         SetAllowedChild(root, originalStart, 0);
    55 
    56         StartSymbol = root;
    57       }
    58 
     47    private void Initialize() {     
    5948      var add = new Addition();
    6049      var sub = new Subtraction();
     
    7665      constant.MinValue = -20;
    7766      constant.MaxValue = 20;
    78       variableSymbol = new Variable();
     67      variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
    7968
    8069      var allSymbols = new List<Symbol>() { add, sub, mul, div, mean, sin, cos, tan, log, exp, @if, gt, lt, and, or, not, constant, variableSymbol };
     
    8776
    8877      foreach (var funSymb in functionSymbols) {
    89         SetMinSubtreeCount(funSymb, 1);
    90         SetMaxSubtreeCount(funSymb, 3);
     78        SetSubtreeCount(funSymb, 1, 3);
    9179      }
    9280      foreach (var funSymb in unaryFunctionSymbols) {
    93         SetMinSubtreeCount(funSymb, 1);
    94         SetMaxSubtreeCount(funSymb, 1);
     81        SetSubtreeCount(funSymb, 1, 1);
    9582      }
    9683      foreach (var funSymb in binaryFunctionSymbols) {
    97         SetMinSubtreeCount(funSymb, 2);
    98         SetMaxSubtreeCount(funSymb, 2);
     84        SetSubtreeCount(funSymb, 2, 2);
    9985      }
    10086
    101       SetMinSubtreeCount(@if, 3);
    102       SetMaxSubtreeCount(@if, 3);
    103       SetMinSubtreeCount(constant, 0);
    104       SetMaxSubtreeCount(constant, 0);
    105       SetMinSubtreeCount(variableSymbol, 0);
    106       SetMaxSubtreeCount(variableSymbol, 0);
     87      SetSubtreeCount(@if, 3, 3);
     88      SetSubtreeCount(constant, 0, 0);
     89      SetSubtreeCount(variableSymbol, 0, 0);
    10790
    10891      // allow each symbol as child of the start symbol
    10992      foreach (var symb in allSymbols) {
    110         SetAllowedChild(originalStart, symb, 0);
     93        AddAllowedChildSymbol(StartSymbol, symb, 0);
    11194      }
    11295
    11396      // allow each symbol as child of every other symbol (except for terminals that have maxSubtreeCount == 0)
    11497      foreach (var parent in allSymbols) {
    115         for (int i = 0; i < GetMaxSubtreeCount(parent); i++)
     98        for (int i = 0; i < GetMaximumSubtreeCount(parent); i++)
    11699          foreach (var child in allSymbols) {
    117             SetAllowedChild(parent, child, i);
     100            AddAllowedChildSymbol(parent, child, i);
    118101          }
    119102      }
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.ExternalEvaluation.GP/3.4/ExternalEvaluationSymbolicExpressionTreeStringConverter.cs

    r5745 r5750  
    3030  [StorableClass]
    3131  public class SymbolicExpressionTreeStringConverter : SymbolicExpressionTreeConverter {
    32     private SymbolicExpressionTreeStringFormatter formatter;
     32    private ExternalEvaluationSymbolicExpressionTreeStringFormatter formatter;
    3333
    3434    [StorableConstructor]
     
    3636    protected SymbolicExpressionTreeStringConverter(SymbolicExpressionTreeStringConverter original, Cloner cloner)
    3737      : base(original, cloner) {
    38       formatter = new SymbolicExpressionTreeStringFormatter();
     38      formatter = new ExternalEvaluationSymbolicExpressionTreeStringFormatter();
    3939      formatter.Indent = original.formatter.Indent;
    4040    }
     
    5454
    5555    private void Initialize() {
    56       formatter = new SymbolicExpressionTreeStringFormatter();
     56      formatter = new ExternalEvaluationSymbolicExpressionTreeStringFormatter();
    5757      formatter.Indent = false;
    5858    }
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.ExternalEvaluation.GP/3.4/ExternalEvaluationSymbolicExpressionTreeStringFormatter.cs

    r5745 r5750  
    2525using HeuristicLab.Common;
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     28using HeuristicLab.Problems.DataAnalysis.Symbolic;
     29using System;
    2730
    28 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     31namespace HeuristicLab.Problems.ExternalEvaluation.GP {
    2932
    30   [Item("SymbolicExpressionTreeStringFormatter", "The default string formatter for symbolic expression trees.")]
     33  [Item("ExternalEvaluationSymbolicExpressionTreeStringFormatter", "A string formatter for symbolic expression trees for external evaluation.")]
    3134  [StorableClass]
    32   public class SymbolicExpressionTreeStringFormatter : NamedItem, ISymbolicExpressionTreeStringFormatter {
     35  public class ExternalEvaluationSymbolicExpressionTreeStringFormatter : NamedItem, ISymbolicExpressionTreeStringFormatter {
    3336
    3437    public bool Indent { get; set; }
    3538
    3639    [StorableConstructor]
    37     protected SymbolicExpressionTreeStringFormatter(bool deserializing) : base(deserializing) { }
    38     protected SymbolicExpressionTreeStringFormatter(SymbolicExpressionTreeStringFormatter original, Cloner cloner)
     40    protected ExternalEvaluationSymbolicExpressionTreeStringFormatter(bool deserializing) : base(deserializing) { }
     41    protected ExternalEvaluationSymbolicExpressionTreeStringFormatter(ExternalEvaluationSymbolicExpressionTreeStringFormatter original, Cloner cloner)
    3942      : base(original, cloner) {
    4043      Indent = original.Indent;
    4144    }
    42     public SymbolicExpressionTreeStringFormatter()
     45    public ExternalEvaluationSymbolicExpressionTreeStringFormatter()
    4346      : base() {
    44       Name = "Default String Formatter";
     47      Name = "External Evaluation Symbolic Expression Tree Formatter";
    4548      Indent = true;
    4649    }
    4750
    4851    public string Format(ISymbolicExpressionTree symbolicExpressionTree) {
    49       return FormatRecursively(symbolicExpressionTree.Root, 0);
     52      // skip root and start symbols
     53      return FormatRecursively(symbolicExpressionTree.Root.GetSubtree(0).GetSubtree(0), 0);
    5054    }
    5155
     
    5761      if (node.Subtrees.Count() > 0) {
    5862        // symbol on same line as '('
    59         strBuilder.AppendLine(node.ToString());
     63        if (node.Symbol is Addition) {
     64          strBuilder.AppendLine("+");
     65        } else if (node.Symbol is And) {
     66          strBuilder.AppendLine("&&");
     67        } else if (node.Symbol is Average) {
     68          strBuilder.AppendLine("avg");
     69        } else if (node.Symbol is Cosine) {
     70          strBuilder.AppendLine("cos");
     71        } else if (node.Symbol is Division) {
     72          strBuilder.AppendLine("/");
     73        } else if (node.Symbol is Exponential) {
     74          strBuilder.AppendLine("exp");
     75        } else if (node.Symbol is GreaterThan) {
     76          strBuilder.AppendLine(">");
     77        } else if (node.Symbol is IfThenElse) {
     78          strBuilder.AppendLine("if");
     79        } else if (node.Symbol is LessThan) {
     80          strBuilder.AppendLine("<");
     81        } else if (node.Symbol is Logarithm) {
     82          strBuilder.AppendLine("ln");
     83        } else if (node.Symbol is Multiplication) {
     84          strBuilder.AppendLine("*");
     85        } else if (node.Symbol is Not) {
     86          strBuilder.AppendLine("!");
     87        } else if (node.Symbol is Or) {
     88          strBuilder.AppendLine("||");
     89        } else if (node.Symbol is Sine) {
     90          strBuilder.AppendLine("sin");
     91        } else if (node.Symbol is Subtraction) {
     92          strBuilder.AppendLine("-");
     93        } else if (node.Symbol is Tangent) {
     94          strBuilder.AppendLine("tan");
     95        } else {
     96          throw new NotSupportedException("Formatting of symbol: " + node.Symbol + " not supported for external evaluation.");
     97        }
    6098        // each subtree expression on a new line
    6199        // and closing ')' also on new line
     100
    62101        foreach (var subtree in node.Subtrees) {
    63102          strBuilder.AppendLine(FormatRecursively(subtree, indentLength + 2));
     
    66105        strBuilder.Append(")");
    67106      } else {
    68         // symbol in the same line with as '(' and ')'
    69         strBuilder.Append(node.ToString());
    70         strBuilder.Append(")");
     107        if (node is VariableTreeNode) {
     108          var varNode = node as VariableTreeNode;
     109          // symbol in the same line with as '(' and ')'
     110          strBuilder.Append(";" + varNode.VariableName + ";" + varNode.Weight.ToString("E4"));
     111          strBuilder.Append(")");
     112        } else if (node is ConstantTreeNode) {
     113          var constNode = node as ConstantTreeNode;
     114          // symbol in the same line with as '(' and ')'
     115          strBuilder.Append(";" + constNode.Value.ToString("E4"));
     116          strBuilder.Append(")");
     117        } else {
     118          throw new NotSupportedException("Formatting of symbol: " + node.Symbol + " not supported for external evaluation.");
     119        }
    71120      }
    72121      return strBuilder.ToString();
     
    74123
    75124    public override IDeepCloneable Clone(Cloner cloner) {
    76       return new SymbolicExpressionTreeStringFormatter(this, cloner);
     125      return new ExternalEvaluationSymbolicExpressionTreeStringFormatter(this, cloner);
    77126    }
    78127  }
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.ExternalEvaluation.GP/3.4/HeuristicLab.Problems.ExternalEvaluation.GP-3.4.csproj

    r5572 r5750  
    108108  <ItemGroup>
    109109    <None Include="HeuristicLabProblemsExternalEvaluationGPPlugin.cs.frame" />
     110    <Compile Include="ExternalEvaluationExpressionGrammar.cs" />
     111    <Compile Include="ExternalEvaluationSymbolicExpressionTreeBinaryConverter.cs" />
     112    <Compile Include="ExternalEvaluationSymbolicExpressionTreeConverter.cs" />
     113    <Compile Include="ExternalEvaluationSymbolicExpressionTreeStringConverter.cs" />
     114    <Compile Include="ExternalEvaluationSymbolicExpressionTreeStringFormatter.cs" />
    110115    <Compile Include="HeuristicLabProblemsExternalEvaluationGPPlugin.cs" />
    111116    <Compile Include="Properties\AssemblyInfo.cs" />
    112117    <None Include="Properties\AssemblyInfo.frame" />
    113     <Compile Include="SymbolicExpressionTreeBinaryConverter.cs" />
    114     <Compile Include="SymbolicExpressionTreeConverter.cs" />
    115     <Compile Include="SymbolicExpressionTreeStringConverter.cs" />
    116118  </ItemGroup>
    117119  <ItemGroup>
     
    147149      <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project>
    148150      <Name>HeuristicLab.PluginInfrastructure-3.3</Name>
     151    </ProjectReference>
     152    <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Symbolic\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj">
     153      <Project>{3D28463F-EC96-4D82-AFEE-38BE91A0CA00}</Project>
     154      <Name>HeuristicLab.Problems.DataAnalysis.Symbolic-3.4</Name>
    149155    </ProjectReference>
    150156    <ProjectReference Include="..\..\HeuristicLab.Problems.ExternalEvaluation\3.3\HeuristicLab.Problems.ExternalEvaluation-3.3.csproj">
     
    176182      <Install>true</Install>
    177183    </BootstrapperPackage>
     184  </ItemGroup>
     185  <ItemGroup>
     186    <Content Include="ExternalEvaluationGrammar.txt" />
    178187  </ItemGroup>
    179188  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • branches/DataAnalysis Refactoring/HeuristicLab/3.3/Files.txt

    r5699 r5750  
    7575HeuristicLab.Problems.ExternalEvaluation.GP\3.4:HeuristicLab.Problems.ExternalEvaluation.GP-3.4.dll
    7676HeuristicLab.Problems.ExternalEvaluation.GP.Views\3.3:HeuristicLab.Problems.ExternalEvaluation.GP.Views-3.3.dll
    77 HeuristicLab.Problems.ExternalEvaluation.GP.Views\3.4:HeuristicLab.Problems.ExternalEvaluation.GP.Views-3.4.dll
    7877HeuristicLab.Problems.Knapsack\3.3:HeuristicLab.Problems.Knapsack-3.3.dll
    7978HeuristicLab.Problems.Knapsack.Views\3.3:HeuristicLab.Problems.Knapsack.Views-3.3.dll
  • branches/DataAnalysis Refactoring/HeuristicLab/3.3/Tests/HeuristicLab-3.3.Tests.csproj

    r5697 r5750  
    439439      <Name>HeuristicLab.Problems.ExternalEvaluation.GP.Views-3.3</Name>
    440440    </ProjectReference>
    441     <ProjectReference Include="..\..\..\HeuristicLab.Problems.ExternalEvaluation.GP.Views\3.4\HeuristicLab.Problems.ExternalEvaluation.GP.Views-3.4.csproj">
    442       <Project>{A0AF4D54-6A04-483E-A26D-97F8C1141526}</Project>
    443       <Name>HeuristicLab.Problems.ExternalEvaluation.GP.Views-3.4</Name>
    444     </ProjectReference>
    445441    <ProjectReference Include="..\..\..\HeuristicLab.Problems.ExternalEvaluation.GP\3.3\HeuristicLab.Problems.ExternalEvaluation.GP-3.3.csproj">
    446442      <Project>{E86E215D-E3CE-4244-978D-555D4E17AC09}</Project>
Note: See TracChangeset for help on using the changeset viewer.