Changeset 2212 for branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3
- Timestamp:
- 07/30/09 10:47:00 (15 years ago)
- Location:
- branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3
- Files:
-
- 2 deleted
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/BinaryFunction.cs
r2211 r2212 24 24 using System.Linq; 25 25 using System.Text; 26 using HeuristicLab.Constraints;27 26 28 27 namespace HeuristicLab.GP { -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/FunctionBase.cs
r2211 r2212 23 23 using System.Collections.Generic; 24 24 using System.Text; 25 using HeuristicLab.Data;26 25 using HeuristicLab.Core; 27 26 using System.Xml; 28 using HeuristicLab.Constraints;29 27 using System.Diagnostics; 30 28 using HeuristicLab.GP.Interfaces; … … 111 109 } 112 110 113 //private List<IConstraint> constraints = new List<IConstraint>();114 //public ICollection<IConstraint> Constraints {115 // get { return constraints; }116 //}117 118 //private void RefreshArity() {119 // minArity = 2; maxArity = 2; // default arity is 2120 // foreach (IConstraint constraint in Constraints) {121 // NumberOfSubOperatorsConstraint theConstraint = constraint as NumberOfSubOperatorsConstraint;122 // if (theConstraint != null) {123 // minArity = theConstraint.MinOperators.Data;124 // maxArity = theConstraint.MaxOperators.Data;125 // }126 // }127 //}128 129 111 public ICollection<IFunction> GetAllowedSubFunctions(int index) { 130 112 if (index < 0 || index > MaxSubTrees) throw new ArgumentException("Index outside of allowed range. index = " + index); 131 //if (allowedSubFunctions == null) {132 // // first time: analyze the constraint and create a cached copy of the allowed sub-functions133 // allowedSubFunctions = new List<IFunction>[MaxArity];134 // for (int i = 0; i < MaxArity; i++) {135 // allowedSubFunctions[i] = GetAllowedSubFunctions(i);136 // }137 //}138 113 return allowedSubFunctions[index]; 139 114 } … … 156 131 public bool IsAllowedSubFunction(IFunction function, int index) { 157 132 return GetAllowedSubFunctions(index).Contains(function); 158 }159 160 //private List<IFunction> GetAllowedSubFunctions(int index) {161 // List<IFunction> allowedSubFunctions = new List<IFunction>();162 // foreach (IConstraint constraint in Constraints) {163 // if (constraint is SubOperatorTypeConstraint) {164 // SubOperatorTypeConstraint subOpConstraint = constraint as SubOperatorTypeConstraint;165 // if (subOpConstraint.SubOperatorIndex.Data == index) {166 // foreach (IFunction f in subOpConstraint.AllowedSubOperators) allowedSubFunctions.Add(f);167 // subOpConstraint.Changed += new EventHandler(subOpConstraint_Changed); // register an event-handler to invalidate the cache on constraint changes168 // return allowedSubFunctions;169 // }170 // } else if (constraint is AllSubOperatorsTypeConstraint) {171 // AllSubOperatorsTypeConstraint subOpConstraint = constraint as AllSubOperatorsTypeConstraint;172 // foreach (IFunction f in subOpConstraint.AllowedSubOperators) allowedSubFunctions.Add(f);173 // subOpConstraint.Changed += new EventHandler(subOpConstraint_Changed); // register an event-handler to invalidate the cache on constraint changes174 // return allowedSubFunctions;175 // }176 // }177 // return allowedSubFunctions;178 //}179 180 //private void subOpConstraint_Changed(object sender, EventArgs e) {181 // allowedSubFunctions = null;182 //}183 184 public override IView CreateView() {185 return new FunView(this);186 133 } 187 134 -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/Terminal.cs
r2211 r2212 24 24 using System.Linq; 25 25 using System.Text; 26 using HeuristicLab.Constraints;27 26 28 27 namespace HeuristicLab.GP { -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/UnaryFunction.cs
r2211 r2212 24 24 using System.Linq; 25 25 using System.Text; 26 using HeuristicLab.Constraints;27 26 28 27 namespace HeuristicLab.GP { -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/FunctionLibrary.cs
r2210 r2212 26 26 using HeuristicLab.Core; 27 27 using System.Xml; 28 using HeuristicLab.Data;29 using HeuristicLab.Constraints;30 28 using HeuristicLab.GP.Interfaces; 31 29 … … 41 39 } 42 40 43 44 41 public void AddFunction(IFunction fun) { 45 if (!functions.Contains(fun)) functions.Add(fun); 46 // OnFunctionAdded(fun); 42 if (!functions.Contains(fun)) { 43 functions.Add(fun); 44 OnChanged(); 45 } 47 46 } 48 49 //void UpdateTreeBounds(object sender, EventArgs e) {50 // RecalculateMinimalTreeBounds();51 //}52 53 54 //private void GetMinMaxArity(IOperator op, out int minArity, out int maxArity) {55 // foreach (IConstraint constraint in op.Constraints) {56 // NumberOfSubOperatorsConstraint theConstraint = constraint as NumberOfSubOperatorsConstraint;57 // if (theConstraint != null) {58 // minArity = theConstraint.MinOperators.Data;59 // maxArity = theConstraint.MaxOperators.Data;60 // return;61 // }62 // }63 // // the default arity is 264 // minArity = 2;65 // maxArity = 2;66 //}67 47 68 48 public void RemoveFunction(IFunction fun) { 69 49 functions.Remove(fun); 70 50 71 // remove the operator from the allowed sub-functions of the remaining operators51 // remove the operator from the allowed sub-functions of all functions 72 52 foreach (IFunction f in Functions) { 73 if (f != fun) { 53 for (int i = 0; i < f.MaxSubTrees; i++) { 54 f.RemoveAllowedSubFunction(fun, i); 74 55 } 75 56 } 76 // OnFunctionRemoved(fun);57 OnChanged(); 77 58 } 78 79 //public event EventHandler FunctionAdded;80 //public event EventHandler FunctionRemoved;81 82 //protected virtual void OnFunctionAdded(IFunction fun) {83 // if (FunctionAdded != null) {84 // FunctionAdded(this, new EventArgs(fun));85 // }86 //}87 //protected virtual void OnFunctionRemoved(IFunction fun) {88 // if (FunctionRemoved != null) {89 // FunctionRemoved(this, new EventArgs(fun));90 // }91 //}92 59 93 60 public override IView CreateView() { -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/FunctionLibraryEditor.Designer.cs
r2202 r2212 45 45 /// </summary> 46 46 private void InitializeComponent() { 47 this.operatorLibraryEditor = new HeuristicLab.Core.OperatorLibraryEditor();48 47 this.tabControl = new System.Windows.Forms.TabControl(); 49 this. operatorLibraryTabPage = new System.Windows.Forms.TabPage();48 this.functionsTabPage = new System.Windows.Forms.TabPage(); 50 49 this.initializationTabPage = new System.Windows.Forms.TabPage(); 51 50 this.initSplitContainer = new System.Windows.Forms.SplitContainer(); … … 56 55 this.mutationListView = new System.Windows.Forms.ListView(); 57 56 this.mutationVariableView = new HeuristicLab.Core.VariableView(); 57 this.addButton = new System.Windows.Forms.Button(); 58 this.removeButton = new System.Windows.Forms.Button(); 59 this.functionsListView = new System.Windows.Forms.ListView(); 58 60 this.tabControl.SuspendLayout(); 59 this. operatorLibraryTabPage.SuspendLayout();61 this.functionsTabPage.SuspendLayout(); 60 62 this.initializationTabPage.SuspendLayout(); 61 63 this.initSplitContainer.Panel1.SuspendLayout(); … … 68 70 this.SuspendLayout(); 69 71 // 70 // operatorLibraryEditor71 //72 this.operatorLibraryEditor.Caption = "Operator Library";73 this.operatorLibraryEditor.Dock = System.Windows.Forms.DockStyle.Fill;74 this.operatorLibraryEditor.Filename = null;75 this.operatorLibraryEditor.Location = new System.Drawing.Point(3, 3);76 this.operatorLibraryEditor.Name = "operatorLibraryEditor";77 this.operatorLibraryEditor.OperatorLibrary = null;78 this.operatorLibraryEditor.Size = new System.Drawing.Size(663, 529);79 this.operatorLibraryEditor.TabIndex = 0;80 //81 72 // tabControl 82 73 // 83 this.tabControl.Controls.Add(this. operatorLibraryTabPage);74 this.tabControl.Controls.Add(this.functionsTabPage); 84 75 this.tabControl.Controls.Add(this.initializationTabPage); 85 76 this.tabControl.Controls.Add(this.mutationTabPage); … … 91 82 this.tabControl.TabIndex = 1; 92 83 // 93 // operatorLibraryTabPage 94 // 95 this.operatorLibraryTabPage.Controls.Add(this.operatorLibraryEditor); 96 this.operatorLibraryTabPage.Location = new System.Drawing.Point(4, 22); 97 this.operatorLibraryTabPage.Name = "operatorLibraryTabPage"; 98 this.operatorLibraryTabPage.Padding = new System.Windows.Forms.Padding(3); 99 this.operatorLibraryTabPage.Size = new System.Drawing.Size(669, 535); 100 this.operatorLibraryTabPage.TabIndex = 0; 101 this.operatorLibraryTabPage.Text = "Operator Library"; 102 this.operatorLibraryTabPage.UseVisualStyleBackColor = true; 84 // functionsTabPage 85 // 86 this.functionsTabPage.Controls.Add(this.functionsListView); 87 this.functionsTabPage.Controls.Add(this.removeButton); 88 this.functionsTabPage.Controls.Add(this.addButton); 89 this.functionsTabPage.Location = new System.Drawing.Point(4, 22); 90 this.functionsTabPage.Name = "functionsTabPage"; 91 this.functionsTabPage.Padding = new System.Windows.Forms.Padding(3); 92 this.functionsTabPage.Size = new System.Drawing.Size(669, 535); 93 this.functionsTabPage.TabIndex = 0; 94 this.functionsTabPage.Text = "Functions"; 95 this.functionsTabPage.UseVisualStyleBackColor = true; 103 96 // 104 97 // initializationTabPage … … 201 194 this.mutationVariableView.Variable = null; 202 195 // 203 // GPOperatorLibraryEditor 196 // addButton 197 // 198 this.addButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 199 this.addButton.Location = new System.Drawing.Point(6, 506); 200 this.addButton.Name = "addButton"; 201 this.addButton.Size = new System.Drawing.Size(75, 23); 202 this.addButton.TabIndex = 1; 203 this.addButton.Text = "Add..."; 204 this.addButton.UseVisualStyleBackColor = true; 205 this.addButton.Click += new System.EventHandler(this.addButton_Click); 206 // 207 // removeButton 208 // 209 this.removeButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 210 this.removeButton.Location = new System.Drawing.Point(87, 506); 211 this.removeButton.Name = "removeButton"; 212 this.removeButton.Size = new System.Drawing.Size(75, 23); 213 this.removeButton.TabIndex = 2; 214 this.removeButton.Text = "Remove"; 215 this.removeButton.UseVisualStyleBackColor = true; 216 this.removeButton.Click += new System.EventHandler(this.removeButton_Click); 217 // 218 // functionsListView 219 // 220 this.functionsListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 221 | System.Windows.Forms.AnchorStyles.Left) 222 | System.Windows.Forms.AnchorStyles.Right))); 223 this.functionsListView.Location = new System.Drawing.Point(3, 6); 224 this.functionsListView.Name = "functionsListView"; 225 this.functionsListView.Size = new System.Drawing.Size(660, 494); 226 this.functionsListView.TabIndex = 3; 227 this.functionsListView.UseCompatibleStateImageBehavior = false; 228 this.functionsListView.SelectedIndexChanged += new System.EventHandler(this.functionsListView_SelectedIndexChanged); 229 // 230 // FunctionLibraryEditor 204 231 // 205 232 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 206 233 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 207 234 this.Controls.Add(this.tabControl); 208 this.Name = " GPOperatorLibraryEditor";235 this.Name = "FunctionLibraryEditor"; 209 236 this.Size = new System.Drawing.Size(677, 561); 210 237 this.tabControl.ResumeLayout(false); 211 this. operatorLibraryTabPage.ResumeLayout(false);238 this.functionsTabPage.ResumeLayout(false); 212 239 this.initializationTabPage.ResumeLayout(false); 213 240 this.initSplitContainer.Panel1.ResumeLayout(false); … … 224 251 #endregion 225 252 226 private HeuristicLab.Core.OperatorLibraryEditor operatorLibraryEditor;227 253 private System.Windows.Forms.TabControl tabControl; 228 private System.Windows.Forms.TabPage operatorLibraryTabPage;254 private System.Windows.Forms.TabPage functionsTabPage; 229 255 private System.Windows.Forms.TabPage initializationTabPage; 230 256 private System.Windows.Forms.TabPage mutationTabPage; … … 235 261 private System.Windows.Forms.ListView initListView; 236 262 private System.Windows.Forms.ListView mutationListView; 263 private System.Windows.Forms.Button removeButton; 264 private System.Windows.Forms.Button addButton; 265 private System.Windows.Forms.ListView functionsListView; 237 266 } 238 267 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/FunctionLibraryEditor.cs
r2210 r2212 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.ComponentModel;25 using System.Drawing;26 using System.Data;27 24 using System.Linq; 28 using System.Text;29 25 using System.Windows.Forms; 30 26 using HeuristicLab.Core; 31 using System.Diagnostics;32 using HeuristicLab.Data;33 using HeuristicLab.Operators;34 using HeuristicLab.Random;35 27 using HeuristicLab.GP.Interfaces; 36 28 37 29 namespace HeuristicLab.GP { 38 30 public partial class FunctionLibraryEditor : EditorBase { 31 private ChooseItemDialog chooseFunctionDialog; 39 32 public FunctionLibrary FunctionLibrary { 40 33 get { return (FunctionLibrary)Item; } … … 46 39 InitializeComponent(); 47 40 FunctionLibrary = library; 48 49 mutationVariableView.Enabled = false;50 initVariableView.Enabled = false;51 52 foreach (IFunction fun in library.Functions) {53 if (fun.Manipulator != null) {54 ListViewItem item = new ListViewItem();55 item.Text = fun.Name;56 item.Name = fun.Name;57 item.Tag = fun;58 mutationListView.Items.Add(item);59 }60 if (fun.Initializer != null) {61 ListViewItem item = new ListViewItem();62 item.Name = fun.Name;63 item.Text = fun.Name;64 item.Tag = fun;65 initListView.Items.Add(item);66 }67 }68 41 } 69 42 … … 75 48 protected override void UpdateControls() { 76 49 base.UpdateControls(); 50 foreach (IFunction fun in FunctionLibrary.Functions) { 51 if (fun.Manipulator != null) { 52 mutationListView.Items.Add(CreateListViewItem(fun)); 53 } 54 if (fun.Initializer != null) { 55 initListView.Items.Add(CreateListViewItem(fun)); 56 } 57 } 77 58 } 78 59 79 //private void GPOperatorLibraryView_OperatorAdded(object sender, EventArgs e) {80 // IOperator op = ((OperatorEventArgs)e).op;81 // if(op.GetVariable(FunctionBase.MANIPULATION) != null) {82 // ListViewItem operatorMutationItem = new ListViewItem();83 // operatorMutationItem.Name = op.Name;84 // operatorMutationItem.Text = op.Name;85 // operatorMutationItem.Tag = op;86 // mutationListView.Items.Add(operatorMutationItem);87 // }88 89 // if(op.GetVariable(FunctionBase.INITIALIZATION) != null) {90 // ListViewItem operatorInitItem = new ListViewItem();91 // operatorInitItem.Name = op.Name;92 // operatorInitItem.Text = op.Name;93 // operatorInitItem.Tag = op;94 // initListView.Items.Add(operatorInitItem);95 // }96 97 // op.NameChanged += new EventHandler(op_NameChanged);98 // Refresh();99 //}100 101 //private void op_NameChanged(object sender, EventArgs e) {102 // IOperator srcOp = (IOperator)sender;103 // foreach(ListViewItem item in mutationListView.Items) {104 // if(item.Tag == srcOp) {105 // item.Name = srcOp.Name;106 // item.Text = srcOp.Name;107 // break;108 // }109 // }110 // foreach(ListViewItem item in initListView.Items) {111 // if(item.Tag == srcOp) {112 // item.Name = srcOp.Name;113 // item.Text = srcOp.Name;114 // break;115 // }116 // }117 //}118 119 120 //private void GPOperatorGroup_OperatorRemoved(object sender, EventArgs e) {121 // IOperator op = ((OperatorEventArgs)e).op;122 123 // foreach(ListViewItem item in mutationListView.Items) {124 // if(item.Tag == op) {125 // mutationListView.Items.Remove(item);126 // break;127 // }128 // }129 130 // foreach(ListViewItem item in initListView.Items) {131 // if(item.Tag == op) {132 // initListView.Items.Remove(item);133 // break;134 // }135 // }136 //}137 138 60 private void mutationListView_SelectedIndexChanged(object sender, EventArgs e) { 139 //if(mutationListView.SelectedItems.Count>0 && mutationListView.SelectedItems[0].Tag != null) {140 // IVariable variable= ((IFunction)mutationListView.SelectedItems[0].Tag).Manipulator;141 //mutationVariableView.Enabled = true;142 // mutationVariableView.Variable = variable;143 //} else {144 //mutationVariableView.Enabled = false;145 //}61 if (mutationListView.SelectedItems.Count > 0 && mutationListView.SelectedItems[0].Tag != null) { 62 IOperator manipulator = ((IFunction)mutationListView.SelectedItems[0].Tag).Manipulator; 63 mutationVariableView.Enabled = true; 64 mutationVariableView.Variable = new Variable("Manipulator", manipulator); 65 } else { 66 mutationVariableView.Enabled = false; 67 } 146 68 } 147 69 148 70 private void initListView_SelectedIndexChanged(object sender, EventArgs e) { 149 //if(initListView.SelectedItems.Count>0 && initListView.SelectedItems[0].Tag != null) { 150 // IVariable variable = ((IFunction)initListView.SelectedItems[0].Tag).Initializer; 151 // initVariableView.Enabled = true; 152 // initVariableView.Variable = variable; 153 //} else { 154 // initVariableView.Enabled = false; 155 //} 71 if (initListView.SelectedItems.Count > 0 && initListView.SelectedItems[0].Tag != null) { 72 IOperator initializer = ((IFunction)initListView.SelectedItems[0].Tag).Initializer; 73 initVariableView.Enabled = true; 74 initVariableView.Variable = new Variable("Initializer", initializer); 75 } else { 76 initVariableView.Enabled = false; 77 } 78 } 79 80 private void addButton_Click(object sender, EventArgs e) { 81 if (chooseFunctionDialog == null) chooseFunctionDialog = new ChooseItemDialog(typeof(IFunction)); 82 if (chooseFunctionDialog.ShowDialog(this) == DialogResult.OK) { 83 FunctionLibrary.AddFunction((IFunction)chooseFunctionDialog.Item); 84 functionsListView.Items.Add(CreateListViewItem((IFunction)chooseFunctionDialog.Item)); 85 functionsListView.Sort(); 86 } 87 } 88 89 private void removeButton_Click(object sender, EventArgs e) { 90 // delete from the end of the list 91 IEnumerable<int> removeIndices = functionsListView.SelectedIndices.OfType<int>().OrderBy(x => 1.0 / x); 92 foreach (int selectedIndex in removeIndices) { 93 FunctionLibrary.RemoveFunction((IFunction)functionsListView.Items[selectedIndex].Tag); 94 functionsListView.Items.RemoveAt(selectedIndex); 95 } 96 } 97 98 private void functionsListView_SelectedIndexChanged(object sender, EventArgs e) { 99 removeButton.Enabled = functionsListView.SelectedIndices.Count > 0; 100 } 101 102 private ListViewItem CreateListViewItem(IFunction function) { 103 ListViewItem item = new ListViewItem(); 104 item.Name = function.Name; 105 item.Text = function.Name; 106 item.Tag = function; 107 return item; 156 108 } 157 109 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/FunctionTreeView.Designer.cs
r2202 r2212 36 36 components.Dispose(); 37 37 } 38 if(selectedVariable != null) {39 selectedVariable.Value.Changed -= new EventHandler(selectedVariable_ValueChanged);40 }41 38 base.Dispose(disposing); 42 39 } … … 49 46 /// </summary> 50 47 private void InitializeComponent() { 51 this. components = new System.ComponentModel.Container();48 this.treeNodeContextMenu = new System.Windows.Forms.ContextMenu(); 52 49 this.funTreeView = new System.Windows.Forms.TreeView(); 53 this.splitContainer = new System.Windows.Forms.SplitContainer();54 this.variablesGroupBox = new System.Windows.Forms.GroupBox();55 this.variablesSplitContainer = new System.Windows.Forms.SplitContainer();56 this.variablesListBox = new System.Windows.Forms.ListBox();57 this.label1 = new System.Windows.Forms.Label();58 this.templateTextBox = new System.Windows.Forms.TextBox();59 this.editButton = new System.Windows.Forms.Button();60 this.treeNodeContextMenu = new System.Windows.Forms.ContextMenu();61 this.splitContainer.Panel1.SuspendLayout();62 this.splitContainer.Panel2.SuspendLayout();63 this.splitContainer.SuspendLayout();64 this.variablesGroupBox.SuspendLayout();65 this.variablesSplitContainer.Panel1.SuspendLayout();66 this.variablesSplitContainer.SuspendLayout();67 50 this.SuspendLayout(); 68 51 // … … 73 56 this.funTreeView.Location = new System.Drawing.Point(0, 0); 74 57 this.funTreeView.Name = "funTreeView"; 75 this.funTreeView.Size = new System.Drawing.Size( 182, 532);58 this.funTreeView.Size = new System.Drawing.Size(432, 514); 76 59 this.funTreeView.TabIndex = 0; 77 60 this.funTreeView.MouseUp += new System.Windows.Forms.MouseEventHandler(this.funTreeView_MouseUp); 78 this.funTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.functionTreeView_AfterSelect);79 //80 // splitContainer81 //82 this.splitContainer.Dock = System.Windows.Forms.DockStyle.Fill;83 this.splitContainer.Location = new System.Drawing.Point(0, 0);84 this.splitContainer.Name = "splitContainer";85 //86 // splitContainer.Panel187 //88 this.splitContainer.Panel1.Controls.Add(this.funTreeView);89 //90 // splitContainer.Panel291 //92 this.splitContainer.Panel2.Controls.Add(this.variablesGroupBox);93 this.splitContainer.Panel2.Controls.Add(this.label1);94 this.splitContainer.Panel2.Controls.Add(this.templateTextBox);95 this.splitContainer.Panel2.Controls.Add(this.editButton);96 this.splitContainer.Size = new System.Drawing.Size(735, 532);97 this.splitContainer.SplitterDistance = 182;98 this.splitContainer.TabIndex = 1;99 //100 // variablesGroupBox101 //102 this.variablesGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)103 | System.Windows.Forms.AnchorStyles.Left)104 | System.Windows.Forms.AnchorStyles.Right)));105 this.variablesGroupBox.Controls.Add(this.variablesSplitContainer);106 this.variablesGroupBox.Location = new System.Drawing.Point(3, 31);107 this.variablesGroupBox.Name = "variablesGroupBox";108 this.variablesGroupBox.Size = new System.Drawing.Size(543, 498);109 this.variablesGroupBox.TabIndex = 5;110 this.variablesGroupBox.TabStop = false;111 this.variablesGroupBox.Text = "Local variables";112 //113 // variablesSplitContainer114 //115 this.variablesSplitContainer.Dock = System.Windows.Forms.DockStyle.Fill;116 this.variablesSplitContainer.Location = new System.Drawing.Point(3, 16);117 this.variablesSplitContainer.Name = "variablesSplitContainer";118 //119 // variablesSplitContainer.Panel1120 //121 this.variablesSplitContainer.Panel1.Controls.Add(this.variablesListBox);122 this.variablesSplitContainer.Size = new System.Drawing.Size(537, 479);123 this.variablesSplitContainer.SplitterDistance = 179;124 this.variablesSplitContainer.TabIndex = 0;125 //126 // variablesListBox127 //128 this.variablesListBox.Dock = System.Windows.Forms.DockStyle.Fill;129 this.variablesListBox.FormattingEnabled = true;130 this.variablesListBox.Location = new System.Drawing.Point(0, 0);131 this.variablesListBox.Name = "variablesListBox";132 this.variablesListBox.Size = new System.Drawing.Size(179, 472);133 this.variablesListBox.TabIndex = 0;134 this.variablesListBox.SelectedIndexChanged += new System.EventHandler(this.variablesListBox_SelectedIndexChanged);135 //136 // label1137 //138 this.label1.AutoSize = true;139 this.label1.Location = new System.Drawing.Point(3, 10);140 this.label1.Name = "label1";141 this.label1.Size = new System.Drawing.Size(96, 13);142 this.label1.TabIndex = 3;143 this.label1.Text = "Function definition:";144 //145 // templateTextBox146 //147 this.templateTextBox.Location = new System.Drawing.Point(105, 7);148 this.templateTextBox.Name = "templateTextBox";149 this.templateTextBox.ReadOnly = true;150 this.templateTextBox.Size = new System.Drawing.Size(190, 20);151 this.templateTextBox.TabIndex = 2;152 //153 // editButton154 //155 this.editButton.Enabled = false;156 this.editButton.Location = new System.Drawing.Point(301, 5);157 this.editButton.Name = "editButton";158 this.editButton.Size = new System.Drawing.Size(49, 23);159 this.editButton.TabIndex = 1;160 this.editButton.Text = "Edit...";161 this.editButton.UseVisualStyleBackColor = true;162 this.editButton.Click += new System.EventHandler(this.editButton_Click);163 //164 // treeNodeContextMenu165 //166 this.treeNodeContextMenu.Name = "treeNodeContextMenu";167 61 // 168 62 // FunctionTreeView … … 170 64 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 171 65 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 172 this.Controls.Add(this. splitContainer);66 this.Controls.Add(this.funTreeView); 173 67 this.Name = "FunctionTreeView"; 174 this.Size = new System.Drawing.Size(735, 532); 175 this.splitContainer.Panel1.ResumeLayout(false); 176 this.splitContainer.Panel2.ResumeLayout(false); 177 this.splitContainer.Panel2.PerformLayout(); 178 this.splitContainer.ResumeLayout(false); 179 this.variablesGroupBox.ResumeLayout(false); 180 this.variablesSplitContainer.Panel1.ResumeLayout(false); 181 this.variablesSplitContainer.ResumeLayout(false); 68 this.Size = new System.Drawing.Size(432, 514); 182 69 this.ResumeLayout(false); 183 70 … … 186 73 #endregion 187 74 75 private System.Windows.Forms.ContextMenu treeNodeContextMenu; 188 76 private System.Windows.Forms.TreeView funTreeView; 189 private System.Windows.Forms.SplitContainer splitContainer;190 private System.Windows.Forms.TextBox templateTextBox;191 private System.Windows.Forms.Button editButton;192 private System.Windows.Forms.GroupBox variablesGroupBox;193 private System.Windows.Forms.SplitContainer variablesSplitContainer;194 private System.Windows.Forms.ListBox variablesListBox;195 private System.Windows.Forms.Label label1;196 private System.Windows.Forms.ContextMenu treeNodeContextMenu;197 77 } 198 78 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/FunctionTreeView.cs
r2210 r2212 21 21 22 22 using System; 23 using System.Collections.Generic;24 using System.ComponentModel;25 using System.Drawing;26 using System.Data;27 using System.Linq;28 using System.Text;29 23 using System.Windows.Forms; 30 24 using HeuristicLab.Core; 31 25 using HeuristicLab.PluginInfrastructure; 32 using HeuristicLab.Data;33 26 using HeuristicLab.GP.Interfaces; 34 27 … … 36 29 public partial class FunctionTreeView : ViewBase { 37 30 private IFunctionTree functionTree; 38 39 31 private IFunctionTree selectedBranch; 40 private IVariable selectedVariable;41 32 private IFunctionTreeNameGenerator nameGenerator; 42 33 private IFunctionTreeNameGenerator[] allNameGenerators; … … 130 121 } 131 122 132 private void functionTreeView_AfterSelect(object sender, TreeViewEventArgs e) {133 variablesListBox.Items.Clear();134 variablesSplitContainer.Panel2.Controls.Clear();135 templateTextBox.Clear();136 editButton.Enabled = false;137 if (funTreeView.SelectedNode != null && funTreeView.SelectedNode.Tag != null) {138 IFunctionTree selectedBranch = (IFunctionTree)funTreeView.SelectedNode.Tag;139 // UpdateVariablesList(selectedBranch);140 templateTextBox.Text = nameGenerator.GetName(selectedBranch);141 this.selectedBranch = selectedBranch;142 editButton.Enabled = true;143 }144 }145 146 //private void UpdateVariablesList(IFunctionTree functionTree) {147 // foreach (IVariable variable in functionTree.LocalVariables) {148 // variablesListBox.Items.Add(variable.Name);149 // }150 //}151 152 private void variablesListBox_SelectedIndexChanged(object sender, EventArgs e) {153 //// in case we had an event-handler registered for a different variable => unregister the event-handler154 //if (selectedVariable != null) {155 // selectedVariable.Value.Changed -= new EventHandler(selectedVariable_ValueChanged);156 //}157 //if (variablesListBox.SelectedItem != null) {158 // string selectedVariableName = (string)variablesListBox.SelectedItem;159 // selectedVariable = selectedBranch.GetLocalVariable(selectedVariableName);160 // variablesSplitContainer.Panel2.Controls.Clear();161 // Control editor = (Control)selectedVariable.CreateView();162 // variablesSplitContainer.Panel2.Controls.Add(editor);163 // editor.Dock = DockStyle.Fill;164 // // register an event handler that updates the treenode when the value of the variable is changed by the user165 // selectedVariable.Value.Changed += new EventHandler(selectedVariable_ValueChanged);166 //} else {167 // variablesSplitContainer.Panel2.Controls.Clear();168 //}169 }170 171 void selectedVariable_ValueChanged(object sender, EventArgs e) {172 if (funTreeView.SelectedNode != null && funTreeView.SelectedNode.Tag != null) {173 TreeNode node = funTreeView.SelectedNode;174 node.Text = nameGenerator.GetName(functionTree);175 }176 }177 178 protected virtual void editButton_Click(object sender, EventArgs e) {179 PluginManager.ControlManager.ShowControl(selectedBranch.Function.CreateView());180 }181 182 123 private void funTreeView_MouseUp(object sender, MouseEventArgs e) { 183 124 if (e.Button == MouseButtons.Right) { -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/FunctionTreeView.resx
r2202 r2212 118 118 <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> 119 119 </resheader> 120 <metadata name="representationContextMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">121 <value>180, 17</value>122 </metadata>123 120 <metadata name="treeNodeContextMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 124 121 <value>17, 17</value> -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/HeuristicLab.GP-3.3.csproj
r2210 r2212 100 100 <DependentUpon>FunctionTreeView.cs</DependentUpon> 101 101 </Compile> 102 <Compile Include="FunView.cs">103 <SubType>UserControl</SubType>104 </Compile>105 <Compile Include="FunView.Designer.cs">106 <DependentUpon>FunView.cs</DependentUpon>107 </Compile>108 102 <Compile Include="GeneticProgrammingModel.cs" /> 109 <Compile Include="Initialization\ProbabilisticTreeCreator.cs" />110 <Compile Include="Initialization\RampedTreeCreator.cs" />111 <Compile Include="Manipulation\GPManipulatorBase.cs" />112 <Compile Include="TrainingWindowSlider.cs" />113 103 <Compile Include="DefaultFunctionTreeNameGenerator.cs" /> 114 <Compile Include="EqualiserController.cs" />115 <Compile Include="Logging\TreeArityAnalyser.cs" />116 <Compile Include="OffspringEqualiser.cs" />117 <Compile Include="Recombination\SizeConstrictedGPCrossoverBase.cs" />118 <Compile Include="Recombination\GPCrossoverBase.cs" />119 <Compile Include="Recombination\UniformCrossover.cs" />120 104 <Compile Include="UnknownFunctionException.cs" /> 121 105 <Compile Include="HeuristicLabGPPlugin.cs" /> 122 <Compile Include="Manipulation\ChangeNodeTypeManipulation.cs" />123 <Compile Include="Manipulation\CutOutNodeManipulation.cs" />124 <Compile Include="Manipulation\DeleteSubTreeManipulation.cs" />125 <Compile Include="Manipulation\FullTreeShaker.cs" />126 <Compile Include="Manipulation\OnePointShaker.cs" />127 <Compile Include="Manipulation\SubstituteSubTreeManipulation.cs" />128 106 <Compile Include="Properties\AssemblyInfo.cs" /> 129 <Compile Include="Recombination\LangdonHomologousCrossOver.cs" />130 <Compile Include="Recombination\OnePointCrossOver.cs" />131 <Compile Include="Recombination\SizeFairCrossOver.cs" />132 <Compile Include="Recombination\StandardCrossOver.cs" />133 107 <Compile Include="TreeGardener.cs" /> 134 108 </ItemGroup> 135 109 <ItemGroup> 136 <ProjectReference Include="..\..\HeuristicLab.Constraints\3.2\HeuristicLab.Constraints-3.2.csproj">137 <Project>{FCD62C6F-4793-4593-AE9A-0BDCA256EE99}</Project>138 <Name>HeuristicLab.Constraints-3.2</Name>139 </ProjectReference>140 110 <ProjectReference Include="..\..\HeuristicLab.Core\3.2\HeuristicLab.Core-3.2.csproj"> 141 111 <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project> 142 112 <Name>HeuristicLab.Core-3.2</Name> 143 113 </ProjectReference> 144 <ProjectReference Include="..\..\HeuristicLab.Data\3.2\HeuristicLab.Data-3.2.csproj">145 <Project>{F473D9AF-3F09-4296-9F28-3C65118DAFFA}</Project>146 <Name>HeuristicLab.Data-3.2</Name>147 </ProjectReference>148 <ProjectReference Include="..\..\HeuristicLab.Evolutionary\3.2\HeuristicLab.Evolutionary-3.2.csproj">149 <Project>{F5614C53-153C-4A37-A608-121E1C087F07}</Project>150 <Name>HeuristicLab.Evolutionary-3.2</Name>151 </ProjectReference>152 114 <ProjectReference Include="..\..\HeuristicLab.GP.Interfaces\3.3\HeuristicLab.GP.Interfaces-3.3.csproj"> 153 115 <Project>{924B6BEA-9A99-40FE-9334-5C01E8D540EC}</Project> 154 116 <Name>HeuristicLab.GP.Interfaces-3.3</Name> 155 </ProjectReference>156 <ProjectReference Include="..\..\HeuristicLab.Operators\3.2\HeuristicLab.Operators-3.2.csproj">157 <Project>{A9983BA2-B3B2-475E-8E2C-62050B71D1C5}</Project>158 <Name>HeuristicLab.Operators-3.2</Name>159 117 </ProjectReference> 160 118 <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj"> … … 165 123 <Project>{47019A74-F7F7-482E-83AA-D3F4F777E879}</Project> 166 124 <Name>HeuristicLab.Random-3.2</Name> 167 </ProjectReference>168 <ProjectReference Include="..\..\HeuristicLab.Selection\3.2\HeuristicLab.Selection-3.2.csproj">169 <Project>{F7CF0571-25CB-43D5-8443-0843A1E2861A}</Project>170 <Name>HeuristicLab.Selection-3.2</Name>171 125 </ProjectReference> 172 126 </ItemGroup> -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/HeuristicLabGPPlugin.cs
r2210 r2212 29 29 [PluginFile(Filename = "HeuristicLab.GP-3.3.dll", Filetype = PluginFileType.Assembly)] 30 30 [Dependency(Dependency = "HeuristicLab.GP.Interfaces-3.3")] 31 [Dependency(Dependency = "HeuristicLab.Constraints-3.2")]32 [Dependency(Dependency = "HeuristicLab.Core-3.2")]33 [Dependency(Dependency = "HeuristicLab.Data-3.2")]34 [Dependency(Dependency = "HeuristicLab.Evolutionary-3.2")]35 [Dependency(Dependency = "HeuristicLab.Operators-3.2")]36 31 [Dependency(Dependency = "HeuristicLab.Random-3.2")] 37 [Dependency(Dependency = "HeuristicLab.Selection-3.2")]38 32 public class HeuristicLabGPPlugin : PluginBase { 39 33 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/TreeGardener.cs
r2211 r2212 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Text;25 24 using HeuristicLab.Core; 26 using HeuristicLab.Constraints;27 using System.Diagnostics;28 using HeuristicLab.Data;29 25 using System.Linq; 30 using HeuristicLab.Random;31 using HeuristicLab.Operators;32 26 using System.Collections; 33 using HeuristicLab.Selection;34 27 using HeuristicLab.GP.Interfaces; 35 28 36 29 namespace HeuristicLab.GP { 37 internalclass TreeGardener {30 public class TreeGardener { 38 31 private IRandom random; 39 32 private FunctionLibrary funLibrary; … … 41 34 42 35 private List<IFunction> terminals; 43 internalIList<IFunction> Terminals {36 public IList<IFunction> Terminals { 44 37 get { return terminals; } 45 38 } 46 39 47 40 private List<IFunction> allFunctions; 48 internalIList<IFunction> AllFunctions {41 public IList<IFunction> AllFunctions { 49 42 get { return allFunctions; } 50 43 } 51 44 52 45 #region constructors 53 internalTreeGardener(IRandom random, FunctionLibrary funLibrary) {46 public TreeGardener(IRandom random, FunctionLibrary funLibrary) { 54 47 this.random = random; 55 48 this.funLibrary = funLibrary; … … 78 71 /// <param name="maxTreeHeight">Maximal height of the tree.</param> 79 72 /// <returns></returns> 80 internalIFunctionTree CreateBalancedRandomTree(int maxTreeSize, int maxTreeHeight) {73 public IFunctionTree CreateBalancedRandomTree(int maxTreeSize, int maxTreeHeight) { 81 74 IFunction rootFunction = GetRandomRoot(maxTreeSize, maxTreeHeight); 82 75 IFunctionTree tree = MakeBalancedTree(rootFunction, maxTreeHeight - 1); … … 91 84 /// <param name="maxTreeHeight">Maximal height of the tree.</param> 92 85 /// <returns></returns> 93 internalIFunctionTree CreateUnbalancedRandomTree(int maxTreeSize, int maxTreeHeight) {86 public IFunctionTree CreateUnbalancedRandomTree(int maxTreeSize, int maxTreeHeight) { 94 87 IFunction rootFunction = GetRandomRoot(maxTreeSize, maxTreeHeight); 95 88 IFunctionTree tree = MakeUnbalancedTree(rootFunction, maxTreeHeight - 1); … … 177 170 /// <param name="maxTreeHeight">Maximal height of the tree.</param> 178 171 /// <returns>New random unbalanced tree</returns> 179 internalIFunctionTree CreateRandomTree(ICollection<IFunction> allowedFunctions, int maxTreeSize, int maxTreeHeight) {172 public IFunctionTree CreateRandomTree(ICollection<IFunction> allowedFunctions, int maxTreeSize, int maxTreeHeight) { 180 173 // get the minimal needed height based on allowed functions and extend the max-height if necessary 181 174 int minTreeHeight = allowedFunctions.Select(f => f.MinTreeHeight).Min(); … … 201 194 return root; 202 195 } 203 204 internal static CompositeOperation CreateInitializationOperation(ICollection<IFunctionTree> trees, IScope scope) {205 // create a backup of sub scopes to restore after initialization206 Scope backupScope = new Scope("backup");207 foreach (Scope subScope in scope.SubScopes) {208 backupScope.AddSubScope(subScope);209 }210 211 CompositeOperation initializationOperation = new CompositeOperation();212 Scope tempScope = new Scope("Temp. initialization scope");213 214 var parametricTrees = trees.Where(t => t.HasLocalParameters);215 foreach(IFunctionTree tree in parametricTrees) {216 initializationOperation.AddOperation(tree.CreateInitOperation(tempScope));217 }218 scope.AddSubScope(tempScope);219 scope.AddSubScope(backupScope);220 // add an operation to remove the temporary scopes221 initializationOperation.AddOperation(new AtomicOperation(new RightReducer(), scope));222 return initializationOperation;223 }224 196 #endregion 225 197 226 198 #region tree information gathering 227 internalIFunctionTree GetRandomParentNode(IFunctionTree tree) {199 public IFunctionTree GetRandomParentNode(IFunctionTree tree) { 228 200 List<IFunctionTree> parentNodes = new List<IFunctionTree>(); 229 201 … … 240 212 } 241 213 242 internalstatic ICollection<IFunctionTree> GetAllSubTrees(IFunctionTree root) {214 public static ICollection<IFunctionTree> GetAllSubTrees(IFunctionTree root) { 243 215 List<IFunctionTree> allTrees = new List<IFunctionTree>(); 244 216 TreeForEach(root, t => { allTrees.Add(t); }); … … 256 228 /// <param name="branch">branch that is searched in the tree</param> 257 229 /// <returns></returns> 258 internalint GetBranchLevel(IFunctionTree tree, IFunctionTree branch) {230 public int GetBranchLevel(IFunctionTree tree, IFunctionTree branch) { 259 231 return GetBranchLevelHelper(tree, branch, 1); 260 232 } … … 272 244 } 273 245 274 internalbool IsValidTree(IFunctionTree tree) {246 public bool IsValidTree(IFunctionTree tree) { 275 247 for(int i = 0; i < tree.SubTrees.Count; i++) { 276 248 if(!tree.Function.GetAllowedSubFunctions(i).Contains(tree.SubTrees[i].Function)) return false; … … 286 258 287 259 // returns a random branch from the specified level in the tree 288 internalIFunctionTree GetRandomBranch(IFunctionTree tree, int level) {260 public IFunctionTree GetRandomBranch(IFunctionTree tree, int level) { 289 261 if(level == 0) return tree; 290 262 List<IFunctionTree> branches = new List<IFunctionTree>(); … … 359 331 return assignments == children.Count - 1; 360 332 } 361 internalIList<IFunction> GetAllowedParents(IFunction child, int childIndex) {333 public IList<IFunction> GetAllowedParents(IFunction child, int childIndex) { 362 334 List<IFunction> parents = new List<IFunction>(); 363 335 foreach(IFunction function in functions) { … … 369 341 return parents; 370 342 } 371 internalstatic bool IsTerminal(IFunction f) {343 public static bool IsTerminal(IFunction f) { 372 344 return f.MinSubTrees == 0 && f.MaxSubTrees == 0; 373 345 } 374 internalICollection<IFunction> GetAllowedSubFunctions(IFunction f, int index) {346 public ICollection<IFunction> GetAllowedSubFunctions(IFunction f, int index) { 375 347 if(f == null) { 376 348 return allFunctions;
Note: See TracChangeset
for help on using the changeset viewer.