Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7012 for trunk


Ignore:
Timestamp:
11/17/11 11:51:09 (13 years ago)
Author:
bburlacu
Message:

#1654: Updated Full-, Grow- and RampedHalfAndHalf tree creators so that the Create call has the exact same signature for all of them (including the probabilistic tree creator); adjusted tests. Added CreateTree interface method and tree creator selection mechanism in the Sample Tree View.

Location:
trunk/sources
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarSampleExpressionTreeView.Designer.cs

    r6803 r7012  
    5252      this.maxTreeDepthTextBox = new System.Windows.Forms.TextBox();
    5353      this.generateSampleTreeButton = new System.Windows.Forms.Button();
     54      this.treeCreatorComboBox = new System.Windows.Forms.ComboBox();
     55      this.treeCreatorLabel = new System.Windows.Forms.Label();
    5456      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    5557      this.sampleTreeGroupBox.SuspendLayout();
     
    6971      // sampleTreeGroupBox
    7072      //
    71       this.sampleTreeGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
    72             | System.Windows.Forms.AnchorStyles.Left)
    73             | System.Windows.Forms.AnchorStyles.Right)));
     73      this.sampleTreeGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     74                  | System.Windows.Forms.AnchorStyles.Left)
     75                  | System.Windows.Forms.AnchorStyles.Right)));
    7476      this.sampleTreeGroupBox.Controls.Add(this.sampleTreeView);
    75       this.sampleTreeGroupBox.Location = new System.Drawing.Point(3, 107);
     77      this.sampleTreeGroupBox.Location = new System.Drawing.Point(3, 134);
    7678      this.sampleTreeGroupBox.Name = "sampleTreeGroupBox";
    77       this.sampleTreeGroupBox.Size = new System.Drawing.Size(431, 292);
     79      this.sampleTreeGroupBox.Size = new System.Drawing.Size(431, 265);
    7880      this.sampleTreeGroupBox.TabIndex = 3;
    7981      this.sampleTreeGroupBox.TabStop = false;
     
    8991      this.sampleTreeView.Name = "sampleTreeView";
    9092      this.sampleTreeView.ReadOnly = false;
    91       this.sampleTreeView.Size = new System.Drawing.Size(425, 273);
     93      this.sampleTreeView.Size = new System.Drawing.Size(425, 246);
    9294      this.sampleTreeView.TabIndex = 0;
    9395      //
     
    112114      // maxTreeLengthTextBox
    113115      //
    114       this.maxTreeLengthTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
    115             | System.Windows.Forms.AnchorStyles.Right)));
     116      this.maxTreeLengthTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     117                  | System.Windows.Forms.AnchorStyles.Right)));
    116118      this.maxTreeLengthTextBox.Location = new System.Drawing.Point(93, 26);
    117119      this.maxTreeLengthTextBox.Name = "maxTreeLengthTextBox";
     
    124126      // maxTreeDepthTextBox
    125127      //
    126       this.maxTreeDepthTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
    127             | System.Windows.Forms.AnchorStyles.Right)));
     128      this.maxTreeDepthTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     129                  | System.Windows.Forms.AnchorStyles.Right)));
    128130      this.maxTreeDepthTextBox.Location = new System.Drawing.Point(93, 52);
    129131      this.maxTreeDepthTextBox.Name = "maxTreeDepthTextBox";
     
    136138      // generateSampleTreeButton
    137139      //
    138       this.generateSampleTreeButton.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
    139             | System.Windows.Forms.AnchorStyles.Right)));
    140       this.generateSampleTreeButton.Location = new System.Drawing.Point(3, 78);
     140      this.generateSampleTreeButton.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     141                  | System.Windows.Forms.AnchorStyles.Right)));
     142      this.generateSampleTreeButton.Location = new System.Drawing.Point(6, 105);
    141143      this.generateSampleTreeButton.Name = "generateSampleTreeButton";
    142144      this.generateSampleTreeButton.Size = new System.Drawing.Size(431, 23);
     
    146148      this.generateSampleTreeButton.Click += new System.EventHandler(this.generateSampleTreeButton_Click);
    147149      //
     150      // treeCreatorComboBox
     151      //
     152      this.treeCreatorComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     153                  | System.Windows.Forms.AnchorStyles.Right)));
     154      this.treeCreatorComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     155      this.treeCreatorComboBox.FormattingEnabled = true;
     156      this.treeCreatorComboBox.Location = new System.Drawing.Point(93, 78);
     157      this.treeCreatorComboBox.Name = "treeCreatorComboBox";
     158      this.treeCreatorComboBox.Size = new System.Drawing.Size(341, 21);
     159      this.treeCreatorComboBox.TabIndex = 9;
     160      this.treeCreatorComboBox.SelectedIndexChanged += new System.EventHandler(this.treeCreatorComboBox_SelectedIndexChanged);
     161      //
     162      // treeCreatorLabel
     163      //
     164      this.treeCreatorLabel.AutoSize = true;
     165      this.treeCreatorLabel.Location = new System.Drawing.Point(3, 81);
     166      this.treeCreatorLabel.Name = "treeCreatorLabel";
     167      this.treeCreatorLabel.Size = new System.Drawing.Size(69, 13);
     168      this.treeCreatorLabel.TabIndex = 10;
     169      this.treeCreatorLabel.Text = "Tree Creator:";
     170      //
    148171      // SymbolicExpressionGrammarSampleExpressionTreeView
    149172      //
    150173      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    151174      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     175      this.Controls.Add(this.treeCreatorLabel);
    152176      this.Controls.Add(this.sampleTreeGroupBox);
    153177      this.Controls.Add(this.maxTreeDepthLabel);
    154178      this.Controls.Add(this.maxTreeLengthTextBox);
     179      this.Controls.Add(this.treeCreatorComboBox);
    155180      this.Controls.Add(this.maxTreeLengthLabel);
    156181      this.Controls.Add(this.maxTreeDepthTextBox);
     
    161186      this.Controls.SetChildIndex(this.maxTreeDepthTextBox, 0);
    162187      this.Controls.SetChildIndex(this.maxTreeLengthLabel, 0);
     188      this.Controls.SetChildIndex(this.treeCreatorComboBox, 0);
    163189      this.Controls.SetChildIndex(this.maxTreeLengthTextBox, 0);
    164190      this.Controls.SetChildIndex(this.maxTreeDepthLabel, 0);
    165191      this.Controls.SetChildIndex(this.sampleTreeGroupBox, 0);
     192      this.Controls.SetChildIndex(this.treeCreatorLabel, 0);
    166193      this.Controls.SetChildIndex(this.nameTextBox, 0);
    167194      this.Controls.SetChildIndex(this.infoLabel, 0);
     
    183210    private System.Windows.Forms.Button generateSampleTreeButton;
    184211    private GraphicalSymbolicExpressionTreeView sampleTreeView;
     212    private System.Windows.Forms.ComboBox treeCreatorComboBox;
     213    private System.Windows.Forms.Label treeCreatorLabel;
    185214  }
    186215}
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarSampleExpressionTreeView.cs

    r6803 r7012  
    3636    public SymbolicExpressionGrammarSampleExpressionTreeView() {
    3737      InitializeComponent();
    38       random = new MersenneTwister();
     38      random = new MersenneTwister();   
    3939      maxSampleTreeLength = int.Parse(maxTreeLengthTextBox.Text);
    4040      maxSampleTreeDepth = int.Parse(maxTreeDepthTextBox.Text);
     41      foreach (var treeCreator in ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeCreator>()) {
     42        treeCreatorComboBox.Items.Add(treeCreator);
     43      }
     44      treeCreatorComboBox.SelectedIndex = 0;
    4145    }
    4246
     
    97101    private void UpdateSampleTreeView() {
    98102      try {
    99         ISymbolicExpressionTree tree = ProbabilisticTreeCreator.Create(random, Content, MaxSampleTreeLength, MaxSampleTreeDepth);
     103        ISymbolicExpressionTreeCreator creator = (SymbolicExpressionTreeCreator)treeCreatorComboBox.SelectedItem;
     104        ISymbolicExpressionTree tree = creator.CreateTree(random, Content, MaxSampleTreeLength, MaxSampleTreeDepth);
    100105        foreach (var node in tree.Root.IterateNodesPrefix().OfType<SymbolicExpressionTreeTopLevelNode>())
    101106          node.SetGrammar(null);
     
    147152    }
    148153    #endregion
     154
     155    private void treeCreatorComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     156    }
    149157  }
    150158}
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/FullTreeCreator.cs

    r6944 r7012  
    2727using HeuristicLab.Parameters;
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HeuristicLab.PluginInfrastructure;
    2930
    3031namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     32  [NonDiscoverableType]
    3133  [StorableClass]
    3234  [Item("FullTreeCreator", "An operator that creates new symbolic expression trees using the 'Full' method")]
     
    6062    public IntValue MaximumSymbolicExpressionTreeDepth {
    6163      get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; }
     64    }
     65   
     66    public IntValue MaximumSymbolicExpressionTreeLength {
     67      get { return MaximumSymbolicExpressionTreeLengthParameter.ActualValue; }
    6268    }
    6369
     
    97103
    98104    protected override ISymbolicExpressionTree Create(IRandom random) {
    99       return Create(random, SymbolicExpressionTreeGrammar, MaximumSymbolicExpressionTreeDepth.Value);
     105      return Create(random, SymbolicExpressionTreeGrammar, MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value);
     106    }
     107
     108    public override ISymbolicExpressionTree CreateTree(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth) {
     109     return Create(random, grammar, maxTreeLength, maxTreeDepth);
    100110    }
    101111
     
    108118    /// <param name="grammar">Available tree grammar</param>
    109119    /// <param name="maxTreeDepth">Maximum tree depth</param>
     120    /// <param name="maxTreeLength">Maximum tree length. This parameter is not used.</param>
    110121    /// <returns></returns>
    111     public static ISymbolicExpressionTree Create(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeDepth) {
     122    public static ISymbolicExpressionTree Create(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth) {
    112123      var tree = new SymbolicExpressionTree();
    113124      var rootNode = (SymbolicExpressionTreeTopLevelNode)grammar.ProgramRootSymbol.CreateTreeNode();
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/GrowTreeCreator.cs

    r6944 r7012  
    2727using HeuristicLab.Parameters;
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HeuristicLab.PluginInfrastructure;
    2930
    3031namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     32  [NonDiscoverableType]
    3133  [StorableClass]
    3234  [Item("GrowTreeCreator", "An operator that creates new symbolic expression trees using the 'Grow' method")]
     
    6062    public IntValue MaximumSymbolicExpressionTreeDepth {
    6163      get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; }
     64    }
     65
     66    public IntValue MaximumSymbolicExpressionTreeLength {
     67      get { return MaximumSymbolicExpressionTreeLengthParameter.ActualValue; }
    6268    }
    6369
     
    97103
    98104    protected override ISymbolicExpressionTree Create(IRandom random) {
    99       return Create(random, SymbolicExpressionTreeGrammar, MaximumSymbolicExpressionTreeDepth.Value);
     105      return Create(random, SymbolicExpressionTreeGrammar, MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value);
     106    }
     107
     108    public override ISymbolicExpressionTree CreateTree(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth) {
     109      return Create(random, grammar, maxTreeLength, maxTreeDepth);
    100110    }
    101111
     
    107117    /// <param name="grammar">Available tree grammar</param>
    108118    /// <param name="maxTreeDepth">Maximum tree depth</param>
     119    /// <param name="maxTreeLength">Maximum tree length. This parameter is not used.</param>
    109120    /// <returns></returns>
    110     public static ISymbolicExpressionTree Create(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeDepth) {
     121    public static ISymbolicExpressionTree Create(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth) {
    111122      var tree = new SymbolicExpressionTree();
    112123      var rootNode = (SymbolicExpressionTreeTopLevelNode)grammar.ProgramRootSymbol.CreateTreeNode();
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs

    r6911 r7012  
    2828using HeuristicLab.Parameters;
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     30using HeuristicLab.PluginInfrastructure;
    3031
    3132namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     33  [NonDiscoverableType]
    3234  [StorableClass]
    3335  [Item("ProbabilisticTreeCreator", "An operator that creates new symbolic expression trees with uniformly distributed length")]
     
    101103    }
    102104
    103     public static ISymbolicExpressionTree Create(IRandom random, ISymbolicExpressionGrammar grammar,
    104       int maxTreeLength, int maxTreeDepth) {
     105    public override ISymbolicExpressionTree CreateTree(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth) {
     106      return Create(random, grammar, maxTreeLength, maxTreeDepth);
     107    }
     108
     109    public static ISymbolicExpressionTree Create(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth) {
    105110      SymbolicExpressionTree tree = new SymbolicExpressionTree();
    106111      var rootNode = (SymbolicExpressionTreeTopLevelNode)grammar.ProgramRootSymbol.CreateTreeNode();
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/RampedHalfAndHalfTreeCreator.cs

    r6887 r7012  
    2929using HeuristicLab.Parameters;
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     31using HeuristicLab.PluginInfrastructure;
    3132
    3233namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     34  [NonDiscoverableType]
    3335  [StorableClass]
    3436  [Item("RampedHalfAndHalfTreeCreator", "An operator that creates new symbolic expression trees in an alternate way: half the trees are created usign the 'Grow' method while the other half are created using the 'Full' method")]
     
    7274    }
    7375
     76    public IntValue MaximumSymbolicExpressionTreeLength {
     77      get { return MaximumSymbolicExpressionTreeLengthParameter.ActualValue; }
     78    }
     79
    7480    public ISymbolicExpressionGrammar SymbolicExpressionTreeGrammar {
    7581      get { return ClonedSymbolicExpressionTreeGrammarParameter.ActualValue; }
     
    106112
    107113    protected override ISymbolicExpressionTree Create(IRandom random) {
    108       return Create(random, SymbolicExpressionTreeGrammar, MaximumSymbolicExpressionTreeDepth.Value);
     114      return Create(random, SymbolicExpressionTreeGrammar, MaximumSymbolicExpressionTreeDepth.Value, MaximumSymbolicExpressionTreeLength.Value);
     115    }
     116
     117    public override ISymbolicExpressionTree CreateTree(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth) {
     118      return Create(random, grammar, maxTreeLength, maxTreeDepth);
    109119    }
    110120
     
    117127    /// <param name="maxTreeDepth">Maximum tree depth</param>
    118128    /// <returns></returns>
    119     public static ISymbolicExpressionTree Create(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeDepth) {
     129    public static ISymbolicExpressionTree Create(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth) {
    120130      var tree = new SymbolicExpressionTree();
    121131      var rootNode = (SymbolicExpressionTreeTopLevelNode)grammar.ProgramRootSymbol.CreateTreeNode();
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/SymbolicExpressionTreeCreator.cs

    r6233 r7012  
    3939    #endregion
    4040
    41     #region Propeties
     41    #region Properties
    4242    public ISymbolicExpressionTree SymbolicExpressionTree {
    4343      get { return SymbolicExpressionTreeParameter.ActualValue; }
     
    6060
    6161    protected abstract ISymbolicExpressionTree Create(IRandom random);
     62    public abstract ISymbolicExpressionTree CreateTree(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth);
    6263  }
    6364}
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/Operators/ISymbolicExpressionTreeCreator.cs

    r5809 r7012  
    2929  public interface ISymbolicExpressionTreeCreator : ISymbolicExpressionTreeOperator, ISolutionCreator {
    3030    ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter { get; }
     31    ISymbolicExpressionTree CreateTree(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth);
    3132  }
    3233}
  • trunk/sources/HeuristicLab.Tests/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4/FullTreeCreatorTest.cs

    r6949 r7012  
    3232    private const int POPULATION_SIZE = 10000;
    3333    private const int MAX_TREE_DEPTH = 10;
     34    private const int MAX_TREE_LENGTH = 1000;
    3435    private TestContext testContextInstance;
    3536
     
    5556      stopwatch.Start();
    5657      for (int i = 0; i != POPULATION_SIZE; i++) {
    57         randomTrees.Add(FullTreeCreator.Create(random, grammar, MAX_TREE_DEPTH));
     58        randomTrees.Add(FullTreeCreator.Create(random, grammar, MAX_TREE_DEPTH, MAX_TREE_LENGTH));
    5859      }
    5960      stopwatch.Stop();
  • trunk/sources/HeuristicLab.Tests/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4/GrowTreeCreatorTest.cs

    r6949 r7012  
    3232    private const int POPULATION_SIZE = 10000;
    3333    private const int MAX_TREE_DEPTH = 10;
     34    private const int MAX_TREE_LENGTH = 50;
    3435    private TestContext testContextInstance;
    3536
     
    5556      stopwatch.Start();
    5657      for (int i = 0; i != POPULATION_SIZE; i++) {
    57         randomTrees.Add(GrowTreeCreator.Create(random, grammar, MAX_TREE_DEPTH));
     58        randomTrees.Add(GrowTreeCreator.Create(random, grammar, MAX_TREE_DEPTH, MAX_TREE_LENGTH));
    5859      }
    5960      stopwatch.Stop();
Note: See TracChangeset for help on using the changeset viewer.