Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/10/17 00:27:31 (7 years ago)
Author:
pkimmesw
Message:

#2665 LexicaseSelector, Performance improvements, UI Fixes, Debugger only shows used stacks, fixed Debugger stepping, Added vector expressions, ERCOptions,

Location:
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/ExpressionSelectionView.cs

    r14777 r14834  
    1919    public ExpressionSelectionView() {
    2020      InitializeComponent();
     21
    2122      InitEvents();
    2223      Name = "Push Expression Selection Editor";
     
    2829      set
    2930      {
     31        if (Content != null) Content.EnabledExpressionsChanged -= EnabledExpressionsChanged;
    3032        base.Content = value;
    3133      }
     
    3537      base.OnReadOnlyChanged();
    3638
    37       this.expressionsTreeView.Enabled = !ReadOnly;
     39      expressionsTreeView.Enabled = !ReadOnly;
    3840    }
    3941
    4042    private void InitEvents() {
    41       this.expressionsTreeView.AfterCheck += ExpressionsTreeViewAfterCheck;
     43      expressionsTreeView.AfterCheck += ExpressionsTreeViewAfterCheck;
    4244    }
    4345
    4446    private void ExpressionsTreeViewAfterCheck(object sender, TreeViewEventArgs e) {
    45       var isStackNode = e.Node.Tag is StackTypes;
     47      if (e.Action == TreeViewAction.Unknown)
     48        return;
    4649
    47       if (isStackNode) {
    48         if (e.Node.Checked) {
    49           Content.EnableStack((StackTypes)e.Node.Tag);
    50           foreach (var subNode in e.Node.Nodes.Cast<TreeNode>())
    51             subNode.Checked = true;
    52         } else {
    53           Content.DisableStack((StackTypes)e.Node.Tag);
    54           foreach (var subNode in e.Node.Nodes.Cast<TreeNode>())
    55             subNode.Checked = false;
    56         }
     50      Content.EnabledExpressionsChanged -= EnabledExpressionsChanged;
     51      var stackType = (StackTypes)e.Node.Tag;
     52
     53      if (e.Node.Parent == null) {
     54        Content.SetStack(stackType, e.Node.Checked, true);
     55        SetStackNodeText(e.Node);
     56        foreach (var subNode in e.Node.Nodes.OfType<TreeNode>().Where(n => n.Checked != e.Node.Checked))
     57          subNode.Checked = e.Node.Checked;
    5758      } else {
    58         if (e.Node.Checked) {
    59           Content.EnableExpression(e.Node.Text);
    60         } else {
    61           Content.DisableExpression(e.Node.Text);
    62         }
     59        Content.SetExpression(e.Node.Text, e.Node.Checked, true);
     60        SetStackNodeText(e.Node.Parent);
     61
     62        if ((e.Node.Checked && !e.Node.Parent.Checked) ||
     63            (!e.Node.Checked && !e.Node.Parent.Nodes.OfType<TreeNode>().Any(n => n.Checked)))
     64          e.Node.Parent.Checked = e.Node.Checked;
    6365      }
     66
     67      Content.EnabledExpressionsChanged += EnabledExpressionsChanged;
    6468    }
    6569
    6670    protected override void OnContentChanged() {
    6771      expressionsTreeView.Nodes.Clear();
     72      nameTextBox.Text = "Push Expression Selection";
    6873
    6974      if (Content == null) {
     
    7176      }
    7277
    73       this.nameTextBox.Text = "Push Expression Selection";
     78      Content.EnabledExpressionsChanged += EnabledExpressionsChanged;
     79      var treeNodes = GetTreeNodes(Content.EnabledExpressions).ToArray();
     80      expressionsTreeView.Nodes.AddRange(treeNodes);
     81    }
     82
     83    private void EnabledExpressionsChanged(object sender, EnabledExpressionsChangedEventArgs e) {
     84      if (InvokeRequired) Invoke(new MethodInvoker(UpdateNodes));
     85      else UpdateNodes();
     86    }
     87
     88    private void UpdateNodes() {
     89      expressionsTreeView.Nodes.Clear();
    7490
    7591      var treeNodes = GetTreeNodes(Content.EnabledExpressions).ToArray();
     
    8096      foreach (var stackType in ExpressionTable.StackTypeToNamesTable.Keys) {
    8197        var stackTreeNode = new TreeNode {
    82           Tag = stackType,
    83           Text = Enum.GetName(typeof(StackTypes), stackType),
     98          Tag = stackType
    8499        };
    85100
    86101        var stackExpressions = ExpressionTable.StackTypeToNamesTable[stackType];
    87         var enabledStackExpressions = enabledExpressions.Intersect(ExpressionTable.StackTypeToNamesTable[stackType]);
     102        var enabledStackExpressions = enabledExpressions.Intersect(stackExpressions).ToList();
    88103
     104        SetStackNodeText(stackTreeNode);
    89105        stackTreeNode.Checked = enabledStackExpressions.Any();
    90106
     
    93109          .Select(name => new TreeNode {
    94110            Text = name,
     111            Tag = stackType,
    95112            Checked = enabledStackExpressions.Contains(name),
    96113          }).ToArray();
     
    101118      }
    102119    }
     120
     121    private void SetStackNodeText(TreeNode node) {
     122      var stackType = (StackTypes)node.Tag;
     123      var stackExpressions = ExpressionTable.StackTypeToNamesTable[stackType];
     124      var enabledStackExpressions = Content.EnabledExpressions.Intersect(stackExpressions).ToList();
     125
     126      node.Text = string.Format(
     127                "{0} ({1}/{2})",
     128                Enum.GetName(typeof(StackTypes), stackType),
     129                enabledStackExpressions.Count,
     130                ExpressionTable.StackTypeToNamesTable[stackType].Count);
     131    }
    103132  }
    104133}
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/PushProgramDebuggerView.Designer.cs

    r14777 r14834  
    3636      this.label1 = new System.Windows.Forms.Label();
    3737      this.debugTableLayout = new System.Windows.Forms.TableLayoutPanel();
    38       this.codeGroupBox = new System.Windows.Forms.GroupBox();
    39       this.codeList = new System.Windows.Forms.ListBox();
    40       this.nameGroupBox = new System.Windows.Forms.GroupBox();
    41       this.nameList = new System.Windows.Forms.ListBox();
    42       this.integerGroupBox = new System.Windows.Forms.GroupBox();
    43       this.integerList = new System.Windows.Forms.ListBox();
    44       this.floatGroupBox = new System.Windows.Forms.GroupBox();
    45       this.groupBox2 = new System.Windows.Forms.GroupBox();
    46       this.listBox2 = new System.Windows.Forms.ListBox();
    47       this.floatList = new System.Windows.Forms.ListBox();
    4838      this.execGroupBox = new System.Windows.Forms.GroupBox();
    49       this.execList = new System.Windows.Forms.ListView();
    50       this.booleanGroupBox = new System.Windows.Forms.GroupBox();
    51       this.groupBox4 = new System.Windows.Forms.GroupBox();
    52       this.listBox3 = new System.Windows.Forms.ListBox();
    53       this.booleanList = new System.Windows.Forms.ListBox();
    54       this.stringGroupBox = new System.Windows.Forms.GroupBox();
    55       this.groupBox6 = new System.Windows.Forms.GroupBox();
    56       this.listBox5 = new System.Windows.Forms.ListBox();
    57       this.stringList = new System.Windows.Forms.ListBox();
    58       this.charGroupBox = new System.Windows.Forms.GroupBox();
    59       this.groupBox8 = new System.Windows.Forms.GroupBox();
    60       this.listBox7 = new System.Windows.Forms.ListBox();
    61       this.charList = new System.Windows.Forms.ListBox();
     39      this.execList = new System.Windows.Forms.ListBox();
    6240      this.tabPage2 = new System.Windows.Forms.TabPage();
    6341      this.resultsDataGrid = new System.Windows.Forms.DataGridView();
     
    6745      ((System.ComponentModel.ISupportInitialize)(this.stepWidthBox)).BeginInit();
    6846      this.debugTableLayout.SuspendLayout();
    69       this.codeGroupBox.SuspendLayout();
    70       this.nameGroupBox.SuspendLayout();
    71       this.integerGroupBox.SuspendLayout();
    72       this.floatGroupBox.SuspendLayout();
    73       this.groupBox2.SuspendLayout();
    7447      this.execGroupBox.SuspendLayout();
    75       this.booleanGroupBox.SuspendLayout();
    76       this.groupBox4.SuspendLayout();
    77       this.stringGroupBox.SuspendLayout();
    78       this.groupBox6.SuspendLayout();
    79       this.charGroupBox.SuspendLayout();
    80       this.groupBox8.SuspendLayout();
    8148      this.tabPage2.SuspendLayout();
    8249      ((System.ComponentModel.ISupportInitialize)(this.resultsDataGrid)).BeginInit();
     
    8754      this.errorProvider.SetIconAlignment(this.nameTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
    8855      this.errorProvider.SetIconPadding(this.nameTextBox, 2);
    89       this.nameTextBox.Size = new System.Drawing.Size(1176, 20);
     56      this.nameTextBox.Size = new System.Drawing.Size(889, 20);
    9057      //
    9158      // infoLabel
    9259      //
    93       this.infoLabel.Location = new System.Drawing.Point(1259, 3);
     60      this.infoLabel.Location = new System.Drawing.Point(972, 3);
    9461      //
    9562      // tabControl
     
    10370      this.tabControl.Name = "tabControl";
    10471      this.tabControl.SelectedIndex = 0;
    105       this.tabControl.Size = new System.Drawing.Size(1269, 698);
     72      this.tabControl.Size = new System.Drawing.Size(982, 668);
    10673      this.tabControl.TabIndex = 12;
    10774      //
    10875      // tabPage1
    10976      //
     77      this.tabPage1.AutoScroll = true;
    11078      this.tabPage1.Controls.Add(this.simplifyButton);
    11179      this.tabPage1.Controls.Add(this.skipNoopsCheckBox);
     
    12088      this.tabPage1.Name = "tabPage1";
    12189      this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
    122       this.tabPage1.Size = new System.Drawing.Size(1261, 672);
     90      this.tabPage1.Size = new System.Drawing.Size(974, 642);
    12391      this.tabPage1.TabIndex = 0;
    12492      this.tabPage1.Text = "Debug";
     
    12795      // simplifyButton
    12896      //
    129       this.simplifyButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    130       this.simplifyButton.Location = new System.Drawing.Point(237, 640);
     97      this.simplifyButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
     98      this.simplifyButton.Location = new System.Drawing.Point(909, 610);
    13199      this.simplifyButton.Name = "simplifyButton";
    132100      this.simplifyButton.Size = new System.Drawing.Size(62, 26);
     
    142110      this.skipNoopsCheckBox.Checked = true;
    143111      this.skipNoopsCheckBox.CheckState = System.Windows.Forms.CheckState.Checked;
    144       this.skipNoopsCheckBox.Location = new System.Drawing.Point(150, 646);
     112      this.skipNoopsCheckBox.Location = new System.Drawing.Point(150, 616);
    145113      this.skipNoopsCheckBox.Name = "skipNoopsCheckBox";
    146114      this.skipNoopsCheckBox.Size = new System.Drawing.Size(81, 17);
     
    153121      this.runButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    154122      this.runButton.Image = ((System.Drawing.Image)(resources.GetObject("runButton.Image")));
    155       this.runButton.Location = new System.Drawing.Point(40, 640);
     123      this.runButton.Location = new System.Drawing.Point(40, 610);
    156124      this.runButton.Name = "runButton";
    157125      this.runButton.Size = new System.Drawing.Size(28, 26);
     
    164132      this.stepWidthBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    165133      this.stepWidthBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    166       this.stepWidthBox.Location = new System.Drawing.Point(73, 641);
     134      this.stepWidthBox.Location = new System.Drawing.Point(73, 611);
    167135      this.stepWidthBox.Maximum = new decimal(new int[] {
    168136            99999,
     
    188156      this.resetButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    189157      this.resetButton.Image = ((System.Drawing.Image)(resources.GetObject("resetButton.Image")));
    190       this.resetButton.Location = new System.Drawing.Point(6, 640);
     158      this.resetButton.Location = new System.Drawing.Point(6, 610);
    191159      this.resetButton.Name = "resetButton";
    192160      this.resetButton.Size = new System.Drawing.Size(28, 26);
    193161      this.resetButton.TabIndex = 14;
    194       this.toolTip.SetToolTip(this.resetButton, "Reset to start");
     162      this.toolTip.SetToolTip(this.resetButton, "ResetDebugging to start");
    195163      this.resetButton.UseVisualStyleBackColor = true;
    196164      //
     
    199167      this.stepButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    200168      this.stepButton.Image = ((System.Drawing.Image)(resources.GetObject("stepButton.Image")));
    201       this.stepButton.Location = new System.Drawing.Point(112, 640);
     169      this.stepButton.Location = new System.Drawing.Point(112, 610);
    202170      this.stepButton.Name = "stepButton";
    203171      this.stepButton.Size = new System.Drawing.Size(28, 26);
     
    213181      this.exampleComboBox.Location = new System.Drawing.Point(58, 6);
    214182      this.exampleComboBox.Name = "exampleComboBox";
    215       this.exampleComboBox.Size = new System.Drawing.Size(1165, 21);
     183      this.exampleComboBox.Size = new System.Drawing.Size(910, 21);
    216184      this.exampleComboBox.TabIndex = 11;
    217185      //
     
    232200      this.debugTableLayout.AutoScroll = true;
    233201      this.debugTableLayout.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
    234       this.debugTableLayout.ColumnCount = 9;
    235       this.debugTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 270F));
    236       this.debugTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 270F));
     202      this.debugTableLayout.ColumnCount = 2;
     203      this.debugTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 250F));
    237204      this.debugTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
    238       this.debugTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
    239       this.debugTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
    240       this.debugTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
    241       this.debugTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
    242       this.debugTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
    243       this.debugTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
    244       this.debugTableLayout.Controls.Add(this.codeGroupBox, 1, 0);
    245       this.debugTableLayout.Controls.Add(this.nameGroupBox, 2, 0);
    246       this.debugTableLayout.Controls.Add(this.integerGroupBox, 3, 0);
    247       this.debugTableLayout.Controls.Add(this.floatGroupBox, 4, 0);
    248205      this.debugTableLayout.Controls.Add(this.execGroupBox, 0, 0);
    249       this.debugTableLayout.Controls.Add(this.booleanGroupBox, 5, 0);
    250       this.debugTableLayout.Controls.Add(this.stringGroupBox, 6, 0);
    251       this.debugTableLayout.Controls.Add(this.charGroupBox, 7, 0);
    252206      this.debugTableLayout.Location = new System.Drawing.Point(6, 33);
    253207      this.debugTableLayout.Name = "debugTableLayout";
    254208      this.debugTableLayout.RowCount = 1;
    255209      this.debugTableLayout.RowStyles.Add(new System.Windows.Forms.RowStyle());
    256       this.debugTableLayout.Size = new System.Drawing.Size(1259, 601);
     210      this.debugTableLayout.Size = new System.Drawing.Size(962, 563);
    257211      this.debugTableLayout.TabIndex = 2;
    258       //
    259       // codeGroupBox
    260       //
    261       this.codeGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    262             | System.Windows.Forms.AnchorStyles.Left)
    263             | System.Windows.Forms.AnchorStyles.Right)));
    264       this.codeGroupBox.Controls.Add(this.codeList);
    265       this.codeGroupBox.Location = new System.Drawing.Point(273, 3);
    266       this.codeGroupBox.Name = "codeGroupBox";
    267       this.codeGroupBox.Size = new System.Drawing.Size(264, 595);
    268       this.codeGroupBox.TabIndex = 5;
    269       this.codeGroupBox.TabStop = false;
    270       this.codeGroupBox.Text = "Code";
    271       //
    272       // codeList
    273       //
    274       this.codeList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    275             | System.Windows.Forms.AnchorStyles.Left)
    276             | System.Windows.Forms.AnchorStyles.Right)));
    277       this.codeList.FormattingEnabled = true;
    278       this.codeList.HorizontalScrollbar = true;
    279       this.codeList.Location = new System.Drawing.Point(7, 19);
    280       this.codeList.Name = "codeList";
    281       this.codeList.SelectionMode = System.Windows.Forms.SelectionMode.None;
    282       this.codeList.Size = new System.Drawing.Size(251, 563);
    283       this.codeList.TabIndex = 1;
    284       //
    285       // nameGroupBox
    286       //
    287       this.nameGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    288             | System.Windows.Forms.AnchorStyles.Left)
    289             | System.Windows.Forms.AnchorStyles.Right)));
    290       this.nameGroupBox.Controls.Add(this.nameList);
    291       this.nameGroupBox.Location = new System.Drawing.Point(543, 3);
    292       this.nameGroupBox.Name = "nameGroupBox";
    293       this.nameGroupBox.Size = new System.Drawing.Size(119, 595);
    294       this.nameGroupBox.TabIndex = 5;
    295       this.nameGroupBox.TabStop = false;
    296       this.nameGroupBox.Text = "Name";
    297       //
    298       // nameList
    299       //
    300       this.nameList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    301             | System.Windows.Forms.AnchorStyles.Left)
    302             | System.Windows.Forms.AnchorStyles.Right)));
    303       this.nameList.FormattingEnabled = true;
    304       this.nameList.HorizontalScrollbar = true;
    305       this.nameList.Location = new System.Drawing.Point(6, 19);
    306       this.nameList.Name = "nameList";
    307       this.nameList.SelectionMode = System.Windows.Forms.SelectionMode.None;
    308       this.nameList.Size = new System.Drawing.Size(107, 563);
    309       this.nameList.TabIndex = 2;
    310       //
    311       // integerGroupBox
    312       //
    313       this.integerGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    314             | System.Windows.Forms.AnchorStyles.Left)
    315             | System.Windows.Forms.AnchorStyles.Right)));
    316       this.integerGroupBox.Controls.Add(this.integerList);
    317       this.integerGroupBox.Location = new System.Drawing.Point(668, 3);
    318       this.integerGroupBox.Name = "integerGroupBox";
    319       this.integerGroupBox.Size = new System.Drawing.Size(119, 595);
    320       this.integerGroupBox.TabIndex = 4;
    321       this.integerGroupBox.TabStop = false;
    322       this.integerGroupBox.Text = "Integer";
    323       //
    324       // integerList
    325       //
    326       this.integerList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    327             | System.Windows.Forms.AnchorStyles.Left)
    328             | System.Windows.Forms.AnchorStyles.Right)));
    329       this.integerList.FormattingEnabled = true;
    330       this.integerList.HorizontalScrollbar = true;
    331       this.integerList.Location = new System.Drawing.Point(6, 19);
    332       this.integerList.Name = "integerList";
    333       this.integerList.SelectionMode = System.Windows.Forms.SelectionMode.None;
    334       this.integerList.Size = new System.Drawing.Size(107, 563);
    335       this.integerList.TabIndex = 3;
    336       //
    337       // floatGroupBox
    338       //
    339       this.floatGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    340             | System.Windows.Forms.AnchorStyles.Left)
    341             | System.Windows.Forms.AnchorStyles.Right)));
    342       this.floatGroupBox.Controls.Add(this.groupBox2);
    343       this.floatGroupBox.Controls.Add(this.floatList);
    344       this.floatGroupBox.Location = new System.Drawing.Point(793, 3);
    345       this.floatGroupBox.Name = "floatGroupBox";
    346       this.floatGroupBox.Size = new System.Drawing.Size(119, 595);
    347       this.floatGroupBox.TabIndex = 5;
    348       this.floatGroupBox.TabStop = false;
    349       this.floatGroupBox.Text = "Float";
    350       //
    351       // groupBox2
    352       //
    353       this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    354             | System.Windows.Forms.AnchorStyles.Left)
    355             | System.Windows.Forms.AnchorStyles.Right)));
    356       this.groupBox2.Controls.Add(this.listBox2);
    357       this.groupBox2.Location = new System.Drawing.Point(1003, 3);
    358       this.groupBox2.Name = "groupBox2";
    359       this.groupBox2.Size = new System.Drawing.Size(253, 595);
    360       this.groupBox2.TabIndex = 6;
    361       this.groupBox2.TabStop = false;
    362       this.groupBox2.Text = "Float";
    363       //
    364       // listBox2
    365       //
    366       this.listBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    367             | System.Windows.Forms.AnchorStyles.Left)
    368             | System.Windows.Forms.AnchorStyles.Right)));
    369       this.listBox2.FormattingEnabled = true;
    370       this.listBox2.HorizontalScrollbar = true;
    371       this.listBox2.Location = new System.Drawing.Point(6, 19);
    372       this.listBox2.Name = "listBox2";
    373       this.listBox2.SelectionMode = System.Windows.Forms.SelectionMode.None;
    374       this.listBox2.Size = new System.Drawing.Size(107, 563);
    375       this.listBox2.TabIndex = 4;
    376       //
    377       // floatList
    378       //
    379       this.floatList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    380             | System.Windows.Forms.AnchorStyles.Left)
    381             | System.Windows.Forms.AnchorStyles.Right)));
    382       this.floatList.FormattingEnabled = true;
    383       this.floatList.HorizontalScrollbar = true;
    384       this.floatList.Location = new System.Drawing.Point(6, 19);
    385       this.floatList.Name = "floatList";
    386       this.floatList.SelectionMode = System.Windows.Forms.SelectionMode.None;
    387       this.floatList.Size = new System.Drawing.Size(107, 563);
    388       this.floatList.TabIndex = 4;
    389212      //
    390213      // execGroupBox
     
    393216            | System.Windows.Forms.AnchorStyles.Left)
    394217            | System.Windows.Forms.AnchorStyles.Right)));
     218      this.execGroupBox.AutoSize = true;
     219      this.execGroupBox.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
    395220      this.execGroupBox.Controls.Add(this.execList);
    396221      this.execGroupBox.Location = new System.Drawing.Point(3, 3);
    397222      this.execGroupBox.Name = "execGroupBox";
    398       this.execGroupBox.Size = new System.Drawing.Size(264, 595);
     223      this.execGroupBox.Size = new System.Drawing.Size(244, 557);
    399224      this.execGroupBox.TabIndex = 3;
    400225      this.execGroupBox.TabStop = false;
     
    403228      // execList
    404229      //
    405       this.execList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    406             | System.Windows.Forms.AnchorStyles.Left)
    407             | System.Windows.Forms.AnchorStyles.Right)));
     230      this.execList.Dock = System.Windows.Forms.DockStyle.Fill;
     231      this.execList.FormattingEnabled = true;
    408232      this.execList.Location = new System.Drawing.Point(3, 16);
    409233      this.execList.Name = "execList";
    410       this.execList.Size = new System.Drawing.Size(255, 571);
    411       this.execList.TabIndex = 1;
    412       this.execList.UseCompatibleStateImageBehavior = false;
    413       this.execList.View = System.Windows.Forms.View.List;
    414       this.execList.VirtualMode = true;
    415       //
    416       // booleanGroupBox
    417       //
    418       this.booleanGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    419             | System.Windows.Forms.AnchorStyles.Left)
    420             | System.Windows.Forms.AnchorStyles.Right)));
    421       this.booleanGroupBox.Controls.Add(this.groupBox4);
    422       this.booleanGroupBox.Controls.Add(this.booleanList);
    423       this.booleanGroupBox.Location = new System.Drawing.Point(918, 3);
    424       this.booleanGroupBox.Name = "booleanGroupBox";
    425       this.booleanGroupBox.Size = new System.Drawing.Size(119, 595);
    426       this.booleanGroupBox.TabIndex = 7;
    427       this.booleanGroupBox.TabStop = false;
    428       this.booleanGroupBox.Text = "Boolean";
    429       //
    430       // groupBox4
    431       //
    432       this.groupBox4.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    433             | System.Windows.Forms.AnchorStyles.Left)
    434             | System.Windows.Forms.AnchorStyles.Right)));
    435       this.groupBox4.Controls.Add(this.listBox3);
    436       this.groupBox4.Location = new System.Drawing.Point(1003, 3);
    437       this.groupBox4.Name = "groupBox4";
    438       this.groupBox4.Size = new System.Drawing.Size(253, 595);
    439       this.groupBox4.TabIndex = 6;
    440       this.groupBox4.TabStop = false;
    441       this.groupBox4.Text = "Float";
    442       //
    443       // listBox3
    444       //
    445       this.listBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    446             | System.Windows.Forms.AnchorStyles.Left)
    447             | System.Windows.Forms.AnchorStyles.Right)));
    448       this.listBox3.FormattingEnabled = true;
    449       this.listBox3.HorizontalScrollbar = true;
    450       this.listBox3.Location = new System.Drawing.Point(6, 19);
    451       this.listBox3.Name = "listBox3";
    452       this.listBox3.SelectionMode = System.Windows.Forms.SelectionMode.None;
    453       this.listBox3.Size = new System.Drawing.Size(107, 563);
    454       this.listBox3.TabIndex = 4;
    455       //
    456       // booleanList
    457       //
    458       this.booleanList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    459             | System.Windows.Forms.AnchorStyles.Left)
    460             | System.Windows.Forms.AnchorStyles.Right)));
    461       this.booleanList.FormattingEnabled = true;
    462       this.booleanList.HorizontalScrollbar = true;
    463       this.booleanList.Location = new System.Drawing.Point(6, 19);
    464       this.booleanList.Name = "booleanList";
    465       this.booleanList.SelectionMode = System.Windows.Forms.SelectionMode.None;
    466       this.booleanList.Size = new System.Drawing.Size(107, 563);
    467       this.booleanList.TabIndex = 4;
    468       //
    469       // stringGroupBox
    470       //
    471       this.stringGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    472             | System.Windows.Forms.AnchorStyles.Left)
    473             | System.Windows.Forms.AnchorStyles.Right)));
    474       this.stringGroupBox.Controls.Add(this.groupBox6);
    475       this.stringGroupBox.Controls.Add(this.stringList);
    476       this.stringGroupBox.Location = new System.Drawing.Point(1043, 3);
    477       this.stringGroupBox.Name = "stringGroupBox";
    478       this.stringGroupBox.Size = new System.Drawing.Size(120, 595);
    479       this.stringGroupBox.TabIndex = 8;
    480       this.stringGroupBox.TabStop = false;
    481       this.stringGroupBox.Text = "String";
    482       //
    483       // groupBox6
    484       //
    485       this.groupBox6.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    486             | System.Windows.Forms.AnchorStyles.Left)
    487             | System.Windows.Forms.AnchorStyles.Right)));
    488       this.groupBox6.Controls.Add(this.listBox5);
    489       this.groupBox6.Location = new System.Drawing.Point(1003, 3);
    490       this.groupBox6.Name = "groupBox6";
    491       this.groupBox6.Size = new System.Drawing.Size(254, 595);
    492       this.groupBox6.TabIndex = 6;
    493       this.groupBox6.TabStop = false;
    494       this.groupBox6.Text = "Float";
    495       //
    496       // listBox5
    497       //
    498       this.listBox5.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    499             | System.Windows.Forms.AnchorStyles.Left)
    500             | System.Windows.Forms.AnchorStyles.Right)));
    501       this.listBox5.FormattingEnabled = true;
    502       this.listBox5.HorizontalScrollbar = true;
    503       this.listBox5.Location = new System.Drawing.Point(6, 19);
    504       this.listBox5.Name = "listBox5";
    505       this.listBox5.SelectionMode = System.Windows.Forms.SelectionMode.None;
    506       this.listBox5.Size = new System.Drawing.Size(108, 563);
    507       this.listBox5.TabIndex = 4;
    508       //
    509       // stringList
    510       //
    511       this.stringList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    512             | System.Windows.Forms.AnchorStyles.Left)
    513             | System.Windows.Forms.AnchorStyles.Right)));
    514       this.stringList.FormattingEnabled = true;
    515       this.stringList.HorizontalScrollbar = true;
    516       this.stringList.Location = new System.Drawing.Point(6, 19);
    517       this.stringList.Name = "stringList";
    518       this.stringList.SelectionMode = System.Windows.Forms.SelectionMode.None;
    519       this.stringList.Size = new System.Drawing.Size(108, 563);
    520       this.stringList.TabIndex = 4;
    521       //
    522       // charGroupBox
    523       //
    524       this.charGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    525             | System.Windows.Forms.AnchorStyles.Left)
    526             | System.Windows.Forms.AnchorStyles.Right)));
    527       this.charGroupBox.Controls.Add(this.groupBox8);
    528       this.charGroupBox.Controls.Add(this.charList);
    529       this.charGroupBox.Location = new System.Drawing.Point(1169, 3);
    530       this.charGroupBox.Name = "charGroupBox";
    531       this.charGroupBox.Size = new System.Drawing.Size(119, 595);
    532       this.charGroupBox.TabIndex = 9;
    533       this.charGroupBox.TabStop = false;
    534       this.charGroupBox.Text = "Char";
    535       //
    536       // groupBox8
    537       //
    538       this.groupBox8.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    539             | System.Windows.Forms.AnchorStyles.Left)
    540             | System.Windows.Forms.AnchorStyles.Right)));
    541       this.groupBox8.Controls.Add(this.listBox7);
    542       this.groupBox8.Location = new System.Drawing.Point(1003, 3);
    543       this.groupBox8.Name = "groupBox8";
    544       this.groupBox8.Size = new System.Drawing.Size(253, 595);
    545       this.groupBox8.TabIndex = 6;
    546       this.groupBox8.TabStop = false;
    547       this.groupBox8.Text = "Float";
    548       //
    549       // listBox7
    550       //
    551       this.listBox7.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    552             | System.Windows.Forms.AnchorStyles.Left)
    553             | System.Windows.Forms.AnchorStyles.Right)));
    554       this.listBox7.FormattingEnabled = true;
    555       this.listBox7.HorizontalScrollbar = true;
    556       this.listBox7.Location = new System.Drawing.Point(6, 19);
    557       this.listBox7.Name = "listBox7";
    558       this.listBox7.SelectionMode = System.Windows.Forms.SelectionMode.None;
    559       this.listBox7.Size = new System.Drawing.Size(107, 563);
    560       this.listBox7.TabIndex = 4;
    561       //
    562       // charList
    563       //
    564       this.charList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    565             | System.Windows.Forms.AnchorStyles.Left)
    566             | System.Windows.Forms.AnchorStyles.Right)));
    567       this.charList.FormattingEnabled = true;
    568       this.charList.HorizontalScrollbar = true;
    569       this.charList.Location = new System.Drawing.Point(6, 19);
    570       this.charList.Name = "charList";
    571       this.charList.SelectionMode = System.Windows.Forms.SelectionMode.None;
    572       this.charList.Size = new System.Drawing.Size(107, 563);
    573       this.charList.TabIndex = 4;
     234      this.execList.Size = new System.Drawing.Size(238, 538);
     235      this.execList.TabIndex = 0;
    574236      //
    575237      // tabPage2
     
    579241      this.tabPage2.Name = "tabPage2";
    580242      this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
    581       this.tabPage2.Size = new System.Drawing.Size(1261, 672);
     243      this.tabPage2.Size = new System.Drawing.Size(974, 608);
    582244      this.tabPage2.TabIndex = 1;
    583245      this.tabPage2.Text = "Results";
     
    588250      this.resultsDataGrid.AllowUserToAddRows = false;
    589251      this.resultsDataGrid.AllowUserToDeleteRows = false;
    590       this.resultsDataGrid.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    591             | System.Windows.Forms.AnchorStyles.Left)
    592             | System.Windows.Forms.AnchorStyles.Right)));
    593252      this.resultsDataGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
     253      this.resultsDataGrid.Dock = System.Windows.Forms.DockStyle.Fill;
    594254      this.resultsDataGrid.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically;
    595       this.resultsDataGrid.Location = new System.Drawing.Point(7, 7);
     255      this.resultsDataGrid.Location = new System.Drawing.Point(3, 3);
    596256      this.resultsDataGrid.Name = "resultsDataGrid";
    597257      this.resultsDataGrid.ReadOnly = true;
    598       this.resultsDataGrid.Size = new System.Drawing.Size(1248, 659);
     258      this.resultsDataGrid.Size = new System.Drawing.Size(968, 602);
    599259      this.resultsDataGrid.TabIndex = 0;
    600260      //
     
    605265      this.Controls.Add(this.tabControl);
    606266      this.Name = "PushProgramDebuggerView";
    607       this.Size = new System.Drawing.Size(1278, 727);
     267      this.Size = new System.Drawing.Size(991, 697);
    608268      this.Controls.SetChildIndex(this.tabControl, 0);
    609269      this.Controls.SetChildIndex(this.nameLabel, 0);
     
    616276      ((System.ComponentModel.ISupportInitialize)(this.stepWidthBox)).EndInit();
    617277      this.debugTableLayout.ResumeLayout(false);
    618       this.codeGroupBox.ResumeLayout(false);
    619       this.nameGroupBox.ResumeLayout(false);
    620       this.integerGroupBox.ResumeLayout(false);
    621       this.floatGroupBox.ResumeLayout(false);
    622       this.groupBox2.ResumeLayout(false);
     278      this.debugTableLayout.PerformLayout();
    623279      this.execGroupBox.ResumeLayout(false);
    624       this.booleanGroupBox.ResumeLayout(false);
    625       this.groupBox4.ResumeLayout(false);
    626       this.stringGroupBox.ResumeLayout(false);
    627       this.groupBox6.ResumeLayout(false);
    628       this.charGroupBox.ResumeLayout(false);
    629       this.groupBox8.ResumeLayout(false);
    630280      this.tabPage2.ResumeLayout(false);
    631281      ((System.ComponentModel.ISupportInitialize)(this.resultsDataGrid)).EndInit();
     
    646296    private System.Windows.Forms.ComboBox exampleComboBox;
    647297    private System.Windows.Forms.Label label1;
    648     private System.Windows.Forms.TableLayoutPanel debugTableLayout;
    649     private System.Windows.Forms.GroupBox codeGroupBox;
    650     private System.Windows.Forms.ListBox codeList;
    651     private System.Windows.Forms.GroupBox nameGroupBox;
    652     private System.Windows.Forms.ListBox nameList;
    653     private System.Windows.Forms.GroupBox integerGroupBox;
    654     private System.Windows.Forms.ListBox integerList;
    655     private System.Windows.Forms.GroupBox floatGroupBox;
    656     private System.Windows.Forms.ListBox floatList;
    657     private System.Windows.Forms.GroupBox execGroupBox;
    658     private System.Windows.Forms.ListView execList;
    659298    private System.Windows.Forms.TabPage tabPage2;
    660299    private System.Windows.Forms.DataGridView resultsDataGrid;
    661300    private System.Windows.Forms.Button simplifyButton;
    662     private System.Windows.Forms.GroupBox stringGroupBox;
    663     private System.Windows.Forms.GroupBox groupBox6;
    664     private System.Windows.Forms.ListBox listBox5;
    665     private System.Windows.Forms.ListBox stringList;
    666     private System.Windows.Forms.GroupBox booleanGroupBox;
    667     private System.Windows.Forms.GroupBox groupBox4;
    668     private System.Windows.Forms.ListBox listBox3;
    669     private System.Windows.Forms.ListBox booleanList;
    670     private System.Windows.Forms.GroupBox groupBox2;
    671     private System.Windows.Forms.ListBox listBox2;
    672     private System.Windows.Forms.GroupBox charGroupBox;
    673     private System.Windows.Forms.GroupBox groupBox8;
    674     private System.Windows.Forms.ListBox listBox7;
    675     private System.Windows.Forms.ListBox charList;
     301    private System.Windows.Forms.GroupBox execGroupBox;
     302    private System.Windows.Forms.TableLayoutPanel debugTableLayout;
     303    private System.Windows.Forms.ListBox execList;
    676304  }
    677305}
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/PushProgramDebuggerView.cs

    r14777 r14834  
    66namespace HeuristicLab.Problems.ProgramSynthesis.Push.Views {
    77  using System;
     8  using System.Collections.Generic;
     9  using System.Drawing;
     10  using System.Globalization;
    811  using System.Linq;
    912
     
    1114  using HeuristicLab.BenchmarkSuite.Problems;
    1215  using HeuristicLab.BenchmarkSuite.Views;
     16  using HeuristicLab.Core;
     17  using HeuristicLab.Encodings.IntegerVectorEncoding;
     18  using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration;
    1319  using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
    1420  using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
    1521  using HeuristicLab.Problems.ProgramSynthesis.Push.Problem;
    1622  using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
    17   using HeuristicLab.Random;
    1823
    1924  [View("Push Program Debugger")]
    2025  [Content(typeof(PushSolution), true)]
    2126  public partial class PushProgramDebuggerView : NamedItemView {
     27    private readonly IDictionary<StackTypes, ListBox> debugControlDict = new Dictionary<StackTypes, ListBox>();
     28
    2229    private const string Separator = ", ";
    2330    private const string EmptySign = "-";
     31
     32    private const string exampleSplitter = " => ";
     33    private const string AbsoluteDiffHeaderText = "Absolute Diff.";
     34    private const string RelativeDiffHeaderText = "Relative Diff.";
     35    private const string InputHeaderStringFormat = "Input {0} : {1}";
     36    private const string EstimatedOuputHeaderStringFormat = "Estimated Output {0} : {1}";
     37    private const string OutputHeaderStringFormat = "Output {0} : {1}";
     38    private const string GroupBoxTextStringFormat = "{0}[{1}]";
     39
    2440    private PushProgram program;
    25 
    26     private ListViewItem[] execListCache; //array to cache items for the virtual list
    27     private int firstExecListItemIndex; //stores the index of the first item in the cache
    28 
    29     private const string exampleSplitter = " => ";
    30     private PushInterpreter interpreter;
     41    private PooledPushInterpreter interpreter;
     42    private PooledPushInterpreter interpreter2; // used to determine noops
     43    private PushInterpreterPool pool;
    3144
    3245    public PushProgramDebuggerView() {
     
    3649
    3750      InitEvents();
    38       InitExecList();
     51    }
     52
     53    ~PushProgramDebuggerView() {
     54      interpreter.Dispose();
     55      interpreter2.Dispose();
    3956    }
    4057
     
    4865
    4966    private void SimplifyButtonClick(object sender, EventArgs e) {
    50 
    51     }
    52 
    53     private void InitExecList() {
    54       execList.RetrieveVirtualItem += ExecListRetrieveVirtualItem;
    55       execList.CacheVirtualItems += ExecListCacheVirtualItems;
    56 
    57       execList.View = View.Details;
    58       execList.HeaderStyle = ColumnHeaderStyle.None;
    59       execList.AutoResizeColumns(ColumnHeaderAutoResizeStyle.None);
    60       execList.Columns.Add(new ColumnHeader { Width = execList.Width - 40 });
    61       execList.VirtualMode = true;
    62       execList.VirtualListSize = 100;
    63     }
    64 
    65     private void ExecListCacheVirtualItems(object sender, CacheVirtualItemsEventArgs e) {
    66       //We've gotten a request to refresh the cache.
    67       //First check if it's really neccesary.
    68       if (execListCache != null &&
    69         e.StartIndex >= firstExecListItemIndex &&
    70         e.EndIndex <= firstExecListItemIndex + execListCache.Length) {
    71         //If the newly requested cache is a subset of the old cache,
    72         //no need to rebuild everything, so do nothing.
    73         return;
    74       }
    75 
    76       //Now we need to rebuild the cache.
    77       UpdateListCache(e.StartIndex, e.EndIndex);
    78     }
    79 
    80     private void ExecListRetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e) {
    81       //check to see if the requested item is currently in the cache
    82       if (execListCache == null ||
    83         e.ItemIndex < firstExecListItemIndex ||
    84         e.ItemIndex >= firstExecListItemIndex + execListCache.Length) {
    85         UpdateListCache(e.ItemIndex, execList.VirtualListSize);
    86       }
    87 
    88       e.Item = e.ItemIndex >= firstExecListItemIndex && e.ItemIndex < firstExecListItemIndex + execListCache.Length
    89           ? execListCache[e.ItemIndex - firstExecListItemIndex]
    90           : e.Item = new ListViewItem();
    91     }
    92 
    93     private void UpdateListCache(int startIndex, int endIndex) {
    94       if (interpreter == null) {
    95         execListCache = new ListViewItem[0];
    96         return;
    97       }
    98 
    99       this.firstExecListItemIndex = startIndex;
    100       var length = Math.Min(endIndex - startIndex + 1, interpreter.ExecStack.Count); //indexes are inclusive
    101       this.execListCache = new ListViewItem[length];
    102 
    103       var expressions = this.interpreter.ExecStack.Peek(length);
    104 
    105       //Fill the cache with the appropriate ListViewItems.
    106       for (var i = 0; i < length; i++)
    107         this.execListCache[i] = new ListViewItem(expressions[length - 1 - i].ToString());
    108 
    109       execList.AutoResizeColumns(ColumnHeaderAutoResizeStyle.None);
    110       execList.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
    111     }
    112 
    113     //protected override void OnEnabledChanged(EventArgs e) {
    114     //  SetReadonlyFields();
    115     //}
    116 
    117     //protected override void OnReadOnlyChanged() {
    118     //  base.OnReadOnlyChanged();
    119 
    120     //  SetReadonlyFields();
    121     //}
    122 
    123     //protected override void SetEnabledStateOfControls()
    124     //{
    125     //  SetReadonlyFields();
    126     //}
    127 
    128     private void SetReadonlyFields() {
    129       var enabled = !ReadOnly;
    130 
    131       exampleComboBox.Enabled = enabled;
    132       execList.Enabled = enabled;
    133       codeList.Enabled = enabled;
    134       nameList.Enabled = enabled;
    135       integerList.Enabled = enabled;
    136       floatList.Enabled = enabled;
    137       booleanList.Enabled = enabled;
    138       stringList.Enabled = enabled;
    139       charList.Enabled = enabled;
    140       stepButton.Enabled = enabled;
    141       runButton.Enabled = enabled;
    142       resetButton.Enabled = enabled;
    143       skipNoopsCheckBox.Enabled = enabled;
    144       stepWidthBox.Enabled = enabled;
     67      var newContent = new PushSolution(
     68                         (IntegerVector)Content.IntegerVector.Clone(),
     69                         Content.Quality,
     70                         (Data)Content.Data.Clone(),
     71                         (IRandom)Content.Random.Clone(),
     72                         Content.Config,
     73                         Content.DataStart,
     74                         Content.DataEnd,
     75                         true);
     76
     77      MainFormManager.MainForm.ShowContent(newContent, GetType());
    14578    }
    14679
     
    15689    }
    15790
    158     private void SyncExecList() {
    159       UpdateExecList();
    160 
    161       this.execGroupBox.Text = string.Format("Exec [{0}]", this.interpreter.ExecStack.Count);
    162     }
    163 
    16491    private void StepButtonClick(object sender, EventArgs e) {
    16592      if (interpreter == null || stepWidthBox.Value <= 0)
     
    16895      var count = Math.Min(stepWidthBox.Value, interpreter.ExecStack.Count);
    16996
     97      if (!interpreter.CanStep)
     98        return;
     99
     100      // skip leading noops
     101      if (interpreter2.ExecCounter == (program.IsProgram ? 1 : 0) &&
     102          skipNoopsCheckBox.Checked &&
     103          SkipNoops()) {
     104        count = 0; // no entries left, cause all were noops
     105      }
     106
    170107      for (var i = 0; i < count; i++) {
    171108        if (skipNoopsCheckBox.Checked) {
    172           bool noop;
    173 
    174           do {
    175             noop = !interpreter.Step();
    176           }
    177           while (interpreter.CanStep && noop);
    178         } else interpreter.Step();
    179       }
    180 
    181       stepWidthBox.Maximum = interpreter.ExecStack.Count;
    182 
    183       SyncExecList();
     109          interpreter.Step();
     110
     111          if (SkipNoops())
     112            break;
     113        } else {
     114          interpreter.Step();
     115          interpreter2.Step();
     116        }
     117      }
     118
     119      stepWidthBox.Maximum = Math.Max(1, interpreter.ExecStack.Count);
     120
     121      UpdateExecList();
    184122      UpdateValueLists();
    185123      CheckIfButtonsCanBeEnabled();
    186124    }
    187125
     126    private bool SkipNoops() {
     127      var skipCount = 0;
     128      bool isNoop;
     129
     130      do {
     131        skipCount++;
     132        isNoop = !interpreter2.Step();
     133      } while (interpreter2.CanStep && isNoop);
     134
     135      if (isNoop) {
     136        interpreter.Step(skipCount);
     137      } else if (skipCount > 1) {
     138        interpreter.Step(skipCount - 1);
     139      }
     140
     141      return isNoop;
     142    }
     143
    188144    private void CheckIfButtonsCanBeEnabled() {
    189       if (interpreter == null)
    190         return;
    191 
    192       runButton.Enabled = interpreter.CanStep;
    193       stepButton.Enabled = interpreter.CanStep;
    194       stepWidthBox.Enabled = interpreter.CanStep;
    195     }
    196 
    197     private void ResetButtonClick(object sender, System.EventArgs e) {
    198       Reset();
    199     }
    200 
    201     private void SelectedExampleIndexChanged(object sender, System.EventArgs e) {
    202       Reset();
     145      runButton.Enabled = interpreter != null && interpreter.CanStep;
     146      stepButton.Enabled = interpreter != null && interpreter.CanStep;
     147      stepWidthBox.Enabled = interpreter != null && interpreter.CanStep;
     148    }
     149
     150    private void ResetButtonClick(object sender, EventArgs e) {
     151      this.ResetDebugging();
     152    }
     153
     154    private void SelectedExampleIndexChanged(object sender, EventArgs e) {
     155      this.ResetDebugging();
    203156    }
    204157
     
    212165    }
    213166
    214     private void Reset() {
     167    private void ResetDebugging() {
    215168      if (Content == null ||
    216         interpreter == null ||
    217         this.exampleComboBox.SelectedIndex < 0)
     169          pool == null ||
     170          program == null ||
     171          exampleComboBox.SelectedIndex < 0)
    218172        return;
    219173
    220       interpreter.Clear();
    221 
    222       var example = Content.Data.Examples[this.exampleComboBox.SelectedIndex];
     174      var example = Content.Data.Examples[exampleComboBox.SelectedIndex];
     175
     176      if (interpreter != null) {
     177        interpreter.Reset();
     178        interpreter2.Reset();
     179      }
    223180
    224181      interpreter.BooleanStack.Push(example.InputBoolean);
     
    226183      interpreter.FloatStack.Push(example.InputFloat);
    227184
     185      interpreter2.BooleanStack.Push(example.InputBoolean);
     186      interpreter2.IntegerStack.Push(example.InputInt);
     187      interpreter2.FloatStack.Push(example.InputFloat);
     188
    228189      interpreter.Run(program, true);
     190      interpreter2.Run(program, true);
     191
    229192      stepWidthBox.Maximum = interpreter.ExecStack.Count;
    230193
     
    237200      if (Content == null) return;
    238201
    239       this.nameTextBox.Text = "Push Solution";
    240 
    241       var random = Content.Random ?? new FastRandom();
    242       interpreter = new PushInterpreter(Content.Config, random);
    243       program = Content.IntegerVector.MapToPushProgram(Content.Config.EnabledExpressions);
     202      Name = "Push Solution";
     203      nameTextBox.Text = Name;
     204
     205      pool = new PushInterpreterPool(Content.Config);
     206      program = Content.IntegerVector.ToPushProgram(Content.Config);
     207
     208      if (interpreter != null) {
     209        interpreter.Dispose();
     210        interpreter2.Dispose();
     211      }
     212
     213      interpreter = pool.Create(Content.Random);
     214      interpreter2 = pool.Create(Content.Random);
     215
     216      if (Content.Simplify)
     217        program = Simplifier.Simplifier.Simplify(program, p => PushEvaluator.Evaluate(p, pool, Content.Random, Content.Data, Content.DataStart, Content.DataEnd).TotalQuality);
    244218
    245219      UpdateExamples(Content.Data);
     220
     221      if (exampleComboBox.SelectedIndex < 0) {
     222        exampleComboBox.SelectedIndex = 0; // Triggers ResetDebugging via event
     223      } else {
     224        ResetDebugging();
     225      }
     226
     227      InitDebugLists(Content.Config);
    246228      InitResultGrid();
    247 
    248       if (this.exampleComboBox.SelectedIndex < 0) {
    249         this.exampleComboBox.SelectedIndex = 0; // Triggers Reset via event
    250       } else {
    251         Reset();
    252       }
     229      ClearLists();
     230      UpdateExecList();
     231      UpdateValueLists();
    253232    }
    254233
    255234    private void InitResultGrid() {
     235      resultsDataGrid.Columns.Clear();
     236      resultsDataGrid.Rows.Clear();
     237
    256238      var cellTemplate = new DataGridViewTextBoxCell();
    257239
     
    259241        var headerTypeName = ViewHelper.GetHeaderTypeName(Content.Data.InputArgumentTypes[i]);
    260242        var column = new DataGridViewColumn {
    261           HeaderText = string.Format("Input {0} : {1}", i + 1, headerTypeName),
     243          HeaderText = string.Format(InputHeaderStringFormat, i + 1, headerTypeName),
    262244          AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill,
    263245          CellTemplate = cellTemplate
    264246        };
    265247
     248        column.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
    266249        resultsDataGrid.Columns.Add(column);
    267250      }
     
    271254
    272255        var estimatedOutputColumn = new DataGridViewColumn {
    273           HeaderText = string.Format("Estimated Output {0} : {1}", i + 1, headerTypeName),
     256          HeaderText = string.Format(EstimatedOuputHeaderStringFormat, i + 1, headerTypeName),
     257          AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill,
     258          CellTemplate = cellTemplate,
     259        };
     260
     261        var outputColumn = new DataGridViewColumn {
     262          HeaderText = string.Format(OutputHeaderStringFormat, i + 1, headerTypeName),
    274263          AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill,
    275264          CellTemplate = cellTemplate
    276265        };
    277266
    278         var outputColumn = new DataGridViewColumn {
    279           HeaderText = string.Format("Output {0} : {1}", i + 1, headerTypeName),
    280           AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill,
    281           CellTemplate = cellTemplate
    282         };
     267        estimatedOutputColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
     268        outputColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
    283269
    284270        resultsDataGrid.Columns.Add(estimatedOutputColumn);
     
    286272      }
    287273
    288       resultsDataGrid.Columns.Add(
    289         new DataGridViewColumn {
    290           HeaderText = "Absolute Diff.",
    291           AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader,
    292           CellTemplate = cellTemplate
    293         });
    294 
    295       resultsDataGrid.Columns.Add(
    296         new DataGridViewColumn {
    297           HeaderText = "Relative Diff.",
    298           AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader,
    299           CellTemplate = cellTemplate,
    300         });
    301 
    302       var pool = new PushInterpreterPool(Content.Config);
    303       var program = Content.IntegerVector.MapToPushProgram(Content.Config.EnabledExpressions);
     274      var absoluteDiffColumn = new DataGridViewColumn {
     275        HeaderText = AbsoluteDiffHeaderText,
     276        AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader,
     277        CellTemplate = cellTemplate
     278      };
     279
     280      var relativeDiffColumn = new DataGridViewColumn {
     281        HeaderText = RelativeDiffHeaderText,
     282        AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader,
     283        CellTemplate = cellTemplate,
     284      };
     285
     286      absoluteDiffColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
     287      relativeDiffColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
     288
     289      resultsDataGrid.Columns.Add(absoluteDiffColumn);
     290      resultsDataGrid.Columns.Add(relativeDiffColumn);
    304291
    305292      using (var pushInterpreter = pool.Create(Content.Random)) {
     
    325312
    326313          this.resultsDataGrid.Rows.Add(row);
    327           pushInterpreter.Clear();
     314          pushInterpreter.Reset();
    328315        }
    329316      }
     
    336323
    337324        case ExampleArgumentType.Float:
    338         case ExampleArgumentType.FloatCollection: return interpreter.FloatStack.IsEmpty ? EmptySign : string.Join(valueSeparator, interpreter.FloatStack.Peek(GetCount(interpreter.FloatStack, example.OutputFloat)));
     325        case ExampleArgumentType.FloatCollection: return interpreter.FloatStack.IsEmpty ? EmptySign : string.Join(valueSeparator, interpreter.FloatStack.Peek(GetCount(interpreter.FloatStack, example.OutputFloat)).Select(d => d.ToString(CultureInfo.CurrentUICulture)));
    339326
    340327        case ExampleArgumentType.Bool: return interpreter.BooleanStack.IsEmpty ? EmptySign : interpreter.BooleanStack.Top.ToString();
     
    347334    }
    348335
    349     private int GetCount<T>(IStack<T> stack, T[] data) {
     336    private int GetCount<T>(IPushStack<T> stack, T[] data) {
    350337      return Math.Max(0, Math.Min(data.Length, stack.Count));
    351338    }
    352339
    353340    private void ClearLists() {
    354       codeList.Items.Clear();
    355       nameList.Items.Clear();
    356       booleanList.Items.Clear();
    357       integerList.Items.Clear();
    358       floatList.Items.Clear();
     341      foreach (var list in debugControlDict.Values) {
     342        list.Items.Clear();
     343      }
    359344    }
    360345
    361346    private void UpdateExecList() {
    362       UpdateListCache(0, execList.VirtualListSize);
    363       execList.Update();
    364 
    365       this.execGroupBox.Text = string.Format("Exec [{0}]", this.execList.Items.Count);
    366     }
     347      execList.Items.Clear();
     348      var expressions = interpreter.ExecStack
     349        .Reverse()
     350        .Select(e => e.StringRepresentation)
     351        .ToArray();
     352
     353      execList.Items.AddRange(expressions);
     354      execGroupBox.Text = string.Format(GroupBoxTextStringFormat, Enum.GetName(typeof(StackTypes), StackTypes.Exec), interpreter.ExecStack.Count);
     355    }
     356
     357    private void InitDebugLists(IReadOnlyPushConfiguration config) {
     358      debugControlDict.Clear();
     359
     360      // 2 = ExecList + EmptyColumn which is required to fill empty space
     361      while (debugTableLayout.ColumnCount > 2) {
     362        debugTableLayout.Controls.RemoveAt(1);
     363        debugTableLayout.ColumnCount--;
     364      }
     365
     366      foreach (StackTypes stackType in Enum.GetValues(typeof(StackTypes))) {
     367        if (stackType != StackTypes.Exec &&
     368            ExpressionTable.GetExpressionsByStackTypes(stackType).Intersect(config.EnabledExpressions).Any()) {
     369          var list = GetDebugList(stackType);
     370          debugControlDict.Add(stackType, list);
     371        }
     372      }
     373    }
     374
     375    private ListBox GetDebugList(StackTypes type) {
     376      var groupBox = new GroupBox {
     377        Anchor = AnchorStyles.Bottom | AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top,
     378        AutoSize = true,
     379        AutoSizeMode = AutoSizeMode.GrowAndShrink,
     380        Text = Enum.GetName(typeof(StackTypes), type)
     381      };
     382
     383      var list = new ListBox {
     384        Dock = DockStyle.Fill,
     385        DrawMode = DrawMode.OwnerDrawFixed
     386      };
     387
     388      var stackEntryType = type.GetStackEntryType();
     389      if (stackEntryType == typeof(double) ||
     390          stackEntryType == typeof(long)) {
     391        list.DrawItem += (sender, e) => {
     392          if (e.Index <= -1) return;
     393          var item = list.Items[e.Index];
     394
     395          e.DrawBackground();
     396          e.DrawFocusRectangle();
     397
     398          var brush = new SolidBrush(e.ForeColor);
     399          var size = e.Graphics.MeasureString(item.ToString(), e.Font);
     400
     401          e.Graphics.DrawString(
     402            item.ToString(),
     403            e.Font,
     404            brush,
     405            e.Bounds.Right - size.Width,
     406            e.Bounds.Top + (e.Bounds.Height / 2 - size.Height / 2));
     407        };
     408      }
     409
     410      groupBox.Controls.Add(list);
     411
     412      var columnWidth = stackEntryType == typeof(Expression) ? 250 : 150;
     413
     414      debugTableLayout.ColumnCount++;
     415      debugTableLayout.ColumnStyles.Insert(1, new ColumnStyle(SizeType.Absolute, columnWidth));
     416      debugTableLayout.Controls.Add(groupBox);
     417      debugTableLayout.Controls.SetChildIndex(groupBox, 1);
     418
     419      return list;
     420    }
     421
    367422
    368423    private void UpdateValueLists() {
     
    372427        return;
    373428
    374       ManageStackType(interpreter.Configuration.IsCodeStackEnabled, codeList, codeGroupBox, interpreter.CodeStack, "Code");
    375       ManageStackType(interpreter.Configuration.IsIntegerStackEnabled, integerList, integerGroupBox, interpreter.IntegerStack, "Integer");
    376       ManageStackType(interpreter.Configuration.IsFloatStackEnabled, floatList, floatGroupBox, interpreter.FloatStack, "Float");
    377       ManageStackType(interpreter.Configuration.IsBooleanStackEnabled, booleanList, booleanGroupBox, interpreter.BooleanStack, "Boolean");
    378       ManageStackType(interpreter.Configuration.IsNameStackEnabled, nameList, nameGroupBox, interpreter.NameStack, "Name");
    379       ManageStackType(interpreter.Configuration.IsStringStackEnabled, stringList, stringGroupBox, interpreter.StringStack, "String");
    380       ManageStackType(interpreter.Configuration.IsCharStackEnabled, charList, charGroupBox, interpreter.CharStack, "Char");
    381     }
    382 
    383     private void ManageStackType<T>(bool enabled, ListBox listbox, GroupBox groupBox, IStack<T> stack, string name) {
    384       if (enabled) {
    385         listbox.Enabled = true;
    386 
    387         foreach (var item in stack.Reverse())
    388           listbox.Items.Add(item);
    389 
    390         groupBox.Text = string.Format("{0} [{1}]", name, listbox.Items.Count);
    391       } else {
    392         listbox.Enabled = false;
    393         groupBox.Text = string.Format("{0} - DISABLED", name);
     429      foreach (var pair in debugControlDict) {
     430        var stack = interpreter.GetStackEntriesByType<object>(pair.Key);
     431        var name = Enum.GetName(typeof(StackTypes), pair.Key);
     432
     433        pair.Value.Items.AddRange(stack.Reverse().ToArray());
     434        ((GroupBox)pair.Value.Parent).Text = string.Format(GroupBoxTextStringFormat, name, pair.Value.Items.Count);
    394435      }
    395436    }
    396437
    397438    private void UpdateExamples(Data data) {
     439      exampleComboBox.Items.Clear();
    398440      if (data == null) return;
    399441
     
    403445        string.Join(Separator, e.OutputArgs));
    404446
    405       exampleComboBox.Items.Clear();
    406447      foreach (var str in stringRepresentations) {
    407448        exampleComboBox.Items.Add(str);
Note: See TracChangeset for help on using the changeset viewer.