Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/30/09 10:47:00 (15 years ago)
Author:
gkronber
Message:

GP Refactoring: #713

  • added project GP.Operators
  • moved operators from plugin GP to plugin GP.Operators
  • deleted unused constraints
  • removed dependency of GP plugins on Constraints plugin
  • moved StructID functions into directory Symbols
  • deleted unused class FunView
  • implemented add and remove functionality for the FunctionLibraryView
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  
    2424using System.Linq;
    2525using System.Text;
    26 using HeuristicLab.Constraints;
    2726
    2827namespace HeuristicLab.GP {
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/FunctionBase.cs

    r2211 r2212  
    2323using System.Collections.Generic;
    2424using System.Text;
    25 using HeuristicLab.Data;
    2625using HeuristicLab.Core;
    2726using System.Xml;
    28 using HeuristicLab.Constraints;
    2927using System.Diagnostics;
    3028using HeuristicLab.GP.Interfaces;
     
    111109    }
    112110
    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 2
    120     //  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 
    129111    public ICollection<IFunction> GetAllowedSubFunctions(int index) {
    130112      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-functions
    133       //  allowedSubFunctions = new List<IFunction>[MaxArity];
    134       //  for (int i = 0; i < MaxArity; i++) {
    135       //    allowedSubFunctions[i] = GetAllowedSubFunctions(i);
    136       //  }
    137       //}
    138113      return allowedSubFunctions[index];
    139114    }
     
    156131    public bool IsAllowedSubFunction(IFunction function, int index) {
    157132      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 changes
    168     //        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 changes
    174     //      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);
    186133    }
    187134
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/Terminal.cs

    r2211 r2212  
    2424using System.Linq;
    2525using System.Text;
    26 using HeuristicLab.Constraints;
    2726
    2827namespace HeuristicLab.GP {
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/UnaryFunction.cs

    r2211 r2212  
    2424using System.Linq;
    2525using System.Text;
    26 using HeuristicLab.Constraints;
    2726
    2827namespace HeuristicLab.GP {
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/FunctionLibrary.cs

    r2210 r2212  
    2626using HeuristicLab.Core;
    2727using System.Xml;
    28 using HeuristicLab.Data;
    29 using HeuristicLab.Constraints;
    3028using HeuristicLab.GP.Interfaces;
    3129
     
    4139    }
    4240
    43 
    4441    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      }
    4746    }
    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 2
    64     //  minArity = 2;
    65     //  maxArity = 2;
    66     //}
    6747
    6848    public void RemoveFunction(IFunction fun) {
    6949      functions.Remove(fun);
    7050
    71       // remove the operator from the allowed sub-functions of the remaining operators
     51      // remove the operator from the allowed sub-functions of all functions
    7252      foreach (IFunction f in Functions) {
    73         if (f != fun) {
     53        for (int i = 0; i < f.MaxSubTrees; i++) {
     54          f.RemoveAllowedSubFunction(fun, i);
    7455        }
    7556      }
    76       // OnFunctionRemoved(fun);
     57      OnChanged();
    7758    }
    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     //}
    9259
    9360    public override IView CreateView() {
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/FunctionLibraryEditor.Designer.cs

    r2202 r2212  
    4545    /// </summary>
    4646    private void InitializeComponent() {
    47       this.operatorLibraryEditor = new HeuristicLab.Core.OperatorLibraryEditor();
    4847      this.tabControl = new System.Windows.Forms.TabControl();
    49       this.operatorLibraryTabPage = new System.Windows.Forms.TabPage();
     48      this.functionsTabPage = new System.Windows.Forms.TabPage();
    5049      this.initializationTabPage = new System.Windows.Forms.TabPage();
    5150      this.initSplitContainer = new System.Windows.Forms.SplitContainer();
     
    5655      this.mutationListView = new System.Windows.Forms.ListView();
    5756      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();
    5860      this.tabControl.SuspendLayout();
    59       this.operatorLibraryTabPage.SuspendLayout();
     61      this.functionsTabPage.SuspendLayout();
    6062      this.initializationTabPage.SuspendLayout();
    6163      this.initSplitContainer.Panel1.SuspendLayout();
     
    6870      this.SuspendLayout();
    6971      //
    70       // operatorLibraryEditor
    71       //
    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       //
    8172      // tabControl
    8273      //
    83       this.tabControl.Controls.Add(this.operatorLibraryTabPage);
     74      this.tabControl.Controls.Add(this.functionsTabPage);
    8475      this.tabControl.Controls.Add(this.initializationTabPage);
    8576      this.tabControl.Controls.Add(this.mutationTabPage);
     
    9182      this.tabControl.TabIndex = 1;
    9283      //
    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;
    10396      //
    10497      // initializationTabPage
     
    201194      this.mutationVariableView.Variable = null;
    202195      //
    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
    204231      //
    205232      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    206233      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    207234      this.Controls.Add(this.tabControl);
    208       this.Name = "GPOperatorLibraryEditor";
     235      this.Name = "FunctionLibraryEditor";
    209236      this.Size = new System.Drawing.Size(677, 561);
    210237      this.tabControl.ResumeLayout(false);
    211       this.operatorLibraryTabPage.ResumeLayout(false);
     238      this.functionsTabPage.ResumeLayout(false);
    212239      this.initializationTabPage.ResumeLayout(false);
    213240      this.initSplitContainer.Panel1.ResumeLayout(false);
     
    224251    #endregion
    225252
    226     private HeuristicLab.Core.OperatorLibraryEditor operatorLibraryEditor;
    227253    private System.Windows.Forms.TabControl tabControl;
    228     private System.Windows.Forms.TabPage operatorLibraryTabPage;
     254    private System.Windows.Forms.TabPage functionsTabPage;
    229255    private System.Windows.Forms.TabPage initializationTabPage;
    230256    private System.Windows.Forms.TabPage mutationTabPage;
     
    235261    private System.Windows.Forms.ListView initListView;
    236262    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;
    237266  }
    238267}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/FunctionLibraryEditor.cs

    r2210 r2212  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.ComponentModel;
    25 using System.Drawing;
    26 using System.Data;
    2724using System.Linq;
    28 using System.Text;
    2925using System.Windows.Forms;
    3026using HeuristicLab.Core;
    31 using System.Diagnostics;
    32 using HeuristicLab.Data;
    33 using HeuristicLab.Operators;
    34 using HeuristicLab.Random;
    3527using HeuristicLab.GP.Interfaces;
    3628
    3729namespace HeuristicLab.GP {
    3830  public partial class FunctionLibraryEditor : EditorBase {
     31    private ChooseItemDialog chooseFunctionDialog;
    3932    public FunctionLibrary FunctionLibrary {
    4033      get { return (FunctionLibrary)Item; }
     
    4639      InitializeComponent();
    4740      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       }
    6841    }
    6942
     
    7548    protected override void UpdateControls() {
    7649      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      }
    7758    }
    7859
    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 
    13860    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      }
    14668    }
    14769
    14870    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;
    156108    }
    157109  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/FunctionTreeView.Designer.cs

    r2202 r2212  
    3636        components.Dispose();
    3737      }
    38       if(selectedVariable != null) {
    39         selectedVariable.Value.Changed -= new EventHandler(selectedVariable_ValueChanged);
    40       }
    4138      base.Dispose(disposing);
    4239    }
     
    4946    /// </summary>
    5047    private void InitializeComponent() {
    51       this.components = new System.ComponentModel.Container();
     48      this.treeNodeContextMenu = new System.Windows.Forms.ContextMenu();
    5249      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();
    6750      this.SuspendLayout();
    6851      //
     
    7356      this.funTreeView.Location = new System.Drawing.Point(0, 0);
    7457      this.funTreeView.Name = "funTreeView";
    75       this.funTreeView.Size = new System.Drawing.Size(182, 532);
     58      this.funTreeView.Size = new System.Drawing.Size(432, 514);
    7659      this.funTreeView.TabIndex = 0;
    7760      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       // splitContainer
    81       //
    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.Panel1
    87       //
    88       this.splitContainer.Panel1.Controls.Add(this.funTreeView);
    89       //
    90       // splitContainer.Panel2
    91       //
    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       // variablesGroupBox
    101       //
    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       // variablesSplitContainer
    114       //
    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.Panel1
    120       //
    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       // variablesListBox
    127       //
    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       // label1
    137       //
    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       // templateTextBox
    146       //
    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       // editButton
    154       //
    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       // treeNodeContextMenu
    165       //
    166       this.treeNodeContextMenu.Name = "treeNodeContextMenu";
    16761      //
    16862      // FunctionTreeView
     
    17064      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    17165      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    172       this.Controls.Add(this.splitContainer);
     66      this.Controls.Add(this.funTreeView);
    17367      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);
    18269      this.ResumeLayout(false);
    18370
     
    18673    #endregion
    18774
     75    private System.Windows.Forms.ContextMenu treeNodeContextMenu;
    18876    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;
    19777  }
    19878}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/FunctionTreeView.cs

    r2210 r2212  
    2121
    2222using 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;
    2923using System.Windows.Forms;
    3024using HeuristicLab.Core;
    3125using HeuristicLab.PluginInfrastructure;
    32 using HeuristicLab.Data;
    3326using HeuristicLab.GP.Interfaces;
    3427
     
    3629  public partial class FunctionTreeView : ViewBase {
    3730    private IFunctionTree functionTree;
    38 
    3931    private IFunctionTree selectedBranch;
    40     private IVariable selectedVariable;
    4132    private IFunctionTreeNameGenerator nameGenerator;
    4233    private IFunctionTreeNameGenerator[] allNameGenerators;
     
    130121    }
    131122
    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-handler
    154       //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 user
    165       //  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 
    182123    private void funTreeView_MouseUp(object sender, MouseEventArgs e) {
    183124      if (e.Button == MouseButtons.Right) {
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/FunctionTreeView.resx

    r2202 r2212  
    118118    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
    119119  </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>
    123120  <metadata name="treeNodeContextMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
    124121    <value>17, 17</value>
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/HeuristicLab.GP-3.3.csproj

    r2210 r2212  
    100100      <DependentUpon>FunctionTreeView.cs</DependentUpon>
    101101    </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>
    108102    <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" />
    113103    <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" />
    120104    <Compile Include="UnknownFunctionException.cs" />
    121105    <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" />
    128106    <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" />
    133107    <Compile Include="TreeGardener.cs" />
    134108  </ItemGroup>
    135109  <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>
    140110    <ProjectReference Include="..\..\HeuristicLab.Core\3.2\HeuristicLab.Core-3.2.csproj">
    141111      <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project>
    142112      <Name>HeuristicLab.Core-3.2</Name>
    143113    </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>
    152114    <ProjectReference Include="..\..\HeuristicLab.GP.Interfaces\3.3\HeuristicLab.GP.Interfaces-3.3.csproj">
    153115      <Project>{924B6BEA-9A99-40FE-9334-5C01E8D540EC}</Project>
    154116      <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>
    159117    </ProjectReference>
    160118    <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj">
     
    165123      <Project>{47019A74-F7F7-482E-83AA-D3F4F777E879}</Project>
    166124      <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>
    171125    </ProjectReference>
    172126  </ItemGroup>
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/HeuristicLabGPPlugin.cs

    r2210 r2212  
    2929  [PluginFile(Filename = "HeuristicLab.GP-3.3.dll", Filetype = PluginFileType.Assembly)]
    3030  [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")]
    3631  [Dependency(Dependency = "HeuristicLab.Random-3.2")]
    37   [Dependency(Dependency = "HeuristicLab.Selection-3.2")]
    3832  public class HeuristicLabGPPlugin : PluginBase {
    3933  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/TreeGardener.cs

    r2211 r2212  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Text;
    2524using HeuristicLab.Core;
    26 using HeuristicLab.Constraints;
    27 using System.Diagnostics;
    28 using HeuristicLab.Data;
    2925using System.Linq;
    30 using HeuristicLab.Random;
    31 using HeuristicLab.Operators;
    3226using System.Collections;
    33 using HeuristicLab.Selection;
    3427using HeuristicLab.GP.Interfaces;
    3528
    3629namespace HeuristicLab.GP {
    37   internal class TreeGardener {
     30  public class TreeGardener {
    3831    private IRandom random;
    3932    private FunctionLibrary funLibrary;
     
    4134
    4235    private List<IFunction> terminals;
    43     internal IList<IFunction> Terminals {
     36    public IList<IFunction> Terminals {
    4437      get { return terminals; }
    4538    }
    4639
    4740    private List<IFunction> allFunctions;
    48     internal IList<IFunction> AllFunctions {
     41    public IList<IFunction> AllFunctions {
    4942      get { return allFunctions; }
    5043    }
    5144
    5245    #region constructors
    53     internal TreeGardener(IRandom random, FunctionLibrary funLibrary) {
     46    public TreeGardener(IRandom random, FunctionLibrary funLibrary) {
    5447      this.random = random;
    5548      this.funLibrary = funLibrary;
     
    7871    /// <param name="maxTreeHeight">Maximal height of the tree.</param>
    7972    /// <returns></returns>
    80     internal IFunctionTree CreateBalancedRandomTree(int maxTreeSize, int maxTreeHeight) {
     73    public IFunctionTree CreateBalancedRandomTree(int maxTreeSize, int maxTreeHeight) {
    8174      IFunction rootFunction = GetRandomRoot(maxTreeSize, maxTreeHeight);
    8275      IFunctionTree tree = MakeBalancedTree(rootFunction, maxTreeHeight - 1);
     
    9184    /// <param name="maxTreeHeight">Maximal height of the tree.</param>
    9285    /// <returns></returns>
    93     internal IFunctionTree CreateUnbalancedRandomTree(int maxTreeSize, int maxTreeHeight) {
     86    public IFunctionTree CreateUnbalancedRandomTree(int maxTreeSize, int maxTreeHeight) {
    9487      IFunction rootFunction = GetRandomRoot(maxTreeSize, maxTreeHeight);
    9588      IFunctionTree tree = MakeUnbalancedTree(rootFunction, maxTreeHeight - 1);
     
    177170    /// <param name="maxTreeHeight">Maximal height of the tree.</param>
    178171    /// <returns>New random unbalanced tree</returns>
    179     internal IFunctionTree CreateRandomTree(ICollection<IFunction> allowedFunctions, int maxTreeSize, int maxTreeHeight) {
     172    public IFunctionTree CreateRandomTree(ICollection<IFunction> allowedFunctions, int maxTreeSize, int maxTreeHeight) {
    180173      // get the minimal needed height based on allowed functions and extend the max-height if necessary
    181174      int minTreeHeight = allowedFunctions.Select(f => f.MinTreeHeight).Min();
     
    201194      return root;
    202195    }
    203 
    204     internal static CompositeOperation CreateInitializationOperation(ICollection<IFunctionTree> trees, IScope scope) {
    205       // create a backup of sub scopes to restore after initialization
    206       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 scopes       
    221       initializationOperation.AddOperation(new AtomicOperation(new RightReducer(), scope));
    222       return initializationOperation;
    223     }
    224196    #endregion
    225197
    226198    #region tree information gathering
    227     internal IFunctionTree GetRandomParentNode(IFunctionTree tree) {
     199    public IFunctionTree GetRandomParentNode(IFunctionTree tree) {
    228200      List<IFunctionTree> parentNodes = new List<IFunctionTree>();
    229201
     
    240212    }
    241213
    242     internal static ICollection<IFunctionTree> GetAllSubTrees(IFunctionTree root) {
     214    public static ICollection<IFunctionTree> GetAllSubTrees(IFunctionTree root) {
    243215      List<IFunctionTree> allTrees = new List<IFunctionTree>();
    244216      TreeForEach(root, t => { allTrees.Add(t); });
     
    256228    /// <param name="branch">branch that is searched in the tree</param>
    257229    /// <returns></returns>
    258     internal int GetBranchLevel(IFunctionTree tree, IFunctionTree branch) {
     230    public int GetBranchLevel(IFunctionTree tree, IFunctionTree branch) {
    259231      return GetBranchLevelHelper(tree, branch, 1);
    260232    }
     
    272244    }
    273245
    274     internal bool IsValidTree(IFunctionTree tree) {
     246    public bool IsValidTree(IFunctionTree tree) {
    275247      for(int i = 0; i < tree.SubTrees.Count; i++) {
    276248        if(!tree.Function.GetAllowedSubFunctions(i).Contains(tree.SubTrees[i].Function)) return false;
     
    286258
    287259    // returns a random branch from the specified level in the tree
    288     internal IFunctionTree GetRandomBranch(IFunctionTree tree, int level) {
     260    public IFunctionTree GetRandomBranch(IFunctionTree tree, int level) {
    289261      if(level == 0) return tree;
    290262      List<IFunctionTree> branches = new List<IFunctionTree>();
     
    359331      return assignments == children.Count - 1;
    360332    }
    361     internal IList<IFunction> GetAllowedParents(IFunction child, int childIndex) {
     333    public IList<IFunction> GetAllowedParents(IFunction child, int childIndex) {
    362334      List<IFunction> parents = new List<IFunction>();
    363335      foreach(IFunction function in functions) {
     
    369341      return parents;
    370342    }
    371     internal static bool IsTerminal(IFunction f) {
     343    public static bool IsTerminal(IFunction f) {
    372344      return f.MinSubTrees == 0 && f.MaxSubTrees == 0;
    373345    }
    374     internal ICollection<IFunction> GetAllowedSubFunctions(IFunction f, int index) {
     346    public ICollection<IFunction> GetAllowedSubFunctions(IFunction f, int index) {
    375347      if(f == null) {
    376348        return allFunctions;
Note: See TracChangeset for help on using the changeset viewer.