Changeset 6337
- Timestamp:
- 05/30/11 16:59:50 (13 years ago)
- 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 96 96 97 97 private void checkBoxEnabled_CheckedChanged(object sender, EventArgs e) { 98 Content.Enabled = checkBoxEnabled.Checked; 98 if (Content != null) 99 Content.Enabled = checkBoxEnabled.Checked; 99 100 } 100 101 #endregion -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarEditorView.Designer.cs
r6285 r6337 25 25 private void InitializeComponent() { 26 26 this.components = new System.ComponentModel.Container(); 27 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SymbolicExpressionGrammarEditorView)); 27 28 this.grpSymbols = new System.Windows.Forms.GroupBox(); 28 29 this.splitContainer1 = new System.Windows.Forms.SplitContainer(); … … 30 31 this.imageList = new System.Windows.Forms.ImageList(this.components); 31 32 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(); 32 37 this.symbolicExpressionTreeChart = new HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.SymbolicExpressionTreeChart(); 33 this.symbolViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();34 38 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); 35 39 this.grpSymbols.SuspendLayout(); … … 75 79 // splitContainer1.Panel1 76 80 // 81 this.splitContainer1.Panel1.Controls.Add(this.showDetailsCheckBox); 82 this.splitContainer1.Panel1.Controls.Add(this.removeButton); 83 this.splitContainer1.Panel1.Controls.Add(this.addButton); 77 84 this.splitContainer1.Panel1.Controls.Add(this.symbolsTreeView); 78 85 // … … 86 93 // symbolsTreeView 87 94 // 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))); 88 98 this.symbolsTreeView.CheckBoxes = true; 89 this.symbolsTreeView.Dock = System.Windows.Forms.DockStyle.Fill;90 99 this.symbolsTreeView.ImageIndex = 0; 91 100 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); 93 102 this.symbolsTreeView.Name = "symbolsTreeView"; 94 103 this.symbolsTreeView.SelectedImageIndex = 0; 95 this.symbolsTreeView.Size = new System.Drawing.Size(1 91, 359);104 this.symbolsTreeView.Size = new System.Drawing.Size(185, 331); 96 105 this.symbolsTreeView.TabIndex = 0; 97 106 this.symbolsTreeView.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.symbolsTreeView_AfterCheck); 107 this.symbolsTreeView.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.symbolsTreeView_ItemDrag); 98 108 this.symbolsTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.symbolsTreeView_AfterSelect); 99 109 // … … 121 131 this.splitContainer2.SplitterDistance = 165; 122 132 this.splitContainer2.TabIndex = 0; 123 //124 // symbolicExpressionTreeChart125 //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;136 133 // 137 134 // symbolViewHost … … 148 145 this.symbolViewHost.ViewsLabelVisible = true; 149 146 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); 150 203 // 151 204 // SymbolicExpressionGrammarEditorView … … 174 227 175 228 } 176 177 229 #endregion 178 230 … … 184 236 private MainForm.WindowsForms.ViewHost symbolViewHost; 185 237 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; 186 241 } 187 242 } -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarEditorView.cs
r6299 r6337 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Drawing; 24 25 using System.Linq; 25 26 using System.Windows.Forms; 27 using HeuristicLab.Collections; 26 28 using HeuristicLab.Common; 27 29 using HeuristicLab.Core.Views; … … 33 35 [Content(typeof(ISymbolicExpressionGrammar), false)] 34 36 public partial class SymbolicExpressionGrammarEditorView : NamedItemView { 37 private ObservableList<ISymbolicExpressionTreeNode> selectedSymbolicExpressionTreeNodes; 38 35 39 public SymbolicExpressionGrammarEditorView() { 36 40 InitializeComponent(); 41 selectedSymbolicExpressionTreeNodes = new ObservableList<ISymbolicExpressionTreeNode>(); 37 42 } 38 43 … … 74 79 symbol = (ISymbol)symbolsTreeView.SelectedNode.Tag; 75 80 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 } 80 87 } 81 88 #endregion … … 98 105 } 99 106 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 111 107 private void AddChildTreeNodes(TreeNodeCollection collection, IEnumerable<ISymbol> symbols) { 112 108 foreach (ISymbol symbol in symbols) { … … 123 119 124 120 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; 127 123 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); 133 128 } 134 129 … … 138 133 var symbol = (ISymbol)e.Node.Tag; 139 134 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 } 140 143 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) { 146 159 var tree = new SymbolicExpressionTree(new SymbolicExpressionTreeNode(symbol)); 147 160 … … 155 168 } 156 169 } 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 } 160 311 161 312 #region helpers 162 private IEnumerable<TreeNode> Iterate TreeNodes(TreeNode node = null) {313 private IEnumerable<TreeNode> IterateSymbolTreeNodes(TreeNode node = null) { 163 314 TreeNodeCollection nodes; 164 315 if (node == null) … … 170 321 171 322 foreach (var childNode in nodes.OfType<TreeNode>()) 172 foreach (var n in Iterate TreeNodes(childNode))323 foreach (var n in IterateSymbolTreeNodes(childNode)) 173 324 yield return n; 174 325 } … … 176 327 protected virtual void RebuildImageList() { 177 328 symbolsTreeView.ImageList.Images.Clear(); 178 foreach (TreeNode treeNode in Iterate TreeNodes()) {329 foreach (TreeNode treeNode in IterateSymbolTreeNodes()) { 179 330 var symbol = (ISymbol)treeNode.Tag; 180 331 symbolsTreeView.ImageList.Images.Add(symbol == null ? HeuristicLab.Common.Resources.VSImageLibrary.Nothing : symbol.ItemImage); … … 182 333 } 183 334 } 335 #endregion 184 336 } 185 #endregion186 337 187 338 [NonDiscoverableType] -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs
r5956 r6337 197 197 } 198 198 199 p rivateVisualSymbolicExpressionTreeNode FindVisualSymbolicExpressionTreeNodeAt(int x, int y) {199 public VisualSymbolicExpressionTreeNode FindVisualSymbolicExpressionTreeNodeAt(int x, int y) { 200 200 foreach (var visualTreeNode in visualTreeNodes.Values) { 201 201 if (x >= visualTreeNode.X && x <= visualTreeNode.X + visualTreeNode.Width && -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs
r6284 r6337 182 182 where s.InitialFrequency > 0.0 183 183 where s.Fixed || parent.Grammar.GetMinimumExpressionDepth(s) < maxDepth - extensionDepth + 1 184 where s.Fixed || parent.Grammar.GetMaximumExpressionLength(s) > targetLength - totalListMinLength - currentLength184 //where s.Fixed || parent.Grammar.GetMaximumExpressionLength(s) > targetLength - totalListMinLength - currentLength 185 185 select s) 186 186 .ToList(); -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs
r6299 r6337 154 154 } 155 155 156 foreach (GroupSymbol group in symbols.Values.OfType<GroupSymbol>()) 157 group.symbols.Remove(symbol); 158 156 159 ClearCaches(); 157 160 OnChanged(); -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/GroupSymbol.cs
r6299 r6337 27 27 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 28 28 public sealed class GroupSymbol : Symbol, IReadOnlySymbol { 29 privateList<ISymbol> symbols;29 internal List<ISymbol> symbols; 30 30 31 31 [Storable] -
branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/TypeCoherentExpressionGrammar.cs
r5809 r6337 21 21 22 22 using System.Collections.Generic; 23 using System.Linq;24 23 using HeuristicLab.Common; 25 24 using HeuristicLab.Core; … … 94 93 * 95 94 * BinaryOperator = 96 * "+" | "-" | "*" | "/" | "Power" 95 * "+" | "-" | "*" | "/" | "Power" | "Root" 97 96 * 98 97 * UnaryOperator = … … 107 106 */ 108 107 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 109 133 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 }; 110 134 … … 112 136 var binaryFunctionSymbols = new List<Symbol>() { add, sub, mul, div, mean, pow, root, variableCondition }; 113 137 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); 136 159 137 160 138 161 // 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 //} 179 202 } 180 203 }
Note: See TracChangeset
for help on using the changeset viewer.