Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6337


Ignore:
Timestamp:
05/30/11 16:59:50 (13 years ago)
Author:
mkommend
Message:

#1479: Added updated version of grammar editor.

Location:
branches/GP.Grammar.Editor
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolView.cs

    r6299 r6337  
    9696
    9797    private void checkBoxEnabled_CheckedChanged(object sender, EventArgs e) {
    98       Content.Enabled = checkBoxEnabled.Checked;
     98      if (Content != null)
     99        Content.Enabled = checkBoxEnabled.Checked;
    99100    }
    100101    #endregion
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarEditorView.Designer.cs

    r6285 r6337  
    2525    private void InitializeComponent() {
    2626      this.components = new System.ComponentModel.Container();
     27      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SymbolicExpressionGrammarEditorView));
    2728      this.grpSymbols = new System.Windows.Forms.GroupBox();
    2829      this.splitContainer1 = new System.Windows.Forms.SplitContainer();
     
    3031      this.imageList = new System.Windows.Forms.ImageList(this.components);
    3132      this.splitContainer2 = new System.Windows.Forms.SplitContainer();
     33      this.symbolViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
     34      this.showDetailsCheckBox = new System.Windows.Forms.CheckBox();
     35      this.removeButton = new System.Windows.Forms.Button();
     36      this.addButton = new System.Windows.Forms.Button();
    3237      this.symbolicExpressionTreeChart = new HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.SymbolicExpressionTreeChart();
    33       this.symbolViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    3438      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    3539      this.grpSymbols.SuspendLayout();
     
    7579      // splitContainer1.Panel1
    7680      //
     81      this.splitContainer1.Panel1.Controls.Add(this.showDetailsCheckBox);
     82      this.splitContainer1.Panel1.Controls.Add(this.removeButton);
     83      this.splitContainer1.Panel1.Controls.Add(this.addButton);
    7784      this.splitContainer1.Panel1.Controls.Add(this.symbolsTreeView);
    7885      //
     
    8693      // symbolsTreeView
    8794      //
     95      this.symbolsTreeView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     96            | System.Windows.Forms.AnchorStyles.Left)
     97            | System.Windows.Forms.AnchorStyles.Right)));
    8898      this.symbolsTreeView.CheckBoxes = true;
    89       this.symbolsTreeView.Dock = System.Windows.Forms.DockStyle.Fill;
    9099      this.symbolsTreeView.ImageIndex = 0;
    91100      this.symbolsTreeView.ImageList = this.imageList;
    92       this.symbolsTreeView.Location = new System.Drawing.Point(0, 0);
     101      this.symbolsTreeView.Location = new System.Drawing.Point(3, 28);
    93102      this.symbolsTreeView.Name = "symbolsTreeView";
    94103      this.symbolsTreeView.SelectedImageIndex = 0;
    95       this.symbolsTreeView.Size = new System.Drawing.Size(191, 359);
     104      this.symbolsTreeView.Size = new System.Drawing.Size(185, 331);
    96105      this.symbolsTreeView.TabIndex = 0;
    97106      this.symbolsTreeView.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.symbolsTreeView_AfterCheck);
     107      this.symbolsTreeView.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.symbolsTreeView_ItemDrag);
    98108      this.symbolsTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.symbolsTreeView_AfterSelect);
    99109      //
     
    121131      this.splitContainer2.SplitterDistance = 165;
    122132      this.splitContainer2.TabIndex = 0;
    123       //
    124       // symbolicExpressionTreeChart
    125       //
    126       this.symbolicExpressionTreeChart.BackgroundColor = System.Drawing.Color.White;
    127       this.symbolicExpressionTreeChart.Dock = System.Windows.Forms.DockStyle.Fill;
    128       this.symbolicExpressionTreeChart.LineColor = System.Drawing.Color.Black;
    129       this.symbolicExpressionTreeChart.Location = new System.Drawing.Point(0, 0);
    130       this.symbolicExpressionTreeChart.Name = "symbolicExpressionTreeChart";
    131       this.symbolicExpressionTreeChart.Size = new System.Drawing.Size(568, 165);
    132       this.symbolicExpressionTreeChart.Spacing = 5;
    133       this.symbolicExpressionTreeChart.TabIndex = 0;
    134       this.symbolicExpressionTreeChart.TextFont = new System.Drawing.Font("Times New Roman", 8F);
    135       this.symbolicExpressionTreeChart.Tree = null;
    136133      //
    137134      // symbolViewHost
     
    148145      this.symbolViewHost.ViewsLabelVisible = true;
    149146      this.symbolViewHost.ViewType = null;
     147      //
     148      // showDetailsCheckBox
     149      //
     150      this.showDetailsCheckBox.Appearance = System.Windows.Forms.Appearance.Button;
     151      this.showDetailsCheckBox.Checked = true;
     152      this.showDetailsCheckBox.CheckState = System.Windows.Forms.CheckState.Checked;
     153      this.showDetailsCheckBox.Image = ((System.Drawing.Image)(resources.GetObject("showDetailsCheckBox.Image")));
     154      this.showDetailsCheckBox.Location = new System.Drawing.Point(63, 3);
     155      this.showDetailsCheckBox.Name = "showDetailsCheckBox";
     156      this.showDetailsCheckBox.Size = new System.Drawing.Size(24, 24);
     157      this.showDetailsCheckBox.TabIndex = 7;
     158      this.toolTip.SetToolTip(this.showDetailsCheckBox, "Show/Hide Details");
     159      this.showDetailsCheckBox.UseVisualStyleBackColor = true;
     160      this.showDetailsCheckBox.CheckedChanged += new System.EventHandler(this.showDetailsCheckBox_CheckedChanged);
     161      //
     162      // removeButton
     163      //
     164      this.removeButton.Enabled = false;
     165      this.removeButton.Image = ((System.Drawing.Image)(resources.GetObject("removeButton.Image")));
     166      this.removeButton.Location = new System.Drawing.Point(33, 3);
     167      this.removeButton.Name = "removeButton";
     168      this.removeButton.Size = new System.Drawing.Size(24, 24);
     169      this.removeButton.TabIndex = 6;
     170      this.toolTip.SetToolTip(this.removeButton, "Remove");
     171      this.removeButton.UseVisualStyleBackColor = true;
     172      this.removeButton.Click += new System.EventHandler(this.removeButton_Click);
     173      //
     174      // addButton
     175      //
     176      this.addButton.Image = ((System.Drawing.Image)(resources.GetObject("addButton.Image")));
     177      this.addButton.Location = new System.Drawing.Point(3, 3);
     178      this.addButton.Name = "addButton";
     179      this.addButton.Size = new System.Drawing.Size(24, 24);
     180      this.addButton.TabIndex = 5;
     181      this.toolTip.SetToolTip(this.addButton, "Add");
     182      this.addButton.UseVisualStyleBackColor = true;
     183      this.addButton.Click += new System.EventHandler(this.addButton_Click);
     184      //
     185      // symbolicExpressionTreeChart
     186      //
     187      this.symbolicExpressionTreeChart.AllowDrop = true;
     188      this.symbolicExpressionTreeChart.BackgroundColor = System.Drawing.Color.White;
     189      this.symbolicExpressionTreeChart.Dock = System.Windows.Forms.DockStyle.Fill;
     190      this.symbolicExpressionTreeChart.LineColor = System.Drawing.Color.Black;
     191      this.symbolicExpressionTreeChart.Location = new System.Drawing.Point(0, 0);
     192      this.symbolicExpressionTreeChart.Name = "symbolicExpressionTreeChart";
     193      this.symbolicExpressionTreeChart.Size = new System.Drawing.Size(568, 165);
     194      this.symbolicExpressionTreeChart.Spacing = 5;
     195      this.symbolicExpressionTreeChart.TabIndex = 0;
     196      this.symbolicExpressionTreeChart.TextFont = new System.Drawing.Font("Times New Roman", 8F);
     197      this.symbolicExpressionTreeChart.Tree = null;
     198      this.symbolicExpressionTreeChart.SymbolicExpressionTreeNodeClicked += new System.Windows.Forms.MouseEventHandler(this.symbolicExpressionTreeChart_SymbolicExpressionTreeNodeClicked);
     199      this.symbolicExpressionTreeChart.DragDrop += new System.Windows.Forms.DragEventHandler(this.symbolicExpressionTreeChart_DragDrop);
     200      this.symbolicExpressionTreeChart.DragEnter += new System.Windows.Forms.DragEventHandler(this.symbolicExpressionTreeChart_DragEnter);
     201      this.symbolicExpressionTreeChart.DragOver += new System.Windows.Forms.DragEventHandler(this.symbolicExpressionTreeChart_DragOver);
     202      this.symbolicExpressionTreeChart.KeyDown += new System.Windows.Forms.KeyEventHandler(this.symbolicExpressionTreeChart_KeyDown);
    150203      //
    151204      // SymbolicExpressionGrammarEditorView
     
    174227
    175228    }
    176 
    177229    #endregion
    178230
     
    184236    private MainForm.WindowsForms.ViewHost symbolViewHost;
    185237    private System.Windows.Forms.ImageList imageList;
     238    protected System.Windows.Forms.CheckBox showDetailsCheckBox;
     239    protected System.Windows.Forms.Button removeButton;
     240    protected System.Windows.Forms.Button addButton;
    186241  }
    187242}
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarEditorView.cs

    r6299 r6337  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Drawing;
    2425using System.Linq;
    2526using System.Windows.Forms;
     27using HeuristicLab.Collections;
    2628using HeuristicLab.Common;
    2729using HeuristicLab.Core.Views;
     
    3335  [Content(typeof(ISymbolicExpressionGrammar), false)]
    3436  public partial class SymbolicExpressionGrammarEditorView : NamedItemView {
     37    private ObservableList<ISymbolicExpressionTreeNode> selectedSymbolicExpressionTreeNodes;
     38
    3539    public SymbolicExpressionGrammarEditorView() {
    3640      InitializeComponent();
     41      selectedSymbolicExpressionTreeNodes = new ObservableList<ISymbolicExpressionTreeNode>();
    3742    }
    3843
     
    7479        symbol = (ISymbol)symbolsTreeView.SelectedNode.Tag;
    7580
    76       OnContentChanged();
    77 
    78       if (symbol != null)
    79         symbolsTreeView.SelectedNode = IterateTreeNodes().Where(n => n.Tag == symbol).FirstOrDefault();
     81      RebuildSymbolsTreeView();
     82      if (symbol != null && Content.ContainsSymbol(symbol)) {
     83        BuildAllowedChildSymbolsTree(symbol);
     84        symbolViewHost.Content = symbol;
     85        symbolsTreeView.SelectedNode = IterateSymbolTreeNodes().Where(n => n.Tag == symbol).ToList().FirstOrDefault();
     86      }
    8087    }
    8188    #endregion
     
    98105    }
    99106
    100     private void RebuildSymbolsTreeView() {
    101       symbolsTreeView.Nodes.Clear();
    102       var symbols = Content.Symbols.ToList();
    103       var groupSymbols = symbols.OfType<GroupSymbol>().ToList();
    104       var topLevelSymbols = Content.Symbols.Where(s => !groupSymbols.Any(g => g.Symbols.Contains(s)));
    105       AddChildTreeNodes(symbolsTreeView.Nodes, topLevelSymbols);
    106 
    107       RebuildImageList();
    108       symbolsTreeView.ExpandAll();
    109     }
    110 
    111107    private void AddChildTreeNodes(TreeNodeCollection collection, IEnumerable<ISymbol> symbols) {
    112108      foreach (ISymbol symbol in symbols) {
     
    123119
    124120    private void symbolsTreeView_AfterSelect(object sender, TreeViewEventArgs e) {
    125       var symbol = (ISymbol)e.Node.Tag;
    126       if (!(symbol is DummySymbol)) {
     121      if (e.Action != TreeViewAction.Unknown) {
     122        var symbol = (ISymbol)e.Node.Tag;
    127123        symbolViewHost.Content = symbol;
    128         symbolicExpressionTreeChart.Tree = BuildAllowedChildSymbolsTree(symbol);
    129       } else {
    130         symbolViewHost.Content = null;
    131         symbolicExpressionTreeChart.Tree = null;
    132       }
     124        selectedSymbolicExpressionTreeNodes.Clear();
     125        BuildAllowedChildSymbolsTree(symbol);
     126      }
     127      removeButton.Enabled = symbolsTreeView.SelectedNode != null && !(symbolsTreeView.SelectedNode.Tag is IReadOnlySymbol);
    133128    }
    134129
     
    138133        var symbol = (ISymbol)e.Node.Tag;
    139134        symbol.Enabled = e.Node.Checked;
     135        foreach (var node in IterateSymbolTreeNodes())
     136          node.Checked = ((ISymbol)node.Tag).Enabled;
     137
     138        if (symbolsTreeView.SelectedNode != null) {
     139          symbol = (ISymbol)symbolsTreeView.SelectedNode.Tag;
     140          selectedSymbolicExpressionTreeNodes.Clear();
     141          BuildAllowedChildSymbolsTree(symbol);
     142        }
    140143        RegisterContentEvents();
    141         Content_Changed(Content, EventArgs.Empty);
    142       }
    143     }
    144 
    145     private ISymbolicExpressionTree BuildAllowedChildSymbolsTree(ISymbol symbol) {
     144      }
     145    }
     146
     147    private void RebuildSymbolsTreeView() {
     148      symbolsTreeView.Nodes.Clear();
     149      var symbols = Content.Symbols.ToList();
     150      var groupSymbols = symbols.OfType<GroupSymbol>().ToList();
     151      var topLevelSymbols = Content.Symbols.Where(s => !groupSymbols.Any(g => g.Symbols.Contains(s)));
     152      AddChildTreeNodes(symbolsTreeView.Nodes, topLevelSymbols);
     153
     154      RebuildImageList();
     155      symbolsTreeView.ExpandAll();
     156    }
     157
     158    private void BuildAllowedChildSymbolsTree(ISymbol symbol) {
    146159      var tree = new SymbolicExpressionTree(new SymbolicExpressionTreeNode(symbol));
    147160
     
    155168        }
    156169      }
    157       return tree;
    158     }
    159 
     170      symbolicExpressionTreeChart.Tree = tree;
     171      UpdateSelectedSymbolicExpressionTreeNodes();
     172    }
     173
     174    private void symbolicExpressionTreeChart_SymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) {
     175      if ((Control.ModifierKeys & Keys.Control) == 0)
     176        selectedSymbolicExpressionTreeNodes.Clear();
     177
     178      VisualSymbolicExpressionTreeNode clickedNode = (VisualSymbolicExpressionTreeNode)sender;
     179      var selectedNode = clickedNode.SymbolicExpressionTreeNode;
     180      if (selectedNode.SubtreesCount == 0) {
     181        if (!selectedSymbolicExpressionTreeNodes.Contains(selectedNode))
     182          selectedSymbolicExpressionTreeNodes.Add(selectedNode);
     183        else
     184          selectedSymbolicExpressionTreeNodes.Remove(selectedNode);
     185      }
     186
     187      UpdateSelectedSymbolicExpressionTreeNodes();
     188    }
     189
     190    private void symbolicExpressionTreeChart_KeyDown(object sender, KeyEventArgs e) {
     191      if (e.KeyCode == Keys.Delete) {
     192        DeregisterContentEvents();
     193        var root = symbolicExpressionTreeChart.Tree.Root;
     194        foreach (var node in selectedSymbolicExpressionTreeNodes) {
     195          int argIndex = root.IndexOfSubtree(node.Parent);
     196          Content.RemoveAllowedChildSymbol(root.Symbol, node.Symbol, argIndex);
     197        }
     198        RegisterContentEvents();
     199        selectedSymbolicExpressionTreeNodes.Clear();
     200        BuildAllowedChildSymbolsTree(root.Symbol);
     201      }
     202    }
     203
     204    private void symbolsTreeView_ItemDrag(object sender, ItemDragEventArgs e) {
     205      if (!Locked) {
     206        DataObject data = new DataObject();
     207        data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, ((TreeNode)e.Item).Tag);
     208        DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
     209      }
     210    }
     211
     212    private bool validDragOperation;
     213    private void symbolicExpressionTreeChart_DragEnter(object sender, DragEventArgs e) {
     214      validDragOperation = false;
     215      var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
     216      var symbol = data as ISymbol;
     217      var symbols = data as IEnumerable<ISymbol>;
     218      if (symbol != null && Content.ContainsSymbol(symbol)) validDragOperation = true;
     219      else if (symbols != null && symbols.All(s => Content.ContainsSymbol(s))) validDragOperation = true;
     220    }
     221
     222
     223    private void symbolicExpressionTreeChart_DragOver(object sender, DragEventArgs e) {
     224      e.Effect = DragDropEffects.None;
     225      if (validDragOperation) {
     226        Point coordinates = symbolicExpressionTreeChart.PointToClient(new Point(e.X, e.Y));
     227        var visualNode = symbolicExpressionTreeChart.FindVisualSymbolicExpressionTreeNodeAt(coordinates.X, coordinates.Y);
     228        if (visualNode != null) {
     229          var node = visualNode.SymbolicExpressionTreeNode;
     230          var root = symbolicExpressionTreeChart.Tree.Root;
     231          if (node == root || node.Parent == root) e.Effect = DragDropEffects.Copy;
     232        }
     233      }
     234    }
     235
     236    private void symbolicExpressionTreeChart_DragDrop(object sender, DragEventArgs e) {
     237      Point coordinates = symbolicExpressionTreeChart.PointToClient(new Point(e.X, e.Y));
     238      var node = symbolicExpressionTreeChart.FindVisualSymbolicExpressionTreeNodeAt(coordinates.X, coordinates.Y);
     239      var root = symbolicExpressionTreeChart.Tree.Root;
     240
     241      var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
     242      var symbol = data as ISymbol;
     243      var symbols = data as IEnumerable<ISymbol>;
     244
     245      DeregisterContentEvents();
     246      if (node.SymbolicExpressionTreeNode == root) {
     247        if (symbol != null)
     248          Content.AddAllowedChildSymbol(root.Symbol, symbol);
     249        else if (symbols != null)
     250          foreach (var s in symbols) Content.AddAllowedChildSymbol(root.Symbol, s);
     251      } else {
     252        int argumentIndex = root.IndexOfSubtree(node.SymbolicExpressionTreeNode);
     253        if (symbol != null)
     254          Content.AddAllowedChildSymbol(root.Symbol, symbol, argumentIndex);
     255        else if (symbols != null)
     256          foreach (var s in symbols) Content.AddAllowedChildSymbol(root.Symbol, s, argumentIndex);
     257      }
     258      RegisterContentEvents();
     259      BuildAllowedChildSymbolsTree(root.Symbol);
     260    }
     261
     262    private void UpdateSelectedSymbolicExpressionTreeNodes() {
     263      foreach (var node in symbolicExpressionTreeChart.Tree.IterateNodesPrefix()) {
     264        var visualNode = symbolicExpressionTreeChart.GetVisualSymbolicExpressionTreeNode(node);
     265        if (!selectedSymbolicExpressionTreeNodes.Contains(node)) {
     266          visualNode.FillColor = Color.White;
     267          visualNode.LineColor = Color.Black;
     268        } else {
     269          visualNode.FillColor = Color.WhiteSmoke;
     270          visualNode.LineColor = Color.DarkOrange;
     271        }
     272      }
     273      symbolicExpressionTreeChart.Repaint();
     274    }
     275
     276    private TypeSelectorDialog typeSelectorDialog;
     277    private void addButton_Click(object sender, EventArgs e) {
     278      if (typeSelectorDialog == null) {
     279        typeSelectorDialog = new TypeSelectorDialog();
     280        typeSelectorDialog.Caption = "Select Symbol";
     281        typeSelectorDialog.TypeSelector.Caption = "Available Symbols";
     282        typeSelectorDialog.TypeSelector.Configure(typeof(ISymbol), false, false, (t) => { return !typeof(IReadOnlySymbol).IsAssignableFrom(t); });
     283      }
     284      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
     285        try {
     286          ISymbol symbol = (ISymbol)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
     287          var originalSymbolName = symbol.Name;
     288          int i = 1;
     289          while (Content.ContainsSymbol(symbol)) {
     290            symbol.Name = originalSymbolName + i;
     291            i++;
     292          }
     293          Content.AddSymbol(symbol);
     294        }
     295        catch (Exception ex) {
     296          ErrorHandling.ShowErrorDialog(this, ex);
     297        }
     298      }
     299    }
     300
     301    private void removeButton_Click(object sender, EventArgs e) {
     302      var symbol = symbolsTreeView.SelectedNode.Tag as ISymbol;
     303      if (symbol != null && !(symbol is IReadOnlySymbol))
     304        Content.RemoveSymbol(symbol);
     305      removeButton.Enabled = false;
     306    }
     307
     308    private void showDetailsCheckBox_CheckedChanged(object sender, EventArgs e) {
     309      splitContainer1.Panel2Collapsed = !showDetailsCheckBox.Checked;
     310    }
    160311
    161312    #region helpers
    162     private IEnumerable<TreeNode> IterateTreeNodes(TreeNode node = null) {
     313    private IEnumerable<TreeNode> IterateSymbolTreeNodes(TreeNode node = null) {
    163314      TreeNodeCollection nodes;
    164315      if (node == null)
     
    170321
    171322      foreach (var childNode in nodes.OfType<TreeNode>())
    172         foreach (var n in IterateTreeNodes(childNode))
     323        foreach (var n in IterateSymbolTreeNodes(childNode))
    173324          yield return n;
    174325    }
     
    176327    protected virtual void RebuildImageList() {
    177328      symbolsTreeView.ImageList.Images.Clear();
    178       foreach (TreeNode treeNode in IterateTreeNodes()) {
     329      foreach (TreeNode treeNode in IterateSymbolTreeNodes()) {
    179330        var symbol = (ISymbol)treeNode.Tag;
    180331        symbolsTreeView.ImageList.Images.Add(symbol == null ? HeuristicLab.Common.Resources.VSImageLibrary.Nothing : symbol.ItemImage);
     
    182333      }
    183334    }
     335    #endregion
    184336  }
    185     #endregion
    186337
    187338  [NonDiscoverableType]
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs

    r5956 r6337  
    197197    }
    198198
    199     private VisualSymbolicExpressionTreeNode FindVisualSymbolicExpressionTreeNodeAt(int x, int y) {
     199    public VisualSymbolicExpressionTreeNode FindVisualSymbolicExpressionTreeNodeAt(int x, int y) {
    200200      foreach (var visualTreeNode in visualTreeNodes.Values) {
    201201        if (x >= visualTreeNode.X && x <= visualTreeNode.X + visualTreeNode.Width &&
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs

    r6284 r6337  
    182182                                where s.InitialFrequency > 0.0
    183183                                where s.Fixed || parent.Grammar.GetMinimumExpressionDepth(s) < maxDepth - extensionDepth + 1
    184                                 where s.Fixed || parent.Grammar.GetMaximumExpressionLength(s) > targetLength - totalListMinLength - currentLength
     184                                //where s.Fixed || parent.Grammar.GetMaximumExpressionLength(s) > targetLength - totalListMinLength - currentLength
    185185                                select s)
    186186                               .ToList();
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs

    r6299 r6337  
    154154      }
    155155
     156      foreach (GroupSymbol group in symbols.Values.OfType<GroupSymbol>())
     157        group.symbols.Remove(symbol);
     158
    156159      ClearCaches();
    157160      OnChanged();
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/GroupSymbol.cs

    r6299 r6337  
    2727namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
    2828  public sealed class GroupSymbol : Symbol, IReadOnlySymbol {
    29     private List<ISymbol> symbols;
     29    internal List<ISymbol> symbols;
    3030
    3131    [Storable]
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/TypeCoherentExpressionGrammar.cs

    r5809 r6337  
    2121
    2222using System.Collections.Generic;
    23 using System.Linq;
    2423using HeuristicLab.Common;
    2524using HeuristicLab.Core;
     
    9493       *
    9594       * BinaryOperator =
    96        *   "+" | "-" | "*" | "/" | "Power"
     95       *   "+" | "-" | "*" | "/" | "Power" | "Root"
    9796       *
    9897       * UnaryOperator =
     
    107106       */
    108107
     108      var arithmeticSymbols = new GroupSymbol("Arithmetic Functions", new List<ISymbol>() { add, sub, mul, div });
     109      var trigonometricSymbols = new GroupSymbol("Trigonometric Functions", new List<ISymbol>() { sin, cos, tan });
     110      var powerSymbols = new GroupSymbol("Power Functions", new List<ISymbol> { pow, root });
     111      var exponentialAndLogarithmicSymbols = new GroupSymbol("Exponential and Logarithmic Functions", new List<ISymbol> { exp, log });
     112      var terminalSymbols = new GroupSymbol("Terminals", new List<ISymbol> { constant, variableSymbol });
     113      var realValuedSymbols = new GroupSymbol("Real valued Symbols",
     114        new List<ISymbol>() { arithmeticSymbols, trigonometricSymbols, powerSymbols, exponentialAndLogarithmicSymbols, terminalSymbols });
     115
     116      AddSymbol(realValuedSymbols);
     117
     118      SetSubtreeCount(arithmeticSymbols, 2, 2);
     119      SetSubtreeCount(trigonometricSymbols, 1, 1);
     120      SetSubtreeCount(powerSymbols, 2, 2);
     121      SetSubtreeCount(exponentialAndLogarithmicSymbols, 1, 1);
     122      SetSubtreeCount(terminalSymbols, 0, 0);
     123
     124      AddAllowedChildSymbol(StartSymbol, realValuedSymbols);
     125      AddAllowedChildSymbol(DefunSymbol, realValuedSymbols);
     126      AddAllowedChildSymbol(realValuedSymbols, realValuedSymbols);
     127
     128      //var unaryBooleanFunctionSymbols = new List<Symbol>() { not };
     129      //var binaryBooleanFunctionSymbols = new List<Symbol>() { or, and };
     130      //var relationalFunctionSymbols = new List<Symbol>() { gt, lt };
     131      //var booleanSymbols = unaryBooleanFunctionSymbols.Concat(binaryBooleanFunctionSymbols).Concat(relationalFunctionSymbols);
     132
    109133      var allSymbols = new List<Symbol>() { add, sub, mul, div, mean, sin, cos, tan, log, pow, root, exp, @if, gt, lt, and, or, not, timeLag, integral, derivative, constant, variableSymbol, laggedVariable, variableCondition };
    110134
     
    112136      var binaryFunctionSymbols = new List<Symbol>() { add, sub, mul, div, mean, pow, root, variableCondition };
    113137
    114       var unaryBooleanFunctionSymbols = new List<Symbol>() { not };
    115       var binaryBooleanFunctionSymbols = new List<Symbol>() { or, and };
    116       var relationalFunctionSymbols = new List<Symbol>() { gt, lt };
    117       var terminalSymbols = new List<Symbol>() { variableSymbol, constant, laggedVariable };
    118       var realValuedSymbols = unaryFunctionSymbols.Concat(binaryFunctionSymbols).Concat(terminalSymbols).Concat(new List<Symbol>() { @if });
    119       var booleanSymbols = unaryBooleanFunctionSymbols.Concat(binaryBooleanFunctionSymbols).Concat(relationalFunctionSymbols);
    120 
    121       foreach (var symb in allSymbols)
    122         AddSymbol(symb);
    123 
    124       foreach (var unaryFun in unaryFunctionSymbols.Concat(unaryBooleanFunctionSymbols)) {
    125         SetSubtreeCount(unaryFun, 1, 1);
    126       }
    127       foreach (var binaryFun in binaryFunctionSymbols.Concat(binaryBooleanFunctionSymbols).Concat(relationalFunctionSymbols)) {
    128         SetSubtreeCount(binaryFun, 2, 2);
    129       }
    130 
    131       foreach (var terminalSymbol in terminalSymbols) {
    132         SetSubtreeCount(terminalSymbol, 0, 0);
    133       }
    134 
    135       SetSubtreeCount(@if, 3, 3);
     138
     139
     140      //var terminalSymbols = new List<Symbol>() { variableSymbol, constant, laggedVariable };
     141      //var realValuedSymbols = unaryFunctionSymbols.Concat(binaryFunctionSymbols).Concat(terminalSymbols).Concat(new List<Symbol>() { @if });
     142
     143
     144      //foreach (var symb in allSymbols)
     145      //  AddSymbol(symb);
     146
     147      //foreach (var unaryFun in unaryFunctionSymbols.Concat(unaryBooleanFunctionSymbols)) {
     148      //  SetSubtreeCount(unaryFun, 1, 1);
     149      //}
     150      //foreach (var binaryFun in binaryFunctionSymbols.Concat(binaryBooleanFunctionSymbols).Concat(relationalFunctionSymbols)) {
     151      //  SetSubtreeCount(binaryFun, 2, 2);
     152      //}
     153
     154      //foreach (var terminalSymbol in terminalSymbols) {
     155      //  SetSubtreeCount(terminalSymbol, 0, 0);
     156      //}
     157
     158      //SetSubtreeCount(@if, 3, 3);
    136159
    137160
    138161      // allow only real-valued expressions as child of the start symbol
    139       foreach (var symb in realValuedSymbols) {
    140         AddAllowedChildSymbol(StartSymbol, symb);
    141         AddAllowedChildSymbol(DefunSymbol, symb);
    142       }
    143 
    144       foreach (var symb in unaryFunctionSymbols) {
    145         foreach (var childSymb in realValuedSymbols) {
    146           AddAllowedChildSymbol(symb, childSymb);
    147         }
    148       }
    149 
    150       foreach (var symb in binaryFunctionSymbols) {
    151         foreach (var childSymb in realValuedSymbols) {
    152           AddAllowedChildSymbol(symb, childSymb);
    153         }
    154       }
    155 
    156       foreach (var childSymb in booleanSymbols) {
    157         AddAllowedChildSymbol(@if, childSymb, 0);
    158       }
    159       foreach (var childSymb in realValuedSymbols) {
    160         AddAllowedChildSymbol(@if, childSymb, 1);
    161         AddAllowedChildSymbol(@if, childSymb, 2);
    162       }
    163 
    164       foreach (var symb in relationalFunctionSymbols) {
    165         foreach (var childSymb in realValuedSymbols) {
    166           AddAllowedChildSymbol(symb, childSymb);
    167         }
    168       }
    169       foreach (var symb in binaryBooleanFunctionSymbols) {
    170         foreach (var childSymb in booleanSymbols) {
    171           AddAllowedChildSymbol(symb, childSymb);
    172         }
    173       }
    174       foreach (var symb in unaryBooleanFunctionSymbols) {
    175         foreach (var childSymb in booleanSymbols) {
    176           AddAllowedChildSymbol(symb, childSymb);
    177         }
    178       }
     162      //foreach (var symb in realValuedSymbols) {
     163      //  AddAllowedChildSymbol(StartSymbol, symb);
     164      //  AddAllowedChildSymbol(DefunSymbol, symb);
     165      //}
     166
     167      //foreach (var symb in unaryFunctionSymbols) {
     168      //  foreach (var childSymb in realValuedSymbols) {
     169      //    AddAllowedChildSymbol(symb, childSymb);
     170      //  }
     171      //}
     172
     173      //foreach (var symb in binaryFunctionSymbols) {
     174      //  foreach (var childSymb in realValuedSymbols) {
     175      //    AddAllowedChildSymbol(symb, childSymb);
     176      //  }
     177      //}
     178
     179      //foreach (var childSymb in booleanSymbols) {
     180      //  AddAllowedChildSymbol(@if, childSymb, 0);
     181      //}
     182      //foreach (var childSymb in realValuedSymbols) {
     183      //  AddAllowedChildSymbol(@if, childSymb, 1);
     184      //  AddAllowedChildSymbol(@if, childSymb, 2);
     185      //}
     186
     187      //foreach (var symb in relationalFunctionSymbols) {
     188      //  foreach (var childSymb in realValuedSymbols) {
     189      //    AddAllowedChildSymbol(symb, childSymb);
     190      //  }
     191      //}
     192      //foreach (var symb in binaryBooleanFunctionSymbols) {
     193      //  foreach (var childSymb in booleanSymbols) {
     194      //    AddAllowedChildSymbol(symb, childSymb);
     195      //  }
     196      //}
     197      //foreach (var symb in unaryBooleanFunctionSymbols) {
     198      //  foreach (var childSymb in booleanSymbols) {
     199      //    AddAllowedChildSymbol(symb, childSymb);
     200      //  }
     201      //}
    179202    }
    180203  }
Note: See TracChangeset for help on using the changeset viewer.